Patch 8.2.0747
Problem:    Cannot forcefully close all popups.
Solution:   Add the "force" argument to popup_clear().  Use it after running a
            test.  Put back the check for a popup when editing a file.
Files:      runtime/doc/popup.txt, src/evalfunc.c, src/popupwin.c,
            src/proto/popupwin.pro, src/tag.c, src/window.c, src/misc2.c,
            src/ex_cmds.c, src/channel.c, src/testdir/runtest.vim,
            src/testdir/test_terminal.vim


*** ../vim-8.2.0746/runtime/doc/popup.txt       2020-02-20 20:11:50.358377694 
+0100
--- runtime/doc/popup.txt       2020-05-13 01:22:11.519475665 +0200
***************
*** 229,236 ****
                        GetText()->popup_beval({})
  <
                                                        *popup_clear()*
! popup_clear() Emergency solution to a misbehaving plugin: close all popup
                windows for the current tab and global popups.
  
  
  popup_close({id} [, {result}])                                *popup_close()*
--- 236,250 ----
                        GetText()->popup_beval({})
  <
                                                        *popup_clear()*
! popup_clear([{force}])
!               Emergency solution to a misbehaving plugin: close all popup
                windows for the current tab and global popups.
+               Close callbacks are not invoked.
+               When {force} is not present this will fail if the current
+               window is a popup.
+               When {force} is present and |TRUE| the popup is also closed
+               when it is the current window.  If a terminal is running in a
+               popup it is killed.
  
  
  popup_close({id} [, {result}])                                *popup_close()*
*** ../vim-8.2.0746/src/evalfunc.c      2020-04-29 22:30:09.313356305 +0200
--- src/evalfunc.c      2020-05-13 01:11:26.965843221 +0200
***************
*** 704,710 ****
                        },
      {"popup_atcursor",        2, 2, FEARG_1,    ret_number,   
PROP_FUNC(f_popup_atcursor)},
      {"popup_beval",   2, 2, FEARG_1,    ret_number,   
PROP_FUNC(f_popup_beval)},
!     {"popup_clear",   0, 0, 0,          ret_void,     
PROP_FUNC(f_popup_clear)},
      {"popup_close",   1, 2, FEARG_1,    ret_void,     
PROP_FUNC(f_popup_close)},
      {"popup_create",  2, 2, FEARG_1,    ret_number,   
PROP_FUNC(f_popup_create)},
      {"popup_dialog",  2, 2, FEARG_1,    ret_number,   
PROP_FUNC(f_popup_dialog)},
--- 704,710 ----
                        },
      {"popup_atcursor",        2, 2, FEARG_1,    ret_number,   
PROP_FUNC(f_popup_atcursor)},
      {"popup_beval",   2, 2, FEARG_1,    ret_number,   
PROP_FUNC(f_popup_beval)},
!     {"popup_clear",   0, 1, 0,          ret_void,     
PROP_FUNC(f_popup_clear)},
      {"popup_close",   1, 2, FEARG_1,    ret_void,     
PROP_FUNC(f_popup_close)},
      {"popup_create",  2, 2, FEARG_1,    ret_number,   
PROP_FUNC(f_popup_create)},
      {"popup_dialog",  2, 2, FEARG_1,    ret_number,   
PROP_FUNC(f_popup_dialog)},
*** ../vim-8.2.0746/src/popupwin.c      2020-05-13 01:04:26.555407600 +0200
--- src/popupwin.c      2020-05-13 01:19:50.363992289 +0200
***************
*** 2054,2062 ****
   * popup_clear()
   */
      void
! f_popup_clear(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
  {
!     close_all_popups();
  }
  
  /*
--- 2054,2066 ----
   * popup_clear()
   */
      void
! f_popup_clear(typval_T *argvars, typval_T *rettv UNUSED)
  {
!     int force = FALSE;
! 
!     if (argvars[0].v_type != VAR_UNKNOWN)
!       force = (int)tv_get_number(&argvars[0]);
!     close_all_popups(force);
  }
  
  /*
***************
*** 2163,2169 ****
        // Careful: This may make "wp" invalid.
        invoke_popup_callback(wp, arg);
  
!     popup_close(id);
      CHECK_CURBUF;
  }
  
--- 2167,2173 ----
        // Careful: This may make "wp" invalid.
        invoke_popup_callback(wp, arg);
  
!     popup_close(id, FALSE);
      CHECK_CURBUF;
  }
  
***************
*** 2250,2256 ****
  }
  
  /*
!  * popup_filter_menu({text}, {options})
   */
      void
  f_popup_filter_menu(typval_T *argvars, typval_T *rettv)
--- 2254,2260 ----
  }
  
  /*
!  * popup_filter_menu({id}, {key})
   */
      void
  f_popup_filter_menu(typval_T *argvars, typval_T *rettv)
