diff options
author | zeertzjq <zeertzjq@outlook.com> | 2021-12-25 06:56:33 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2021-12-25 07:42:06 +0800 |
commit | 8eff0ca6d50bf2ef0897a08f5fdbc0abed7c1266 (patch) | |
tree | f7622e277f4acf39ec8bc061cf983001ffc26176 /src | |
parent | 0d7a97224f28cdf47d7ecc80b6d300c8c67c0b29 (diff) | |
download | rneovim-8eff0ca6d50bf2ef0897a08f5fdbc0abed7c1266.tar.gz rneovim-8eff0ca6d50bf2ef0897a08f5fdbc0abed7c1266.tar.bz2 rneovim-8eff0ca6d50bf2ef0897a08f5fdbc0abed7c1266.zip |
vim-patch:8.2.2468: not easy to get the full command name from a shortened one
Problem: Not easy to get the full command name from a shortened one.
Solution: Add fullcommand(). (Martin Tournoij, closes vim/vim#7777)
https://github.com/vim/vim/commit/038e09ee7645731de0296d255aabb17603276443
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval.lua | 1 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 25 | ||||
-rw-r--r-- | src/nvim/ex_docmd.h | 1 | ||||
-rw-r--r-- | src/nvim/testdir/test_cmdline.vim | 37 |
4 files changed, 64 insertions, 0 deletions
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 9507a12a02..e445a08227 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -133,6 +133,7 @@ return { foldtext={}, foldtextresult={args=1, base=1}, foreground={}, + fullcommand={args=1, base=1}, funcref={args={1, 3}, base=1}, ['function']={args={1, 3}, base=1}, garbagecollect={args={0, 1}}, diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index ee7946fe3e..61686b48f0 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -2900,6 +2900,31 @@ int cmd_exists(const char *const name) return ea.cmdidx == CMD_SIZE ? 0 : (full ? 2 : 1); } +// "fullcommand" function +void f_fullcommand(typval_T *argvars, typval_T *rettv, FunPtr fptr) +{ + exarg_T ea; + char_u *name = argvars[0].vval.v_string; + + while (name[0] != NUL && name[0] == ':') { + name++; + } + name = skip_range(name, NULL); + + rettv->v_type = VAR_STRING; + + ea.cmd = (*name == '2' || *name == '3') ? name + 1 : name; + ea.cmdidx = (cmdidx_T)0; + char_u *p = find_command(&ea, NULL); + if (p == NULL || ea.cmdidx == CMD_SIZE) { + return; + } + + rettv->vval.v_string = vim_strsave(ea.cmdidx < 0 + ? get_user_commands(NULL, ea.useridx) + : cmdnames[ea.cmdidx].cmd_name); +} + /// This is all pretty much copied from do_one_cmd(), with all the extra stuff /// we don't need/want deleted. Maybe this could be done better if we didn't /// repeat all this stuff. The only problem is that they may not stay diff --git a/src/nvim/ex_docmd.h b/src/nvim/ex_docmd.h index 7ec4fad277..a302d4a3c5 100644 --- a/src/nvim/ex_docmd.h +++ b/src/nvim/ex_docmd.h @@ -2,6 +2,7 @@ #define NVIM_EX_DOCMD_H #include "nvim/ex_cmds_defs.h" +#include "nvim/eval/funcs.h" #include "nvim/globals.h" // flags for do_cmdline() diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 49a5386337..1672b0e840 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -467,6 +467,43 @@ func Test_getcompletion() call assert_fails('call getcompletion("abc", [])', 'E475:') endfunc +func Test_fullcommand() + let tests = { + \ '': '', + \ ':': '', + \ ':::': '', + \ ':::5': '', + \ 'not_a_cmd': '', + \ 'Check': '', + \ 'syntax': 'syntax', + \ ':syntax': 'syntax', + \ '::::syntax': 'syntax', + \ 'sy': 'syntax', + \ 'syn': 'syntax', + \ 'synt': 'syntax', + \ ':sy': 'syntax', + \ '::::sy': 'syntax', + \ 'match': 'match', + \ '2match': 'match', + \ '3match': 'match', + \ 'aboveleft': 'aboveleft', + \ 'abo': 'aboveleft', + \ 's': 'substitute', + \ '5s': 'substitute', + \ ':5s': 'substitute', + \ "'<,'>s": 'substitute', + \ ":'<,'>s": 'substitute', + \ 'CheckUni': 'CheckUnix', + \ 'CheckUnix': 'CheckUnix', + \ } + + for [in, want] in items(tests) + call assert_equal(want, fullcommand(in)) + endfor + + call assert_equal('syntax', 'syn'->fullcommand()) +endfunc + func Test_shellcmd_completion() let save_path = $PATH |