0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

Merge ec8c74e8480d77f655ca1136ff530395d457a37a into a494ce1c64a2637719a5c1339abf19ec7c48089c

This commit is contained in:
h_east 2025-07-04 23:21:30 +00:00 committed by GitHub
commit 2ddaca9348
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 81 additions and 56 deletions

View File

@ -1,4 +1,4 @@
*builtin.txt* For Vim version 9.1. Last change: 2025 Jul 03 *builtin.txt* For Vim version 9.1. Last change: 2025 Jul 04
VIM REFERENCE MANUAL by Bram Moolenaar VIM REFERENCE MANUAL by Bram Moolenaar
@ -238,8 +238,8 @@ getcharsearch() Dict last character search
getcharstr([{expr} [, {opts}]]) String get one character from the user getcharstr([{expr} [, {opts}]]) String get one character from the user
getcmdcomplpat() String return the completion pattern of the getcmdcomplpat() String return the completion pattern of the
current command-line completion current command-line completion
getcmdcompltype({pat}) String return the type of command-line getcmdcompltype() String return the type of the current
completion command-line completion
getcmdline() String return the current command-line input getcmdline() String return the current command-line input
getcmdpos() Number return cursor position in command-line getcmdpos() Number return cursor position in command-line
getcmdprompt() String return the current command-line prompt getcmdprompt() String return the current command-line prompt
@ -249,6 +249,8 @@ getcmdtype() String return current command-line type
getcmdwintype() String return current command-line window type getcmdwintype() String return current command-line window type
getcompletion({pat}, {type} [, {filtered}]) getcompletion({pat}, {type} [, {filtered}])
List list of cmdline completion matches List list of cmdline completion matches
getcompletiontype({pat}) String return the type of the command-line
completion using {pat}
getcurpos([{winnr}]) List position of the cursor getcurpos([{winnr}]) List position of the cursor
getcursorcharpos([{winnr}]) List character position of the cursor getcursorcharpos([{winnr}]) List character position of the cursor
getcwd([{winnr} [, {tabnr}]]) String get the current working directory getcwd([{winnr} [, {tabnr}]]) String get the current working directory
@ -4201,16 +4203,18 @@ getcmdcomplpat() *getcmdcomplpat()*
Return type: |String| Return type: |String|
getcmdcompltype([{pat}]) *getcmdcompltype()* getcmdcompltype() *getcmdcompltype()*
Return the type of command-line completion using {pat}. Return the type of the current command-line completion.
If {pat} is omited, only works when the command line is being Only works when the command line is being edited, thus
edited, thus requires use of |c_CTRL-\_e| or |c_CTRL-R_=|. requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
See |:command-completion| for the return string. See |:command-completion| for the return string.
Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|, Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
|getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|. |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|.
Returns an empty string when completion is not defined. Returns an empty string when completion is not defined.
To get the type of the command-line completion for the
specified string, use |getcompletiontype()|.
Return type: |String| Return type: |String|
@ -4369,6 +4373,15 @@ getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
< <
Return type: list<string> Return type: list<string>
getcompletiontype({pat}) *getcompletiontype()*
Return the type of the command-line completion using {pat}.
When no corresponding completion type is found, an empty
string is returned.
To get the current command-line completion type, use
|getcmdcompltype()|.
Return type: |String|
*getcurpos()* *getcurpos()*
getcurpos([{winid}]) getcurpos([{winid}])
Get the position of the cursor. This is like getpos('.'), but Get the position of the cursor. This is like getpos('.'), but

View File