***************
*** 2305,2311 ****
  }
  
  /*
!  * popup_filter_yesno({text}, {options})
   */
      void
  f_popup_filter_yesno(typval_T *argvars, typval_T *rettv)
--- 2309,2315 ----
  }
  
  /*
!  * popup_filter_yesno({id}, {key})
   */
      void
  f_popup_filter_yesno(typval_T *argvars, typval_T *rettv)
***************
*** 2534,2540 ****
   * Return OK if the popup was closed, FAIL otherwise.
   */
      int
! popup_close(int id)
  {
      win_T     *wp;
      tabpage_T *tp;
--- 2538,2544 ----
   * Return OK if the popup was closed, FAIL otherwise.
   */
      int
! popup_close(int id, int force)
  {
      win_T     *wp;
      tabpage_T *tp;
***************
*** 2546,2553 ****
        {
            if (wp == curwin)
            {
!               error_for_popup_window();
!               return FAIL;
            }
            if (prev == NULL)
                first_popupwin = wp->w_next;
--- 2550,2561 ----
        {
            if (wp == curwin)
            {
!               if (!force)
!               {
!                   error_for_popup_window();
!                   return FAIL;
!               }
!               win_enter(firstwin, FALSE);
            }
            if (prev == NULL)
                first_popupwin = wp->w_next;
***************
*** 2559,2565 ****
  
      // go through tab-local popups
      FOR_ALL_TABPAGES(tp)
!       if (popup_close_tabpage(tp, id) == OK)
            return OK;
      return FAIL;
  }
--- 2567,2573 ----
  
      // go through tab-local popups
      FOR_ALL_TABPAGES(tp)
!       if (popup_close_tabpage(tp, id, force) == OK)
            return OK;
      return FAIL;
  }
***************
*** 2568,2574 ****
   * Close a popup window with Window-id "id" in tabpage "tp".
   */
      int
! popup_close_tabpage(tabpage_T *tp, int id)
  {
      win_T     *wp;
      win_T     **root = &tp->tp_first_popupwin;
--- 2576,2582 ----
   * Close a popup window with Window-id "id" in tabpage "tp".
   */
      int
! popup_close_tabpage(tabpage_T *tp, int id, int force)
  {
      win_T     *wp;
      win_T     **root = &tp->tp_first_popupwin;
***************
*** 2579,2586 ****
        {
            if (wp == curwin)
            {
!               error_for_popup_window();
!               return FAIL;
            }
            if (prev == NULL)
                *root = wp->w_next;
--- 2587,2598 ----
        {
            if (wp == curwin)
            {
!               if (!force)
!               {
!                   error_for_popup_window();
!                   return FAIL;
!               }
!               win_enter(firstwin, FALSE);
            }
            if (prev == NULL)
                *root = wp->w_next;
***************
*** 2593,2607 ****
  }
  
      void
! close_all_popups(void)
  {
!     if (ERROR_IF_ANY_POPUP_WINDOW)
        return;
      while (first_popupwin != NULL)
!       if (popup_close(first_popupwin->w_id) == FAIL)
            return;
      while (curtab->tp_first_popupwin != NULL)
!       if (popup_close(curtab->tp_first_popupwin->w_id) == FAIL)
            return;
  }
  
--- 2605,2619 ----
  }
  
      void
! close_all_popups(int force)
  {
!     if (!force && ERROR_IF_ANY_POPUP_WINDOW)
        return;
      while (first_popupwin != NULL)
!       if (popup_close(first_popupwin->w_id, force) == FAIL)
            return;
      while (curtab->tp_first_popupwin != NULL)
!       if (popup_close(curtab->tp_first_popupwin->w_id, force) == FAIL)
            return;
  }
  
*** ../vim-8.2.0746/src/proto/popupwin.pro      2020-05-13 01:04:26.555407600 
+0200
--- src/proto/popupwin.pro      2020-05-13 01:19:10.636137848 +0200
***************
*** 34,42 ****
  void f_popup_show(typval_T *argvars, typval_T *rettv);
  void f_popup_settext(typval_T *argvars, typval_T *rettv);
  int error_if_popup_window(int also_with_term);
! int popup_close(int id);
! int popup_close_tabpage(tabpage_T *tp, int id);
! void close_all_popups(void);
  void f_popup_move(typval_T *argvars, typval_T *rettv);
  void f_popup_setoptions(typval_T *argvars, typval_T *rettv);
  void f_popup_getpos(typval_T *argvars, typval_T *rettv);
--- 34,42 ----
  void f_popup_show(typval_T *argvars, typval_T *rettv);
  void f_popup_settext(typval_T *argvars, typval_T *rettv);
  int error_if_popup_window(int also_with_term);
! int popup_close(int id, int force);
! int popup_close_tabpage(tabpage_T *tp, int id, int force);
! void close_all_popups(int force);
  void f_popup_move(typval_T *argvars, typval_T *rettv);
  void f_popup_setoptions(typval_T *argvars, typval_T *rettv);
  void f_popup_getpos(typval_T *argvars, typval_T *rettv);
*** ../vim-8.2.0746/src/tag.c   2020-04-12 19:37:13.526297236 +0200
--- src/tag.c   2020-05-13 01:15:40.116910586 +0200
***************
*** 3684,3690 ****
  
            if (win_valid(curwin_save))
                win_enter(curwin_save, TRUE);
!           popup_close(wp->w_id);
        }
  #endif
      }
--- 3684,3690 ----
  
            if (win_valid(curwin_save))
                win_enter(curwin_save, TRUE);
!           popup_close(wp->w_id, FALSE);
        }
  #endif
      }
