• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revisionac6f5741b155669e5484c2d361261080253ba859 (tree)
Time2022-11-19 23:00:03
AuthorBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 9.0.0910: setting lines in another buffer may not work well

Commit: https://github.com/vim/vim/commit/c934bfa1b765505e5fc491f2ee7cc106894cafc8
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Nov 19 13:59:43 2022 +0000

patch 9.0.0910: setting lines in another buffer may not work well
Problem: Setting lines in another buffer may not work well.
Solution: Make sure the buffer being changed has a window. (issue https://github.com/vim/vim/issues/11558)

Change Summary

Incremental Difference

diff -r f1872b62216a -r ac6f5741b155 src/evalbuffer.c
--- a/src/evalbuffer.c Sat Nov 19 14:15:03 2022 +0100
+++ b/src/evalbuffer.c Sat Nov 19 15:00:03 2022 +0100
@@ -137,14 +137,15 @@
137137 listitem_T *li = NULL;
138138 long added = 0;
139139 linenr_T append_lnum;
140- buf_T *curbuf_save = NULL;
141140 win_T *curwin_save = NULL;
142- int is_curbuf = buf == curbuf;
141+ aco_save_T aco;
142+ int using_aco = FALSE;
143143 int save_VIsual_active = VIsual_active;
144144
145145 // When using the current buffer ml_mfp will be set if needed. Useful when
146146 // setline() is used on startup. For other buffers the buffer must be
147147 // loaded.
148+ int is_curbuf = buf == curbuf;
148149 if (buf == NULL || (!is_curbuf && buf->b_ml.ml_mfp == NULL) || lnum < 1)
149150 {
150151 rettv->vval.v_number = 1; // FAIL
@@ -155,11 +156,21 @@
155156
156157 if (!is_curbuf)
157158 {
159+ // Set "curbuf" to the buffer being changed. Then make sure there is a
160+ // window for it to handle any side effects.
158161 VIsual_active = FALSE;
159- curbuf_save = curbuf;
160162 curwin_save = curwin;
161163 curbuf = buf;
162- find_win_for_curbuf();
164+ find_win_for_curbuf(); // simplest: find existing window for "buf"
165+
166+ if (curwin->w_buffer != buf)
167+ {
168+ // No existing window for this buffer. It is dangerous to have
169+ // curwin->w_buffer differ from "curbuf", use the autocmd window.
170+ curbuf = curwin->w_buffer;
171+ aucmd_prepbuf(&aco, buf);
172+ using_aco = TRUE;
173+ }
163174 }
164175
165176 if (append)
@@ -262,8 +273,15 @@
262273 done:
263274 if (!is_curbuf)
264275 {
265- curbuf = curbuf_save;
266- curwin = curwin_save;
276+ if (using_aco)
277+ {
278+ aucmd_restbuf(&aco);
279+ }
280+ else
281+ {
282+ curwin = curwin_save;
283+ curbuf = curwin->w_buffer;
284+ }
267285 VIsual_active = save_VIsual_active;
268286 }
269287 }
diff -r f1872b62216a -r ac6f5741b155 src/version.c
--- a/src/version.c Sat Nov 19 14:15:03 2022 +0100
+++ b/src/version.c Sat Nov 19 15:00:03 2022 +0100
@@ -696,6 +696,8 @@
696696 static int included_patches[] =
697697 { /* Add new patch number below this line */
698698 /**/
699+ 910,
700+/**/
699701 909,
700702 /**/
701703 908,
Show on old repository browser