Skip to content

Commit e9d0e54

Browse files
committedDec 9, 2024·
feat: add plain log templates and default keymaps
This is a useful log actions that should be supported by default
1 parent aad3aaf commit e9d0e54

File tree

3 files changed

+53
-17
lines changed

3 files changed

+53
-17
lines changed
 

Diff for: ‎README.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,21 @@ You will need to call `require("timber").setup()` to intialize the plugin. You c
113113
cpp = [[std::cout << "%log_target: " << %log_target << std::endl;]],
114114
java = [[System.out.println("%log_target: " + %log_target);]],
115115
},
116+
plain = {
117+
javascript = [[console.log("%insert_cursor")]],
118+
typescript = [[console.log("%insert_cursor")]],
119+
jsx = [[console.log("%insert_cursor")]],
120+
tsx = [[console.log("%insert_cursor")]],
121+
lua = [[print("%insert_cursor")]],
122+
ruby = [[puts("%insert_cursor")]],
123+
elixir = [[IO.puts(%insert_cursor)]],
124+
go = [[log.Printf("%insert_cursor")]],
125+
rust = [[println!("%insert_cursor");]],
126+
python = [[print("%insert_cursor")]],
127+
c = [[printf("%insert_cursor \n");]],
128+
cpp = [[std::cout << "%insert_cursor" << std::endl;]],
129+
java = [[System.out.println("%insert_cursor");]],
130+
},
116131
},
117132
batch_log_templates = {
118133
default = {
@@ -146,6 +161,8 @@ You will need to call `require("timber").setup()` to intialize the plugin. You c
146161
-- insert_log_below = false,
147162
insert_log_below = "glj",
148163
insert_log_above = "glk",
164+
insert_plain_log_below = "glo",
165+
insert_plain_log_above = "gl<S-o>",
149166
insert_batch_log = "glb",
150167
add_log_targets_to_batch = "gla",
151168
insert_log_below_operator = "g<S-l>j",
@@ -173,10 +190,12 @@ The default configuration comes with a set of default keymaps:
173190
| - | - | - |
174191
| insert_log_below | glj | Insert a log statement below the cursor |
175192
| insert_log_above | glk | Insert a log statement above the cursor |
193+
| insert_plain_log_below | glo | Insert a plain log statement below the cursor |
194+
| insert_plain_log_above | gl<S-o> | Insert a plain log statement above the cursor |
176195
| add_log_targets_to_batch | gla | Add a log target to the batch |
177196
| insert_batch_log | glb | Insert a batch log statement |
178197

179-
To insert plain log statements, time tracking log statements, etc, see [RECIPES](https://github.com/Goose97/timber.nvim/blob/main/doc/RECIPES.md#advanced-logging-use-cases) guide for keymap inspiration.
198+
To include context in log statements, insert time tracking log statements, etc, see [RECIPES](https://github.com/Goose97/timber.nvim/blob/main/doc/RECIPES.md#advanced-logging-use-cases) guide for keymap inspiration.
180199

181200
## Usage
182201

Diff for: ‎doc/RECIPES.md

-16
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,6 @@ end, {
2020

2121
</details>
2222

23-
### Plain log statements
24-
25-
<details>
26-
<summary>Show config</summary>
27-
28-
```lua
29-
vim.keymap.set("n", "glo", function()
30-
require("timber.actions").insert_log({ template = "plain", position = "below" })
31-
end, { desc = "[G]o [L]og: Insert a plain log statement below the current line" })
32-
33-
vim.keymap.set("n", "gl<S-o>", function()
34-
require("timber.actions").insert_log({ template = "plain", position = "above" })
35-
end, { desc = "[G]o [L]og: Insert a plain log statement above the current line" })
36-
```
37-
</details>
38-
3923
### Surround log statements
4024

4125
<details>

Diff for: ‎lua/timber/config.lua

+33
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,21 @@ local default_config = {
3737
cpp = [[std::cout << "%log_target: " << %log_target << std::endl;]],
3838
java = [[System.out.println("%log_target: " + %log_target);]],
3939
},
40+
plain = {
41+
javascript = [[console.log("%insert_cursor")]],
42+
typescript = [[console.log("%insert_cursor")]],
43+
jsx = [[console.log("%insert_cursor")]],
44+
tsx = [[console.log("%insert_cursor")]],
45+
lua = [[print("%insert_cursor")]],
46+
ruby = [[puts("%insert_cursor")]],
47+
elixir = [[IO.puts(%insert_cursor)]],
48+
go = [[log.Printf("%insert_cursor")]],
49+
rust = [[println!("%insert_cursor");]],
50+
python = [[print("%insert_cursor")]],
51+
c = [[printf("%insert_cursor \n");]],
52+
cpp = [[std::cout << "%insert_cursor" << std::endl;]],
53+
java = [[System.out.println("%insert_cursor");]],
54+
},
4055
},
4156
batch_log_templates = {
4257
default = {
@@ -64,6 +79,8 @@ local default_config = {
6479
keymaps = {
6580
insert_log_below = "glj",
6681
insert_log_above = "glk",
82+
insert_plain_log_below = "glo",
83+
insert_plain_log_above = "gl<S-o>",
6784
insert_batch_log = "glb",
6885
add_log_targets_to_batch = "gla",
6986
insert_log_below_operator = "g<S-l>j",
@@ -144,6 +161,20 @@ local function setup_keymaps()
144161
})
145162
end, { mode = { "n", "v" }, desc = "Insert log statement above" })
146163

164+
setup_keymap("insert_plain_log_below", function()
165+
require("timber.actions").insert_log({
166+
template = "plain",
167+
position = "below",
168+
})
169+
end, { mode = "n", desc = "Insert log plain statement below" })
170+
171+
setup_keymap("insert_plain_log_above", function()
172+
require("timber.actions").insert_log({
173+
template = "plain",
174+
position = "above",
175+
})
176+
end, { mode = "n", desc = "Insert log plain statement above" })
177+
147178
setup_keymap("insert_batch_log", function()
148179
require("timber.actions").insert_batch_log()
149180
end, { mode = "n" })
@@ -195,6 +226,8 @@ function M.reset_default_key_mappings()
195226

196227
reset_keymap("glj", { "n", "v" })
197228
reset_keymap("glk", { "n", "v" })
229+
reset_keymap("glo", { "n" })
230+
reset_keymap("gl<S-o>", { "n" })
198231
reset_keymap("gla", { "n", "v" })
199232
reset_keymap("glb", { "n", "v" })
200233
reset_keymap("g<S-l>j", { "n" })

0 commit comments

Comments
 (0)
Please sign in to comment.