Patch 8.2.2426
Problem:    Allowing 'completefunc' to switch windows causes trouble.
Solution:   use "textwinlock" instead of "textlock".
Files:      src/insexpand.c, src/testdir/test_ins_complete.vim,
            src/testdir/test_popup.vim


*** ../vim-8.2.2425/src/insexpand.c     2020-12-27 18:03:18.688859822 +0100
--- src/insexpand.c     2021-01-29 19:55:26.090343143 +0100
***************
*** 2218,2226 ****
      pos = curwin->w_cursor;
      curwin_save = curwin;
      curbuf_save = curbuf;
!     // Lock the text to avoid weird things from happening.  Do allow switching
!     // to another window temporarily.
!     ++textlock;
  
      // Call a function, which returns a list or dict.
      if (call_vim_function(funcname, 2, args, &rettv) == OK)
--- 2218,2227 ----
      pos = curwin->w_cursor;
      curwin_save = curwin;
      curbuf_save = curbuf;
!     // Lock the text to avoid weird things from happening.  Also disallow
!     // switching to another window, it should not be needed and may end up in
!     // Insert mode in another buffer.
!     ++textwinlock;
  
      // Call a function, which returns a list or dict.
      if (call_vim_function(funcname, 2, args, &rettv) == OK)
***************
*** 2243,2249 ****
                break;
        }
      }
!     --textlock;
  
      if (curwin_save != curwin || curbuf_save != curbuf)
      {
--- 2244,2250 ----
                break;
        }
      }
!     --textwinlock;
  
      if (curwin_save != curwin || curbuf_save != curbuf)
      {
***************
*** 3226,3232 ****
        return -1;
  
      if (compl_leader != NULL
!                       && (compl_shown_match->cp_flags & CP_ORIGINAL_TEXT) == 
0)
      {
        // Set "compl_shown_match" to the actually shown match, it may differ
        // when "compl_leader" is used to omit some of the matches.
--- 3227,3233 ----
        return -1;
  
      if (compl_leader != NULL
!                     && (compl_shown_match->cp_flags & CP_ORIGINAL_TEXT) == 0)
      {
        // Set "compl_shown_match" to the actually shown match, it may differ
        // when "compl_leader" is used to omit some of the matches.
*** ../vim-8.2.2425/src/testdir/test_ins_complete.vim   2021-01-28 
18:34:27.783630494 +0100
--- src/testdir/test_ins_complete.vim   2021-01-29 19:58:29.401677250 +0100
***************
*** 562,592 ****
    call setline(1, ['', 'abcd', ''])
    call assert_fails('exe "normal 2G$a\<C-X>\<C-U>"', 'E578:')
  
-   set completefunc&
-   delfunc CompleteFunc
-   delfunc CompleteFunc2
-   close!
- endfunc
- 
- func Test_completefunc_error_not_asan()
-   " The following test causes an ASAN failure.
-   CheckNotAsan
- 
    " Jump to a different window from the complete function
!   func! CompleteFunc(findstart, base)
      if a:findstart == 1
        return col('.') - 1
      endif
      wincmd p
      return ['a', 'b']
    endfunc
!   set completefunc=CompleteFunc
    new
!   call assert_fails('exe "normal a\<C-X>\<C-U>"', 'E839:')
    close!
  
    set completefunc&
    delfunc CompleteFunc
  endfunc
  
  " Test for returning non-string values from 'completefunc'
--- 562,585 ----
    call setline(1, ['', 'abcd', ''])
    call assert_fails('exe "normal 2G$a\<C-X>\<C-U>"', 'E578:')
  
    " Jump to a different window from the complete function
!   func CompleteFunc3(findstart, base)
      if a:findstart == 1
        return col('.') - 1
      endif
      wincmd p
      return ['a', 'b']
    endfunc
!   set completefunc=CompleteFunc3
    new
!   call assert_fails('exe "normal a\<C-X>\<C-U>"', 'E565:')
    close!
  
    set completefunc&
    delfunc CompleteFunc
+   delfunc CompleteFunc2
+   delfunc CompleteFunc3
+   close!
  endfunc
  
  " Test for returning non-string values from 'completefunc'
*** ../vim-8.2.2425/src/testdir/test_popup.vim  2020-12-24 18:38:37.181858419 
+0100
--- src/testdir/test_popup.vim  2021-01-29 21:03:16.416179578 +0100
***************
*** 342,348 ****
    setlocal completefunc=DummyCompleteOne
    call setline(1, 'one')
    /^one
!   call assert_fails('call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")', 
'E578:')
    call assert_equal(winid, win_getid())
    call assert_equal('onedef', getline(1))
    q!
--- 342,348 ----
    setlocal completefunc=DummyCompleteOne
    call setline(1, 'one')
    /^one
!   call assert_fails('call feedkeys("A\<C-X>\<C-U>\<C-N>\<Esc>", "x")', 
'E565:')
    call assert_equal(winid, win_getid())
    call assert_equal('onedef', getline(1))
    q!
***************
*** 642,649 ****
    set completefunc=MessComplete
    new
    call setline(1, 'Ju')
!   call feedkeys("A\<c-x>\<c-u>/\<esc>", 'tx')
!   call assert_equal('Oct/Oct', getline(1))
    bwipe!
    set completefunc=
  endfunc
--- 642,649 ----
    set completefunc=MessComplete
    new
    call setline(1, 'Ju')
!   call assert_fails('call feedkeys("A\<c-x>\<c-u>/\<esc>", "tx")', 'E578:')
!   call assert_equal('Jan/', getline(1))
    bwipe!
    set completefunc=
  endfunc
*** ../vim-8.2.2425/src/version.c       2021-01-28 20:18:04.800631715 +0100
--- src/version.c       2021-01-29 19:56:42.314065568 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2426,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
265. Your reason for not staying in touch with family is that
     they do not have e-mail addresses.

 /// 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/202101292007.10TK7bOm444131%40masaka.moolenaar.net.

Raspunde prin e-mail lui