*** ../vim-8.2.0746/src/window.c        2020-04-30 22:29:36.626024141 +0200
--- src/window.c        2020-05-13 01:24:33.582980028 +0200
***************
*** 2766,2774 ****
        (void)win_free_mem(aucmd_win, &dummy, NULL);
        aucmd_win = NULL;
      }
- # ifdef FEAT_PROP_POPUP
-     close_all_popups();
- # endif
  
      while (firstwin != NULL)
        (void)win_free_mem(firstwin, &dummy, NULL);
--- 2766,2771 ----
***************
*** 3801,3807 ****
  # endif
  # ifdef FEAT_PROP_POPUP
      while (tp->tp_first_popupwin != NULL)
!       popup_close_tabpage(tp, tp->tp_first_popupwin->w_id);
  #endif
      for (idx = 0; idx < SNAP_COUNT; ++idx)
        clear_snapshot(tp, idx);
--- 3798,3804 ----
  # endif
  # ifdef FEAT_PROP_POPUP
      while (tp->tp_first_popupwin != NULL)
!       popup_close_tabpage(tp, tp->tp_first_popupwin->w_id, TRUE);
  #endif
      for (idx = 0; idx < SNAP_COUNT; ++idx)
        clear_snapshot(tp, idx);
*** ../vim-8.2.0746/src/misc2.c 2020-05-12 23:45:12.168749489 +0200
--- src/misc2.c 2020-05-13 02:13:53.897659683 +0200
***************
*** 1069,1081 ****
  # if defined(FEAT_BEVAL_TERM)
      ui_remove_balloon();
  # endif
! # if defined(FEAT_PROP_POPUP)
      if (curwin != NULL)
!     {
!       while (popup_is_popup(curwin))
!           popup_close_with_retval(curwin, 0);
!       close_all_popups();
!     }
  # endif
  
      // Clear user commands (before deleting buffers).
--- 1069,1077 ----
  # if defined(FEAT_BEVAL_TERM)
      ui_remove_balloon();
  # endif
! # ifdef FEAT_PROP_POPUP
      if (curwin != NULL)
!       close_all_popups(TRUE);
  # endif
  
      // Clear user commands (before deleting buffers).
*** ../vim-8.2.0746/src/ex_cmds.c       2020-05-12 23:45:12.168749489 +0200
--- src/ex_cmds.c       2020-05-12 23:50:03.459802716 +0200
***************
*** 2484,2489 ****
--- 2484,2494 ----
      int               did_inc_redrawing_disabled = FALSE;
      long        *so_ptr = curwin->w_p_so >= 0 ? &curwin->w_p_so : &p_so;
  
