mirror of
https://github.com/neovim/neovim.git
synced 2025-09-27 05:28:33 +00:00
fix(api): nvim_set_keymap() throws error even in pcall() #33228
Problem: When `nvim_set_keymap` tries to overwrite a `<unique>` mapping,
it throws an error even when called in `pcall`.
Solution: src/nvim/mapping.c:buf_do_map no longer calls `semsg`. Its
callers now decide whether to ignore the error, or use
`semsg` (not caught)/`api_set_error` (caught by `pcall`).
(cherry picked from commit ec18ebcb41
)
This commit is contained in:

committed by
github-actions[bot]
![github-actions[bot]](/assets/img/avatar_default.png)
parent
2b2a90051e
commit
5fc6bd6454
@@ -1465,4 +1465,24 @@ describe('nvim_buf_set_keymap, nvim_buf_del_keymap', function()
|
||||
eq(1, exec_lua [[return GlobalCount]])
|
||||
eq('\nNo mapping found', n.exec_capture('nmap <C-I>'))
|
||||
end)
|
||||
|
||||
it('does not overwrite in <unique> mappings', function()
|
||||
api.nvim_buf_set_keymap(0, 'i', 'lhs', 'rhs', {})
|
||||
eq(
|
||||
'E227: Mapping already exists for lhs',
|
||||
pcall_err(api.nvim_buf_set_keymap, 0, 'i', 'lhs', 'rhs', { unique = true })
|
||||
)
|
||||
|
||||
api.nvim_buf_set_keymap(0, 'ia', 'lhs2', 'rhs2', {})
|
||||
eq(
|
||||
'E226: Abbreviation already exists for lhs2',
|
||||
pcall_err(api.nvim_buf_set_keymap, 0, 'ia', 'lhs2', 'rhs2', { unique = true })
|
||||
)
|
||||
|
||||
api.nvim_set_keymap('n', 'lhs', 'rhs', {})
|
||||
eq(
|
||||
'E225: Global mapping already exists for lhs',
|
||||
pcall_err(api.nvim_buf_set_keymap, 0, 'n', 'lhs', 'rhs', { unique = true })
|
||||
)
|
||||
end)
|
||||
end)
|
||||
|
Reference in New Issue
Block a user