Patch 8.2.2468
Problem:    Not easy to get the full command name from a shortened one.
Solution:   Add fullcommand(). (Martin Tournoij, closes #7777)
Files:      runtime/doc/eval.txt, runtime/doc/usr_41.txt, src/evalfunc.c,
            src/ex_docmd.c, src/proto/evalfunc.pro,
            src/testdir/test_cmdline.vim


*** ../vim-8.2.2467/runtime/doc/eval.txt        2021-02-01 20:14:44.562705088 
+0100
--- runtime/doc/eval.txt        2021-02-06 12:35:09.840218816 +0100
***************
*** 2562,2567 ****
--- 2562,2568 ----
  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}])
***************
*** 4902,4907 ****
--- 4903,4923 ----
                {only in the Win32, Athena, 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.
+ 
+               {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 functions).
+ 
+               For example `fullcommand('s')`, `fullcommand('sub')`,
+               `fullcommand(':%substitute')` all return "substitute".
+ 
+               Can also be used as a |method|: >
+                       GetName()->fullcommand()
+ <
                                                *funcref()*
  funcref({name} [, {arglist}] [, {dict}])
                Just like |function()|, but the returned Funcref will lookup
*** ../vim-8.2.2467/runtime/doc/usr_41.txt      2021-02-01 20:14:44.562705088 
+0100
--- runtime/doc/usr_41.txt      2021-02-06 12:32:12.436947503 +0100
***************
*** 883,888 ****
--- 883,889 ----
        getcmdtype()            return the current command-line type
        getcmdwintype()         return the current command-line window type
        getcompletion()         list of command-line completion matches
+       fullcommand()           get full command name
  
  Quickfix and location lists:                  *quickfix-functions*
        getqflist()             list of quickfix errors
*** ../vim-8.2.2467/src/evalfunc.c      2021-02-04 22:07:13.460979948 +0100
--- src/evalfunc.c      2021-02-06 12:32:12.436947503 +0100
***************
*** 978,983 ****
--- 978,985 ----
                        ret_string,         f_foldtextresult},
      {"foreground",    0, 0, 0,            NULL,
                        ret_void,           f_foreground},
+     {"fullcommand",   1, 1, FEARG_1,      arg1_string,
+                       ret_string,         f_fullcommand},
      {"funcref",               1, 3, FEARG_1,      NULL,
                        ret_func_any,       f_funcref},
      {"function",      1, 3, FEARG_1,      NULL,
*** ../vim-8.2.2467/src/ex_docmd.c      2021-02-02 21:33:48.074488746 +0100
--- src/ex_docmd.c      2021-02-06 12:36:22.375920841 +0100
***************
*** 3668,3673 ****
--- 3668,3700 ----
        return 0;       // trailing garbage
      return (ea.cmdidx == CMD_SIZE ? 0 : (full ? 2 : 1));
  }
+ 
+ /*
+  * "fullcommand" function
+  */
+     void
+ f_fullcommand(typval_T *argvars, typval_T *rettv)
+ {
+     exarg_T  ea;
+     char_u   *name = argvars[0].vval.v_string;
+     char_u   *p;
+ 
+     while (name[0] != NUL && name[0] == ':')
+       name++;
+     name = skip_range(name, TRUE, NULL);
+ 
+     rettv->v_type = VAR_STRING;
+ 
+     ea.cmd = (*name == '2' || *name == '3') ? name + 1 : name;
+     ea.cmdidx = (cmdidx_T)0;
+     p = find_ex_command(&ea, NULL, NULL, NULL);
+     if (p == NULL || ea.cmdidx == CMD_SIZE)
+       return;
+ 
+     rettv->vval.v_string = vim_strsave(IS_USER_CMDIDX(ea.cmdidx)
+                                   ? get_user_commands(NULL, ea.useridx)
+                                   : cmdnames[ea.cmdidx].cmd_name);
+ }
  #endif
  
      cmdidx_T
*** ../vim-8.2.2467/src/proto/evalfunc.pro      2021-01-16 16:06:58.126713782 
+0100
--- src/proto/evalfunc.pro      2021-02-06 12:32:12.436947503 +0100
***************
*** 23,26 ****
--- 23,27 ----
  float_T vim_round(float_T f);
  long do_searchpair(char_u *spat, char_u *mpat, char_u *epat, int dir, 
typval_T *skip, int flags, pos_T *match_pos, linenr_T lnum_stop, long 
time_limit);
  void f_string(typval_T *argvars, typval_T *rettv);
+ void f_fullcommand(typval_T *argvars, typval_T *rettv);
  /* vim: set ft=c : */
*** ../vim-8.2.2467/src/testdir/test_cmdline.vim        2021-01-30 
21:40:00.155043125 +0100
--- src/testdir/test_cmdline.vim        2021-02-06 12:32:12.436947503 +0100
***************
*** 442,447 ****
--- 442,484 ----
    call assert_fails('call getcompletion("abc", [])', 'E475:')
  endfunc
  
+ func Test_fullcommand()
+   let tests = {
+         \ '':           '',
+         \ ':':          '',
+         \ ':::':        '',
+         \ ':::5':       '',
+         \ 'not_a_cmd':  '',
+         \ 'Check':      '',
+         \ 'syntax':     'syntax',
+         \ ':syntax':    'syntax',
+         \ '::::syntax': 'syntax',
+         \ 'sy':         'syntax',
+         \ 'syn':        'syntax',
+         \ 'synt':       'syntax',
+         \ ':sy':        'syntax',
+         \ '::::sy':     'syntax',
+         \ 'match':      'match',
+         \ '2match':     'match',
+         \ '3match':     'match',
+         \ 'aboveleft':  'aboveleft',
+         \ 'abo':        'aboveleft',
+         \ 's':          'substitute',
+         \ '5s':         'substitute',
+         \ ':5s':        'substitute',
+         \ "'<,'>s":     'substitute',
+         \ ":'<,'>s":    'substitute',
+         \ 'CheckUni':   'CheckUnix',
+         \ 'CheckUnix':  'CheckUnix',
+   \ }
+ 
+   for [in, want] in items(tests)
+     call assert_equal(want, fullcommand(in))
+   endfor
+ 
+   call assert_equal('syntax', 'syn'->fullcommand())
+ endfunc
+ 
  func Test_shellcmd_completion()
    let save_path = $PATH
  
*** ../vim-8.2.2467/src/version.c       2021-02-05 21:55:47.991995220 +0100
--- src/version.c       2021-02-06 12:33:56.312520852 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2468,
  /**/

-- 
   LAUNCELOT leaps into SHOT with a mighty cry and runs the GUARD through and
   hacks him to the floor.  Blood.  Swashbuckling music (perhaps).
   LAUNCELOT races through into the castle screaming.
SECOND SENTRY: Hey!
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            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/202102061139.116BdMDf2543803%40masaka.moolenaar.net.

Raspunde prin e-mail lui