Skip to content

Commit d8558bb

Browse files
committed
docs(#3088): tidy api map names
1 parent b4b9b20 commit d8558bb

8 files changed

Lines changed: 50 additions & 46 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ local function my_on_attach(bufnr)
9797
end
9898

9999
-- default mappings
100-
api.map.default_on_attach(bufnr)
100+
api.map.on_attach.default(bufnr)
101101

102102
-- custom mappings
103103
vim.keymap.set('n', '<C-t>', api.tree.change_root_to_parent, opts('Up'))

doc/nvim-tree-lua.txt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ via |nvim_tree.config| {on_attach} e.g. >lua
179179
end
180180

181181
-- default mappings
182-
api.map.default_on_attach(bufnr)
182+
api.map.on_attach.default(bufnr)
183183

184184
-- custom mappings
185185
vim.keymap.set("n", "<C-t>", api.tree.change_root_to_parent, opts("Up"))
@@ -348,7 +348,7 @@ The `on_attach` function is passed the `bufnr` of nvim-tree. Use
348348
vim.keymap.set("n", "<C-e>", api.node.open.replace_tree_buffer, opts("Open: In Place"))
349349
---
350350
-- OR use all default mappings
351-
api.map.default_on_attach.default_on_attach(bufnr)
351+
api.map.on_attach.default.on_attach_default(bufnr)
352352

353353
-- remove a default
354354
vim.keymap.del("n", "<C-]>", { buffer = bufnr })
@@ -397,7 +397,7 @@ You are encouraged to copy these to your {on_attach} function. >lua
397397
return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
398398
end
399399

400-
-- BEGIN_DEFAULT_ON_ATTACH
400+
-- BEGIN_ON_ATTACH_DEFAULT
401401
vim.keymap.set("n", "<C-]>", api.tree.change_root_to_node, opts("CD"))
402402
vim.keymap.set("n", "<C-e>", api.node.open.replace_tree_buffer, opts("Open: In Place"))
403403
vim.keymap.set("n", "<C-k>", api.node.show_info_popup, opts("Info"))
@@ -457,10 +457,10 @@ You are encouraged to copy these to your {on_attach} function. >lua
457457
vim.keymap.set("n", "Y", api.fs.copy.relative_path, opts("Copy Relative Path"))
458458
vim.keymap.set("n", "<2-LeftMouse>", api.node.open.edit, opts("Open"))
459459
vim.keymap.set("n", "<2-RightMouse>", api.tree.change_root_to_node, opts("CD"))
460-
-- END_DEFAULT_ON_ATTACH
460+
-- END_ON_ATTACH_DEFAULT
461461
<
462462
Alternatively, you may apply these default mappings from your
463-
|nvim_tree.config| {on_attach} via |nvim_tree.api.map.default_on_attach()| e.g. >lua
463+
|nvim_tree.config| {on_attach} via |nvim_tree.api.map.on_attach.default()| e.g. >lua
464464

465465
local function my_on_attach(bufnr)
466466
local api = require("nvim-tree.api")
@@ -469,7 +469,7 @@ Alternatively, you may apply these default mappings from your
469469
return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
470470
end
471471

472-
api.map.default_on_attach.default_on_attach(bufnr)
472+
api.map.on_attach.default.on_attach_default(bufnr)
473473

474474
-- your removals and mappings go here
475475
end
@@ -1011,9 +1011,9 @@ Legacy: API *nvim-tree-legacy-api*
10111011
Some API functions have been refactored however the previous function will
10121012
continue to be available.
10131013

1014-
`api.config.mappings.get_keymap` |nvim_tree.api.map.get_keymap()|
1015-
`api.config.mappings.get_keymap_default` |nvim_tree.api.map.get_keymap_default()|
1016-
`api.config.mappings.default_on_attach` |nvim_tree.api.map.default_on_attach()|
1014+
`api.config.mappings.get_keymap` |nvim_tree.api.map.keymap.current()|
1015+
`api.config.mappings.get_keymap_default` |nvim_tree.api.map.keymap.default()|
1016+
`api.config.mappings.default_on_attach` |nvim_tree.api.map.on_attach.default()|
10171017

10181018
`api.diagnostics.hi_test` |nvim_tree.api.health.hi_test()|
10191019

@@ -2615,28 +2615,28 @@ hi_test() *nvim_tree.api.health.hi_test()*
26152615
==============================================================================
26162616
API: map *nvim-tree-api-map*
26172617

2618-
default_on_attach({bufnr}) *nvim_tree.api.map.default_on_attach()*
2619-
Apply all |nvim-tree-mappings-default|. Call from your |nvim_tree.config|
2620-
{on_attach}.
2621-
2622-
Parameters: ~
2623-
{bufnr} (`integer`) use the `bufnr` passed to {on_attach}
2624-
2625-
get_keymap() *nvim_tree.api.map.get_keymap()*
2618+
keymap.current() *nvim_tree.api.map.keymap.current()*
26262619
Retrieve all buffer local mappings for nvim-tree. These are the mappings
26272620
that are applied by |nvim_tree.config| {on_attach}, which may include
26282621
default mappings.
26292622

26302623
Return: ~
26312624
(`vim.api.keyset.get_keymap[]`)
26322625

2633-
get_keymap_default() *nvim_tree.api.map.get_keymap_default()*
2626+
keymap.default() *nvim_tree.api.map.keymap.default()*
26342627
Retrieves the buffer local mappings for nvim-tree that are applied by
2635-
|nvim_tree.api.map.default_on_attach()|
2628+
|nvim_tree.api.map.on_attach.default()|
26362629

26372630
Return: ~
26382631
(`vim.api.keyset.get_keymap[]`)
26392632

2633+
on_attach.default({bufnr}) *nvim_tree.api.map.on_attach.default()*
2634+
Apply all |nvim-tree-mappings-default|. Call from your |nvim_tree.config|
2635+
{on_attach}.
2636+
2637+
Parameters: ~
2638+
{bufnr} (`integer`) use the `bufnr` passed to {on_attach}
2639+
26402640

26412641
==============================================================================
26422642
API: marks *nvim-tree-api-marks*

lua/nvim-tree/_meta/api/map.lua

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,26 @@
11
---@meta
22
local nvim_tree = { api = { map = {} } }
33

4+
nvim_tree.api.map.keymap = {}
5+
46
---
57
---Retrieve all buffer local mappings for nvim-tree. These are the mappings that are applied by [nvim_tree.config] {on_attach}, which may include default mappings.
68
---
79
---@return vim.api.keyset.get_keymap[]
8-
function nvim_tree.api.map.get_keymap() end
10+
function nvim_tree.api.map.keymap.current() end
911

1012
---
11-
--- Retrieves the buffer local mappings for nvim-tree that are applied by [nvim_tree.api.map.default_on_attach()]
13+
--- Retrieves the buffer local mappings for nvim-tree that are applied by [nvim_tree.api.map.on_attach.default()]
1214
---
1315
---@return vim.api.keyset.get_keymap[]
14-
function nvim_tree.api.map.get_keymap_default() end
16+
function nvim_tree.api.map.keymap.default() end
17+
18+
nvim_tree.api.map.on_attach = {}
1519

1620
---
1721
---Apply all [nvim-tree-mappings-default]. Call from your [nvim_tree.config] {on_attach}.
1822
---
1923
---@param bufnr integer use the `bufnr` passed to {on_attach}
20-
function nvim_tree.api.map.default_on_attach(bufnr) end
24+
function nvim_tree.api.map.on_attach.default(bufnr) end
2125

2226
return nvim_tree.api.map

lua/nvim-tree/api/impl/pre.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ local function hydrate_pre(api)
3838
api.events.Event = events.Event
3939
api.events.subscribe = events.subscribe
4040

41-
api.map.default_on_attach = keymap.default_on_attach
41+
api.map.on_attach.default = keymap.on_attach_default
4242

4343

4444
--

lua/nvim-tree/help.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ local function tidy_lhs(lhs)
4545
end
4646

4747
--- Remove prefix 'nvim-tree: '
48-
--- Hardcoded to keep default_on_attach simple
48+
--- Hardcoded to keep on_attach_default simple
4949
---@param desc string
5050
---@return string
5151
local function tidy_desc(desc)

lua/nvim-tree/keymap.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
local M = {}
22

33
--- Apply mappings to a scratch buffer and return buffer local mappings
4-
---@param fn fun(bufnr: integer) on_attach or default_on_attach
4+
---@param fn fun(bufnr: integer) on_attach or on_attach_default
55
---@return table as per vim.api.nvim_buf_get_keymap
66
local function generate_keymap(fn)
77
-- create an unlisted scratch buffer
@@ -26,11 +26,11 @@ end
2626

2727
---@return table
2828
function M.get_keymap_default()
29-
return generate_keymap(M.default_on_attach)
29+
return generate_keymap(M.on_attach_default)
3030
end
3131

3232
---@param bufnr integer
33-
function M.default_on_attach(bufnr)
33+
function M.on_attach_default(bufnr)
3434
local api = require("nvim-tree.api")
3535

3636
local function opts(desc)
@@ -43,7 +43,7 @@ function M.default_on_attach(bufnr)
4343
}
4444
end
4545

