@@ -8,6 +8,16 @@ local M = {
8
8
legacy_active = {},
9
9
}
10
10
11
+ local BEGIN_ON_ATTACH = [[
12
+ local api = require('nvim-tree.api')
13
+
14
+ local on_attach = function(bufnr)
15
+ ]]
16
+
17
+ local END_ON_ATTACH = [[
18
+ end
19
+ ]]
20
+
11
21
local DEFAULT_ON_ATTACH = [[
12
22
-- BEGIN_DEFAULT_ON_ATTACH
13
23
vim.keymap.set('n', '<C-]>', api.tree.change_root_to_node, { desc = 'CD', buffer = bufnr, noremap = true, silent = true, nowait = true })
@@ -169,15 +179,11 @@ local function generate_on_attach_function(list, unmapped_keys, remove_defaults)
169
179
end
170
180
171
181
local function generate_on_attach_lua (list , unmapped_keys , remove_defaults )
172
- local lua = [[
173
- local api = require('nvim-tree.api')
174
-
175
- local on_attach = function(bufnr)
176
- ]]
182
+ local lua = BEGIN_ON_ATTACH .. " \n "
177
183
178
184
if remove_defaults then
179
185
-- no defaults
180
- lua = lua .. " \n -- remove_keymaps = true\n "
186
+ lua = lua .. " \n -- remove_keymaps = true OR view.mappings.custom_only = true \n "
181
187
else
182
188
-- defaults with explicit removals
183
189
lua = lua .. DEFAULT_ON_ATTACH
@@ -216,12 +222,12 @@ local on_attach = function(bufnr)
216
222
[[ end, { desc = '%s', buffer = bufnr, noremap = true, silent = true, nowait = true })]] ,
217
223
m .action
218
224
)
219
- .. " \n "
225
+ .. " \n\n "
220
226
end
221
227
end
222
228
end
223
229
224
- return lua
230
+ return lua .. " \n " .. END_ON_ATTACH
225
231
end
226
232
227
233
local function generate_legacy_default_mappings ()
@@ -273,6 +279,8 @@ local function generate_legacy_active_mappings(list, defaults, unmapped_keys, re
273
279
end
274
280
275
281
function M .generate_legacy_on_attach (opts )
282
+ M .on_attach_lua = BEGIN_ON_ATTACH .. " \n " .. DEFAULT_ON_ATTACH .. " \n " .. END_ON_ATTACH
283
+
276
284
if type (opts .on_attach ) == " function" then
277
285
return
278
286
end
@@ -300,7 +308,6 @@ function M.generate_on_attach()
300
308
local name = " /tmp/my_on_attach.lua"
301
309
local file = io.output (name )
302
310
io.write (M .on_attach_lua )
303
- io.write " end"
304
311
io.close (file )
305
312
open_file .fn (" edit" , name )
306
313
end
0 commit comments