mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
fix(defaults): omit extraneous info from unimpaired mapping errors (#30983)
This commit is contained in:
@@ -219,132 +219,150 @@ do
|
|||||||
|
|
||||||
--- vim-unimpaired style mappings. See: https://github.com/tpope/vim-unimpaired
|
--- vim-unimpaired style mappings. See: https://github.com/tpope/vim-unimpaired
|
||||||
do
|
do
|
||||||
---@param lhs string
|
--- Execute a command and print errors without a stacktrace.
|
||||||
---@param rhs function
|
--- @param opts table Arguments to |nvim_cmd()|
|
||||||
---@param desc string
|
local function cmd(opts)
|
||||||
local function create_unimpaired_mapping(lhs, rhs, desc)
|
local _, err = pcall(vim.api.nvim_cmd, opts, {})
|
||||||
vim.keymap.set('n', lhs, function()
|
|
||||||
local _, err = pcall(rhs) ---@type any, string
|
|
||||||
if err then
|
if err then
|
||||||
vim.api.nvim_err_writeln(err)
|
vim.api.nvim_err_writeln(err:sub(#'Vim:' + 1))
|
||||||
end
|
end
|
||||||
end, { desc = desc })
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Quickfix mappings
|
-- Quickfix mappings
|
||||||
create_unimpaired_mapping('[q', function()
|
vim.keymap.set('n', '[q', function()
|
||||||
vim.cmd.cprevious({ count = vim.v.count1 })
|
cmd({ cmd = 'cprevious', count = vim.v.count1 })
|
||||||
end, ':cprevious')
|
end, { desc = ':cprevious' })
|
||||||
create_unimpaired_mapping(']q', function()
|
|
||||||
vim.cmd.cnext({ count = vim.v.count1 })
|
vim.keymap.set('n', ']q', function()
|
||||||
end, ':cnext')
|
cmd({ cmd = 'cnext', count = vim.v.count1 })
|
||||||
create_unimpaired_mapping('[Q', function()
|
end, { desc = ':cnext' })
|
||||||
vim.cmd.crewind({ count = vim.v.count ~= 0 and vim.v.count or nil })
|
|
||||||
end, ':crewind')
|
vim.keymap.set('n', '[Q', function()
|
||||||
create_unimpaired_mapping(']Q', function()
|
cmd({ cmd = 'crewind', count = vim.v.count ~= 0 and vim.v.count or nil })
|
||||||
vim.cmd.clast({ count = vim.v.count ~= 0 and vim.v.count or nil })
|
end, { desc = ':crewind' })
|
||||||
end, ':clast')
|
|
||||||
create_unimpaired_mapping('[<C-Q>', function()
|
vim.keymap.set('n', ']Q', function()
|
||||||
vim.cmd.cpfile({ count = vim.v.count1 })
|
cmd({ cmd = 'clast', count = vim.v.count ~= 0 and vim.v.count or nil })
|
||||||
end, ':cpfile')
|
end, { desc = ':clast' })
|
||||||
create_unimpaired_mapping(']<C-Q>', function()
|
|
||||||
vim.cmd.cnfile({ count = vim.v.count1 })
|
vim.keymap.set('n', '[<C-Q>', function()
|
||||||
end, ':cnfile')
|
cmd({ cmd = 'cpfile', count = vim.v.count1 })
|
||||||
|
end, { desc = ':cpfile' })
|
||||||
|
|
||||||
|
vim.keymap.set('n', ']<C-Q>', function()
|
||||||
|
cmd({ cmd = 'cnfile', count = vim.v.count1 })
|
||||||
|
end, { desc = ':cnfile' })
|
||||||
|
|
||||||
-- Location list mappings
|
-- Location list mappings
|
||||||
create_unimpaired_mapping('[l', function()
|
vim.keymap.set('n', '[l', function()
|
||||||
vim.cmd.lprevious({ count = vim.v.count1 })
|
cmd({ cmd = 'lprevious', count = vim.v.count1 })
|
||||||
end, ':lprevious')
|
end, { desc = ':lprevious' })
|
||||||
create_unimpaired_mapping(']l', function()
|
|
||||||
vim.cmd.lnext({ count = vim.v.count1 })
|
vim.keymap.set('n', ']l', function()
|
||||||
end, ':lnext')
|
cmd({ cmd = 'lnext', count = vim.v.count1 })
|
||||||
create_unimpaired_mapping('[L', function()
|
end, { desc = ':lnext' })
|
||||||
vim.cmd.lrewind({ count = vim.v.count ~= 0 and vim.v.count or nil })
|
|
||||||
end, ':lrewind')
|
vim.keymap.set('n', '[L', function()
|
||||||
create_unimpaired_mapping(']L', function()
|
cmd({ cmd = 'lrewind', count = vim.v.count ~= 0 and vim.v.count or nil })
|
||||||
vim.cmd.llast({ count = vim.v.count ~= 0 and vim.v.count or nil })
|
end, { desc = ':lrewind' })
|
||||||
end, ':llast')
|
|
||||||
create_unimpaired_mapping('[<C-L>', function()
|
vim.keymap.set('n', ']L', function()
|
||||||
vim.cmd.lpfile({ count = vim.v.count1 })
|
cmd({ cmd = 'llast', count = vim.v.count ~= 0 and vim.v.count or nil })
|
||||||
end, ':lpfile')
|
end, { desc = ':llast' })
|
||||||
create_unimpaired_mapping(']<C-L>', function()
|
|
||||||
vim.cmd.lnfile({ count = vim.v.count1 })
|
vim.keymap.set('n', '[<C-L>', function()
|
||||||
end, ':lnfile')
|
cmd({ cmd = 'lpfile', count = vim.v.count1 })
|
||||||
|
end, { desc = ':lpfile' })
|
||||||
|
|
||||||
|
vim.keymap.set('n', ']<C-L>', function()
|
||||||
|
cmd({ cmd = 'lnfile', count = vim.v.count1 })
|
||||||
|
end, { desc = ':lnfile' })
|
||||||
|
|
||||||
-- Argument list
|
-- Argument list
|
||||||
create_unimpaired_mapping('[a', function()
|
vim.keymap.set('n', '[a', function()
|
||||||
vim.cmd.previous({ count = vim.v.count1 })
|
cmd({ cmd = 'previous', count = vim.v.count1 })
|
||||||
end, ':previous')
|
end, { desc = ':previous' })
|
||||||
create_unimpaired_mapping(']a', function()
|
|
||||||
|
vim.keymap.set('n', ']a', function()
|
||||||
-- count doesn't work with :next, must use range. See #30641.
|
-- count doesn't work with :next, must use range. See #30641.
|
||||||
vim.cmd.next({ range = { vim.v.count1 } })
|
cmd({ cmd = 'next', range = { vim.v.count1 } })
|
||||||
end, ':next')
|
end, { desc = ':next' })
|
||||||
create_unimpaired_mapping('[A', function()
|
|
||||||
|
vim.keymap.set('n', '[A', function()
|
||||||
if vim.v.count ~= 0 then
|
if vim.v.count ~= 0 then
|
||||||
vim.cmd.argument({ count = vim.v.count })
|
cmd({ cmd = 'argument', count = vim.v.count })
|
||||||
else
|
else
|
||||||
vim.cmd.rewind()
|
cmd({ cmd = 'rewind' })
|
||||||
end
|
end
|
||||||
end, ':rewind')
|
end, { desc = ':rewind' })
|
||||||
create_unimpaired_mapping(']A', function()
|
|
||||||
|
vim.keymap.set('n', ']A', function()
|
||||||
if vim.v.count ~= 0 then
|
if vim.v.count ~= 0 then
|
||||||
vim.cmd.argument({ count = vim.v.count })
|
cmd({ cmd = 'argument', count = vim.v.count })
|
||||||
else
|
else
|
||||||
vim.cmd.last()
|
cmd({ cmd = 'last' })
|
||||||
end
|
end
|
||||||
end, ':last')
|
end, { desc = ':last' })
|
||||||
|
|
||||||
-- Tags
|
-- Tags
|
||||||
create_unimpaired_mapping('[t', function()
|
vim.keymap.set('n', '[t', function()
|
||||||
-- count doesn't work with :tprevious, must use range. See #30641.
|
-- count doesn't work with :tprevious, must use range. See #30641.
|
||||||
vim.cmd.tprevious({ range = { vim.v.count1 } })
|
cmd({ cmd = 'tprevious', range = { vim.v.count1 } })
|
||||||
end, ':tprevious')
|
end, { desc = ':tprevious' })
|
||||||
create_unimpaired_mapping(']t', function()
|
|
||||||
|
vim.keymap.set('n', ']t', function()
|
||||||
-- count doesn't work with :tnext, must use range. See #30641.
|
-- count doesn't work with :tnext, must use range. See #30641.
|
||||||
vim.cmd.tnext({ range = { vim.v.count1 } })
|
cmd({ cmd = 'tnext', range = { vim.v.count1 } })
|
||||||
end, ':tnext')
|
end, { desc = ':tnext' })
|
||||||
create_unimpaired_mapping('[T', function()
|
|
||||||
|
vim.keymap.set('n', '[T', function()
|
||||||
-- count doesn't work with :trewind, must use range. See #30641.
|
-- count doesn't work with :trewind, must use range. See #30641.
|
||||||
vim.cmd.trewind({ range = vim.v.count ~= 0 and { vim.v.count } or nil })
|
cmd({ cmd = 'trewind', range = vim.v.count ~= 0 and { vim.v.count } or nil })
|
||||||
end, ':trewind')
|
end, { desc = ':trewind' })
|
||||||
create_unimpaired_mapping(']T', function()
|
|
||||||
|
vim.keymap.set('n', ']T', function()
|
||||||
-- :tlast does not accept a count, so use :trewind if count given
|
-- :tlast does not accept a count, so use :trewind if count given
|
||||||
if vim.v.count ~= 0 then
|
if vim.v.count ~= 0 then
|
||||||
vim.cmd.trewind({ range = { vim.v.count } })
|
cmd({ cmd = 'trewind', range = { vim.v.count } })
|
||||||
else
|
else
|
||||||
vim.cmd.tlast()
|
cmd({ cmd = 'tlast' })
|
||||||
end
|
end
|
||||||
end, ':tlast')
|
end, { desc = ':tlast' })
|
||||||
create_unimpaired_mapping('[<C-T>', function()
|
|
||||||
|
vim.keymap.set('n', '[<C-T>', function()
|
||||||
-- count doesn't work with :ptprevious, must use range. See #30641.
|
-- count doesn't work with :ptprevious, must use range. See #30641.
|
||||||
vim.cmd.ptprevious({ range = { vim.v.count1 } })
|
cmd({ cmd = 'ptprevious', range = { vim.v.count1 } })
|
||||||
end, ' :ptprevious')
|
end, { desc = ' :ptprevious' })
|
||||||
create_unimpaired_mapping(']<C-T>', function()
|
|
||||||
|
vim.keymap.set('n', ']<C-T>', function()
|
||||||
-- count doesn't work with :ptnext, must use range. See #30641.
|
-- count doesn't work with :ptnext, must use range. See #30641.
|
||||||
vim.cmd.ptnext({ range = { vim.v.count1 } })
|
cmd({ cmd = 'ptnext', range = { vim.v.count1 } })
|
||||||
end, ':ptnext')
|
end, { desc = ':ptnext' })
|
||||||
|
|
||||||
-- Buffers
|
-- Buffers
|
||||||
create_unimpaired_mapping('[b', function()
|
vim.keymap.set('n', '[b', function()
|
||||||
vim.cmd.bprevious({ count = vim.v.count1 })
|
cmd({ cmd = 'bprevious', count = vim.v.count1 })
|
||||||
end, ':bprevious')
|
end, { desc = ':bprevious' })
|
||||||
create_unimpaired_mapping(']b', function()
|
|
||||||
vim.cmd.bnext({ count = vim.v.count1 })
|
vim.keymap.set('n', ']b', function()
|
||||||
end, ':bnext')
|
cmd({ cmd = 'bnext', count = vim.v.count1 })
|
||||||
create_unimpaired_mapping('[B', function()
|
end, { desc = ':bnext' })
|
||||||
|
|
||||||
|
vim.keymap.set('n', '[B', function()
|
||||||
if vim.v.count ~= 0 then
|
if vim.v.count ~= 0 then
|
||||||
vim.cmd.buffer({ count = vim.v.count })
|
cmd({ cmd = 'buffer', count = vim.v.count })
|
||||||
else
|
else
|
||||||
vim.cmd.brewind()
|
cmd({ cmd = 'brewind' })
|
||||||
end
|
end
|
||||||
end, ':brewind')
|
end, { desc = ':brewind' })
|
||||||
create_unimpaired_mapping(']B', function()
|
|
||||||
|
vim.keymap.set('n', ']B', function()
|
||||||
if vim.v.count ~= 0 then
|
if vim.v.count ~= 0 then
|
||||||
vim.cmd.buffer({ count = vim.v.count })
|
cmd({ cmd = 'buffer', count = vim.v.count })
|
||||||
else
|
else
|
||||||
vim.cmd.blast()
|
cmd({ cmd = 'blast' })
|
||||||
end
|
end
|
||||||
end, ':blast')
|
end, { desc = ':blast' })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@ -95,6 +95,63 @@ describe('default', function()
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- describe('key mappings', function()
|
describe('key mappings', function()
|
||||||
-- end)
|
describe('unimpaired-style mappings', function()
|
||||||
|
it('do not show a full stack trace #30625', function()
|
||||||
|
n.clear({ args_rm = { '--cmd' } })
|
||||||
|
local screen = Screen.new(40, 8)
|
||||||
|
screen:attach()
|
||||||
|
screen:set_default_attr_ids({
|
||||||
|
[1] = { foreground = Screen.colors.NvimDarkGray4 },
|
||||||
|
[2] = {
|
||||||
|
background = Screen.colors.NvimLightGrey3,
|
||||||
|
foreground = Screen.colors.NvimDarkGray3,
|
||||||
|
},
|
||||||
|
[3] = { foreground = Screen.colors.NvimLightRed },
|
||||||
|
[4] = { foreground = Screen.colors.NvimLightCyan },
|
||||||
|
})
|
||||||
|
|
||||||
|
n.feed('[a')
|
||||||
|
screen:expect({
|
||||||
|
grid = [[
|
||||||
|
|
|
||||||
|
{1:~ }|*4
|
||||||
|
{2: }|
|
||||||
|
{3:E163: There is only one file to edit} |
|
||||||
|
{4:Press ENTER or type command to continue}^ |
|
||||||
|
]],
|
||||||
|
})
|
||||||
|
|
||||||
|
n.feed('[q')
|
||||||
|
screen:expect({
|
||||||
|
grid = [[
|
||||||
|
^ |
|
||||||
|
{1:~ }|*5
|
||||||
|
{2:[No Name] 0,0-1 All}|
|
||||||
|
{3:E42: No Errors} |
|
||||||
|
]],
|
||||||
|
})
|
||||||
|
|
||||||
|
n.feed('[l')
|
||||||
|
screen:expect({
|
||||||
|
grid = [[
|
||||||
|
^ |
|
||||||
|
{1:~ }|*5
|
||||||
|
{2:[No Name] 0,0-1 All}|
|
||||||
|
{3:E776: No location list} |
|
||||||
|
]],
|
||||||
|
})
|
||||||
|
|
||||||
|
n.feed('[t')
|
||||||
|
screen:expect({
|
||||||
|
grid = [[
|
||||||
|
^ |
|
||||||
|
{1:~ }|*5
|
||||||
|
{2:[No Name] 0,0-1 All}|
|
||||||
|
{3:E73: Tag stack empty} |
|
||||||
|
]],
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
Reference in New Issue
Block a user