46-
-- BEGIN_DEFAULT_ON_ATTACH
46+
-- BEGIN_ON_ATTACH_DEFAULT
4747
vim.keymap.set("n", "<C-]>", api.tree.change_root_to_node, opts("CD"))
4848
vim.keymap.set("n", "<C-e>", api.node.open.replace_tree_buffer, opts("Open: In Place"))
4949
vim.keymap.set("n", "<C-k>", api.node.show_info_popup, opts("Info"))
@@ -103,12 +103,12 @@ function M.default_on_attach(bufnr)
103103
vim.keymap.set("n", "Y", api.fs.copy.relative_path, opts("Copy Relative Path"))
104104
vim.keymap.set("n", "<2-LeftMouse>", api.node.open.edit, opts("Open"))
105105
vim.keymap.set("n", "<2-RightMouse>", api.tree.change_root_to_node, opts("CD"))
106-
-- END_DEFAULT_ON_ATTACH
106+
-- END_ON_ATTACH_DEFAULT
107107
end
108108

109109
function M.setup(opts)
110110
if type(opts.on_attach) ~= "function" then
111-
M.on_attach = M.default_on_attach
111+
M.on_attach = M.on_attach_default
112112
else
113113
M.on_attach = opts.on_attach
114114
end

lua/nvim-tree/legacy.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ end
168168
function M.map_api(api)
169169
api.config = api.config or {}
170170
api.config.mappings = api.config.mappings or {}
171-
api.config.mappings.get_keymap = api.map.get_keymap
172-
api.config.mappings.get_keymap_default = api.map.get_keymap_default
173-
api.config.mappings.default_on_attach = api.map.default_on_attach
171+
api.config.mappings.get_keymap = api.map.keymap.current
172+
api.config.mappings.get_keymap_default = api.map.keymap.default
173+
api.config.mappings.default_on_attach = api.map.on_attach.default
174174

