Skip to content

Commit a8900d7

Browse files
author
Andrew Ferrier
committed
feat: Change all 'dq' keymappings to 'g?'
1 parent c5e875f commit a8900d7

File tree

3 files changed

+76
-40
lines changed

3 files changed

+76
-40
lines changed

README.md

+11-10
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,17 @@ following table.
9494

9595
| Keymap | Purpose | Equivalent Lua Function |
9696
| ------ | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- |
97-
| `dqp` | Insert a 'plain' debug line appropriate to the filetype just below the current line | `require('debugprint').debugprint()` |
98-
| `dqP` | The same, but above the current line | `require('debugprint').debugprint({above = true})` |
99-
| `dQP` | Insert a variable debugging line below the current line. If the cursor is on a variable name, use that, otherwise prompt for one. | `require('debugprint').debugprint({variable = true})` |
100-
| `dQP` | The same, but above the current line | `require('debugprint').debugprint({above = true, variable = true})` |
97+
| `g?p` | Insert a 'plain' debug line appropriate to the filetype just below the current line | `require('debugprint').debugprint()` |
98+
| `g?P` | The same, but above the current line | `require('debugprint').debugprint({above = true})` |
99+
| `g?v` | Insert a variable debugging line below the current line. If the cursor is on a variable name, use that, otherwise prompt for one. | `require('debugprint').debugprint({variable = true})` |
100+
| `g?V` | The same, but above the current line | `require('debugprint').debugprint({above = true, variable = true})` |
101101
| None by default | Always prompt for a variable name, and insert a debugging line just below the current line which outputs it | `require('debugprint').debugprint({ignore_treesitter = true, variable = true})` |
102102
| None by default | Always prompt for a variable name, and insert a debugging line just above the current line which outputs it | `require('debugprint').debugprint({ignore_treesitter = true, above = true, variable = true})` |
103103

