summaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c43
1 files changed, 29 insertions, 14 deletions
diff --git a/src/buffer.c b/src/buffer.c
index f99da25e88..eba5dd2d57 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -150,11 +150,15 @@ buffer_ensure_loaded(buf_T *buf)
{
aco_save_T aco;
+ // Make sure the buffer is in a window. If not then skip it.
aucmd_prepbuf(&aco, buf);
- if (swap_exists_action != SEA_READONLY)
- swap_exists_action = SEA_NONE;
- open_buffer(FALSE, NULL, 0);
- aucmd_restbuf(&aco);
+ if (curbuf == buf)
+ {
+ if (swap_exists_action != SEA_READONLY)
+ swap_exists_action = SEA_NONE;
+ open_buffer(FALSE, NULL, 0);
+ aucmd_restbuf(&aco);
+ }
}
}
#endif
@@ -361,21 +365,26 @@ open_buffer(
{
aco_save_T aco;
- // Go to the buffer that was opened.
+ // Go to the buffer that was opened, make sure it is in a window.
+ // If not then skip it.
aucmd_prepbuf(&aco, old_curbuf.br_buf);
- do_modelines(0);
- curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED);
+ if (curbuf == old_curbuf.br_buf)
+ {
+ do_modelines(0);
+ curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED);
- if ((flags & READ_NOWINENTER) == 0)
+ if ((flags & READ_NOWINENTER) == 0)
#ifdef FEAT_EVAL
- apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, FALSE,
- curbuf, &retval);
+ apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL,
+ FALSE, curbuf, &retval);
#else
- apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf);
+ apply_autocmds(EVENT_BUFWINENTER, NULL, NULL,
+ FALSE, curbuf);
#endif
- // restore curwin/curbuf and a few other things
- aucmd_restbuf(&aco);
+ // restore curwin/curbuf and a few other things
+ aucmd_restbuf(&aco);
+ }
}
}
@@ -5942,8 +5951,14 @@ buf_contents_changed(buf_T *buf)
return TRUE;
}
- // set curwin/curbuf to buf and save a few things
+ // Set curwin/curbuf to buf and save a few things.
aucmd_prepbuf(&aco, newbuf);
+ if (curbuf != newbuf)
+ {
+ // Failed to find a window for "newbuf".
+ wipe_buffer(newbuf, FALSE);
+ return TRUE;
+ }
if (ml_open(curbuf) == OK
&& readfile(buf->b_ffname, buf->b_fname,