void
ex_doautoall(exarg_T *eap)
{
- int retval;
+ int retval = OK;
aco_save_T aco;
buf_T *buf;
bufref_T bufref;
*/
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)
{
// find a window for this buffer and save some values
aucmd_prepbuf(&aco, buf);
retval = do_doautocmd(arg, FALSE, &did_aucmd);
if (call_do_modelines && did_aucmd)
- {
// Execute the modeline settings, but don't set window-local
// options if we are using the current window for another
// buffer.
do_modelines(curwin == aucmd_win ? OPT_NOWIN : 0);
- }
// restore the current window
aucmd_restbuf(&aco);
// stop if there is some error or buffer was deleted
if (retval == FAIL || !bufref_valid(&bufref))
+ {
+ retval = FAIL;
break;
+ }
}
}
+ // Execute autocommands for the current buffer last.
+ if (retval == OK)
+ {
+ do_doautocmd(arg, FALSE, &did_aucmd);
+ if (call_do_modelines && did_aucmd)
+ do_modelines(0);
+ }
+
check_cursor(); // just in case lines got deleted
}
while (au_pending_free_buf != NULL)
{
buf_T *b = au_pending_free_buf->b_next;
+
vim_free(au_pending_free_buf);
au_pending_free_buf = b;
}
while (au_pending_free_win != NULL)
{
win_T *w = au_pending_free_win->w_next;
+
vim_free(au_pending_free_win);
au_pending_free_win = w;
}
%bw!
edit one.txt
tabnew two.txt
+ vnew three.txt
+ tabnew four.txt
+ tabprevious
let g:blist = []
augroup aucmd_win_test1
au!
augroup END
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_test1
au!