mirror of
https://github.com/vim/vim.git
synced 2025-07-26 11:04:33 -04:00
patch 9.0.0473: fullcommand() only works for the current script version
Problem: fullcommand() only works for the current script version. Solution: Add an optional argument for the script version.
This commit is contained in:
parent
a4abe514ec
commit
aa5341477c
@ -195,7 +195,7 @@ foldlevel({lnum}) Number fold level at {lnum}
|
|||||||
foldtext() String line displayed for closed fold
|
foldtext() String line displayed for closed fold
|
||||||
foldtextresult({lnum}) String text for closed fold at {lnum}
|
foldtextresult({lnum}) String text for closed fold at {lnum}
|
||||||
foreground() Number bring the Vim window to the foreground
|
foreground() Number bring the Vim window to the foreground
|
||||||
fullcommand({name}) String get full command from {name}
|
fullcommand({name} [, {vim9}]) String get full command from {name}
|
||||||
funcref({name} [, {arglist}] [, {dict}])
|
funcref({name} [, {arglist}] [, {dict}])
|
||||||
Funcref reference to function {name}
|
Funcref reference to function {name}
|
||||||
function({name} [, {arglist}] [, {dict}])
|
function({name} [, {arglist}] [, {dict}])
|
||||||
@ -2967,14 +2967,20 @@ foreground() Move the Vim window to the foreground. Useful when sent from
|
|||||||
{only in the Win32, Motif and GTK GUI versions and the
|
{only in the Win32, Motif and GTK GUI versions and the
|
||||||
Win32 console version}
|
Win32 console version}
|
||||||
|
|
||||||
fullcommand({name}) *fullcommand()*
|
fullcommand({name} [, {vim9}]) *fullcommand()*
|
||||||
Get the full command name from a short abbreviated command
|
Get the full command name from a short abbreviated command
|
||||||
name; see |20.2| for details on command abbreviations.
|
name; see |20.2| for details on command abbreviations.
|
||||||
|
|
||||||
The string argument {name} may start with a `:` and can
|
The string argument {name} may start with a `:` and can
|
||||||
include a [range], these are skipped and not returned.
|
include a [range], these are skipped and not returned.
|
||||||
Returns an empty string if a command doesn't exist or if it's
|
Returns an empty string if a command doesn't exist, if it's
|
||||||
ambiguous (for user-defined commands).
|
ambiguous (for user-defined commands) or cannot be shortened
|
||||||
|
this way. |vim9-no-shorten|
|
||||||
|
|
||||||
|
Without the {vim9} argument uses the current script version.
|
||||||
|
If {vim9} is present and FALSE then legacy script rules are
|
||||||
|
used. When {vim9} is present and TRUE then Vim9 rules are
|
||||||
|
used, e.g. "en" is not a short form of "endif".
|
||||||
|
|
||||||
For example `fullcommand('s')`, `fullcommand('sub')`,
|
For example `fullcommand('s')`, `fullcommand('sub')`,
|
||||||
`fullcommand(':%substitute')` all return "substitute".
|
`fullcommand(':%substitute')` all return "substitute".
|
||||||
|
@ -4051,17 +4051,28 @@ f_fullcommand(typval_T *argvars, typval_T *rettv)
|
|||||||
exarg_T ea;
|
exarg_T ea;
|
||||||
char_u *name;
|
char_u *name;
|
||||||
char_u *p;
|
char_u *p;
|
||||||
|
int vim9script = in_vim9script();
|
||||||
|
int save_cmod_flags = cmdmod.cmod_flags;
|
||||||
|
|
||||||
rettv->v_type = VAR_STRING;
|
rettv->v_type = VAR_STRING;
|
||||||
rettv->vval.v_string = NULL;
|
rettv->vval.v_string = NULL;
|
||||||
|
|
||||||
if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
|
if (in_vim9script()
|
||||||
|
&& (check_for_string_arg(argvars, 0) == FAIL
|
||||||
|
|| check_for_opt_bool_arg(argvars, 1) == FAIL))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
name = argvars[0].vval.v_string;
|
name = argvars[0].vval.v_string;
|
||||||
if (name == NULL)
|
if (name == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (argvars[1].v_type != VAR_UNKNOWN)
|
||||||
|
{
|
||||||
|
vim9script = tv_get_bool(&argvars[1]);
|
||||||
|
cmdmod.cmod_flags &= ~(CMOD_VIM9CMD | CMOD_LEGACY);
|
||||||
|
cmdmod.cmod_flags |= vim9script ? CMOD_VIM9CMD : CMOD_LEGACY;
|
||||||
|
}
|
||||||
|
|
||||||
while (*name == ':')
|
while (*name == ':')
|
||||||
name++;
|
name++;
|
||||||
name = skip_range(name, TRUE, NULL);
|
name = skip_range(name, TRUE, NULL);
|
||||||
@ -4069,10 +4080,13 @@ f_fullcommand(typval_T *argvars, typval_T *rettv)
|
|||||||
ea.cmd = (*name == '2' || *name == '3') ? name + 1 : name;
|
ea.cmd = (*name == '2' || *name == '3') ? name + 1 : name;
|
||||||
ea.cmdidx = (cmdidx_T)0;
|
ea.cmdidx = (cmdidx_T)0;
|
||||||
ea.addr_count = 0;
|
ea.addr_count = 0;
|
||||||
|
++emsg_silent; // don't complain about using "en" in Vim9 script
|
||||||
p = find_ex_command(&ea, NULL, NULL, NULL);
|
p = find_ex_command(&ea, NULL, NULL, NULL);
|
||||||
|
--emsg_silent;
|
||||||
if (p == NULL || ea.cmdidx == CMD_SIZE)
|
if (p == NULL || ea.cmdidx == CMD_SIZE)
|
||||||
return;
|
goto theend;
|
||||||
if (in_vim9script())
|
|
||||||
|
if (vim9script)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
@ -4081,12 +4095,14 @@ f_fullcommand(typval_T *argvars, typval_T *rettv)
|
|||||||
--emsg_silent;
|
--emsg_silent;
|
||||||
|
|
||||||
if (res == FAIL)
|
if (res == FAIL)
|
||||||
return;
|
goto theend;
|
||||||
}
|
}
|
||||||
|
|
||||||
rettv->vval.v_string = vim_strsave(IS_USER_CMDIDX(ea.cmdidx)
|
rettv->vval.v_string = vim_strsave(IS_USER_CMDIDX(ea.cmdidx)
|
||||||
? get_user_command_name(ea.useridx, ea.cmdidx)
|
? get_user_command_name(ea.useridx, ea.cmdidx)
|
||||||
: cmdnames[ea.cmdidx].cmd_name);
|
: cmdnames[ea.cmdidx].cmd_name);
|
||||||
|
theend:
|
||||||
|
cmdmod.cmod_flags = save_cmod_flags;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -662,6 +662,9 @@ func Test_fullcommand()
|
|||||||
\ '3match': 'match',
|
\ '3match': 'match',
|
||||||
\ 'aboveleft': 'aboveleft',
|
\ 'aboveleft': 'aboveleft',
|
||||||
\ 'abo': 'aboveleft',
|
\ 'abo': 'aboveleft',
|
||||||
|
\ 'en': 'endif',
|
||||||
|
\ 'end': 'endif',
|
||||||
|
\ 'endi': 'endif',
|
||||||
\ 's': 'substitute',
|
\ 's': 'substitute',
|
||||||
\ '5s': 'substitute',
|
\ '5s': 'substitute',
|
||||||
\ ':5s': 'substitute',
|
\ ':5s': 'substitute',
|
||||||
|
@ -1530,6 +1530,13 @@ def Test_fullcommand()
|
|||||||
assert_equal('scriptnames', fullcommand('scr'))
|
assert_equal('scriptnames', fullcommand('scr'))
|
||||||
assert_equal('', fullcommand('scg'))
|
assert_equal('', fullcommand('scg'))
|
||||||
fullcommand('')->assert_equal('')
|
fullcommand('')->assert_equal('')
|
||||||
|
|
||||||
|
assert_equal('', fullcommand('en'))
|
||||||
|
legacy call assert_equal('endif', fullcommand('en'))
|
||||||
|
assert_equal('endif', fullcommand('en', 0))
|
||||||
|
legacy call assert_equal('endif', fullcommand('en', 0))
|
||||||
|
assert_equal('', fullcommand('en', 1))
|
||||||
|
legacy call assert_equal('', fullcommand('en', 1))
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_funcref()
|
def Test_funcref()
|
||||||
|
@ -703,6 +703,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
473,
|
||||||
/**/
|
/**/
|
||||||
472,
|
472,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user