Skip to content

Commit 293395c

Browse files
tradiffcseickel
andauthored
docs: fix help tags for custom commands and mappings (#1061)
Co-authored-by: Chris Seickel <cseickel@gmail.com>
1 parent 9d7a757 commit 293395c

File tree

3 files changed

+97
-95
lines changed

3 files changed

+97
-95
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ use {
193193
},
194194
-- A list of functions, each representing a global custom command
195195
-- that will be available in all sources (if not overridden in `opts[source_name].commands`)
196-
-- see `:h neo-tree-global-custom-commands`
196+
-- see `:h neo-tree-custom-commands-global`
197197
commands = {},
198198
window = {
199199
position = "left",

doc/neo-tree.txt

Lines changed: 95 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ Mappings .................... |neo-tree-mappings|
99
View Changes .............. |neo-tree-view-changes|
1010
File Actions .............. |neo-tree-file-actions|
1111
Filter .................... |neo-tree-filter|
12-
Global custom commands .... |neo-tree-custom-commands-global|
12+
Custom Mappings ........... |neo-tree-custom-mappings|
13+
Custom Commands ........... |neo-tree-custom-commands|
1314
Configuration ............... |neo-tree-configuration|
1415
Setup ..................... |neo-tree-setup|
1516
Source Selector ........... |neo-tree-source-selector|
@@ -427,96 +428,7 @@ section in the default config instead of at the root level, that means it is
427428
specific to that source and will not work for others.
428429

429430

430-
CUSTOM COMMANDS *neo-tree-custom-commands*
431-
432-
If you want to define your own command, you have two options:
433-
1. You can define (or override) a command in the `commands` section of the
434-
config for each source, then reference that by name in a mapping.
435-
2. You can map directly to a function and skip defining a command.
436-
437-
You probably want #2:
438-
>lua
439-
require("neo-tree").setup({
440-
filesystem = {
441-
window = {
442-
mappings = {
443-
["?"] = function(state)
444-
local node = state.tree:get_node()
445-
print(node.name)
446-
end
447-
}
448-
}
449-
}
450-
})
451-
<
452-
..or
453-
>lua
454-
local print_me = function(state)
455-
local node = state.tree:get_node()
456-
print(node.name)
457-
end
458-
459-
require("neo-tree").setup({
460-
filesystem = {
461-
window = {
462-
mappings = {
463-
["?"] = print_me
464-
}
465-
}
466-
}
467-
})
468-
<
469-
...but if you want #1, here is how that works:
470-
471-
>lua
472-
require("neo-tree").setup({
473-
filesystem = {
474-
commands = {
475-
print_me = function(state)
476-
local node = state.tree:get_node()
477-
print(node.name)
478-
end
479-
},
480-
mappings = {
481-
["?"] = "print_me"
482-
}
483-
}
484-
})
485-
<
486-
487-
GLOBAL CUSTOM COMMANDS *neo-tree-custom-commands-global*
488-
489-
You can also have global custom commands that will be added to all available
490-
sources. If you need it you can then override it in a specific source.
491-
>lua
492-
require("neo-tree").setup({
493-
commands = {
494-
hello = function() -- define a global "hello world" function
495-
print("Hello world")
496-
end
497-
},
498-
499-
window = {
500-
mappings = {
501-
["<C-c>"] = "hello"
502-
-- define a global mapping to call 'hello' in every source
503-
}
504-
},
505-
506-
filesystem = {
507-
commands = {
508-
-- override implementation of the 'hello' action in filesystem source
509-
hello = function()
510-
print("Hello inside filesystem")
511-
end
512-
}
513-
}
514-
})
515-
<
516-
Now when pressing `<C-c>` in 'buffers' or 'git_status' it will print "Hello world",
517-
but in 'filesystem' it will print "Hello inside filesystem".
518-
519-
CUSTOM MAPPINGS WITH VISUAL MODE
431+
CUSTOM MAPPINGS WITH VISUAL MODE *neo-tree-custom-mappings-visual*
520432

521433
If you want to create a mapping that supports visual mode, the way to do that
522434
is to add a second command where the name is the same as the normal mode
@@ -544,7 +456,7 @@ For example, this is how the built-in `delete` command is defined:
544456
end
545457
<
546458

547-
CUSTOM MAPPINGS WITH ARGUMENTS
459+
CUSTOM MAPPINGS WITH ARGUMENTS *neo-tree-custom-mappings-args*
548460

549461
If you want to include options for your mappings, such as `nowait`, you can
550462
set this for all mappings using the `mapping_options` key, or on individual
@@ -594,7 +506,7 @@ assigning it to the `command` key:
594506
See |:map-arguments| for possible values to include. "buffer" and "nnoremap"
595507
are enabled by default.
596508

597-
CUSTOM MAPPINGS WITH CONFIG
509+
CUSTOM MAPPINGS WITH CONFIG *neo-tree-custom-mappings-config*
598510

599511
Some mappings may accept an optional `config` table to control it's behavior.
600512
When that is the case, the command is specified using the table syntax, and
@@ -624,6 +536,96 @@ passed to the command function:
624536
...
625537
<
626538

539+
CUSTOM COMMANDS *neo-tree-custom-commands*
540+
541+
If you want to define your own command, you have two options:
542+
1. You can define (or override) a command in the `commands` section of the
543+
config for each source, then reference that by name in a mapping.
544+
2. You can map directly to a function and skip defining a command.
545+
546+
You probably want #2:
547+
>lua
548+
require("neo-tree").setup({
549+
filesystem = {
550+
window = {
551+
mappings = {
552+
["?"] = function(state)
553+
local node = state.tree:get_node()
554+
print(node.name)
555+
end
556+
}
557+
}
558+
}
559+
})
560+
<
561+
..or
562+
>lua
563+
local print_me = function(state)
564+
local node = state.tree:get_node()
565+
print(node.name)
566+
end
567+
568+
require("neo-tree").setup({
569+
filesystem = {
570+
window = {
571+
mappings = {
572+
["?"] = print_me
573+
}
574+
}
575+
}
576+
})
577+
<
578+
...but if you want #1, here is how that works:
579+
580+
>lua
581+
require("neo-tree").setup({
582+
filesystem = {
583+
commands = {
584+
print_me = function(state)
585+
local node = state.tree:get_node()
586+
print(node.name)
587+
end
588+
},
589+
mappings = {
590+
["?"] = "print_me"
591+
}
592+
}
593+
})
594+
<
595+
596+
GLOBAL CUSTOM COMMANDS *neo-tree-custom-commands-global*
597+
598+
You can also have global custom commands that will be added to all available
599+
sources. If you need it you can then override it in a specific source.
600+
>lua
601+
require("neo-tree").setup({
602+
commands = {
603+
hello = function() -- define a global "hello world" function
604+
print("Hello world")
605+
end
606+
},
607+
608+
window = {
609+
mappings = {
610+
["<C-c>"] = "hello"
611+
-- define a global mapping to call 'hello' in every source
612+
}
613+
},
614+
615+
filesystem = {
616+
commands = {
617+
-- override implementation of the 'hello' action in filesystem source
618+
hello = function()
619+
print("Hello inside filesystem")
620+
end
621+
}
622+
}
623+
})
624+
<
625+
Now when pressing `<C-c>` in 'buffers' or 'git_status' it will print "Hello world",
626+
but in 'filesystem' it will print "Hello inside filesystem".
627+
628+
627629
================================================================================
628630
CONFIGURATION ~
629631
================================================================================

lua/neo-tree/defaults.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ local config = {
302302
-- end | } | print("Hello world in filesystem")
303303
-- } | } | end
304304
--
305-
-- see `:h neo-tree-global-custom-commands`
305+
-- see `:h neo-tree-custom-commands-global`
306306
commands = {}, -- A list of functions
307307

308308
window = { -- see https://github.com/MunifTanjim/nui.nvim/tree/main/lua/nui/popup for

0 commit comments

Comments
 (0)