feat(defaults): add :Inspect to right-click menu (#28181)

Ref #21393

- Move default user commands to _defaults.lua as that now contains all
  kinds of defaults rather than just default mappings and menus.
- Remove the :aunmenu as there are no menus when _defaults.lua is run.
This commit is contained in:
zeertzjq
2024-04-05 18:08:54 +08:00
committed by GitHub
parent a500c5f808
commit 9711370c26
6 changed files with 46 additions and 49 deletions

View File

@@ -443,18 +443,18 @@ You can define the special menu "PopUp". This is the menu that is displayed
when the right mouse button is pressed, if 'mousemodel' is set to popup or when the right mouse button is pressed, if 'mousemodel' is set to popup or
popup_setpos. popup_setpos.
The default "PopUp" menu is: > The default "PopUp" menu is: >vim
aunmenu PopUp vnoremenu PopUp.Cut "+x
vnoremenu PopUp.Cut "+x vnoremenu PopUp.Copy "+y
vnoremenu PopUp.Copy "+y anoremenu PopUp.Paste "+gP
anoremenu PopUp.Paste "+gP vnoremenu PopUp.Paste "+P
vnoremenu PopUp.Paste "+P vnoremenu PopUp.Delete "_x
vnoremenu PopUp.Delete "_x nnoremenu PopUp.Select\ All ggVG
nnoremenu PopUp.Select\ All ggVG vnoremenu PopUp.Select\ All gg0oG$
vnoremenu PopUp.Select\ All gg0oG$ inoremenu PopUp.Select\ All <C-Home><C-O>VG
inoremenu PopUp.Select\ All <C-Home><C-O>VG anoremenu PopUp.Inspect <Cmd>Inspect<CR>
anoremenu PopUp.-1- <Nop> anoremenu PopUp.-1- <Nop>
anoremenu PopUp.How-to\ disable\ mouse <Cmd>help disable-mouse<CR> anoremenu PopUp.How-to\ disable\ mouse <Cmd>help disable-mouse<CR>
< <
Showing What Menus Are Mapped To *showing-menus* Showing What Menus Are Mapped To *showing-menus*

View File

@@ -1,3 +1,31 @@
--- Default user commands
do
vim.api.nvim_create_user_command('Inspect', function(cmd)
if cmd.bang then
vim.print(vim.inspect_pos())
else
vim.show_pos()
end
end, { desc = 'Inspect highlights and extmarks at the cursor', bang = true })
vim.api.nvim_create_user_command('InspectTree', function(cmd)
if cmd.mods ~= '' or cmd.count ~= 0 then
local count = cmd.count ~= 0 and cmd.count or ''
local new = cmd.mods ~= '' and 'new' or 'vnew'
vim.treesitter.inspect_tree({
command = ('%s %s%s'):format(cmd.mods, count, new),
})
else
vim.treesitter.inspect_tree()
end
end, { desc = 'Inspect treesitter language tree for buffer', count = true })
vim.api.nvim_create_user_command('EditQuery', function(cmd)
vim.treesitter.query.edit(cmd.fargs[1])
end, { desc = 'Edit treesitter query', nargs = '?' })
end
--- Default mappings --- Default mappings
do do
--- Default maps for * and # in visual mode. --- Default maps for * and # in visual mode.
@@ -93,7 +121,6 @@ do
--- Right click popup menu --- Right click popup menu
-- TODO VimScript, no l10n -- TODO VimScript, no l10n
vim.cmd([[ vim.cmd([[
aunmenu *
vnoremenu PopUp.Cut "+x vnoremenu PopUp.Cut "+x
vnoremenu PopUp.Copy "+y vnoremenu PopUp.Copy "+y
anoremenu PopUp.Paste "+gP anoremenu PopUp.Paste "+gP
@@ -102,6 +129,7 @@ do
nnoremenu PopUp.Select\ All ggVG nnoremenu PopUp.Select\ All ggVG
vnoremenu PopUp.Select\ All gg0oG$ vnoremenu PopUp.Select\ All gg0oG$
inoremenu PopUp.Select\ All <C-Home><C-O>VG inoremenu PopUp.Select\ All <C-Home><C-O>VG
anoremenu PopUp.Inspect <Cmd>Inspect<CR>
anoremenu PopUp.-1- <Nop> anoremenu PopUp.-1- <Nop>
anoremenu PopUp.How-to\ disable\ mouse <Cmd>help disable-mouse<CR> anoremenu PopUp.How-to\ disable\ mouse <Cmd>help disable-mouse<CR>
]]) ]])

View File

@@ -1,24 +0,0 @@
vim.api.nvim_create_user_command('Inspect', function(cmd)
if cmd.bang then
vim.print(vim.inspect_pos())
else
vim.show_pos()
end
end, { desc = 'Inspect highlights and extmarks at the cursor', bang = true })
vim.api.nvim_create_user_command('InspectTree', function(cmd)
if cmd.mods ~= '' or cmd.count ~= 0 then
local count = cmd.count ~= 0 and cmd.count or ''
local new = cmd.mods ~= '' and 'new' or 'vnew'
vim.treesitter.inspect_tree({
command = ('%s %s%s'):format(cmd.mods, count, new),
})
else
vim.treesitter.inspect_tree()
end
end, { desc = 'Inspect treesitter language tree for buffer', count = true })
vim.api.nvim_create_user_command('EditQuery', function(cmd)
vim.treesitter.query.edit(cmd.fargs[1])
end, { desc = 'Edit treesitter query', nargs = '?' })

View File

@@ -101,15 +101,7 @@ describe('startup', function()
VIMRUNTIME = os.getenv('VIMRUNTIME'), VIMRUNTIME = os.getenv('VIMRUNTIME'),
}, },
}) })
screen:expect([[ screen:expect({ any = pesc('Entering Debug mode. Type "cont" to continue.') })
^ |
|
Entering Debug mode. Type "cont" to continue. |
nvim_exec2() |
cmd: aunmenu * |
> |
|
]])
fn.chansend(id, 'cont\n') fn.chansend(id, 'cont\n')
screen:expect([[ screen:expect([[
^ | ^ |

View File

@@ -37,9 +37,9 @@ module.nvim_argv = {
runtime_set, runtime_set,
'--cmd', '--cmd',
module.nvim_set, module.nvim_set,
-- Remove default mappings. -- Remove default user commands and mappings.
'--cmd', '--cmd',
'mapclear | mapclear!', 'comclear | mapclear | mapclear!',
-- Make screentest work after changing to the new default color scheme -- Make screentest work after changing to the new default color scheme
-- Source 'vim' color scheme without side effects -- Source 'vim' color scheme without side effects
-- TODO: rewrite tests -- TODO: rewrite tests

View File

@@ -44,7 +44,8 @@ if exists('s:did_load')
endif endif
let s:did_load = 1 let s:did_load = 1
" Clear Nvim default mappings and menus. " Clear Nvim default user commands, mappings and menus.
comclear
mapclear mapclear
mapclear! mapclear!
aunmenu * aunmenu *