diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-11-29 21:07:29 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-29 21:07:29 +0800 |
commit | d311c5481dede47d752fa39cb00d728ba18ef5bc (patch) | |
tree | dd2c01f384b4c3713a1d9c5b976cd7c0f8c91fcd /src/nvim/quickfix.c | |
parent | 89f0987bde8124f8fcbbcbf8320dbdabe0d69ba9 (diff) | |
parent | 95f5cf96912727a1ede055211645ac9779f3da44 (diff) | |
download | rneovim-d311c5481dede47d752fa39cb00d728ba18ef5bc.tar.gz rneovim-d311c5481dede47d752fa39cb00d728ba18ef5bc.tar.bz2 rneovim-d311c5481dede47d752fa39cb00d728ba18ef5bc.zip |
Merge pull request #21234 from zeertzjq/vim-9.0.0965
vim-patch:9.0.{0965,0966,0967}: using one window for executing autocommands is insufficient
Diffstat (limited to 'src/nvim/quickfix.c')
-rw-r--r-- | src/nvim/quickfix.c | 96 |
1 files changed, 53 insertions, 43 deletions
diff --git a/src/nvim/quickfix.c b/src/nvim/quickfix.c index f083b6792b..be6ddede2e 100644 --- a/src/nvim/quickfix.c +++ b/src/nvim/quickfix.c @@ -3902,21 +3902,27 @@ static void qf_update_buffer(qf_info_T *qi, qfline_T *old_last) aco_save_T aco; + bool do_fill = true; if (old_last == NULL) { // set curwin/curbuf to buf and save a few things aucmd_prepbuf(&aco, buf); + if (curbuf != buf) { + do_fill = false; // failed to find a window for "buf" + } } - qf_update_win_titlevar(qi); + if (do_fill) { + qf_update_win_titlevar(qi); - qf_fill_buffer(qf_get_curlist(qi), buf, old_last, qf_winid); - buf_inc_changedtick(buf); + qf_fill_buffer(qf_get_curlist(qi), buf, old_last, qf_winid); + buf_inc_changedtick(buf); - if (old_last == NULL) { - (void)qf_win_pos_update(qi, 0); + if (old_last == NULL) { + (void)qf_win_pos_update(qi, 0); - // restore curwin/curbuf and a few other things - aucmd_restbuf(&aco); + // restore curwin/curbuf and a few other things + aucmd_restbuf(&aco); + } } // Only redraw when added lines are visible. This avoids flickering when @@ -5463,9 +5469,11 @@ static int vgr_process_files(win_T *wp, qf_info_T *qi, vgr_args_T *cmd_args, boo // options! aco_save_T aco; aucmd_prepbuf(&aco, buf); - apply_autocmds(EVENT_FILETYPE, buf->b_p_ft, buf->b_fname, true, buf); - do_modelines(OPT_NOWIN); - aucmd_restbuf(&aco); + if (curbuf == buf) { + apply_autocmds(EVENT_FILETYPE, buf->b_p_ft, buf->b_fname, true, buf); + do_modelines(OPT_NOWIN); + aucmd_restbuf(&aco); + } } } } @@ -5623,41 +5631,43 @@ static buf_T *load_dummy_buffer(char *fname, char *dirname_start, char *resultin // set curwin/curbuf to buf and save a few things aco_save_T aco; aucmd_prepbuf(&aco, newbuf); - - // Need to set the filename for autocommands. - (void)setfname(curbuf, fname, NULL, false); - - // Create swap file now to avoid the ATTENTION message. - check_need_swap(true); - - // Remove the "dummy" flag, otherwise autocommands may not - // work. - curbuf->b_flags &= ~BF_DUMMY; - - bufref_T newbuf_to_wipe; - newbuf_to_wipe.br_buf = NULL; - int readfile_result = readfile(fname, NULL, (linenr_T)0, (linenr_T)0, - (linenr_T)MAXLNUM, NULL, - READ_NEW | READ_DUMMY, false); - newbuf->b_locked--; - if (readfile_result == OK - && !got_int - && !(curbuf->b_flags & BF_NEW)) { - failed = false; - if (curbuf != newbuf) { - // Bloody autocommands changed the buffer! Can happen when - // using netrw and editing a remote file. Use the current - // buffer instead, delete the dummy one after restoring the - // window stuff. - set_bufref(&newbuf_to_wipe, newbuf); - newbuf = curbuf; + if (curbuf == newbuf) { + // Need to set the filename for autocommands. + (void)setfname(curbuf, fname, NULL, false); + + // Create swap file now to avoid the ATTENTION message. + check_need_swap(true); + + // Remove the "dummy" flag, otherwise autocommands may not + // work. + curbuf->b_flags &= ~BF_DUMMY; + + bufref_T newbuf_to_wipe; + newbuf_to_wipe.br_buf = NULL; + int readfile_result = readfile(fname, NULL, (linenr_T)0, (linenr_T)0, + (linenr_T)MAXLNUM, NULL, + READ_NEW | READ_DUMMY, false); + newbuf->b_locked--; + if (readfile_result == OK + && !got_int + && !(curbuf->b_flags & BF_NEW)) { + failed = false; + if (curbuf != newbuf) { + // Bloody autocommands changed the buffer! Can happen when + // using netrw and editing a remote file. Use the current + // buffer instead, delete the dummy one after restoring the + // window stuff. + set_bufref(&newbuf_to_wipe, newbuf); + newbuf = curbuf; + } } - } - // Restore curwin/curbuf and a few other things. - aucmd_restbuf(&aco); - if (newbuf_to_wipe.br_buf != NULL && bufref_valid(&newbuf_to_wipe)) { - wipe_buffer(newbuf_to_wipe.br_buf, false); + // Restore curwin/curbuf and a few other things. + aucmd_restbuf(&aco); + + if (newbuf_to_wipe.br_buf != NULL && bufref_valid(&newbuf_to_wipe)) { + wipe_buffer(newbuf_to_wipe.br_buf, false); + } } // Add back the "dummy" flag, otherwise buflist_findname_file_id() |