mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 14:38:32 +00:00
vim-patch:8.2.2596: :doautocmd may confuse scripts listening to WinEnter
Problem: :doautocmd may confuse scripts listening to WinEnter.
Solution: Do the current buffer last. (closes vim/vim#7958)
41cd80335c
This commit is contained in:
@@ -968,7 +968,7 @@ static int do_autocmd_event(event_T event,
|
|||||||
// Implementation of ":doautocmd [group] event [fname]".
|
// Implementation of ":doautocmd [group] event [fname]".
|
||||||
// Return OK for success, FAIL for failure;
|
// Return OK for success, FAIL for failure;
|
||||||
int do_doautocmd(char_u *arg,
|
int do_doautocmd(char_u *arg,
|
||||||
int do_msg, // give message for no matching autocmds?
|
bool do_msg, // give message for no matching autocmds?
|
||||||
bool *did_something)
|
bool *did_something)
|
||||||
{
|
{
|
||||||
char_u *fname;
|
char_u *fname;
|
||||||
@@ -1017,11 +1017,12 @@ int do_doautocmd(char_u *arg,
|
|||||||
// ":doautoall": execute autocommands for each loaded buffer.
|
// ":doautoall": execute autocommands for each loaded buffer.
|
||||||
void ex_doautoall(exarg_T *eap)
|
void ex_doautoall(exarg_T *eap)
|
||||||
{
|
{
|
||||||
int retval;
|
int retval = OK;
|
||||||
aco_save_T aco;
|
aco_save_T aco;
|
||||||
char_u *arg = eap->arg;
|
char_u *arg = eap->arg;
|
||||||
int call_do_modelines = check_nomodeline(&arg);
|
int call_do_modelines = check_nomodeline(&arg);
|
||||||
bufref_T bufref;
|
bufref_T bufref;
|
||||||
|
bool did_aucmd;
|
||||||
|
|
||||||
// This is a bit tricky: For some commands curwin->w_buffer needs to be
|
// This is a bit tricky: For some commands curwin->w_buffer needs to be
|
||||||
// equal to curbuf, but for some buffers there may not be a window.
|
// equal to curbuf, but for some buffers there may not be a window.
|
||||||
@@ -1029,14 +1030,14 @@ void ex_doautoall(exarg_T *eap)
|
|||||||
// gives problems when the autocommands make changes to the list of
|
// gives problems when the autocommands make changes to the list of
|
||||||
// buffers or windows...
|
// buffers or windows...
|
||||||
FOR_ALL_BUFFERS(buf) {
|
FOR_ALL_BUFFERS(buf) {
|
||||||
if (buf->b_ml.ml_mfp == NULL) {
|
// Only do loaded buffers and skip the current buffer, it's done last.
|
||||||
|
if (buf->b_ml.ml_mfp == NULL || buf == curbuf) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Find a window for this buffer and save some values.
|
// Find a window for this buffer and save some values.
|
||||||
aucmd_prepbuf(&aco, buf);
|
aucmd_prepbuf(&aco, buf);
|
||||||
set_bufref(&bufref, buf);
|
set_bufref(&bufref, buf);
|
||||||
|
|
||||||
bool did_aucmd;
|
|
||||||
// execute the autocommands for this buffer
|
// execute the autocommands for this buffer
|
||||||
retval = do_doautocmd(arg, false, &did_aucmd);
|
retval = do_doautocmd(arg, false, &did_aucmd);
|
||||||
|
|
||||||
@@ -1052,10 +1053,19 @@ void ex_doautoall(exarg_T *eap)
|
|||||||
|
|
||||||
// Stop if there is some error or buffer was deleted.
|
// Stop if there is some error or buffer was deleted.
|
||||||
if (retval == FAIL || !bufref_valid(&bufref)) {
|
if (retval == FAIL || !bufref_valid(&bufref)) {
|
||||||
|
retval = FAIL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Execute autocommands for the current buffer last.
|
||||||
|
if (retval == OK) {
|
||||||
|
(void)do_doautocmd(arg, false, &did_aucmd);
|
||||||
|
if (call_do_modelines && did_aucmd) {
|
||||||
|
do_modelines(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
check_cursor(); // just in case lines got deleted
|
check_cursor(); // just in case lines got deleted
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1661,11 +1671,13 @@ static bool apply_autocmds_group(event_T event,
|
|||||||
did_filetype = false;
|
did_filetype = false;
|
||||||
while (au_pending_free_buf != NULL) {
|
while (au_pending_free_buf != NULL) {
|
||||||
buf_T *b = au_pending_free_buf->b_next;
|
buf_T *b = au_pending_free_buf->b_next;
|
||||||
|
|
||||||
xfree(au_pending_free_buf);
|
xfree(au_pending_free_buf);
|
||||||
au_pending_free_buf = b;
|
au_pending_free_buf = b;
|
||||||
}
|
}
|
||||||
while (au_pending_free_win != NULL) {
|
while (au_pending_free_win != NULL) {
|
||||||
win_T *w = au_pending_free_win->w_next;
|
win_T *w = au_pending_free_win->w_next;
|
||||||
|
|
||||||
xfree(au_pending_free_win);
|
xfree(au_pending_free_win);
|
||||||
au_pending_free_win = w;
|
au_pending_free_win = w;
|
||||||
}
|
}
|
||||||
|
@@ -1922,20 +1922,28 @@ func Test_autocmd_window()
|
|||||||
%bw!
|
%bw!
|
||||||
edit one.txt
|
edit one.txt
|
||||||
tabnew two.txt
|
tabnew two.txt
|
||||||
|
vnew three.txt
|
||||||
|
tabnew four.txt
|
||||||
|
tabprevious
|
||||||
let g:blist = []
|
let g:blist = []
|
||||||
augroup aucmd_win_test
|
augroup aucmd_win_test1
|
||||||
au!
|
au!
|
||||||
au BufEnter * call add(g:blist, [expand('<afile>'),
|
au BufEnter * call add(g:blist, [expand('<afile>'),
|
||||||
\ win_gettype(bufwinnr(expand('<afile>')))])
|
\ win_gettype(bufwinnr(expand('<afile>')))])
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
doautoall BufEnter
|
doautoall BufEnter
|
||||||
call assert_equal([['one.txt', 'autocmd'], ['two.txt', '']], g:blist)
|
call assert_equal([
|
||||||
|
\ ['one.txt', 'autocmd'],
|
||||||
|
\ ['two.txt', ''],
|
||||||
|
\ ['four.txt', 'autocmd'],
|
||||||
|
\ ['three.txt', ''],
|
||||||
|
\ ], g:blist)
|
||||||
|
|
||||||
augroup aucmd_win_test
|
augroup aucmd_win_test1
|
||||||
au!
|
au!
|
||||||
augroup END
|
augroup END
|
||||||
augroup! aucmd_win_test
|
augroup! aucmd_win_test1
|
||||||
%bw!
|
%bw!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user