Merge pull request #35252 from zeertzjq/vim-9.1.1608

vim-patch:9.1.{0748,1608}
This commit is contained in:
zeertzjq
2025-08-09 08:25:09 +08:00
committed by GitHub
5 changed files with 101 additions and 2 deletions

View File

@@ -2020,6 +2020,7 @@ static const char *set_context_by_cmdname(const char *cmd, cmdidx_T cmdidx, expa
case CMD_tab: case CMD_tab:
case CMD_tabdo: case CMD_tabdo:
case CMD_topleft: case CMD_topleft:
case CMD_unsilent:
case CMD_verbose: case CMD_verbose:
case CMD_vertical: case CMD_vertical:
case CMD_windo: case CMD_windo:

View File

@@ -3025,13 +3025,16 @@ static void append_command(const char *cmd)
} }
/// Return true and set "*idx" if "p" points to a one letter command. /// Return true and set "*idx" if "p" points to a one letter command.
/// - The 'k' command can directly be followed by any character. /// - The 'k' command can directly be followed by any character
/// but :keepa[lt] is another command, as are :keepj[umps],
/// :kee[pmarks] and :keepp[atterns].
/// - The 's' command can be followed directly by 'c', 'g', 'i', 'I' or 'r' /// - The 's' command can be followed directly by 'c', 'g', 'i', 'I' or 'r'
/// but :sre[wind] is another command, as are :scr[iptnames], /// but :sre[wind] is another command, as are :scr[iptnames],
/// :scs[cope], :sim[alt], :sig[ns] and :sil[ent]. /// :scs[cope], :sim[alt], :sig[ns] and :sil[ent].
static int one_letter_cmd(const char *p, cmdidx_T *idx) static int one_letter_cmd(const char *p, cmdidx_T *idx)
{ {
if (*p == 'k') { if (p[0] == 'k'
&& (p[1] != 'e' || (p[1] == 'e' && p[2] != 'e'))) {
*idx = CMD_k; *idx = CMD_k;
return true; return true;
} }
@@ -3064,6 +3067,9 @@ char *find_ex_command(exarg_T *eap, int *full)
char *p = eap->cmd; char *p = eap->cmd;
if (one_letter_cmd(p, &eap->cmdidx)) { if (one_letter_cmd(p, &eap->cmdidx)) {
p++; p++;
if (full != NULL) {
*full = true;
}
} else { } else {
while (ASCII_ISALPHA(*p)) { while (ASCII_ISALPHA(*p)) {
p++; p++;

View File

@@ -1244,6 +1244,10 @@ func Test_cmdline_complete_various()
call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt') call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
call assert_equal("\"ka\<C-A>", @:) call assert_equal("\"ka\<C-A>", @:)
" completion for :keepmarks command
call feedkeys(":kee edi\<C-A>\<C-B>\"\<CR>", 'xt')
call assert_equal("\"kee edit", @:)
" completion for short version of the :s command " completion for short version of the :s command
call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt') call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
call assert_equal("\"sI \<C-A>", @:) call assert_equal("\"sI \<C-A>", @:)
@@ -4350,6 +4354,28 @@ func Test_term_option()
let &cpo = _cpo let &cpo = _cpo
endfunc endfunc
func Test_ex_command_completion()
" required for :*
" set cpo+=*
let list = filter(getcompletion('', 'command'), 'exists(":" . v:val) == 0')
" :++ and :-- are only valid in Vim9 script context, so they can be ignored
" call assert_equal(['++', '--'], sort(list))
call assert_equal([], sort(list))
call assert_equal(2, exists(':k'))
call assert_equal(0, exists(':ke'))
call assert_equal(1, exists(':kee'))
call assert_equal(1, exists(':keep'))
call assert_equal(1, exists(':keepm'))
call assert_equal(1, exists(':keepma'))
call assert_equal(1, exists(':keepmar'))
call assert_equal(1, exists(':keepmark'))
call assert_equal(2, exists(':keepmarks'))
call assert_equal(2, exists(':keepalt'))
call assert_equal(2, exists(':keepjumps'))
call assert_equal(2, exists(':keeppatterns'))
set cpo-=*
endfunc
func Test_cd_bslash_completion_windows() func Test_cd_bslash_completion_windows()
CheckMSWindows CheckMSWindows
let save_shellslash = &shellslash let save_shellslash = &shellslash

View File

@@ -0,0 +1,59 @@
" Test for all command modifiers in
let s:luaeval_cmdmods =<< trim END
vim.iter(loadfile('../../../src/nvim/ex_cmds.lua')()):map(function(cmd)
if cmd.func == 'ex_wrongmodifier' or cmd.command == 'hide' then
return cmd.command
else
return nil
end
end):totable()
END
let s:cmdmods = []
func s:get_cmdmods()
if empty(s:cmdmods)
let s:cmdmods = luaeval(s:luaeval_cmdmods->join("\n"))
endif
return s:cmdmods
endfunc
func Test_keep_cmdmods_names()
call assert_equal('k', fullcommand(':k'))
call assert_equal('k', fullcommand(':ke'))
call assert_equal('keepmarks', fullcommand(':kee'))
call assert_equal('keepmarks', fullcommand(':keep'))
call assert_equal('keepmarks', fullcommand(':keepm'))
call assert_equal('keepmarks', fullcommand(':keepma'))
call assert_equal('keepmarks', fullcommand(':keepmar'))
call assert_equal('keepmarks', fullcommand(':keepmark'))
call assert_equal('keepmarks', fullcommand(':keepmarks'))
call assert_equal('keepalt', fullcommand(':keepa'))
call assert_equal('keepalt', fullcommand(':keepal'))
call assert_equal('keepalt', fullcommand(':keepalt'))
call assert_equal('keepjumps', fullcommand(':keepj'))
call assert_equal('keepjumps', fullcommand(':keepju'))
call assert_equal('keepjumps', fullcommand(':keepjum'))
call assert_equal('keepjumps', fullcommand(':keepjump'))
call assert_equal('keepjumps', fullcommand(':keepjumps'))
call assert_equal('keeppatterns', fullcommand(':keepp'))
call assert_equal('keeppatterns', fullcommand(':keeppa'))
call assert_equal('keeppatterns', fullcommand(':keeppat'))
call assert_equal('keeppatterns', fullcommand(':keeppatt'))
call assert_equal('keeppatterns', fullcommand(':keeppatte'))
call assert_equal('keeppatterns', fullcommand(':keeppatter'))
call assert_equal('keeppatterns', fullcommand(':keeppattern'))
call assert_equal('keeppatterns', fullcommand(':keeppatterns'))
endfunc
func Test_cmdmod_completion()
for mod in s:get_cmdmods()
let cmd = $'{mod} ed'
if mod == 'filter'
let cmd = $'{mod} /pattern/ ed'
endif
call assert_equal('edit', getcompletion(cmd, 'cmdline')[0])
endfor
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@@ -105,6 +105,13 @@ func Test_exists()
" Internal command with a count " Internal command with a count
call assert_equal(0, exists(':3buffer')) call assert_equal(0, exists(':3buffer'))
" Valid internal command (full match)
call assert_equal(2, exists(':k'))
" Non-existing internal command (':k' with arg 'e')
call assert_equal(0, exists(':ke'))
" Valid internal command (partial match)
call assert_equal(1, exists(':kee'))
" User defined command (full match) " User defined command (full match)
command! MyCmd :echo 'My command' command! MyCmd :echo 'My command'
call assert_equal(2, exists(':MyCmd')) call assert_equal(2, exists(':MyCmd'))