Patch 8.2.1636
Problem:    Get stuck if a popup filter causes an error.
Solution:   Check whether the function can be called and does not cause an
            error.  (closes #6902)
Files:      src/structs.h, src/popupwin.c, src/testdir/test_popupwin.vim
            src/testdir/dumps/Test_popupwin_wrong_name.dump,
            src/testdir/dumps/Test_popupwin_three_errors_1.dump,
            src/testdir/dumps/Test_popupwin_three_errors_2.dump


*** ../vim-8.2.1635/src/structs.h       2020-08-31 21:58:36.115898718 +0200
--- src/structs.h       2020-09-08 21:30:50.795915168 +0200
***************
*** 3338,3343 ****
--- 3338,3344 ----
                                      // with "cursorline" set
      callback_T        w_close_cb;         // popup close callback
      callback_T        w_filter_cb;        // popup filter callback
+     int               w_filter_errors;    // popup filter error count
      int               w_filter_mode;      // mode when filter callback is used
  
      win_T     *w_popup_curwin;    // close popup if curwin differs
*** ../vim-8.2.1635/src/popupwin.c      2020-09-02 22:33:20.824524597 +0200
--- src/popupwin.c      2020-09-08 22:04:31.605374591 +0200
***************
*** 3126,3131 ****
--- 3126,3132 ----
      typval_T  argv[3];
      char_u    buf[NUMBUFLEN];
      linenr_T  old_lnum = wp->w_cursor.lnum;
+     int               prev_called_emsg = called_emsg;
  
      // Emergency exit: CTRL-C closes the popup.
      if (c == Ctrl_C)
***************
*** 3151,3160 ****
      argv[2].v_type = VAR_UNKNOWN;
  
      // NOTE: The callback might close the popup and make "wp" invalid.
!     call_callback(&wp->w_filter_cb, -1, &rettv, 2, argv);
      if (win_valid_popup(wp) && old_lnum != wp->w_cursor.lnum)
        popup_highlight_curline(wp);
!     res = tv_get_bool(&rettv);
  
      vim_free(argv[1].vval.v_string);
      clear_tv(&rettv);
--- 3152,3186 ----
      argv[2].v_type = VAR_UNKNOWN;
  
      // NOTE: The callback might close the popup and make "wp" invalid.
!     if (call_callback(&wp->w_filter_cb, -1, &rettv, 2, argv) == FAIL)
!     {
!       // Cannot call the function, close the popup to avoid that the filter
!       // eats keys and the user can't get out.
!       popup_close_with_retval(wp, -1);
!       return 1;
!     }
! 
      if (win_valid_popup(wp) && old_lnum != wp->w_cursor.lnum)
        popup_highlight_curline(wp);
! 
!     // If an error was given always return FALSE, so that keys are not
!     // consumed and the user can type something.
!     // If we get three errors in a row then close the popup.  Decrement the
!     // error count by 1/10 if there are no errors, thus allowing up to 1 in
!     // 10 calls to cause an error.
!     if (win_valid_popup(wp) && called_emsg > prev_called_emsg)
!     {
!       wp->w_filter_errors += 10;
!       if (wp->w_filter_errors >= 30)
!           popup_close_with_retval(wp, -1);
!       res = FALSE;
!     }
!     else
!     {
!       if (win_valid_popup(wp) && wp->w_filter_errors > 0)
!           --wp->w_filter_errors;
!       res = tv_get_bool(&rettv);
!     }
  
      vim_free(argv[1].vval.v_string);
      clear_tv(&rettv);
*** ../vim-8.2.1635/src/testdir/test_popupwin.vim       2020-09-04 
21:18:40.484161926 +0200
--- src/testdir/test_popupwin.vim       2020-09-08 21:51:49.447792103 +0200
***************
*** 3516,3522 ****
    call VerifyScreenDump(buf, 'Test_popupwin_ctrl_c', {})
  
    call StopVimInTerminal(buf)
!   call delete('XtestPopupCorners')
  endfunc
  
  func Test_popupwin_atcursor_far_right()
--- 3516,3559 ----
    call VerifyScreenDump(buf, 'Test_popupwin_ctrl_c', {})
  
    call StopVimInTerminal(buf)
!   call delete('XtestPopupCtrlC')
! endfunc
! 
! func Test_popupwin_filter_close_wrong_name()
!   CheckScreendump
! 
!   let lines =<< trim END
!       call popup_create('one two three...', {'filter': 'NoSuchFunc'})
!   END
!   call writefile(lines, 'XtestPopupWrongName')
! 
!   let buf = RunVimInTerminal('-S XtestPopupWrongName', #{rows: 10})
! 
!   call term_sendkeys(buf, "j")
!   call VerifyScreenDump(buf, 'Test_popupwin_wrong_name', {})
! 
!   call StopVimInTerminal(buf)
!   call delete('XtestPopupWrongName')
! endfunc
! 
! func Test_popupwin_filter_close_three_errors()
!   CheckScreendump
! 
!   let lines =<< trim END
!       set cmdheight=2
!       call popup_create('one two three...', {'filter': 'filter'})
!   END
!   call writefile(lines, 'XtestPopupThreeErrors')
! 
!   let buf = RunVimInTerminal('-S XtestPopupThreeErrors', #{rows: 10})
! 
!   call term_sendkeys(buf, "jj")
!   call VerifyScreenDump(buf, 'Test_popupwin_three_errors_1', {})
!   call term_sendkeys(buf, "j")
!   call VerifyScreenDump(buf, 'Test_popupwin_three_errors_2', {})
! 
!   call StopVimInTerminal(buf)
!   call delete('XtestPopupThreeErrors')
  endfunc
  
  func Test_popupwin_atcursor_far_right()
*** ../vim-8.2.1635/src/testdir/dumps/Test_popupwin_wrong_name.dump     
2020-09-08 22:05:40.421147922 +0200
--- src/testdir/dumps/Test_popupwin_wrong_name.dump     2020-09-08 
21:48:26.380379649 +0200
***************
*** 0 ****
--- 1,10 ----
+ > +0&#ffffff0@74
+ |~+0#4040ff13&| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |E+0#ffffff16#e000002|1@1|7|:| |U|n|k|n|o|w|n| |f|u|n|c|t|i|o|n|:| 
|N|o|S|u|c|h|F|u|n|c| +0#0000000#ffffff0@22|0|,|0|-|1| @8|A|l@1| 
*** ../vim-8.2.1635/src/testdir/dumps/Test_popupwin_three_errors_1.dump 
2020-09-08 22:05:40.425147907 +0200
--- src/testdir/dumps/Test_popupwin_three_errors_1.dump 2020-09-08 
21:52:15.963712771 +0200
***************
*** 0 ****
--- 1,10 ----
+ > +0&#ffffff0@74
+ |~+0#4040ff13&| @73
+ |~| @73
+ |~| @73
+ |~| @27|o+0#0000001#ffd7ff255|n|e| |t|w|o| |t|h|r|e@1|.@2| 
+0#4040ff13#ffffff0@29
+ |~| @73
+ |~| @73
+ |~| @73
+ |E+0#ffffff16#e000002|8|9|6|:| |A|r|g|u|m|e|n|t| |o|f| |f|i|l|t|e|r|(|)| 
|m|u|s|t| |b|e| |a| |L|i|s|t|,| |D|i|c|t|i|o|n|a|r|y| |o|r| |B|l|o|b| 
+0#0000000#ffffff0@13
+ @57|0|,|0|-|1| @8|A|l@1| 
*** ../vim-8.2.1635/src/testdir/dumps/Test_popupwin_three_errors_2.dump 
2020-09-08 22:05:40.429147896 +0200
--- src/testdir/dumps/Test_popupwin_three_errors_2.dump 2020-09-08 
21:52:17.011709626 +0200
***************
*** 0 ****
--- 1,10 ----
+ > +0&#ffffff0@74
+ |~+0#4040ff13&| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |~| @73
+ |E+0#ffffff16#e000002|8|9|6|:| |A|r|g|u|m|e|n|t| |o|f| |f|i|l|t|e|r|(|)| 
|m|u|s|t| |b|e| |a| |L|i|s|t|,| |D|i|c|t|i|o|n|a|r|y| |o|r| |B|l|o|b| 
+0#0000000#ffffff0@13
+ @57|0|,|0|-|1| @8|A|l@1| 
*** ../vim-8.2.1635/src/version.c       2020-09-08 19:05:41.723819080 +0200
--- src/version.c       2020-09-08 21:25:50.372923132 +0200
***************
*** 756,757 ****
--- 756,759 ----
  {   /* Add new patch number below this line */
+ /**/
+     1636,
  /**/

-- 
TIM:   That is not an ordinary rabbit ... 'tis the most foul cruel and
       bad-tempered thing you ever set eyes on.
ROBIN: You tit.  I soiled my armour I was so scared!
                 "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/202009082007.088K7D1u141835%40masaka.moolenaar.net.

Raspunde prin e-mail lui