104-
These keybindings are chosen not to conflict with any standard Vim keys (or any
105-
common plugins, at least that I'm aware of). You can disable them from being
106-
created by setting `create_keymaps`, and map them yourself if you prefer:
104+
These keybindings are chosen specifically because by default in NeoVim they are
105+
used to convert sections to ROT-13, which most folks don't use. You can disable
106+
them from being created by setting `create_keymaps`, and map them yourself to
107+
something else if you prefer:
107108

108109
```lua
109110
opts = {
@@ -202,8 +203,8 @@ The keys in the configuration are used like this:
202203

203204
| Type of debug line | Default keys | How debug line is constructed
204205
| - | - | - |
205-
| Plain debug line | `dqp`/`dqP` | `my_fileformat.left .. "auto-gen DEBUG string" .. my_fileformat.right` |
206-
| Variable debug line | `dQp`/`dQP` | `my_fileformat.left .. "auto-gen DEBUG string, variable=" .. my_file_format.mid_var .. variable .. my_fileformat.right_var` |
206+
| Plain debug line | `g?p`/`g?P` | `my_fileformat.left .. "auto-gen DEBUG string" .. my_fileformat.right` |
207+
| Variable debug line | `g?v`/`g?V` | `my_fileformat.left .. "auto-gen DEBUG string, variable=" .. my_file_format.mid_var .. variable .. my_fileformat.right_var` |
207208

208209
If it helps to understand these, you can look at the built-in configurations in
209210
[filetypes.lua](lua/debugprint/filetypes.lua).
@@ -220,7 +221,7 @@ If it helps to understand these, you can look at the built-in configurations in
220221
## Known Limitations
221222

222223
* `debugprint` only supports variable names or simple expressions when using
223-
`dQp`/`dQP` - in particular, it does not make any attempt to escape
224+
`g?v`/`g?V` - in particular, it does not make any attempt to escape
224225
expressions, and may generate invalid syntax if you try to be too clever.
225226
There's [an issue to look at ways of improving
226227
this](https://github.com/andrewferrier/debugprint.nvim/issues/20).

lua/debugprint/init.lua

+35
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@ local debugprint_cache = function(o)
169169
set_callback("v:lua.require'debugprint'.debugprint_callback")
170170
end
171171

172+
local notify_deprecated = function()
173+
vim.notify(
174+
"dqp and similar keymappings are deprecated for debugprint and are "
175+
.. "replaced with g?p, g?P, g?q, and g?Q. If you wish to continue "
176+
.. "using dqp etc., please see the Keymappings section in the README "
177+
.. "on how to map your own keymappings and map them explicitly. Thanks!",
178+
vim.log.levels.WARN
179+
)
180+
end
181+
172182
M.debugprint_callback = function()
173183
debugprint_cache()
174184
end
@@ -196,22 +206,47 @@ M.setup = function(o)
196206
})
197207

198208
if opts.create_keymaps then
209+
vim.keymap.set("n", "g?p", function()
210+
return M.debugprint()
211+
end, {
212+
expr = true,
213+
})
214+
vim.keymap.set("n", "g?P", function()
215+
return M.debugprint({ above = true })
216+
end, {
217+
expr = true,
218+
})
219+
vim.keymap.set("n", "g?v", function()
220+
return M.debugprint({ variable = true })
221+
end, {
222+
expr = true,
223+
})
224+
vim.keymap.set("n", "g?V", function()
225+
return M.debugprint({ above = true, variable = true })
226+
end, {
227+
expr = true,
228+
})
229+
199230
vim.keymap.set("n", "dqp", function()
231+
notify_deprecated()
200232
return M.debugprint()
201233
end, {
202234
expr = true,
203235
})
204236
vim.keymap.set("n", "dqP", function()
237+
notify_deprecated()
205238
return M.debugprint({ above = true })
206239
end, {
207240
expr = true,
208241
})
209242
vim.keymap.set("n", "dQp", function()
243+
notify_deprecated()
210244
return M.debugprint({ variable = true })
211245
end, {
212246
expr = true,
213247
})
214248
vim.keymap.set("n", "dQP", function()
249+
notify_deprecated()
215250
return M.debugprint({ above = true, variable = true })
216251
end, {
217252
expr = true,

tests/debugprint.lua

+30-30
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe("can do basic debug statement insertion", function()
4646

4747
local filename = write_file("lua")
4848
vim.api.nvim_win_set_cursor(0, { 1, 0 })
49-
feedkeys("dqp")
49+
feedkeys("g?p")
5050

5151
check_lines({
5252
"foo",
@@ -63,7 +63,7 @@ describe("can do basic debug statement insertion", function()
6363

6464
local filename = write_file("lua")
6565
vim.api.nvim_win_set_cursor(0, { 1, 0 })
66-
feedkeys("dqP")
66+
feedkeys("g?P")
6767

6868
check_lines({
6969
"print('DEBUG[1]: " .. filename .. ":1')",
@@ -80,8 +80,8 @@ describe("can do basic debug statement insertion", function()
8080

8181
local filename = write_file("lua")
8282
vim.api.nvim_win_set_cursor(0, { 1, 0 })
83-
feedkeys("dqP")
84-
feedkeys("dqP")
83+
feedkeys("g?P")
84+
feedkeys("g?P")
8585

8686
check_lines({
8787
"print('DEBUG[1]: " .. filename .. ":1')",
@@ -99,7 +99,7 @@ describe("can do basic debug statement insertion", function()
9999

100100
local filename = write_file("lua")
101101
vim.api.nvim_win_set_cursor(0, { 2, 0 })
102-
feedkeys("dqp")
102+
feedkeys("g?p")
103103

104104
check_lines({
105105
"foo",
@@ -122,7 +122,7 @@ describe("can do variable debug statement insertion", function()
122122

123123
local filename = write_file("lua")
124124
vim.api.nvim_win_set_cursor(0, { 1, 0 })
125-
feedkeys("dQpbanana<CR>")
125+
feedkeys("g?vbanana<CR>")
126126

127127
check_lines({
128128
"foo",
@@ -141,7 +141,7 @@ describe("can do variable debug statement insertion", function()
141141

142142
local filename = write_file("lua")
143143
vim.api.nvim_win_set_cursor(0, { 1, 0 })
144-
feedkeys("dQPbanana<CR>")
144+
feedkeys("g?Vbanana<CR>")
145145

146146
check_lines({
147147
"print('DEBUG[1]: "
@@ -166,7 +166,7 @@ describe("can do various file types", function()
166166

167167
local filename = write_file("vim")
168168
vim.api.nvim_win_set_cursor(0, { 1, 0 })
169-
feedkeys("dqp")
169+
feedkeys("g?p")
170170

171171
check_lines({
172172
"foo",
@@ -183,7 +183,7 @@ describe("can do various file types", function()
183183

184184
local filename = write_file("vim")
185185
vim.api.nvim_win_set_cursor(0, { 1, 0 })
186-
feedkeys("dQpbanana<CR>")
186+
feedkeys("g?vbanana<CR>")
187187

188188
check_lines({
189189
"foo",
@@ -200,7 +200,7 @@ describe("can do various file types", function()
200200

201201
write_file("foo")
202202
vim.api.nvim_win_set_cursor(0, { 1, 0 })
203-
feedkeys("dqp")
203+
feedkeys("g?p")
204204
assert.are.same(
205205
"Don't have debugprint configuration for filetype foo",
206206
notify_message
@@ -220,7 +220,7 @@ describe("can do various file types", function()
220220

221221
write_file("foo")
222222
vim.api.nvim_win_set_cursor(0, { 1, 0 })
223-
feedkeys("dQp")
223+
feedkeys("g?v")
224224
feedkeys("<CR>")
225225
assert.are.same(
226226
"Don't have debugprint configuration for filetype foo",
@@ -248,7 +248,7 @@ describe("can do indenting correctly", function()
248248
local filename = write_file("lua")
249249
vim.api.nvim_set_option_value("shiftwidth", 4, {})
250250
vim.api.nvim_win_set_cursor(0, { 1, 0 })
251-
feedkeys("dqp")
251+
feedkeys("g?p")
252252

253253
check_lines({
254254
"function()",
@@ -266,7 +266,7 @@ describe("can do indenting correctly", function()
266266
local filename = write_file("lua")
267267
vim.api.nvim_set_option_value("shiftwidth", 4, {})
268268
vim.api.nvim_win_set_cursor(0, { 2, 0 })
269-
feedkeys("dqP")
269+
feedkeys("g?P")
270270

271271
check_lines({
272272
"function()",
@@ -284,7 +284,7 @@ describe("can do indenting correctly", function()
284284
local filename = write_file("lua")
285285
vim.api.nvim_set_option_value("shiftwidth", 4, {})
286286
vim.api.nvim_win_set_cursor(0, { 1, 0 })
287-
feedkeys("dqP")
287+
feedkeys("g?P")
288288

289289
check_lines({
290290
"print('DEBUG[1]: " .. filename .. ":1')",
@@ -303,7 +303,7 @@ describe("can do indenting correctly", function()
303303
vim.api.nvim_set_option_value("expandtab", false, {})
304304
vim.api.nvim_set_option_value("shiftwidth", 8, {})
305305
vim.api.nvim_win_set_cursor(0, { 1, 0 })
306-
feedkeys("dqp")
306+
feedkeys("g?p")
307307

308308
check_lines({
309309
"function()",
@@ -339,7 +339,7 @@ describe("add custom filetype with setup()", function()
339339

340340
local filename = write_file("wibble")
341341
vim.api.nvim_win_set_cursor(0, { 1, 0 })
342-
feedkeys("dqp")
342+
feedkeys("g?p")
343343

344344
check_lines({
345345
"foo",
@@ -356,7 +356,7 @@ describe("add custom filetype with setup()", function()
356356

357357
local filename = write_file("wibble")
358358
vim.api.nvim_win_set_cursor(0, { 1, 0 })
359-
feedkeys("dQpapple<CR>")
359+
feedkeys("g?vapple<CR>")
360360

361361
check_lines({
362362
"foo",
@@ -390,7 +390,7 @@ describe("add custom filetype with add_custom_filetypes()", function()
390390
})
391391
local filename = write_file("foo")
392392
vim.api.nvim_win_set_cursor(0, { 1, 0 })
393-
feedkeys("dqp")
393+
feedkeys("g?p")
394394

395395
check_lines({
396396
"foo",
@@ -419,7 +419,7 @@ describe("move to new line", function()
419419

420420
local filename = write_file("lua")
421421
vim.api.nvim_win_set_cursor(0, { 1, 0 })
422-
feedkeys("dqp")
422+
feedkeys("g?p")
423423

424424
check_lines({
425425
"foo",
@@ -443,7 +443,7 @@ describe("move to new line", function()
443443

444444
local filename = write_file("lua")
445445
vim.api.nvim_win_set_cursor(0, { 1, 0 })
446-
feedkeys("dqP")
446+
feedkeys("g?P")
447447

448448
check_lines({
449449
"print('DEBUG[1]: " .. filename .. ":1')",
@@ -467,7 +467,7 @@ describe("move to new line", function()
467467

468468
local filename = write_file("lua")
469469
vim.api.nvim_win_set_cursor(0, { 1, 0 })
470-
feedkeys("dqp")
470+
feedkeys("g?p")
471471

472472
check_lines({
473473
"foo",
@@ -495,7 +495,7 @@ describe("can repeat", function()
495495

496496
local filename = write_file("lua")
497497
vim.api.nvim_win_set_cursor(0, { 1, 0 })
498-
feedkeys("dqp")
498+
feedkeys("g?p")
499499
feedkeys(".")
500500

501501
check_lines({
@@ -514,7 +514,7 @@ describe("can repeat", function()
514514

515515
local filename = write_file("lua")
516516
vim.api.nvim_win_set_cursor(0, { 1, 0 })
517-
feedkeys("dqP")
517+
feedkeys("g?P")
518518
feedkeys(".")
519519

520520
check_lines({
@@ -535,9 +535,9 @@ describe("can repeat", function()
535535

536536
local filename = write_file("lua")
537537
vim.api.nvim_win_set_cursor(0, { 1, 0 })
538-
feedkeys("dqP")
538+
feedkeys("g?P")
539539
feedkeys(".")
540-
feedkeys("jdqp")
540+
feedkeys("jg?p")
541541
feedkeys(".")
542542

543543
check_lines({
@@ -559,9 +559,9 @@ describe("can repeat", function()
559559

560560
local filename = write_file("lua")
561561
vim.api.nvim_win_set_cursor(0, { 1, 0 })
562-
feedkeys("dQpbanana<CR>")
562+
feedkeys("g?vbanana<CR>")
563563
feedkeys(".")
564-
feedkeys("dQPapple<CR>")
564+
feedkeys("g?Vapple<CR>")
565565
feedkeys(".")
566566

567567
check_lines({
@@ -597,7 +597,7 @@ describe("can repeat with move to line", function()
597597

598598
local filename = write_file("lua")
599599
vim.api.nvim_win_set_cursor(0, { 1, 0 })
600-
feedkeys("dqp")
600+
feedkeys("g?p")
601601
feedkeys(".")
602602

603603
check_lines({
@@ -623,7 +623,7 @@ describe("can handle treesitter identifiers", function()
623623

624624
local filename = write_file("lua")
625625
vim.api.nvim_win_set_cursor(0, { 2, 6 })
626-
feedkeys("dQp<CR>")
626+
feedkeys("g?v<CR>")
627627

628628
check_lines({
629629
"function x() {",
@@ -646,7 +646,7 @@ describe("can handle treesitter identifiers", function()
646646

647647
local filename = write_file("lua")
648648
vim.api.nvim_win_set_cursor(0, { 2, 6 })
649-
feedkeys("dQpapple<CR>")
649+
feedkeys("g?vapple<CR>")
650650

651651
check_lines({
652652
"function x() {",

0 commit comments

Comments
 (0)