diff options
author | bfredl <bjorn.linse@gmail.com> | 2022-05-20 14:22:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-20 14:22:44 +0200 |
commit | 1d160a76ec46e7eb4cfa627fb85987059fae55c4 (patch) | |
tree | a4b9e2aa2303970ea1af9012ea07704ab03de413 | |
parent | a4862cbb5fe4fb368a679adf198506a56a104413 (diff) | |
parent | fb8fa004d8c91b7b591509539a228e97ebc57d9d (diff) | |
download | rneovim-1d160a76ec46e7eb4cfa627fb85987059fae55c4.tar.gz rneovim-1d160a76ec46e7eb4cfa627fb85987059fae55c4.tar.bz2 rneovim-1d160a76ec46e7eb4cfa627fb85987059fae55c4.zip |
Merge pull request #18641 from famiu/fix/nvim_cmd/keymap_error_suppress
fix: make `nvim_cmd` not suppress errors inside key mapping
-rw-r--r-- | src/nvim/api/vimscript.c | 27 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 17 | ||||
-rw-r--r-- | test/functional/api/vim_spec.lua | 8 |
3 files changed, 35 insertions, 17 deletions
diff --git a/src/nvim/api/vimscript.c b/src/nvim/api/vimscript.c index b8f7b33cd5..e71f1a11ec 100644 --- a/src/nvim/api/vimscript.c +++ b/src/nvim/api/vimscript.c @@ -1304,20 +1304,23 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Error capture_ga = &capture_local; } - try_start(); - if (output) { - msg_silent++; - } + TRY_WRAP({ + try_start(); + if (output) { + msg_silent++; + } - WITH_SCRIPT_CONTEXT(channel_id, { - execute_cmd(&ea, &cmdinfo); - }); + WITH_SCRIPT_CONTEXT(channel_id, { + execute_cmd(&ea, &cmdinfo); + }); - if (output) { - capture_ga = save_capture_ga; - msg_silent = save_msg_silent; - } - try_end(err); + if (output) { + capture_ga = save_capture_ga; + msg_silent = save_msg_silent; + } + + try_end(err); + }); if (ERROR_SET(err)) { goto clear_ga; diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 7506c353dd..5f9d73a25a 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -1583,13 +1583,14 @@ bool parse_cmdline(char *cmdline, exarg_T *eap, CmdParseInfo *cmdinfo, char **er /// @param cmdinfo Command parse information void execute_cmd(exarg_T *eap, CmdParseInfo *cmdinfo) { + char *errormsg = NULL; + #define ERROR(msg) \ do { \ - emsg(msg); \ + errormsg = msg; \ goto end; \ } while (0) - char *errormsg = NULL; cmdmod_T save_cmdmod = cmdmod; cmdmod = cmdinfo->cmdmod; @@ -1648,7 +1649,7 @@ void execute_cmd(exarg_T *eap, CmdParseInfo *cmdinfo) // If filename expansion is enabled, expand filenames if (cmdinfo->magic.file) { if (expand_filename(eap, (char_u **)eap->cmdlinep, &errormsg) == FAIL) { - ERROR(errormsg); + goto end; } } @@ -1706,14 +1707,20 @@ void execute_cmd(exarg_T *eap, CmdParseInfo *cmdinfo) eap->errmsg = NULL; (cmdnames[eap->cmdidx].cmd_func)(eap); if (eap->errmsg != NULL) { - ERROR(_(eap->errmsg)); + errormsg = _(eap->errmsg); } } + end: + if (errormsg != NULL && *errormsg != NUL) { + emsg(errormsg); + } // Undo command modifiers undo_cmdmod(eap, msg_scroll); cmdmod = save_cmdmod; - + if (eap->did_sandbox) { + sandbox--; + } #undef ERROR } diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index c4748cc00d..c5e8cfee23 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -3636,5 +3636,13 @@ describe('API', function() meths.cmd({ cmd = "update" }, {}) meths.cmd({ cmd = "buffer", count = 0 }, {}) end) + it('doesn\'t suppress errors when used in keymapping', function() + meths.exec_lua([[ + vim.keymap.set("n", "[l", + function() vim.api.nvim_cmd({ cmd = "echo", args = {"foo"} }, {}) end) + ]], {}) + feed("[l") + neq(nil, string.find(eval("v:errmsg"), "E5108:")) + end) end) end) |