+ #ifdef FEAT_PROP_POPUP
+     if (ERROR_IF_TERM_POPUP_WINDOW)
+       return FAIL;
+ #endif
+ 
      if (eap != NULL)
        command = eap->do_ecmd_cmd;
      set_bufref(&old_curbuf, curbuf);
*** ../vim-8.2.0746/src/channel.c       2020-05-07 17:46:56.018107854 +0200
--- src/channel.c       2020-05-13 13:29:44.961432242 +0200
***************
*** 156,164 ****
      if (log_fd != NULL)
      {
        if (*fname != NUL)
!           ch_log(NULL, "closing, opening %s", fname);
        else
!           ch_log(NULL, "closing");
        fclose(log_fd);
      }
  
--- 156,164 ----
      if (log_fd != NULL)
      {
        if (*fname != NUL)
!           ch_log(NULL, "closing this logfile, opening %s", fname);
        else
!           ch_log(NULL, "closing logfile");
        fclose(log_fd);
      }
  
*** ../vim-8.2.0746/src/testdir/runtest.vim     2020-04-19 14:02:22.427687032 
+0200
--- src/testdir/runtest.vim     2020-05-13 01:35:48.517634947 +0200
***************
*** 188,196 ****
    au!
    au SwapExists * call HandleSwapExists()
  
!   " Close any stray popup windows
    if has('popupwin')
!     call popup_clear()
    endif
  
    " Close any extra tab pages and windows and make the current one not 
modified.
--- 188,196 ----
    au!
    au SwapExists * call HandleSwapExists()
  
!   " Close any stray popup windows.
    if has('popupwin')
!     call popup_clear(1)
    endif
  
    " Close any extra tab pages and windows and make the current one not 
modified.
*** ../vim-8.2.0746/src/testdir/test_terminal.vim       2020-05-11 
22:04:46.928845435 +0200
--- src/testdir/test_terminal.vim       2020-05-13 02:09:05.382743929 +0200
***************
*** 2617,2643 ****
  
  func Test_term_nasty_callback()
    CheckExecutable sh
-   func OpenTerms()
-     set hidden
-     let g:buf0 = term_start('sh', #{hidden: 1})
-     call popup_create(g:buf0, {})
-     let g:buf1 = term_start('sh', #{hidden: 1, term_finish: 'close'})
-     call popup_create(g:buf1, {})
-     let g:buf2 = term_start(['sh', '-c'], #{curwin: 1, exit_cb: 
function('TermExit')})
-     call TermWait(g:buf2, 50)
-     call popup_close(win_getid())
-   endfunc
-   func TermExit(...)
-     let altbuf = bufnr('#')
-     call term_sendkeys(altbuf, "exit\<CR>")
-     call TermWait(altbuf)
-     call popup_close(win_getid())
-   endfunc
-   call OpenTerms()
  
!   call term_sendkeys(g:buf0, "exit\<CR>")
!   call TermWait(g:buf0, 50)
!   exe g:buf0 .. 'bwipe!'
    set hidden&
  endfunc
  
--- 2617,2631 ----
  
  func Test_term_nasty_callback()
    CheckExecutable sh
  
!   set hidden
!   let g:buf0 = term_start('sh', #{hidden: 1})
!   call popup_create(g:buf0, {})
!   let g:buf1 = term_start('sh', #{hidden: 1, term_finish: 'close'})
!   call popup_create(g:buf1, {})
!   call assert_fails("call term_start(['sh', '-c'], #{curwin: 1})", 'E863:')
! 
!   call popup_clear(1)
    set hidden&
  endfunc
  
*** ../vim-8.2.0746/src/version.c       2020-05-13 01:04:26.555407600 +0200
--- src/version.c       2020-05-13 01:31:44.530246652 +0200
***************
*** 748,749 ****
--- 748,751 ----
  {   /* Add new patch number below this line */
+ /**/
+     747,
  /**/

-- 
>From "know your smileys":
 %      Bike accident.  A bit far-fetched, I suppose; although...
             o      _     _         _
     _o     /\_   _ \\o  (_)\__/o  (_)
   _< \_   _>(_) (_)/<_    \_| \   _|/' \/
  (_)>(_) (_)        (_)   (_)    (_)'  _\o_

 /// 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/202005131140.04DBemts032387%40masaka.moolenaar.net.

Raspunde prin e-mail lui