Patch 9.0.0473
Problem: fullcommand() only works for the current script version.
Solution: Add an optional argument for the script version.
Files: runtime/doc/builtin.txt, src/ex_docmd.c,
src/testdir/test_cmdline.vim, src/testdir/test_vim9_builtin.vim
*** ../vim-9.0.0472/runtime/doc/builtin.txt 2022-09-12 13:37:07.066693383
+0100
--- runtime/doc/builtin.txt 2022-09-15 21:36:01.305900040 +0100
***************
*** 195,201 ****
foldtext() String line displayed for closed fold
foldtextresult({lnum}) String text for closed fold at {lnum}
foreground() Number bring the Vim window to the foreground
! fullcommand({name}) String get full command from {name}
funcref({name} [, {arglist}] [, {dict}])
Funcref reference to function {name}
function({name} [, {arglist}] [, {dict}])
--- 195,201 ----
foldtext() String line displayed for closed fold
foldtextresult({lnum}) String text for closed fold at {lnum}
foreground() Number bring the Vim window to the foreground
! fullcommand({name} [, {vim9}]) String get full command from {name}
funcref({name} [, {arglist}] [, {dict}])
Funcref reference to function {name}
function({name} [, {arglist}] [, {dict}])
***************
*** 2961,2974 ****
{only in the Win32, Motif and GTK GUI versions and the
Win32 console version}
! fullcommand({name}) *fullcommand()*
Get the full command name from a short abbreviated command
name; see |20.2| for details on command abbreviations.
The string argument {name} may start with a `:` and can
include a [range], these are skipped and not returned.
! Returns an empty string if a command doesn't exist or if it's
! ambiguous (for user-defined commands).
For example `fullcommand('s')`, `fullcommand('sub')`,
`fullcommand(':%substitute')` all return "substitute".
--- 2967,2986 ----
{only in the Win32, Motif and GTK GUI versions and the
Win32 console version}
! fullcommand({name} [, {vim9}]) *fullcommand()*
Get the full command name from a short abbreviated command
name; see |20.2| for details on command abbreviations.
The string argument {name} may start with a `:` and can
include a [range], these are skipped and not returned.
! Returns an empty string if a command doesn't exist, if it's
! 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')`,
`fullcommand(':%substitute')` all return "substitute".
*** ../vim-9.0.0472/src/ex_docmd.c 2022-09-11 15:14:00.547020055 +0100
--- src/ex_docmd.c 2022-09-15 21:39:45.441817544 +0100
***************
*** 4048,4067 ****
void
f_fullcommand(typval_T *argvars, typval_T *rettv)
{
! exarg_T ea;
! char_u *name;
! char_u *p;
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
! if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL)
return;
name = argvars[0].vval.v_string;
if (name == NULL)
return;
while (*name == ':')
name++;
name = skip_range(name, TRUE, NULL);
--- 4048,4078 ----
void
f_fullcommand(typval_T *argvars, typval_T *rettv)
{
! exarg_T ea;
! char_u *name;
! char_u *p;
! int vim9script = in_vim9script();
! int save_cmod_flags = cmdmod.cmod_flags;
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
! if (in_vim9script()
! && (check_for_string_arg(argvars, 0) == FAIL
! || check_for_opt_bool_arg(argvars, 1) == FAIL))
return;
name = argvars[0].vval.v_string;
if (name == NULL)
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 == ':')
name++;
name = skip_range(name, TRUE, NULL);
***************
*** 4069,4078 ****
ea.cmd = (*name == '2' || *name == '3') ? name + 1 : name;
ea.cmdidx = (cmdidx_T)0;
ea.addr_count = 0;
p = find_ex_command(&ea, NULL, NULL, NULL);
if (p == NULL || ea.cmdidx == CMD_SIZE)
! return;
! if (in_vim9script())
{
int res;
--- 4080,4092 ----
ea.cmd = (*name == '2' || *name == '3') ? name + 1 : name;
ea.cmdidx = (cmdidx_T)0;
ea.addr_count = 0;
+ ++emsg_silent; // don't complain about using "en" in Vim9 script
p = find_ex_command(&ea, NULL, NULL, NULL);
+ --emsg_silent;
if (p == NULL || ea.cmdidx == CMD_SIZE)
! goto theend;
!
! if (vim9script)
{
int res;
***************
*** 4081,4092 ****
--emsg_silent;
if (res == FAIL)
! return;
}
rettv->vval.v_string = vim_strsave(IS_USER_CMDIDX(ea.cmdidx)
? get_user_command_name(ea.useridx, ea.cmdidx)
: cmdnames[ea.cmdidx].cmd_name);
}
#endif
--- 4095,4108 ----
--emsg_silent;
if (res == FAIL)
! goto theend;
}
rettv->vval.v_string = vim_strsave(IS_USER_CMDIDX(ea.cmdidx)
? get_user_command_name(ea.useridx, ea.cmdidx)
: cmdnames[ea.cmdidx].cmd_name);
+ theend:
+ cmdmod.cmod_flags = save_cmod_flags;
}
#endif
*** ../vim-9.0.0472/src/testdir/test_cmdline.vim 2022-09-14
12:51:43.397770087 +0100
--- src/testdir/test_cmdline.vim 2022-09-15 21:44:29.225604862 +0100
***************
*** 662,667 ****
--- 662,670 ----
\ '3match': 'match',
\ 'aboveleft': 'aboveleft',
\ 'abo': 'aboveleft',
+ \ 'en': 'endif',
+ \ 'end': 'endif',
+ \ 'endi': 'endif',
\ 's': 'substitute',
\ '5s': 'substitute',
\ ':5s': 'substitute',
*** ../vim-9.0.0472/src/testdir/test_vim9_builtin.vim 2022-09-09
18:46:41.558660414 +0100
--- src/testdir/test_vim9_builtin.vim 2022-09-15 21:40:49.841777937 +0100
***************
*** 1530,1535 ****
--- 1530,1542 ----
assert_equal('scriptnames', fullcommand('scr'))
assert_equal('', fullcommand('scg'))
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
def Test_funcref()
*** ../vim-9.0.0472/src/version.c 2022-09-15 19:43:48.908462529 +0100
--- src/version.c 2022-09-15 21:33:33.297996123 +0100
***************
*** 705,706 ****
--- 705,708 ----
{ /* Add new patch number below this line */
+ /**/
+ 473,
/**/
--
>From "know your smileys":
:^[/ mean-smiley-with-cigarette
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20220915204630.6D76D1C0739%40moolenaar.net.