0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.1.2017: cannot execute commands after closing the cmdline window

Problem:    Cannot execute commands after closing the cmdline window.
Solution:   Also trigger BufEnter and WinEnter. (closes #4762)
This commit is contained in:
Bram Moolenaar 2019-09-09 18:35:33 +02:00
parent adbde3fbed
commit 96e38a86a7
5 changed files with 58 additions and 39 deletions

View File

@ -554,16 +554,14 @@ CmdlineLeave Before leaving the command line.
*CmdwinEnter* *CmdwinEnter*
CmdwinEnter After entering the command-line window. CmdwinEnter After entering the command-line window.
Useful for setting options specifically for Useful for setting options specifically for
this special type of window. This is this special type of window.
triggered _instead_ of BufEnter and WinEnter.
<afile> is set to a single character, <afile> is set to a single character,
indicating the type of command-line. indicating the type of command-line.
|cmdwin-char| |cmdwin-char|
*CmdwinLeave* *CmdwinLeave*
CmdwinLeave Before leaving the command-line window. CmdwinLeave Before leaving the command-line window.
Useful to clean up any global setting done Useful to clean up any global setting done
with CmdwinEnter. This is triggered _instead_ with CmdwinEnter.
of BufLeave and WinLeave.
<afile> is set to a single character, <afile> is set to a single character,
indicating the type of command-line. indicating the type of command-line.
|cmdwin-char| |cmdwin-char|

View File

@ -1171,11 +1171,9 @@ edited as described in |cmdwin-char|.
AUTOCOMMANDS AUTOCOMMANDS
Two autocommand events are used: |CmdwinEnter| and |CmdwinLeave|. Since this Two autocommand events are used: |CmdwinEnter| and |CmdwinLeave|. You can use
window is of a special type, the WinEnter, WinLeave, BufEnter and BufLeave the Cmdwin events to do settings specifically for the command-line window.
events are not triggered. You can use the Cmdwin events to do settings Be careful not to cause side effects!
specifically for the command-line window. Be careful not to cause side
effects!
Example: > Example: >
:au CmdwinEnter : let b:cpt_save = &cpt | set cpt=. :au CmdwinEnter : let b:cpt_save = &cpt | set cpt=.
:au CmdwinLeave : let &cpt = b:cpt_save :au CmdwinLeave : let &cpt = b:cpt_save

View File

@ -4069,30 +4069,26 @@ open_cmdwin(void)
} }
set_bufref(&old_curbuf, curbuf); set_bufref(&old_curbuf, curbuf);
/* Save current window sizes. */ // Save current window sizes.
win_size_save(&winsizes); win_size_save(&winsizes);
/* Don't execute autocommands while creating the window. */
block_autocmds();
// When using completion in Insert mode with <C-R>=<C-F> one can open the // When using completion in Insert mode with <C-R>=<C-F> one can open the
// command line window, but we don't want the popup menu then. // command line window, but we don't want the popup menu then.
pum_undisplay(); pum_undisplay();
/* don't use a new tab page */ // don't use a new tab page
cmdmod.tab = 0; cmdmod.tab = 0;
cmdmod.noswapfile = 1; cmdmod.noswapfile = 1;
/* Create a window for the command-line buffer. */ // Create a window for the command-line buffer.
if (win_split((int)p_cwh, WSP_BOT) == FAIL) if (win_split((int)p_cwh, WSP_BOT) == FAIL)
{ {
beep_flush(); beep_flush();
unblock_autocmds();
return K_IGNORE; return K_IGNORE;
} }
cmdwin_type = get_cmdline_type(); cmdwin_type = get_cmdline_type();
/* Create the command-line buffer empty. */ // Create the command-line buffer empty.
(void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL); (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, NULL);
(void)setfname(curbuf, (char_u *)"[Command Line]", NULL, TRUE); (void)setfname(curbuf, (char_u *)"[Command Line]", NULL, TRUE);
set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL); set_option_value((char_u *)"bt", 0L, (char_u *)"nofile", OPT_LOCAL);
@ -4106,12 +4102,10 @@ open_cmdwin(void)
# endif # endif
RESET_BINDING(curwin); RESET_BINDING(curwin);
/* Do execute autocommands for setting the filetype (load syntax). */ // Don't allow switching to another buffer.
unblock_autocmds();
/* But don't allow switching to another buffer. */
++curbuf_lock; ++curbuf_lock;
/* Showing the prompt may have set need_wait_return, reset it. */ // Showing the prompt may have set need_wait_return, reset it.
need_wait_return = FALSE; need_wait_return = FALSE;
histtype = hist_char2type(cmdwin_type); histtype = hist_char2type(cmdwin_type);
@ -4126,11 +4120,11 @@ open_cmdwin(void)
} }
--curbuf_lock; --curbuf_lock;
/* Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin // Reset 'textwidth' after setting 'filetype' (the Vim filetype plugin
* sets 'textwidth' to 78). */ // sets 'textwidth' to 78).
curbuf->b_p_tw = 0; curbuf->b_p_tw = 0;
/* Fill the buffer with the history. */ // Fill the buffer with the history.
init_history(); init_history();
if (get_hislen() > 0) if (get_hislen() > 0)
{ {
@ -4167,9 +4161,9 @@ open_cmdwin(void)
setmouse(); setmouse();
# endif # endif
/* Trigger CmdwinEnter autocommands. */ // Trigger CmdwinEnter autocommands.
trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER); trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINENTER);
if (restart_edit != 0) /* autocmd with ":startinsert" */ if (restart_edit != 0) // autocmd with ":startinsert"
stuffcharReadbuff(K_NOP); stuffcharReadbuff(K_NOP);
i = RedrawingDisabled; i = RedrawingDisabled;
@ -4187,11 +4181,11 @@ open_cmdwin(void)
save_KeyTyped = KeyTyped; save_KeyTyped = KeyTyped;
# endif # endif
/* Trigger CmdwinLeave autocommands. */ // Trigger CmdwinLeave autocommands.
trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE); trigger_cmd_autocmd(cmdwin_type, EVENT_CMDWINLEAVE);
# ifdef FEAT_FOLDING # ifdef FEAT_FOLDING
/* Restore KeyTyped in case it is modified by autocommands */ // Restore KeyTyped in case it is modified by autocommands
KeyTyped = save_KeyTyped; KeyTyped = save_KeyTyped;
# endif # endif
@ -4268,10 +4262,8 @@ open_cmdwin(void)
} }
} }
/* Don't execute autocommands while deleting the window. */
block_autocmds();
# ifdef FEAT_CONCEAL # ifdef FEAT_CONCEAL
/* Avoid command-line window first character being concealed. */ // Avoid command-line window first character being concealed.
curwin->w_p_cole = 0; curwin->w_p_cole = 0;
# endif # endif
wp = curwin; wp = curwin;
@ -4279,15 +4271,13 @@ open_cmdwin(void)
win_goto(old_curwin); win_goto(old_curwin);
win_close(wp, TRUE); win_close(wp, TRUE);
/* win_close() may have already wiped the buffer when 'bh' is // win_close() may have already wiped the buffer when 'bh' is
* set to 'wipe' */ // set to 'wipe'
if (bufref_valid(&bufref)) if (bufref_valid(&bufref))
close_buffer(NULL, bufref.br_buf, DOBUF_WIPE, FALSE); close_buffer(NULL, bufref.br_buf, DOBUF_WIPE, FALSE);
/* Restore window sizes. */ // Restore window sizes.
win_size_restore(&winsizes); win_size_restore(&winsizes);
unblock_autocmds();
} }
ga_clear(&winsizes); ga_clear(&winsizes);
@ -4303,7 +4293,7 @@ open_cmdwin(void)
return cmdwin_result; return cmdwin_result;
} }
#endif /* FEAT_CMDWIN */ #endif // FEAT_CMDWIN
/* /*
* Used for commands that either take a simple command string argument, or: * Used for commands that either take a simple command string argument, or:

View File

@ -604,6 +604,8 @@ func Check_cmdline(cmdtype)
return '' return ''
endfunc endfunc
set cpo&
func Test_getcmdtype() func Test_getcmdtype()
call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt") call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
@ -644,6 +646,37 @@ func Test_getcmdwintype()
call assert_equal('', getcmdwintype()) call assert_equal('', getcmdwintype())
endfunc endfunc
func Test_getcmdwin_autocmd()
let s:seq = []
augroup CmdWin
au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid())
au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid())
au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr())
au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr())
au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid())
au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid())
let org_winid = win_getid()
let org_bufnr = bufnr()
call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!')
call assert_equal(':', a)
call assert_equal([
\ 'WinLeave ' .. org_winid,
\ 'WinEnter ' .. s:cmd_winid,
\ 'BufLeave ' .. org_bufnr,
\ 'BufEnter ' .. s:cmd_bufnr,
\ 'CmdWinEnter ' .. s:cmd_winid,
\ 'CmdWinLeave ' .. s:cmd_winid,
\ 'BufLeave ' .. s:cmd_bufnr,
\ 'WinLeave ' .. s:cmd_winid,
\ 'WinEnter ' .. org_winid,
\ 'BufEnter ' .. org_bufnr,
\ ], s:seq)
au!
augroup END
endfunc
func Test_verbosefile() func Test_verbosefile()
set verbosefile=Xlog set verbosefile=Xlog
echomsg 'foo' echomsg 'foo'
@ -701,5 +734,3 @@ func Test_cmdline_overstrike()
let &encoding = encoding_save let &encoding = encoding_save
endfunc endfunc
set cpo&

View File

@ -757,6 +757,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
2017,
/**/ /**/
2016, 2016,
/**/ /**/