mirror of
https://github.com/neovim/neovim.git
synced 2025-09-15 07:48:18 +00:00
vim-patch:8.1.2017: cannot execute commands after closing cmdline window #11479
Problem: Cannot execute commands after closing the cmdline window.
Solution: Also trigger BufEnter and WinEnter. (closes vim/vim#4762)
96e38a86a7
Fixes https://github.com/neovim/neovim/issues/11279.
This commit is contained in:

committed by
Justin M. Keyes

parent
e138c4c874
commit
f33371c03f
@@ -559,16 +559,14 @@ CmdlineLeave Before leaving the command-line (including
|
|||||||
*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|
|
||||||
|
@@ -1122,11 +1122,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
|
||||||
|
@@ -6078,12 +6078,9 @@ static int 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(true);
|
pum_undisplay(true);
|
||||||
@@ -6092,10 +6089,9 @@ static int open_cmdwin(void)
|
|||||||
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();
|
||||||
@@ -6110,13 +6106,11 @@ static int open_cmdwin(void)
|
|||||||
curbuf->b_p_ma = true;
|
curbuf->b_p_ma = true;
|
||||||
curwin->w_p_fen = false;
|
curwin->w_p_fen = false;
|
||||||
|
|
||||||
// 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;
|
||||||
|
|
||||||
const int histtype = hist_char2type(cmdwin_type);
|
const int histtype = hist_char2type(cmdwin_type);
|
||||||
if (histtype == HIST_CMD || histtype == HIST_DEBUG) {
|
if (histtype == HIST_CMD || histtype == HIST_DEBUG) {
|
||||||
@@ -6128,11 +6122,11 @@ static int 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 (hislen > 0 && histtype != HIST_INVALID) {
|
if (hislen > 0 && histtype != HIST_INVALID) {
|
||||||
i = hisidx[histtype];
|
i = hisidx[histtype];
|
||||||
@@ -6173,9 +6167,10 @@ static int open_cmdwin(void)
|
|||||||
// Trigger CmdwinEnter autocommands.
|
// Trigger CmdwinEnter autocommands.
|
||||||
typestr[0] = (char_u)cmdwin_type;
|
typestr[0] = (char_u)cmdwin_type;
|
||||||
typestr[1] = NUL;
|
typestr[1] = NUL;
|
||||||
apply_autocmds(EVENT_CMDWINENTER, typestr, typestr, FALSE, curbuf);
|
apply_autocmds(EVENT_CMDWINENTER, typestr, typestr, false, curbuf);
|
||||||
if (restart_edit != 0) /* autocmd with ":startinsert" */
|
if (restart_edit != 0) { // autocmd with ":startinsert"
|
||||||
stuffcharReadbuff(K_NOP);
|
stuffcharReadbuff(K_NOP);
|
||||||
|
}
|
||||||
|
|
||||||
i = RedrawingDisabled;
|
i = RedrawingDisabled;
|
||||||
RedrawingDisabled = 0;
|
RedrawingDisabled = 0;
|
||||||
@@ -6192,10 +6187,10 @@ static int open_cmdwin(void)
|
|||||||
|
|
||||||
const bool save_KeyTyped = KeyTyped;
|
const bool save_KeyTyped = KeyTyped;
|
||||||
|
|
||||||
/* Trigger CmdwinLeave autocommands. */
|
// Trigger CmdwinLeave autocommands.
|
||||||
apply_autocmds(EVENT_CMDWINLEAVE, typestr, typestr, FALSE, curbuf);
|
apply_autocmds(EVENT_CMDWINLEAVE, typestr, typestr, false, curbuf);
|
||||||
|
|
||||||
/* Restore KeyTyped in case it is modified by autocommands */
|
// Restore KeyTyped in case it is modified by autocommands
|
||||||
KeyTyped = save_KeyTyped;
|
KeyTyped = save_KeyTyped;
|
||||||
|
|
||||||
// Restore the command line info.
|
// Restore the command line info.
|
||||||
@@ -6254,9 +6249,7 @@ static int open_cmdwin(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Don't execute autocommands while deleting the window. */
|
// Avoid command-line window first character being concealed.
|
||||||
block_autocmds();
|
|
||||||
// Avoid command-line window first character being concealed
|
|
||||||
curwin->w_p_cole = 0;
|
curwin->w_p_cole = 0;
|
||||||
wp = curwin;
|
wp = curwin;
|
||||||
set_bufref(&bufref, curbuf);
|
set_bufref(&bufref, curbuf);
|
||||||
@@ -6269,10 +6262,8 @@ static int open_cmdwin(void)
|
|||||||
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);
|
||||||
|
@@ -619,6 +619,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")
|
||||||
|
|
||||||
@@ -659,6 +661,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'
|
||||||
@@ -717,5 +750,3 @@ func Test_cmdline_overstrike()
|
|||||||
|
|
||||||
let &encoding = encoding_save
|
let &encoding = encoding_save
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
set cpo&
|
|
||||||
|
Reference in New Issue
Block a user