To: vim_dev@googlegroups.com Subject: Patch 8.2.2596 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2596 Problem: :doautocmd may confuse scripts listening to WinEnter. Solution: Do the current buffer last. (closes #7958) Files: src/autocmd.c, src/testdir/test_autocmd.vim *** ../vim-8.2.2595/src/autocmd.c 2021-01-28 13:47:55.056905117 +0100 --- src/autocmd.c 2021-03-13 15:47:24.441861511 +0100 *************** *** 1336,1342 **** void ex_doautoall(exarg_T *eap) { ! int retval; aco_save_T aco; buf_T *buf; bufref_T bufref; --- 1336,1342 ---- void ex_doautoall(exarg_T *eap) { ! int retval = OK; aco_save_T aco; buf_T *buf; bufref_T bufref; *************** *** 1353,1359 **** */ FOR_ALL_BUFFERS(buf) { ! if (buf->b_ml.ml_mfp != NULL) { // find a window for this buffer and save some values aucmd_prepbuf(&aco, buf); --- 1353,1360 ---- */ FOR_ALL_BUFFERS(buf) { ! // 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,1384 **** 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)) break; } } check_cursor(); // just in case lines got deleted } --- 1364,1394 ---- 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,2177 **** --- 2176,2189 ---- 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; } *** ../vim-8.2.2595/src/testdir/test_autocmd.vim 2021-02-07 13:32:42.602587161 +0100 --- src/testdir/test_autocmd.vim 2021-03-13 15:43:07.670908877 +0100 *************** *** 2670,2675 **** --- 2670,2678 ---- %bw! edit one.txt tabnew two.txt + vnew three.txt + tabnew four.txt + tabprevious let g:blist = [] augroup aucmd_win_test1 au! *************** *** 2678,2684 **** augroup END doautoall BufEnter ! call assert_equal([['one.txt', 'autocmd'], ['two.txt', '']], g:blist) augroup aucmd_win_test1 au! --- 2681,2692 ---- augroup END doautoall BufEnter ! call assert_equal([ ! \ ['one.txt', 'autocmd'], ! \ ['two.txt', ''], ! \ ['four.txt', 'autocmd'], ! \ ['three.txt', ''], ! \ ], g:blist) augroup aucmd_win_test1 au! *** ../vim-8.2.2595/src/version.c 2021-03-13 14:28:59.339594607 +0100 --- src/version.c 2021-03-13 15:47:35.077819147 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2596, /**/ -- I have read and understood the above. X________________ /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///