1
1
local utils = require " nvim-tree.utils"
2
- local log = require " nvim-tree.log "
2
+ local open_file = require " nvim-tree.actions.node.open-file "
3
3
4
4
local DEFAULT_KEYMAPS = require (" nvim-tree.keymap" ).DEFAULT_KEYMAPS
5
5
@@ -358,13 +358,23 @@ local function build_on_attach(call_list)
358
358
return nil
359
359
end
360
360
361
- M .on_attach_lua = " local Api = require('nvim-tree.api')\n\n local on_attach = function(bufnr)\n "
361
+ M .on_attach_lua = [[
362
+ local Api = require('nvim-tree.api')
363
+ local Lib = require('nvim-tree.lib')
364
+
365
+ local on_attach = function(bufnr)
366
+ ]]
367
+
362
368
for _ , el in pairs (call_list ) do
363
369
if el .action_cb then
364
- M .on_attach_lua = string.format (" %s -- TODO action_cb\n " , M .on_attach_lua )
370
+ M .on_attach_lua = string.format (
371
+ ' %s vim.keymap.set("n", "%s", function()\n local node = Lib.get_node_at_cursor()\n -- my code\n end, { buffer = bufnr, noremap = true, silent = true, nowait = true, desc = "my description" })\n ' ,
372
+ M .on_attach_lua ,
373
+ el .key
374
+ )
365
375
elseif el .keymap then
366
376
M .on_attach_lua = string.format (
367
- " %s vim.keymap.set('n', '%s', %s, { buffer = bufnr, noremap = true, silent = true, nowait = true, desc = '%s', })\n " ,
377
+ " %s vim.keymap.set('n', '%s', %s, { buffer = bufnr, noremap = true, silent = true, nowait = true, desc = '%s' })\n " ,
368
378
M .on_attach_lua ,
369
379
el .key ,
370
380
LEGACY_CALLBACKS [el .keymap .legacy_action ],
@@ -373,7 +383,6 @@ local function build_on_attach(call_list)
373
383
end
374
384
end
375
385
M .on_attach_lua = string.format (" %send\n " , M .on_attach_lua )
376
- log .raw (" dev" , " %s" , M .on_attach_lua )
377
386
378
387
return function (bufnr )
379
388
for _ , el in pairs (call_list ) do
@@ -401,7 +410,7 @@ function M.move_mappings_to_keymap(opts)
401
410
opts .view .mappings .custom_only = nil
402
411
end
403
412
if list then
404
- local keymap_by_action = utils .key_by (DEFAULT_KEYMAPS , " legacy_action" )
413
+ local keymap_by_legacy_action = utils .key_by (DEFAULT_KEYMAPS , " legacy_action" )
405
414
if not custom_only then
406
415
opts .remove_keymaps = {}
407
416
end
@@ -414,8 +423,8 @@ function M.move_mappings_to_keymap(opts)
414
423
if map .action ~= " " then
415
424
if map .action_cb then
416
425
action_cb = map .action_cb
417
- elseif keymap_by_action [map .action ] then
418
- keymap = keymap_by_action [map .action ]
426
+ elseif keymap_by_legacy_action [map .action ] then
427
+ keymap = keymap_by_legacy_action [map .action ]
419
428
end
420
429
end
421
430
@@ -437,6 +446,19 @@ function M.move_mappings_to_keymap(opts)
437
446
end
438
447
end
439
448
449
+ function M .generate_on_attach ()
450
+ if # M .on_attach_lua > 0 then
451
+ local name = " /tmp/my_on_attach.lua"
452
+ local file = io.open (name , " w" )
453
+ io.output (file )
454
+ io.write (M .on_attach_lua )
455
+ io.close (file )
456
+ open_file .fn (" edit" , name )
457
+ else
458
+ utils .notify .info " no custom mappings"
459
+ end
460
+ end
461
+
440
462
function M .migrate_legacy_options (opts )
441
463
-- g: options
442
464
local msg
0 commit comments