Mercurial > vim
comparison src/autocmd.c @ 24110:03438d77d8ab v8.2.2596
patch 8.2.2596: :doautocmd may confuse scripts listening to WinEnter
Commit: https://github.com/vim/vim/commit/41cd80335cf318c15c8b0139f53ab5e8a02561ef
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Mar 13 15:47:56 2021 +0100
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 https://github.com/vim/vim/issues/7958)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 13 Mar 2021 16:00:03 +0100 |
parents | 97296182d336 |
children | f8619a303e9d |
comparison
equal
deleted
inserted
replaced
24109:f26a7a00f121 | 24110:03438d77d8ab |
---|---|
1334 * ":doautoall": execute autocommands for each loaded buffer. | 1334 * ":doautoall": execute autocommands for each loaded buffer. |
1335 */ | 1335 */ |
1336 void | 1336 void |
1337 ex_doautoall(exarg_T *eap) | 1337 ex_doautoall(exarg_T *eap) |
1338 { | 1338 { |
1339 int retval; | 1339 int retval = OK; |
1340 aco_save_T aco; | 1340 aco_save_T aco; |
1341 buf_T *buf; | 1341 buf_T *buf; |
1342 bufref_T bufref; | 1342 bufref_T bufref; |
1343 char_u *arg = eap->arg; | 1343 char_u *arg = eap->arg; |
1344 int call_do_modelines = check_nomodeline(&arg); | 1344 int call_do_modelines = check_nomodeline(&arg); |
1351 * gives problems when the autocommands make changes to the list of | 1351 * gives problems when the autocommands make changes to the list of |
1352 * buffers or windows... | 1352 * buffers or windows... |
1353 */ | 1353 */ |
1354 FOR_ALL_BUFFERS(buf) | 1354 FOR_ALL_BUFFERS(buf) |
1355 { | 1355 { |
1356 if (buf->b_ml.ml_mfp != NULL) | 1356 // Only do loaded buffers and skip the current buffer, it's done last. |
1357 if (buf->b_ml.ml_mfp != NULL && buf != curbuf) | |
1357 { | 1358 { |
1358 // find a window for this buffer and save some values | 1359 // find a window for this buffer and save some values |
1359 aucmd_prepbuf(&aco, buf); | 1360 aucmd_prepbuf(&aco, buf); |
1360 set_bufref(&bufref, buf); | 1361 set_bufref(&bufref, buf); |
1361 | 1362 |
1362 // execute the autocommands for this buffer | 1363 // execute the autocommands for this buffer |
1363 retval = do_doautocmd(arg, FALSE, &did_aucmd); | 1364 retval = do_doautocmd(arg, FALSE, &did_aucmd); |
1364 | 1365 |
1365 if (call_do_modelines && did_aucmd) | 1366 if (call_do_modelines && did_aucmd) |
1366 { | |
1367 // Execute the modeline settings, but don't set window-local | 1367 // Execute the modeline settings, but don't set window-local |
1368 // options if we are using the current window for another | 1368 // options if we are using the current window for another |
1369 // buffer. | 1369 // buffer. |
1370 do_modelines(curwin == aucmd_win ? OPT_NOWIN : 0); | 1370 do_modelines(curwin == aucmd_win ? OPT_NOWIN : 0); |
1371 } | |
1372 | 1371 |
1373 // restore the current window | 1372 // restore the current window |
1374 aucmd_restbuf(&aco); | 1373 aucmd_restbuf(&aco); |
1375 | 1374 |
1376 // stop if there is some error or buffer was deleted | 1375 // stop if there is some error or buffer was deleted |
1377 if (retval == FAIL || !bufref_valid(&bufref)) | 1376 if (retval == FAIL || !bufref_valid(&bufref)) |
1377 { | |
1378 retval = FAIL; | |
1378 break; | 1379 break; |
1379 } | 1380 } |
1381 } | |
1382 } | |
1383 | |
1384 // Execute autocommands for the current buffer last. | |
1385 if (retval == OK) | |
1386 { | |
1387 do_doautocmd(arg, FALSE, &did_aucmd); | |
1388 if (call_do_modelines && did_aucmd) | |
1389 do_modelines(0); | |
1380 } | 1390 } |
1381 | 1391 |
1382 check_cursor(); // just in case lines got deleted | 1392 check_cursor(); // just in case lines got deleted |
1383 } | 1393 } |
1384 | 1394 |
2164 restoreRedobuff(&save_redo); | 2174 restoreRedobuff(&save_redo); |
2165 did_filetype = FALSE; | 2175 did_filetype = FALSE; |
2166 while (au_pending_free_buf != NULL) | 2176 while (au_pending_free_buf != NULL) |
2167 { | 2177 { |
2168 buf_T *b = au_pending_free_buf->b_next; | 2178 buf_T *b = au_pending_free_buf->b_next; |
2179 | |
2169 vim_free(au_pending_free_buf); | 2180 vim_free(au_pending_free_buf); |
2170 au_pending_free_buf = b; | 2181 au_pending_free_buf = b; |
2171 } | 2182 } |
2172 while (au_pending_free_win != NULL) | 2183 while (au_pending_free_win != NULL) |
2173 { | 2184 { |
2174 win_T *w = au_pending_free_win->w_next; | 2185 win_T *w = au_pending_free_win->w_next; |
2186 | |
2175 vim_free(au_pending_free_win); | 2187 vim_free(au_pending_free_win); |
2176 au_pending_free_win = w; | 2188 au_pending_free_win = w; |
2177 } | 2189 } |
2178 } | 2190 } |
2179 | 2191 |