@@ -2,102 +2,139 @@ local M = {}
2
2
3
3
local debugprint = require (" debugprint" )
4
4
5
- local map_key = function (mode , lhs , opts )
6
- if lhs ~= nil then
5
+ local map_key = function (mode , lhs , buffer , opts )
6
+ if lhs ~= nil and vim . api . nvim_buf_get_option ( buffer , " modifiable " ) then
7
7
opts = vim .tbl_extend (" force" , { expr = true }, opts )
8
8
9
- vim .api .nvim_set_keymap ( mode , lhs , " " , opts )
9
+ vim .api .nvim_buf_set_keymap ( buffer , mode , lhs , " " , opts )
10
10
end
11
11
end
12
12
13
13
M .map_keys_and_commands = function (global_opts )
14
- map_key (" n" , global_opts .keymaps .normal .plain_below , {
15
- callback = function ()
16
- return debugprint .debugprint ({})
17
- end ,
18
- desc = " Plain debug below current line" ,
19
- })
20
-
21
- map_key (" n" , global_opts .keymaps .normal .plain_above , {
22
- callback = function ()
23
- return debugprint .debugprint ({ above = true })
24
- end ,
25
- desc = " Plain debug below current line" ,
26
- })
27
-
28
- map_key (" n" , global_opts .keymaps .normal .variable_below , {
29
- callback = function ()
30
- return debugprint .debugprint ({ variable = true })
31
- end ,
32
- desc = " Variable debug below current line" ,
33
- })
34
-
35
- map_key (" n" , global_opts .keymaps .normal .variable_above , {
36
- callback = function ()
37
- return debugprint .debugprint ({ above = true , variable = true })
38
- end ,
39
- desc = " Variable debug above current line" ,
40
- })
41
-
42
- map_key (" n" , global_opts .keymaps .normal .variable_below_alwaysprompt , {
43
- callback = function ()
44
- return debugprint .debugprint ({
45
- variable = true ,
46
- ignore_treesitter = true ,
14
+ vim .api .nvim_create_autocmd ({ " BufReadPost" , " BufNewFile" }, {
15
+ group = vim .api .nvim_create_augroup (
16
+ " debugprint_augroup" ,
17
+ { clear = true }
18
+ ),
19
+ callback = function (opts )
20
+ map_key (" n" , global_opts .keymaps .normal .plain_below , opts .buf , {
21
+ callback = function ()
22
+ return debugprint .debugprint ({})
23
+ end ,
24
+ desc = " Plain debug below current line" ,
47
25
})
48
- end ,
49
- desc = " Variable debug below current line (always prompt})" ,
50
- })
51
26
52
- map_key (" n" , global_opts .keymaps .normal .variable_above_alwaysprompt , {
53
- callback = function ()
54
- return debugprint .debugprint ({
55
- above = true ,
56
- variable = true ,
57
- ignore_treesitter = true ,
27
+ map_key (" n" , global_opts .keymaps .normal .plain_above , opts .buf , {
28
+ callback = function ()
29
+ return debugprint .debugprint ({ above = true })
30
+ end ,
31
+ desc = " Plain debug below current line" ,
58
32
})
59
- end ,
60
- desc = " Variable debug above current line (always prompt})" ,
61
- })
62
33
63
- map_key (" n" , global_opts .keymaps .normal .textobj_below , {
64
- callback = function ()
65
- return debugprint .debugprint ({ motion = true })
66
- end ,
67
- desc = " Text-obj-selected variable debug below current line" ,
68
- })
34
+ map_key (" n" , global_opts .keymaps .normal .variable_below , opts . buf , {
35
+ callback = function ()
36
+ return debugprint .debugprint ({ variable = true })
37
+ end ,
38
+ desc = " Variable debug below current line" ,
39
+ })
69
40
70
- map_key (" n" , global_opts .keymaps .normal .textobj_above , {
71
- callback = function ()
72
- return debugprint .debugprint ({ motion = true , above = true })
73
- end ,
74
- desc = " Text-obj-selected variable debug above current line" ,
75
- })
41
+ map_key (" n" , global_opts .keymaps .normal .variable_above , opts .buf , {
42
+ callback = function ()
43
+ return debugprint .debugprint ({
44
+ above = true ,
45
+ variable = true ,
46
+ })
47
+ end ,
48
+ desc = " Variable debug above current line" ,
49
+ })
76
50
77
- map_key (" n" , global_opts .keymaps .normal .delete_debug_prints , {
78
- callback = debugprint .deleteprints ,
79
- desc = " Delete all debugprint statements in the current buffer" ,
80
- expr = false ,
81
- })
51
+ map_key (
52
+ " n" ,
53
+ global_opts .keymaps .normal .variable_below_alwaysprompt ,
54
+ opts .buf ,
55
+ {
56
+ callback = function ()
57
+ return debugprint .debugprint ({
58
+ variable = true ,
59
+ ignore_treesitter = true ,
60
+ })
61
+ end ,
62
+ desc = " Variable debug below current line (always prompt})" ,
63
+ }
64
+ )
65
+
66
+ map_key (
67
+ " n" ,
68
+ global_opts .keymaps .normal .variable_above_alwaysprompt ,
69
+ opts .buf ,
70
+ {
71
+ callback = function ()
72
+ return debugprint .debugprint ({
73
+ above = true ,
74
+ variable = true ,
75
+ ignore_treesitter = true ,
76
+ })
77
+ end ,
78
+ desc = " Variable debug above current line (always prompt})" ,
79
+ }
80
+ )
81
+
82
+ map_key (" n" , global_opts .keymaps .normal .textobj_below , opts .buf , {
83
+ callback = function ()
84
+ return debugprint .debugprint ({ motion = true })
85
+ end ,
86
+ desc = " Text-obj-selected variable debug below current line" ,
87
+ })
82
88
83
- map_key (" n" , global_opts .keymaps .normal .toggle_comment_debug_prints , {
84
- callback = debugprint .toggle_comment_debugprints ,
85
- desc = " Comment/uncomment all debugprint statements in the current buffer" ,
86
- expr = false ,
87
- })
89
+ map_key (" n" , global_opts .keymaps .normal .textobj_above , opts .buf , {
90
+ callback = function ()
91
+ return debugprint .debugprint ({
92
+ motion = true ,
93
+ above = true ,
94
+ })
95
+ end ,
96
+ desc = " Text-obj-selected variable debug above current line" ,
97
+ })
88
98
89
- map_key (" x" , global_opts .keymaps .visual .variable_below , {
90
- callback = function ()
91
- return debugprint .debugprint ({ variable = true })
92
- end ,
93
- desc = " Variable debug below current line" ,
94
- })
99
+ map_key (
100
+ " n" ,
101
+ global_opts .keymaps .normal .delete_debug_prints ,
102
+ opts .buf ,
103
+ {
104
+ callback = debugprint .deleteprints ,
105
+ desc = " Delete all debugprint statements in the current buffer" ,
106
+ expr = false ,
107
+ }
108
+ )
109
+
110
+ map_key (
111
+ " n" ,
112
+ global_opts .keymaps .normal .toggle_comment_debug_prints ,
113
+ opts .buf ,
114
+ {
115
+ callback = debugprint .toggle_comment_debugprints ,
116
+ desc = " Comment/uncomment all debugprint statements in the current buffer" ,
117
+ expr = false ,
118
+ }
119
+ )
120
+
121
+ map_key (" x" , global_opts .keymaps .visual .variable_below , opts .buf , {
122
+ callback = function ()
123
+ return debugprint .debugprint ({ variable = true })
124
+ end ,
125
+ desc = " Variable debug below current line" ,
126
+ })
95
127
96
- map_key (" x" , global_opts .keymaps .visual .variable_above , {
97
- callback = function ()
98
- return debugprint .debugprint ({ above = true , variable = true })
128
+ map_key (" x" , global_opts .keymaps .visual .variable_above , opts .buf , {
129
+ callback = function ()
130
+ return debugprint .debugprint ({
131
+ above = true ,
132
+ variable = true ,
133
+ })
134
+ end ,
135
+ desc = " Variable debug above current line" ,
136
+ })
99
137
end ,
100
- desc = " Variable debug above current line" ,
101
138
})
102
139
103
140
if global_opts .commands .delete_debug_prints then
0 commit comments