aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/buffer.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-12-02 20:39:24 +0800
committerGitHub <noreply@github.com>2022-12-02 20:39:24 +0800
commit1145a9b2485a4e5072cffe28a958da983cd59e84 (patch)
tree13059f09a9825a7eae3d75c8556436845dc1e492 /src/nvim/buffer.c
parent805c83f43e3d6832a54bc4a1de1dd4d4da43d58e (diff)
downloadrneovim-1145a9b2485a4e5072cffe28a958da983cd59e84.tar.gz
rneovim-1145a9b2485a4e5072cffe28a958da983cd59e84.tar.bz2
rneovim-1145a9b2485a4e5072cffe28a958da983cd59e84.zip
feat(aucmd_win): allow crazy things with hidden buffers (#21250)
Problem: Crash when doing crazy things with hidden buffers. Solution: Dynamically allocate the list of autocommand windows.
Diffstat (limited to 'src/nvim/buffer.c')
-rw-r--r--src/nvim/buffer.c34
1 files changed, 12 insertions, 22 deletions
diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c
index 2060f799bd..c9fe5f9670 100644
--- a/src/nvim/buffer.c
+++ b/src/nvim/buffer.c
@@ -181,13 +181,11 @@ void buffer_ensure_loaded(buf_T *buf)
if (buf->b_ml.ml_mfp == NULL) {
aco_save_T aco;
- // Make sure the buffer is in a window. If not then skip it.
+ // Make sure the buffer is in a window.
aucmd_prepbuf(&aco, buf);
- if (curbuf == buf) {
- swap_exists_action = SEA_NONE;
- open_buffer(false, NULL, 0);
- aucmd_restbuf(&aco);
- }
+ swap_exists_action = SEA_NONE;
+ open_buffer(false, NULL, 0);
+ aucmd_restbuf(&aco);
}
}
@@ -369,20 +367,17 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags_arg)
aco_save_T aco;
// 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);
- if (curbuf == old_curbuf.br_buf) {
- do_modelines(0);
- curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED);
-
- if ((flags & READ_NOWINENTER) == 0) {
- apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, false, curbuf,
- &retval);
- }
+ do_modelines(0);
+ curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED);
- // restore curwin/curbuf and a few other things
- aucmd_restbuf(&aco);
+ if ((flags & READ_NOWINENTER) == 0) {
+ apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, false, curbuf,
+ &retval);
}
+
+ // restore curwin/curbuf and a few other things
+ aucmd_restbuf(&aco);
}
return retval;
@@ -4177,11 +4172,6 @@ bool buf_contents_changed(buf_T *buf)
// Set curwin/curbuf to buf and save a few things.
aco_save_T aco;
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,