@ -7976,6 +7976,7 @@ getcmdscreenpos() builtin.txt /*getcmdscreenpos()*
getcmdtype() builtin.txt /*getcmdtype()* getcmdtype() builtin.txt /*getcmdtype()*
getcmdwintype() builtin.txt /*getcmdwintype()* getcmdwintype() builtin.txt /*getcmdwintype()*
getcompletion() builtin.txt /*getcompletion()* getcompletion() builtin.txt /*getcompletion()*
getcompletiontype() builtin.txt /*getcompletiontype()*
getcurpos() builtin.txt /*getcurpos()* getcurpos() builtin.txt /*getcurpos()*
getcursorcharpos() builtin.txt /*getcursorcharpos()* getcursorcharpos() builtin.txt /*getcursorcharpos()*
getcwd() builtin.txt /*getcwd()* getcwd() builtin.txt /*getcwd()*

View File

@ -1,4 +1,4 @@
*usr_41.txt* For Vim version 9.1. Last change: 2025 Jul 03 *usr_41.txt* For Vim version 9.1. Last change: 2025 Jul 04
VIM USER MANUAL - by Bram Moolenaar VIM USER MANUAL - by Bram Moolenaar
@ -1100,7 +1100,8 @@ Buffers, windows and the argument list:
Command line: *command-line-functions* Command line: *command-line-functions*
getcmdcomplpat() get completion pattern of the current command getcmdcomplpat() get completion pattern of the current command
line line
getcmdcompltype() get the type of the command line completion getcmdcompltype() get the type of the current command line
completion
getcmdline() get the current command line input getcmdline() get the current command line input
getcmdprompt() get the current command line prompt getcmdprompt() get the current command line prompt
getcmdpos() get position of the cursor in the command line getcmdpos() get position of the cursor in the command line
@ -1111,6 +1112,8 @@ Command line: *command-line-functions*
getcmdtype() return the current command-line type getcmdtype() return the current command-line type
getcmdwintype() return the current command-line window type getcmdwintype() return the current command-line window type
getcompletion() list of command-line completion matches getcompletion() list of command-line completion matches
getcompletiontype() get the type of the command-line completion
for specified string
fullcommand() get full command name fullcommand() get full command name
cmdcomplete_info() get command-line completion information cmdcomplete_info() get command-line completion information

View File

@ -1,4 +1,4 @@
*version9.txt* For Vim version 9.1. Last change: 2025 Jul 03 *version9.txt* For Vim version 9.1. Last change: 2025 Jun 28
VIM REFERENCE MANUAL by Bram Moolenaar VIM REFERENCE MANUAL by Bram Moolenaar
@ -41607,8 +41607,6 @@ Completion: ~
- allow to complete directories from 'cdpath' for |:cd| and similar commands, - allow to complete directories from 'cdpath' for |:cd| and similar commands,
add the "cd_in_path" completion type for e.g. |:command-complete| and add the "cd_in_path" completion type for e.g. |:command-complete| and
|getcompletion()| |getcompletion()|
- |getcompletion()| now accepts a pat and returns the completion type for the
{pat} argument
- allow to complete shell commands and files using the new shellcmdline - allow to complete shell commands and files using the new shellcmdline
completion type using |:command-complete| and |getcmdcomplpat()| completion type using |:command-complete| and |getcmdcomplpat()|
- allow to specify additional attributes in the completion menu (allows to - allow to specify additional attributes in the completion menu (allows to

View File

@ -4556,6 +4556,35 @@ f_getcompletion(typval_T *argvars, typval_T *rettv)
ExpandCleanup(&xpc); ExpandCleanup(&xpc);
} }
/*
* "getcompletiontype()" function
*/
void
f_getcompletiontype(typval_T *argvars, typval_T *rettv)
{
char_u *pat;
expand_T xpc;
int cmdline_len;
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
if (check_for_string_arg(argvars, 0) == FAIL)
return;
pat = tv_get_string(&argvars[0]);
ExpandInit(&xpc);
cmdline_len = (int)STRLEN(pat);
set_cmd_context(&xpc, pat, cmdline_len, cmdline_len, FALSE);
xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
xpc.xp_col = cmdline_len;
rettv->vval.v_string = get_cmdline_completion(&xpc);
ExpandCleanup(&xpc);
}
/* /*
* "cmdcomplete_info()" function * "cmdcomplete_info()" function
*/ */

View File

