diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-03-13 15:47:56 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-03-13 15:47:56 +0100 |
commit | 41cd80335cf318c15c8b0139f53ab5e8a02561ef (patch) | |
tree | cede8c13b2eb2bd865105a7ef02bf6de65e31b73 | |
parent | 9e813b3dea94a8952b732a224fa31beba6e85973 (diff) | |
download | vim-git-41cd80335cf318c15c8b0139f53ab5e8a02561ef.tar.gz |
patch 8.2.2596: :doautocmd may confuse scripts listening to WinEnterv8.2.2596
Problem: :doautocmd may confuse scripts listening to WinEnter.
Solution: Do the current buffer last. (closes #7958)
-rw-r--r-- | src/autocmd.c | 20 | ||||
-rw-r--r-- | src/testdir/test_autocmd.vim | 10 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 27 insertions, 5 deletions
diff --git a/src/autocmd.c b/src/autocmd.c index 2f6001c26..ede8e7dbe 100644 --- a/src/autocmd.c +++ b/src/autocmd.c @@ -1336,7 +1336,7 @@ do_doautocmd( void ex_doautoall(exarg_T *eap) { - int retval; + int retval = OK; aco_save_T aco; buf_T *buf; bufref_T bufref; @@ -1353,7 +1353,8 @@ ex_doautoall(exarg_T *eap) */ 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); @@ -1363,22 +1364,31 @@ ex_doautoall(exarg_T *eap) 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 } @@ -2166,12 +2176,14 @@ apply_autocmds_group( 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; } diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim index e4f67f4fc..8abf911fa 100644 --- a/src/testdir/test_autocmd.vim +++ b/src/testdir/test_autocmd.vim @@ -2670,6 +2670,9 @@ func Test_autocmd_window() %bw! edit one.txt tabnew two.txt + vnew three.txt + tabnew four.txt + tabprevious let g:blist = [] augroup aucmd_win_test1 au! @@ -2678,7 +2681,12 @@ func Test_autocmd_window() 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! diff --git a/src/version.c b/src/version.c index 3981323f8..fbcf57e36 100644 --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2596, +/**/ 2595, /**/ 2594, |