# HG changeset patch # User Christian Brabandt # Date 1718736303 -7200 # Node ID d99ee25b65f459301cbf97c2cdbe7c9ba3c20c76 # Parent 6681c059d628aa06aacb41cb3b4b9a96b6de2841 patch 9.1.0498: getcmdcompltype() interferes with cmdline completion Commit: https://github.com/vim/vim/commit/a821b609f9bb9daef032fe1cb8fb95995822e367 Author: zeertzjq Date: Tue Jun 18 20:31:08 2024 +0200 patch 9.1.0498: getcmdcompltype() interferes with cmdline completion Problem: getcmdcompltype() interferes with cmdline completion. Solution: Don't set expand context when it's already set. (zeertzjq) closes: #15036 Signed-off-by: zeertzjq Signed-off-by: Christian Brabandt diff --git a/src/ex_getln.c b/src/ex_getln.c --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -4176,6 +4176,7 @@ get_cmdline_completion(void) { cmdline_info_T *p; char_u *buffer; + int xp_context; if (cmdline_star > 0) return NULL; @@ -4184,15 +4185,21 @@ get_cmdline_completion(void) if (p == NULL || p->xpc == NULL) return NULL; - set_expand_context(p->xpc); - if (p->xpc->xp_context == EXPAND_UNSUCCESSFUL) + xp_context = p->xpc->xp_context; + if (xp_context == EXPAND_NOTHING) + { + set_expand_context(p->xpc); + xp_context = p->xpc->xp_context; + p->xpc->xp_context = EXPAND_NOTHING; + } + if (xp_context == EXPAND_UNSUCCESSFUL) return NULL; - char_u *cmd_compl = cmdcomplete_type_to_str(p->xpc->xp_context); + char_u *cmd_compl = cmdcomplete_type_to_str(xp_context); if (cmd_compl == NULL) return NULL; - if (p->xpc->xp_context == EXPAND_USER_LIST || p->xpc->xp_context == EXPAND_USER_DEFINED) + if (xp_context == EXPAND_USER_LIST || xp_context == EXPAND_USER_DEFINED) { buffer = alloc(STRLEN(cmd_compl) + STRLEN(p->xpc->xp_arg) + 2); if (buffer == NULL) diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim --- a/src/testdir/test_cmdline.vim +++ b/src/testdir/test_cmdline.vim @@ -3612,7 +3612,7 @@ func Test_cmdline_complete_bang_cmd_argu endfunc func Call_cmd_funcs() - return string([getcmdpos(), getcmdscreenpos(), getcmdcompltype()]) + return [getcmdpos(), getcmdscreenpos(), getcmdcompltype()] endfunc func Test_screenpos_and_completion() @@ -3620,13 +3620,24 @@ func Test_screenpos_and_completion() call assert_equal(0, getcmdscreenpos()) call assert_equal('', getcmdcompltype()) - cnoremap string([getcmdpos(), getcmdscreenpos(), getcmdcompltype()]) + cnoremap string(Call_cmd_funcs()) call feedkeys(":let a\\\"\", "xt") call assert_equal("\"let a[6, 7, 'var']", @:) call feedkeys(":quit \\\"\", "xt") call assert_equal("\"quit [6, 7, '']", @:) call feedkeys(":nosuchcommand \\\"\", "xt") call assert_equal("\"nosuchcommand [15, 16, '']", @:) + + " Check that getcmdcompltype() doesn't interfere with cmdline completion. + let g:results = [] + cnoremap let g:results += [[getcmdline()] + Call_cmd_funcs()] + call feedkeys(":sign un\\\\\\\", "xt") + call assert_equal([ + \ ['sign undefine', 14, 15, 'sign'], + \ ['sign unplace', 13, 14, 'sign'], + \ ['sign un', 8, 9, 'sign']], g:results) + + unlet g:results cunmap endfunc diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -705,6 +705,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 498, +/**/ 497, /**/ 496,