Mirror of the Vim source from https://github.com/vim/vim
Revision | ac6f5741b155669e5484c2d361261080253ba859 (tree) |
---|---|
Time | 2022-11-19 23:00:03 |
Author | Bram Moolenaar <Bram@vim....> |
Commiter | Bram Moolenaar |
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
@@ -137,14 +137,15 @@ | ||
137 | 137 | listitem_T *li = NULL; |
138 | 138 | long added = 0; |
139 | 139 | linenr_T append_lnum; |
140 | - buf_T *curbuf_save = NULL; | |
141 | 140 | win_T *curwin_save = NULL; |
142 | - int is_curbuf = buf == curbuf; | |
141 | + aco_save_T aco; | |
142 | + int using_aco = FALSE; | |
143 | 143 | int save_VIsual_active = VIsual_active; |
144 | 144 | |
145 | 145 | // When using the current buffer ml_mfp will be set if needed. Useful when |
146 | 146 | // setline() is used on startup. For other buffers the buffer must be |
147 | 147 | // loaded. |
148 | + int is_curbuf = buf == curbuf; | |
148 | 149 | if (buf == NULL || (!is_curbuf && buf->b_ml.ml_mfp == NULL) || lnum < 1) |
149 | 150 | { |
150 | 151 | rettv->vval.v_number = 1; // FAIL |
@@ -155,11 +156,21 @@ | ||
155 | 156 | |
156 | 157 | if (!is_curbuf) |
157 | 158 | { |
159 | + // Set "curbuf" to the buffer being changed. Then make sure there is a | |
160 | + // window for it to handle any side effects. | |
158 | 161 | VIsual_active = FALSE; |
159 | - curbuf_save = curbuf; | |
160 | 162 | curwin_save = curwin; |
161 | 163 | 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 | + } | |
163 | 174 | } |
164 | 175 | |
165 | 176 | if (append) |
@@ -262,8 +273,15 @@ | ||
262 | 273 | done: |
263 | 274 | if (!is_curbuf) |
264 | 275 | { |
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 | + } | |
267 | 285 | VIsual_active = save_VIsual_active; |
268 | 286 | } |
269 | 287 | } |
@@ -696,6 +696,8 @@ | ||
696 | 696 | static int included_patches[] = |
697 | 697 | { /* Add new patch number below this line */ |
698 | 698 | /**/ |
699 | + 910, | |
700 | +/**/ | |
699 | 701 | 909, |
700 | 702 | /**/ |
701 | 703 | 908, |