@@ -233,107 +233,97 @@ M.deleteprints = function(opts)
233
233
end
234
234
end
235
235
236
- local map_key = function (mode , lhs , rhs , desc )
236
+ local map_key = function (mode , lhs , opts )
237
237
if lhs ~= nil then
238
- if type (rhs ) == " function" then
239
- vim .api .nvim_set_keymap (
240
- mode ,
241
- lhs ,
242
- " " ,
243
- { expr = true , desc = desc , callback = rhs }
244
- )
245
- else
246
- vim .api .nvim_set_keymap (mode , lhs , " " , {
247
- expr = true ,
248
- desc = desc ,
249
- callback = function ()
250
- return M .debugprint (rhs )
251
- end ,
252
- })
253
- end
238
+ opts = vim .tbl_extend (" force" , { expr = true }, opts )
239
+
240
+ vim .api .nvim_set_keymap (mode , lhs , " " , opts )
254
241
end
255
242
end
256
243
257
244
M .setup = function (opts )
258
245
global_opts =
259
246
require (" debugprint.options" ).get_and_validate_global_opts (opts )
260
247
261
- map_key (
262
- " n " ,
263
- global_opts . keymaps . normal . plain_below ,
264
- {} ,
265
- " Plain debug below current line"
266
- )
248
+ map_key (" n " , global_opts . keymaps . normal . plain_below , {
249
+ callback = function ()
250
+ return M . debugprint ({})
251
+ end ,
252
+ desc = " Plain debug below current line" ,
253
+ } )
267
254
268
- map_key (
269
- " n " ,
270
- global_opts . keymaps . normal . plain_above ,
271
- { above = true } ,
272
- " Plain debug below current line"
273
- )
255
+ map_key (" n " , global_opts . keymaps . normal . plain_above , {
256
+ callback = function ()
257
+ return M . debugprint ({ above = true })
258
+ end ,
259
+ desc = " Plain debug below current line" ,
260
+ } )
274
261
275
- map_key (
276
- " n " ,
277
- global_opts . keymaps . normal . variable_below ,
278
- { variable = true } ,
279
- " Variable debug below current line"
280
- )
262
+ map_key (" n " , global_opts . keymaps . normal . variable_below , {
263
+ callback = function ()
264
+ return M . debugprint ({ variable = true })
265
+ end ,
266
+ desc = " Variable debug below current line" ,
267
+ } )
281
268
282
- map_key (
283
- " n " ,
284
- global_opts . keymaps . normal . variable_above ,
285
- { above = true , variable = true } ,
286
- " Variable debug above current line"
287
- )
269
+ map_key (" n " , global_opts . keymaps . normal . variable_above , {
270
+ callback = function ()
271
+ return M . debugprint ({ above = true , variable = true })
272
+ end ,
273
+ desc = " Variable debug above current line" ,
274
+ } )
288
275
289
- map_key (
290
- " n " ,
291
- global_opts . keymaps . normal . variable_below_alwaysprompt ,
292
- { variable = true , ignore_treesitter = true } ,
293
- " Variable debug below current line (always prompt) "
294
- )
276
+ map_key (" n " , global_opts . keymaps . normal . variable_below_alwaysprompt , {
277
+ callback = function ()
278
+ return M . debugprint ({ variable = true , ignore_treesitter = true })
279
+ end ,
280
+ desc = " Variable debug below current line (always prompt}) " ,
281
+ } )
295
282
296
- map_key (
297
- " n" ,
298
- global_opts .keymaps .normal .variable_above_alwaysprompt ,
299
- { above = true , variable = true , ignore_treesitter = true },
300
- " Variable debug above current line (always prompt)"
301
- )
283
+ map_key (" n" , global_opts .keymaps .normal .variable_above_alwaysprompt , {
284
+ callback = function ()
285
+ return M .debugprint ({
286
+ above = true ,
287
+ variable = true ,
288
+ ignore_treesitter = true ,
289
+ })
290
+ end ,
291
+ desc = " Variable debug above current line (always prompt})" ,
292
+ })
302
293
303
- map_key (
304
- " n " ,
305
- global_opts . keymaps . normal . textobj_below ,
306
- { motion = true } ,
307
- " Text-obj-selected variable debug below current line"
308
- )
294
+ map_key (" n " , global_opts . keymaps . normal . textobj_below , {
295
+ callback = function ()
296
+ return M . debugprint ({ motion = true })
297
+ end ,
298
+ desc = " Text-obj-selected variable debug below current line" ,
299
+ } )
309
300
310
- map_key (
311
- " n " ,
312
- global_opts . keymaps . normal . textobj_above ,
313
- { motion = true , above = true } ,
314
- " Text-obj-selected variable debug above current line"
315
- )
301
+ map_key (" n " , global_opts . keymaps . normal . textobj_above , {
302
+ callback = function ()
303
+ return M . debugprint ({ motion = true , above = true })
304
+ end ,
305
+ desc = " Text-obj-selected variable debug above current line" ,
306
+ } )
316
307
317
- map_key (
318
- " n" ,
319
- global_opts .keymaps .normal .delete_debug_prints ,
320
- M .deleteprints ,
321
- " Delete all debugprint statements in the current buffer"
322
- )
308
+ map_key (" n" , global_opts .keymaps .normal .delete_debug_prints , {
309
+ callback = M .deleteprints ,
310
+ desc = " Delete all debugprint statements in the current buffer" ,
311
+ expr = false ,
312
+ })
323
313
324
- map_key (
325
- " x " ,
326
- global_opts . keymaps . visual . variable_below ,
327
- { variable = true } ,
328
- " Variable debug below current line"
329
- )
314
+ map_key (" x " , global_opts . keymaps . visual . variable_below , {
315
+ callback = function ()
316
+ return M . debugprint ({ variable = true })
317
+ end ,
318
+ desc = " Variable debug below current line" ,
319
+ } )
330
320
331
- map_key (
332
- " x " ,
333
- global_opts . keymaps . visual . variable_above ,
334
- { above = true , variable = true } ,
335
- " Variable debug above current line"
336
- )
321
+ map_key (" x " , global_opts . keymaps . visual . variable_above , {
322
+ callback = function ()
323
+ return M . debugprint ({ above = true , variable = true })
324
+ end ,
325
+ desc = " Variable debug above current line" ,
326
+ } )
337
327
338
328
if global_opts .commands .delete_debug_prints then
339
329
vim .api .nvim_create_user_command (
0 commit comments