fix(defaults): error messages UX for unimpaired mappings #30884

This commit is contained in:
Maria José Solano 2024-10-23 04:40:12 -07:00 committed by GitHub
parent 02749de7d5
commit f6f2334ac2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -215,173 +215,126 @@ 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
---@param rhs function
---@param desc string
local function create_unimpaired_mapping(lhs, rhs, desc)
vim.keymap.set('n', lhs, function()
local _, err = pcall(rhs) ---@type any, string
if err then
vim.api.nvim_err_writeln(err)
end
end, { desc = desc })
end
-- Quickfix mappings -- Quickfix mappings
vim.keymap.set('n', '[q', function() create_unimpaired_mapping('[q', function()
vim.cmd.cprevious({ count = vim.v.count1 }) vim.cmd.cprevious({ count = vim.v.count1 })
end, { end, ':cprevious')
desc = ':cprevious', create_unimpaired_mapping(']q', function()
})
vim.keymap.set('n', ']q', function()
vim.cmd.cnext({ count = vim.v.count1 }) vim.cmd.cnext({ count = vim.v.count1 })
end, { end, ':cnext')
desc = ':cnext', create_unimpaired_mapping('[<C-Q>', function()
})
vim.keymap.set('n', '[Q', function()
vim.cmd.crewind({ count = vim.v.count ~= 0 and vim.v.count or nil })
end, {
desc = ':crewind',
})
vim.keymap.set('n', ']Q', function()
vim.cmd.clast({ count = vim.v.count ~= 0 and vim.v.count or nil })
end, {
desc = ':clast',
})
vim.keymap.set('n', '[<C-Q>', function()
vim.cmd.cpfile({ count = vim.v.count1 }) vim.cmd.cpfile({ count = vim.v.count1 })
end, { end, ':cpfile')
desc = ':cpfile', create_unimpaired_mapping(']<C-Q>', function()
})
vim.keymap.set('n', ']<C-Q>', function()
vim.cmd.cnfile({ count = vim.v.count1 }) vim.cmd.cnfile({ count = vim.v.count1 })
end, { end, ':cnfile')
desc = ':cnfile',
})
-- Location list mappings -- Location list mappings
vim.keymap.set('n', '[l', function() create_unimpaired_mapping('[l', function()
vim.cmd.lprevious({ count = vim.v.count1 }) vim.cmd.lprevious({ count = vim.v.count1 })
end, { end, ':lprevious')
desc = ':lprevious', create_unimpaired_mapping(']l', function()
})
vim.keymap.set('n', ']l', function()
vim.cmd.lnext({ count = vim.v.count1 }) vim.cmd.lnext({ count = vim.v.count1 })
end, { end, ':lnext')
desc = ':lnext', create_unimpaired_mapping('[L', function()
})
vim.keymap.set('n', '[L', function()
vim.cmd.lrewind({ count = vim.v.count ~= 0 and vim.v.count or nil }) vim.cmd.lrewind({ count = vim.v.count ~= 0 and vim.v.count or nil })
end, { end, ':lrewind')
desc = ':lrewind', create_unimpaired_mapping(']L', function()
})
vim.keymap.set('n', ']L', function()
vim.cmd.llast({ 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, { end, ':llast')
desc = ':llast', create_unimpaired_mapping('[<C-L>', function()
})
vim.keymap.set('n', '[<C-L>', function()
vim.cmd.lpfile({ count = vim.v.count1 }) vim.cmd.lpfile({ count = vim.v.count1 })
end, { end, ':lpfile')
desc = ':lpfile', create_unimpaired_mapping(']<C-L>', function()
})
vim.keymap.set('n', ']<C-L>', function()
vim.cmd.lnfile({ count = vim.v.count1 }) vim.cmd.lnfile({ count = vim.v.count1 })
end, { end, ':lnfile')
desc = ':lnfile',
})
-- Argument list -- Argument list
vim.keymap.set('n', '[a', function() create_unimpaired_mapping('[a', function()
vim.cmd.previous({ count = vim.v.count1 }) vim.cmd.previous({ count = vim.v.count1 })
end, { end, ':previous')
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 } }) vim.cmd.next({ range = { vim.v.count1 } })
end, { end, ':next')
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 }) vim.cmd.argument({ count = vim.v.count })
else else
vim.cmd.rewind() vim.cmd.rewind()
end end
end, { end, ':rewind')
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 }) vim.cmd.argument({ count = vim.v.count })
else else
vim.cmd.last() vim.cmd.last()
end end
end, { end, ':last')
desc = ':last',
})
-- Tags -- Tags
vim.keymap.set('n', '[t', function() create_unimpaired_mapping('[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 } }) vim.cmd.tprevious({ range = { vim.v.count1 } })
end, { desc = ':tprevious' }) end, ':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 } }) vim.cmd.tnext({ range = { vim.v.count1 } })
end, { desc = ':tnext' }) end, ':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 }) vim.cmd.trewind({ range = vim.v.count ~= 0 and { vim.v.count } or nil })
end, { desc = ':trewind' }) end, ':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 } }) vim.cmd.trewind({ range = { vim.v.count } })
else else
vim.cmd.tlast() vim.cmd.tlast()
end end
end, { desc = ':tlast' }) end, ':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 } }) vim.cmd.ptprevious({ range = { vim.v.count1 } })
end, { desc = ' :ptprevious' }) end, ' :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 } }) vim.cmd.ptnext({ range = { vim.v.count1 } })
end, { desc = ':ptnext' }) end, ':ptnext')
-- Buffers -- Buffers
vim.keymap.set('n', '[b', function() create_unimpaired_mapping('[b', function()
vim.cmd.bprevious({ count = vim.v.count1 }) vim.cmd.bprevious({ count = vim.v.count1 })
end, { desc = ':bprevious' }) end, ':bprevious')
create_unimpaired_mapping(']b', function()
vim.keymap.set('n', ']b', function()
vim.cmd.bnext({ count = vim.v.count1 }) vim.cmd.bnext({ count = vim.v.count1 })
end, { desc = ':bnext' }) end, ':bnext')
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 }) vim.cmd.buffer({ count = vim.v.count })
else else
vim.cmd.brewind() vim.cmd.brewind()
end end
end, { desc = ':brewind' }) end, ':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 }) vim.cmd.buffer({ count = vim.v.count })
else else
vim.cmd.blast() vim.cmd.blast()
end end
end, { desc = ':blast' }) end, ':blast')
end end
end end