neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 75d9c413d49261b8f9a96f45edda0af9f0e8d947
parent a30e61eb4db55c68d91528b2d241424503d4e6d6
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Mon, 17 Apr 2023 17:44:08 +0800

fix(excmd): make :def unknown rather than unimplemented (#23150)


Diffstat:
Msrc/nvim/ex_cmds.lua | 8+-------
Msrc/nvim/ex_docmd.c | 10++++++++++
Mtest/functional/ex_cmds/excmd_spec.lua | 16+++++++++++++++-
3 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua @@ -715,14 +715,8 @@ module.cmds = { func='ex_debuggreedy', }, { - command='def', - flags=bit.bor(EXTRA, BANG, SBOXOK, CMDWIN, LOCK_OK), - addr_type='ADDR_NONE', - func='ex_ni', - }, - { command='defer', - flags=bit.bor(NEEDARG, EXTRA, NOTRLCOM, CMDWIN, LOCK_OK), + flags=bit.bor(NEEDARG, EXTRA, NOTRLCOM, SBOXOK, CMDWIN, LOCK_OK), addr_type='ADDR_NONE', func='ex_call', }, diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c @@ -2992,6 +2992,11 @@ char *find_ex_command(exarg_T *eap, int *full) } assert(eap->cmdidx >= 0); + if (len == 3 && strncmp("def", eap->cmd, 3) == 0) { + // Make :def an unknown command to avoid confusing behavior. #23149 + eap->cmdidx = CMD_SIZE; + } + for (; (int)eap->cmdidx < CMD_SIZE; eap->cmdidx = (cmdidx_T)((int)eap->cmdidx + 1)) { if (strncmp(cmdnames[(int)eap->cmdidx].cmd_name, eap->cmd, @@ -3146,6 +3151,11 @@ void f_fullcommand(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) cmdidx_T excmd_get_cmdidx(const char *cmd, size_t len) { + if (len == 3 && strncmp("def", cmd, 3) == 0) { + // Make :def an unknown command to avoid confusing behavior. #23149 + return CMD_SIZE; + } + cmdidx_T idx; if (!one_letter_cmd(cmd, &idx)) { diff --git a/test/functional/ex_cmds/excmd_spec.lua b/test/functional/ex_cmds/excmd_spec.lua @@ -2,6 +2,7 @@ local helpers = require("test.functional.helpers")(after_each) local command = helpers.command local eq = helpers.eq local clear = helpers.clear +local funcs = helpers.funcs local pcall_err = helpers.pcall_err local assert_alive = helpers.assert_alive @@ -26,5 +27,18 @@ describe('Ex cmds', function() pcall_err(command, ':bdelete 9999999999999999999999999999999999999999')) assert_alive() end) -end) + it(':def is an unknown command #23149', function() + eq('Vim:E492: Not an editor command: def', pcall_err(command, 'def')) + eq(1, funcs.exists(':d')) + eq('delete', funcs.fullcommand('d')) + eq(1, funcs.exists(':de')) + eq('delete', funcs.fullcommand('de')) + eq(0, funcs.exists(':def')) + eq('', funcs.fullcommand('def')) + eq(1, funcs.exists(':defe')) + eq('defer', funcs.fullcommand('defe')) + eq(2, funcs.exists(':defer')) + eq('defer', funcs.fullcommand('defer')) + end) +end)