Skip to content

Commit 88398b0

Browse files
committed
feat: Support notify_for_registers option
1 parent 22d5575 commit 88398b0

File tree

6 files changed

+51
-18
lines changed

6 files changed

+51
-18
lines changed

README.md

+9-8
Original file line numberDiff line numberDiff line change
@@ -189,14 +189,15 @@ they are used to convert sections to ROT-13, which most folks don't use.
189189

190190
`debugprint` supports the following options in its global `opts` object:
191191

192-
| Option | Default | Purpose |
193-
| ------------------- | ---------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
194-
| `move_to_debugline` | `false` | When adding a debug line, moves the cursor to that line |
195-
| `display_location` | `true` | Include the filename and linenumber of the line being debugged in the debug message |
196-
| `display_counter` | `true` | Include the increasing integer counter in the debug message. (If you want to customize this counter, or make it non-persistent, see instructions in the [showcase](SHOWCASE.md#restoring-non-persistent-display_counter-counter) for an example). |
197-
| `display_snippet` | `true` | Include a snippet of the line above/below in the debug message (plain debug lines only) for context |
198-
| `filetypes` | See ([the code](lua/debugprint/filetypes.lua)) | Custom filetypes - see [showcase](SHOWCASE.md) |
199-
| `print_tag` | `DEBUGPRINT` | The string inserted into each print statement, which can be used to uniquely identify statements inserted by `debugprint`. If you set this to `''` (the empty string), no print tag will be included, but this will disable the ability to delete or comment print statements via `debugprint` |
192+
| Option | Default | Purpose |
193+
| ---------------------- | ---------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
194+
| `move_to_debugline` | `false` | When adding a debug line, moves the cursor to that line |
195+
| `display_location` | `true` | Include the filename and linenumber of the line being debugged in the debug message |
196+
| `display_counter` | `true` | Include the increasing integer counter in the debug message. (If you want to customize this counter, or make it non-persistent, see instructions in the [showcase](SHOWCASE.md#restoring-non-persistent-display_counter-counter) for an example). |
197+
| `display_snippet` | `true` | Include a snippet of the line above/below in the debug message (plain debug lines only) for context |
198+
| `notify_for_registers` | `true` | If set to false, disables the notifications that occur when debugprint lines are inserted or appended to registers |
199+
| `filetypes` | See ([the code](lua/debugprint/filetypes.lua)) | Custom filetypes - see [showcase](SHOWCASE.md) |
200+
| `print_tag` | `DEBUGPRINT` | The string inserted into each print statement, which can be used to uniquely identify statements inserted by `debugprint`. If you set this to `''` (the empty string), no print tag will be included, but this will disable the ability to delete or comment print statements via `debugprint` |
200201

201202
## Known Limitations
202203

SHOWCASE.md

+2
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,5 @@ bar = 456
192192
print('DEBUGPRINT[1]: filename.lua:1: foo=' .. vim.inspect(foo))
193193
print('DEBUGPRINT[2]: filename.lua:2: bar=' .. vim.inspect(bar))
194194
```
195+
196+
The notifications that happen when you add content to a register can be disabled with the global [`notify_for_registers` option](README.md#other-options), should you wish.

lua/debugprint/init.lua

+16-10
Original file line numberDiff line numberDiff line change
@@ -196,18 +196,24 @@ end
196196
local add_to_register = function(opts, keys)
197197
utils_register.set_register(keys)
198198

199-
local content
199+
if global_opts.notify_for_registers then
200+
local content
200201

201-
if opts.variable_name then
202-
content = "variable debug line (" .. opts.variable_name .. ")"
203-
else
204-
content = "plain debug line"
205-
end
202+
if opts.variable_name then
203+
content = "variable debug line (" .. opts.variable_name .. ")"
204+
else
205+
content = "plain debug line"
206+
end
206207

207-
if utils_register.register_append() then
208-
vim.notify("Appended " .. content .. " to register " .. opts.register)
209-
else
210-
vim.notify("Written " .. content .. " to register " .. opts.register)
208+
if utils_register.register_append() then
209+
vim.notify(
210+
"Appended " .. content .. " to register " .. opts.register
211+
)
212+
else
213+
vim.notify(
214+
"Written " .. content .. " to register " .. opts.register
215+
)
216+
end
211217
end
212218
end
213219

lua/debugprint/options.lua

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ local GLOBAL_OPTION_DEFAULTS = {
3333
display_location = true,
3434
display_snippet = true,
3535
move_to_debugline = false,
36+
notify_for_registers = true,
3637
filetypes = require("debugprint.filetypes"),
3738
print_tag = "DEBUGPRINT",
3839
}
@@ -49,6 +50,7 @@ local validate_global_opts = function(o)
4950
display_location = { o.display_location, "boolean" },
5051
display_snippet = { o.display_snippet, "boolean" },
5152
move_to_debugline = { o.move_to_debugline, "boolean" },
53+
notify_for_registers = { o.notify_for_registers, "boolean" },
5254
filetypes = { o.filetypes, "table" },
5355
print_tag = { o.print_tag, "string" },
5456
})

lua/debugprint/types.lua

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
---@field display_location? boolean
2020
---@field display_snippet? boolean
2121
---@field move_to_debugline? boolean
22+
---@field notify_for_registers? boolean
2223
---@field filetypes? DebugprintFileTypeConfig[]
2324
---@field print_tag? string
2425
---Deprecated

tests/debugprint.lua

+21
Original file line numberDiff line numberDiff line change
@@ -2690,6 +2690,27 @@ describe("register support", function()
26902690
})
26912691
end)
26922692

2693+
it("can capture one plain statement - no notification", function()
2694+
debugprint.setup({ notify_for_registers = false })
2695+
assert.equals(notify_message, nil)
2696+
2697+
local filename = init_file({
2698+
"foo",
2699+
"bar",
2700+
}, "lua", 1, 0)
2701+
2702+
feedkeys('"ag?p')
2703+
assert.equals(notify_message, nil)
2704+
feedkeys("j")
2705+
feedkeys('"ap')
2706+
2707+
check_lines({
2708+
"foo",
2709+
"bar",
2710+
"print('DEBUGPRINT[1]: " .. filename .. ":1 (after foo)')",
2711+
})
2712+
end)
2713+
26932714
it("can capture one plain statement above", function()
26942715
assert.equals(notify_message, nil)
26952716

0 commit comments

Comments
 (0)