Patch 8.2.4416
Problem:    Vim9: using a script-local function requires using "s:" when
            setting 'completefunc'.
Solution:   Do not require "s:" in Vim9 script. (closes #9796)
Files:      runtime/doc/options.txt, src/userfunc.c,
            src/testdir/test_ins_complete.vim


*** ../vim-8.2.4415/runtime/doc/options.txt     2022-02-08 12:07:41.831496906 
+0000
--- runtime/doc/options.txt     2022-02-18 17:49:07.241531428 +0000
***************
*** 383,394 ****
        set opfunc=function('MyOpFunc')
        set opfunc=funcref('MyOpFunc')
        set opfunc={a\ ->\ MyOpFunc(a)}
!       " set using a funcref variable
        let Fn = function('MyTagFunc')
!       let &tagfunc = string(Fn)
!       " set using a lambda expression
        let &tagfunc = {t -> MyTagFunc(t)}
!       " set using a variable with lambda expression
        let L = {a, b, c -> MyTagFunc(a, b , c)}
        let &tagfunc = L
  
--- 383,404 ----
        set opfunc=function('MyOpFunc')
        set opfunc=funcref('MyOpFunc')
        set opfunc={a\ ->\ MyOpFunc(a)}
! 
! Set to a script-local function: >
!       set opfunc=s:MyLocalFunc
!       set opfunc=<SID>MyLocalFunc
! In |Vim9| script the "s:" and "<SID>" can be omitted if the function exists in
! the script: >
!       set opfunc=MyLocalFunc
! 
! Set using a funcref variable: >
        let Fn = function('MyTagFunc')
!       let &tagfunc = Fn
! 
! Set using a lambda expression: >
        let &tagfunc = {t -> MyTagFunc(t)}
! 
! Set using a variable with lambda expression: >
        let L = {a, b, c -> MyTagFunc(a, b , c)}
        let &tagfunc = L
  
*** ../vim-8.2.4415/src/userfunc.c      2022-02-13 21:51:02.392484124 +0000
--- src/userfunc.c      2022-02-18 17:35:13.430400788 +0000
***************
*** 4024,4039 ****
  get_scriptlocal_funcname(char_u *funcname)
  {
      char      sid_buf[25];
!     int               off;
      char_u    *newname;
  
      if (funcname == NULL)
        return NULL;
  
      if (STRNCMP(funcname, "s:", 2) != 0
                && STRNCMP(funcname, "<SID>", 5) != 0)
!       // The function name is not a script-local function name
!       return NULL;
  
      if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
      {
--- 4024,4052 ----
  get_scriptlocal_funcname(char_u *funcname)
  {
      char      sid_buf[25];
!     int               off = *funcname == 's' ? 2 : 5;
      char_u    *newname;
+     char_u    *p = funcname;
  
      if (funcname == NULL)
        return NULL;
  
      if (STRNCMP(funcname, "s:", 2) != 0
                && STRNCMP(funcname, "<SID>", 5) != 0)
!     {
!       ufunc_T     *ufunc;
! 
!       // The function name does not have a script-local prefix.  Try finding
!       // it when in a Vim9 script and there is no "g:" prefix.
!       if (!in_vim9script() || STRNCMP(funcname, "g:", 2) == 0)
!           return NULL;
!       ufunc = find_func(funcname, FALSE);
!       if (ufunc == NULL || func_is_global(ufunc)
!                             || (p = vim_strchr(ufunc->uf_name, '_')) == NULL)
!           return NULL;
!       ++p;
!       off = 0;
!     }
  
      if (!SCRIPT_ID_VALID(current_sctx.sc_sid))
      {
***************
*** 4043,4054 ****
      // Expand s: prefix into <SNR>nr_<name>
      vim_snprintf(sid_buf, sizeof(sid_buf), "<SNR>%ld_",
            (long)current_sctx.sc_sid);
!     off = *funcname == 's' ? 2 : 5;
!     newname = alloc(STRLEN(sid_buf) + STRLEN(funcname + off) + 1);
      if (newname == NULL)
        return NULL;
      STRCPY(newname, sid_buf);
!     STRCAT(newname, funcname + off);
  
      return newname;
  }
--- 4056,4066 ----
      // Expand s: prefix into <SNR>nr_<name>
      vim_snprintf(sid_buf, sizeof(sid_buf), "<SNR>%ld_",
            (long)current_sctx.sc_sid);
!     newname = alloc(STRLEN(sid_buf) + STRLEN(p + off) + 1);
      if (newname == NULL)
        return NULL;
      STRCPY(newname, sid_buf);
!     STRCAT(newname, p + off);
  
      return newname;
  }
*** ../vim-8.2.4415/src/testdir/test_ins_complete.vim   2022-02-12 
20:34:47.084825186 +0000
--- src/testdir/test_ins_complete.vim   2022-02-18 17:43:44.913927662 +0000
***************
*** 1455,1460 ****
--- 1455,1477 ----
    bw!
    delfunc s:CompleteFunc3
  
+   " In Vim9 script s: can be omitted
+   let lines =<< trim END
+       vim9script
+       var CompleteFunc4Args = []
+       def CompleteFunc4(findstart: bool, base: string): any
+         add(CompleteFunc4Args, [findstart, base])
+         return findstart ? 0 : []
+       enddef
+       set completefunc=CompleteFunc4
+       new
+       setline(1, 'script1')
+       feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
+       assert_equal([[1, ''], [0, 'script1']], CompleteFunc4Args)
+       bw!
+   END
+   call v9.CheckScriptSuccess(lines)
+ 
    " invalid return value
    let &completefunc = {a -> 'abc'}
    call feedkeys("A\<C-X>\<C-U>\<Esc>", 'x')
*** ../vim-8.2.4415/src/version.c       2022-02-18 13:56:34.630118479 +0000
--- src/version.c       2022-02-18 17:23:37.446348394 +0000
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     4416,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
72. Somebody at IRC just mentioned a way to obtain full motion video without
    a PC using a wireless protocol called NTSC, you wonder how you never
    heard about it

 /// 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/20220218175117.C2E601C0D2C%40moolenaar.net.

Raspunde prin e-mail lui