To: vim_dev@googlegroups.com Subject: Patch 8.2.0196 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.0196 Problem: Blocking commands for a finished job in a popup window. Solution: Do not block commands if the job has finished. Adjust test. Files: src/popupwin.c, src/testdir/test_popupwin.vim, src/window.c, src/terminal.c, src/proto/terminal.pro *** ../vim-8.2.0195/src/popupwin.c 2020-02-01 23:04:20.120422629 +0100 --- src/popupwin.c 2020-02-02 14:41:47.847217579 +0100 *************** *** 2863,2872 **** } # if defined(FEAT_TERMINAL) || defined(PROTO) int error_if_term_popup_window() { ! if (WIN_IS_POPUP(curwin) && curbuf->b_term != NULL) { emsg(_("E899: Not allowed for a terminal in a popup window")); return TRUE; --- 2863,2877 ---- } # if defined(FEAT_TERMINAL) || defined(PROTO) + /* + * Return TRUE if the current window is running a terminal in a popup window. + * Return FALSE when the job has ended. + */ int error_if_term_popup_window() { ! if (WIN_IS_POPUP(curwin) && curbuf->b_term != NULL ! && term_job_running(curbuf->b_term)) { emsg(_("E899: Not allowed for a terminal in a popup window")); return TRUE; *** ../vim-8.2.0195/src/testdir/test_popupwin.vim 2020-01-30 14:55:29.010670407 +0100 --- src/testdir/test_popupwin.vim 2020-02-02 15:22:21.834574190 +0100 *************** *** 2396,2405 **** func Test_popupwin_terminal_buffer() CheckFeature terminal let ptybuf = term_start(&shell, #{hidden: 1}) ! call assert_fails('let winnr = popup_create(ptybuf, #{})', 'E278:') ! exe 'bwipe! ' .. ptybuf endfunc func Test_popupwin_with_buffer_and_filter() --- 2396,2415 ---- func Test_popupwin_terminal_buffer() CheckFeature terminal + CheckUnix + let origwin = win_getid() let ptybuf = term_start(&shell, #{hidden: 1}) ! let winnr = popup_create(ptybuf, #{minwidth: 40, minheight: 10}) ! " Wait for shell to start ! sleep 200m ! " Cannot quit while job is running ! call assert_fails('call feedkeys("\:quit\", "xt")', 'E948:') ! call feedkeys("exit\", 'xt') ! " Wait for shell to exit ! sleep 100m ! call feedkeys(":quit\", 'xt') ! call assert_equal(origwin, win_getid()) endfunc func Test_popupwin_with_buffer_and_filter() *** ../vim-8.2.0195/src/window.c 2020-02-01 23:04:20.124422619 +0100 --- src/window.c 2020-02-02 14:56:14.544563315 +0100 *************** *** 2441,2446 **** --- 2441,2451 ---- int had_diffmode = win->w_p_diff; #endif + #if defined(FEAT_TERMINAL) && defined(FEAT_PROP_POPUP) + // Can close a popup window with a terminal if the job has finished. + if (may_close_term_popup() == OK) + return OK; + #endif if (ERROR_IF_ANY_POPUP_WINDOW) return FAIL; *************** *** 6439,6444 **** --- 6444,6455 ---- int count = 0; win_T *wp; + #if defined(FEAT_PROP_POPUP) + // If the current window is a popup then there always is another window. + if (popup_is_popup(curwin)) + return FALSE; + #endif + // If there is another tab page there always is another window. if (first_tabpage->tp_next != NULL) return FALSE; *** ../vim-8.2.0195/src/terminal.c 2020-02-01 21:57:00.848520936 +0100 --- src/terminal.c 2020-02-02 14:56:31.092489066 +0100 *************** *** 3260,3265 **** --- 3260,3288 ---- return FALSE; } + #if defined(FEAT_PROP_POPUP) || defined(PROTO) + /* + * If the current window is a terminal in a popup window and the job has + * finished, close the popup window and to back to the previous window. + * Otherwise return FAIL. + */ + int + may_close_term_popup(void) + { + if (popup_is_popup(curwin) && curbuf->b_term != NULL + && !term_job_running(curbuf->b_term)) + { + win_T *pwin = curwin; + + if (win_valid(prevwin)) + win_enter(prevwin, FALSE); + popup_close_with_retval(pwin, 0); + return OK; + } + return FAIL; + } + #endif + /* * Called when a channel has been closed. * If this was a channel for a terminal window then finish it up. *** ../vim-8.2.0195/src/proto/terminal.pro 2020-02-01 21:57:00.848520936 +0100 --- src/proto/terminal.pro 2020-02-02 14:56:18.928543606 +0100 *************** *** 19,24 **** --- 19,25 ---- int term_use_loop(void); void term_win_entered(void); int terminal_loop(int blocking); + int may_close_term_popup(void); void term_channel_closed(channel_T *ch); void term_check_channel_closed_recently(void); int term_do_update_window(win_T *wp); *** ../vim-8.2.0195/src/version.c 2020-02-02 13:47:02.688673781 +0100 --- src/version.c 2020-02-02 14:32:22.692283120 +0100 *************** *** 744,745 **** --- 744,747 ---- { /* Add new patch number below this line */ + /**/ + 196, /**/ -- I have a drinking problem -- I don't have a drink! /// Bram Moolenaar -- Bram@Moolenaar.net -- 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 ///