175175
api.git = api.git or {}
176176
api.git.reload = api.tree.reload_git

scripts/help-update.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env sh
22

3-
# run after changing default config or keymap.lua M.default_on_attach
3+
# run after changing default config or keymap.lua M.on_attach_default
44
# scrapes and updates nvim-tree-lua.txt
55
# run from repository root: scripts/help-update.sh OR make help-update
66

@@ -25,25 +25,25 @@ sed -i -e "/${inject}/r /tmp/DEFAULT_OPTS.6.lua" -e "/${inject}/d" doc/nvim-tree
2525
# Inject default mappings
2626
#
2727

28-
begin="BEGIN_DEFAULT_ON_ATTACH"
29-
end="END_DEFAULT_ON_ATTACH"
28+
begin="BEGIN_ON_ATTACH_DEFAULT"
29+
end="END_ON_ATTACH_DEFAULT"
3030

31-
# scrape DEFAULT_ON_ATTACH, indented at 2
32-
sed -n -e "/${begin}/,/${end}/{ /${begin}/d; /${end}/d; p; }" lua/nvim-tree/keymap.lua > /tmp/DEFAULT_ON_ATTACH.lua
31+
# scrape ON_ATTACH_DEFAULT, indented at 2
32+
sed -n -e "/${begin}/,/${end}/{ /${begin}/d; /${end}/d; p; }" lua/nvim-tree/keymap.lua > /tmp/ON_ATTACH_DEFAULT.lua
3333

3434
# help lua
35-
sed -i -e "/${begin}/,/${end}/{ /${begin}/{p; r /tmp/DEFAULT_ON_ATTACH.lua
35+
sed -i -e "/${begin}/,/${end}/{ /${begin}/{p; r /tmp/ON_ATTACH_DEFAULT.lua
3636
}; /${end}/p; d; }" doc/nvim-tree-lua.txt
3737

3838
# help human
39-
echo > /tmp/DEFAULT_ON_ATTACH.help
39+
echo > /tmp/ON_ATTACH_DEFAULT.help
4040
sed -E "s/^ *vim.keymap.set\(\"n\", \"(.*)\",.*api(.*),.*opts\(\"(.*)\".*$/'\`\1\`' '\3' '|nvim_tree.api\2()|'/g
41-
" /tmp/DEFAULT_ON_ATTACH.lua | while read -r line
41+
" /tmp/ON_ATTACH_DEFAULT.lua | while read -r line
4242
do
43-
eval "printf '%-17.17s %-26.26s %s\n' ${line}" >> /tmp/DEFAULT_ON_ATTACH.help
43+
eval "printf '%-17.17s %-26.26s %s\n' ${line}" >> /tmp/ON_ATTACH_DEFAULT.help
4444
done
45-
echo >> /tmp/DEFAULT_ON_ATTACH.help
45+
echo >> /tmp/ON_ATTACH_DEFAULT.help
4646
begin="Show the mappings:"
4747
end="======"
48-
sed -i -e "/${begin}/,/${end}/{ /${begin}/{p; r /tmp/DEFAULT_ON_ATTACH.help
48+
sed -i -e "/${begin}/,/${end}/{ /${begin}/{p; r /tmp/ON_ATTACH_DEFAULT.help
4949
}; /${end}/p; d; }" doc/nvim-tree-lua.txt

0 commit comments

Comments
 (0)