@ -2264,7 +2264,7 @@ static funcentry_T global_functions[] =
ret_string, f_getcharstr}, ret_string, f_getcharstr},
{"getcmdcomplpat", 0, 0, 0, NULL, {"getcmdcomplpat", 0, 0, 0, NULL,
ret_string, f_getcmdcomplpat}, ret_string, f_getcmdcomplpat},
{"getcmdcompltype", 0, 1, FEARG_1, NULL, {"getcmdcompltype", 0, 0, 0, NULL,
ret_string, f_getcmdcompltype}, ret_string, f_getcmdcompltype},
{"getcmdline", 0, 0, 0, NULL, {"getcmdline", 0, 0, 0, NULL,
ret_string, f_getcmdline}, ret_string, f_getcmdline},
@ -2280,6 +2280,8 @@ static funcentry_T global_functions[] =
ret_string, f_getcmdwintype}, ret_string, f_getcmdwintype},
{"getcompletion", 2, 3, FEARG_1, arg3_string_string_bool, {"getcompletion", 2, 3, FEARG_1, arg3_string_string_bool,
ret_list_string, f_getcompletion}, ret_list_string, f_getcompletion},
{"getcompletiontype", 1, 1, FEARG_1, arg1_string,
ret_string, f_getcompletiontype},
{"getcurpos", 0, 1, FEARG_1, arg1_number, {"getcurpos", 0, 1, FEARG_1, arg1_number,
ret_list_number, f_getcurpos}, ret_list_number, f_getcurpos},
{"getcursorcharpos", 0, 1, FEARG_1, arg1_number, {"getcursorcharpos", 0, 1, FEARG_1, arg1_number,

View File

@ -4303,9 +4303,9 @@ get_cmdline_completion_pattern(void)
} }
/* /*
* Get the current command-line completion type. * Get the command-line completion type.
*/ */
static char_u * char_u *
get_cmdline_completion(expand_T *xpc) get_cmdline_completion(expand_T *xpc)
{ {
int xp_context; int xp_context;
@ -4354,40 +4354,16 @@ f_getcmdcomplpat(typval_T *argvars UNUSED, typval_T *rettv)
void void
f_getcmdcompltype(typval_T *argvars UNUSED, typval_T *rettv) f_getcmdcompltype(typval_T *argvars UNUSED, typval_T *rettv)
{ {
if (check_for_opt_string_arg(argvars, 0) == FAIL)
return;
rettv->v_type = VAR_STRING;
if (argvars[0].v_type != VAR_UNKNOWN)
{
char_u *pat;
expand_T xpc;
int cmdline_len;
pat = tv_get_string(&argvars[0]);
ExpandInit(&xpc);
cmdline_len = (int)STRLEN(pat);
set_cmd_context(&xpc, pat, cmdline_len, cmdline_len, FALSE);
xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern);
xpc.xp_col = cmdline_len;
rettv->v_type = VAR_STRING;
rettv->vval.v_string = get_cmdline_completion(&xpc);
ExpandCleanup(&xpc);
}
else
{
cmdline_info_T *p; cmdline_info_T *p;
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
p = get_ccline_ptr(); p = get_ccline_ptr();
if (cmdline_star > 0 || p == NULL || p->xpc == NULL) if (cmdline_star > 0 || p == NULL || p->xpc == NULL)
return; return;
rettv->vval.v_string = get_cmdline_completion(p->xpc); rettv->vval.v_string = get_cmdline_completion(p->xpc);
}
} }
/* /*

View File

@ -24,5 +24,6 @@ int wildmenu_translate_key(cmdline_info_T *cclp, int key, expand_T *xp, int did_
int wildmenu_process_key(cmdline_info_T *cclp, int key, expand_T *xp); int wildmenu_process_key(cmdline_info_T *cclp, int key, expand_T *xp);
void wildmenu_cleanup(cmdline_info_T *cclp); void wildmenu_cleanup(cmdline_info_T *cclp);
void f_getcompletion(typval_T *argvars, typval_T *rettv); void f_getcompletion(typval_T *argvars, typval_T *rettv);
void f_getcompletiontype(typval_T *argvars, typval_T *rettv);
void f_cmdcomplete_info(typval_T *argvars UNUSED, typval_T *rettv); void f_cmdcomplete_info(typval_T *argvars UNUSED, typval_T *rettv);
/* vim: set ft=c : */ /* vim: set ft=c : */

View File

@ -30,6 +30,7 @@ char_u *vim_strsave_fnameescape(char_u *fname, int what);
void escape_fname(char_u **pp); void escape_fname(char_u **pp);
void tilde_replace(char_u *orig_pat, int num_files, char_u **files); void tilde_replace(char_u *orig_pat, int num_files, char_u **files);
cmdline_info_T *get_cmdline_info(void); cmdline_info_T *get_cmdline_info(void);
char_u *get_cmdline_completion(expand_T *xpc);
void f_getcmdcomplpat(typval_T *argvars, typval_T *rettv); void f_getcmdcomplpat(typval_T *argvars, typval_T *rettv);
void f_getcmdcompltype(typval_T *argvars, typval_T *rettv); void f_getcmdcompltype(typval_T *argvars, typval_T *rettv);
void f_getcmdline(typval_T *argvars, typval_T *rettv); void f_getcmdline(typval_T *argvars, typval_T *rettv);

View File

@ -877,6 +877,17 @@ func Test_getcompletion()
call assert_fails('call getcompletion("abc", [])', 'E1174:') call assert_fails('call getcompletion("abc", [])', 'E1174:')
endfunc endfunc
func Test_getcompletiontype()
call assert_fails('call getcompletiontype()', 'E119:')
call assert_fails('call getcompletiontype({})', 'E1174:')
call assert_equal(getcompletiontype(''), 'command')
call assert_equal(getcompletiontype('dummy '), '')
call assert_equal(getcompletiontype('cd '), 'dir_in_path')
call assert_equal(getcompletiontype('let v:n'), 'var')
call assert_equal(getcompletiontype('call tag'), 'function')
call assert_equal(getcompletiontype('help '), 'help')
endfunc
func Test_multibyte_expression() func Test_multibyte_expression()
" Get a dialog in the GUI " Get a dialog in the GUI
CheckNotGui CheckNotGui
@ -4589,14 +4600,4 @@ func Test_range_complete()
set wildcharm=0 set wildcharm=0
endfunc endfunc
func Test_getcmdcompltype_with_pat()
call assert_fails('call getcmdcompltype({})', 'E1174:')
call assert_equal(getcmdcompltype(''), 'command')
call assert_equal(getcmdcompltype('dummy '), '')
call assert_equal(getcmdcompltype('cd '), 'dir_in_path')
call assert_equal(getcmdcompltype('let v:n'), 'var')
call assert_equal(getcmdcompltype('call tag'), 'function')
call assert_equal(getcmdcompltype('help '), 'help')
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab