aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/fileio.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-11-29 18:20:11 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-11-29 20:36:31 +0800
commit3173d07564e7cdf0834099a379f0faf480c76224 (patch)
tree2ced5358c126a6015f0b66a1e015542f039ac29f /src/nvim/fileio.c
parent273358651af6b6d172944cd1b1b41a9869d53b10 (diff)
downloadrneovim-3173d07564e7cdf0834099a379f0faf480c76224.tar.gz
rneovim-3173d07564e7cdf0834099a379f0faf480c76224.tar.bz2
rneovim-3173d07564e7cdf0834099a379f0faf480c76224.zip
vim-patch:9.0.0965: using one window for executing autocommands is insufficient
Problem: Using one window for executing autocommands is insufficient. Solution: Use up to five windows for executing autocommands. https://github.com/vim/vim/commit/e76062c078debed0df818f70e4db14ad7a7cb53a N/A patches for version.c: vim-patch:9.0.0966: some compilers don't allow a declaration after a label Problem: Some compilers don't allow a declaration after a label. Solution: Move the declaration to the start of the block. (John Marriott) https://github.com/vim/vim/commit/f86490ed4fdab213a28f667abd055c023a73d645 Co-authored-by: Bram Moolenaar <Bram@vim.org>
Diffstat (limited to 'src/nvim/fileio.c')
-rw-r--r--src/nvim/fileio.c45
1 files changed, 29 insertions, 16 deletions
diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c
index 2bff0fa2f9..dabec5e95e 100644
--- a/src/nvim/fileio.c
+++ b/src/nvim/fileio.c
@@ -2310,6 +2310,12 @@ int buf_write(buf_T *buf, char *fname, char *sfname, linenr_T start, linenr_T en
// Set curwin/curbuf to buf and save a few things.
aucmd_prepbuf(&aco, buf);
+ if (curbuf != buf) {
+ // Could not find a window for "buf". Doing more might cause
+ // problems, better bail out.
+ return FAIL;
+ }
+
set_bufref(&bufref, buf);
if (append) {
@@ -3612,25 +3618,27 @@ nofail:
// Apply POST autocommands.
// Careful: The autocommands may call buf_write() recursively!
+ // Only do this when a window was found for "buf".
aucmd_prepbuf(&aco, buf);
+ if (curbuf == buf) {
+ if (append) {
+ apply_autocmds_exarg(EVENT_FILEAPPENDPOST, fname, fname,
+ false, curbuf, eap);
+ } else if (filtering) {
+ apply_autocmds_exarg(EVENT_FILTERWRITEPOST, NULL, fname,
+ false, curbuf, eap);
+ } else if (reset_changed && whole) {
+ apply_autocmds_exarg(EVENT_BUFWRITEPOST, fname, fname,
+ false, curbuf, eap);
+ } else {
+ apply_autocmds_exarg(EVENT_FILEWRITEPOST, fname, fname,
+ false, curbuf, eap);
+ }
- if (append) {
- apply_autocmds_exarg(EVENT_FILEAPPENDPOST, fname, fname,
- false, curbuf, eap);
- } else if (filtering) {
- apply_autocmds_exarg(EVENT_FILTERWRITEPOST, NULL, fname,
- false, curbuf, eap);
- } else if (reset_changed && whole) {
- apply_autocmds_exarg(EVENT_BUFWRITEPOST, fname, fname,
- false, curbuf, eap);
- } else {
- apply_autocmds_exarg(EVENT_FILEWRITEPOST, fname, fname,
- false, curbuf, eap);
+ // restore curwin/curbuf and a few other things
+ aucmd_restbuf(&aco);
}
- // restore curwin/curbuf and a few other things
- aucmd_restbuf(&aco);
-
if (aborting()) { // autocmds may abort script processing
retval = false;
}
@@ -5003,8 +5011,13 @@ void buf_reload(buf_T *buf, int orig_mode, bool reload_options)
aco_save_T aco;
int flags = READ_NEW;
- // set curwin/curbuf for "buf" and save some things
+ // Set curwin/curbuf for "buf" and save some things.
aucmd_prepbuf(&aco, buf);
+ if (curbuf != buf) {
+ // Failed to find a window for "buf", it is dangerous to continue,
+ // better bail out.
+ return;
+ }
// Unless reload_options is set, we only want to read the text from the
// file, not reset the syntax highlighting, clear marks, diff status, etc.