mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 03:48:18 +00:00
vim-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 vim/vim#11558)
c934bfa1b7
Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
@@ -76,25 +76,35 @@ static void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append, typval_
|
|||||||
{
|
{
|
||||||
linenr_T lnum = lnum_arg + (append ? 1 : 0);
|
linenr_T lnum = lnum_arg + (append ? 1 : 0);
|
||||||
long added = 0;
|
long added = 0;
|
||||||
buf_T *curbuf_save = NULL;
|
|
||||||
win_T *curwin_save = NULL;
|
win_T *curwin_save = NULL;
|
||||||
const bool is_curbuf = buf == curbuf;
|
aco_save_T aco;
|
||||||
|
int using_aco = false;
|
||||||
const bool save_VIsual_active = VIsual_active;
|
const bool save_VIsual_active = VIsual_active;
|
||||||
|
|
||||||
// When using the current buffer ml_mfp will be set if needed. Useful when
|
// When using the current buffer ml_mfp will be set if needed. Useful when
|
||||||
// setline() is used on startup. For other buffers the buffer must be
|
// setline() is used on startup. For other buffers the buffer must be
|
||||||
// loaded.
|
// loaded.
|
||||||
|
const bool is_curbuf = buf == curbuf;
|
||||||
if (buf == NULL || (!is_curbuf && buf->b_ml.ml_mfp == NULL) || lnum < 1) {
|
if (buf == NULL || (!is_curbuf && buf->b_ml.ml_mfp == NULL) || lnum < 1) {
|
||||||
rettv->vval.v_number = 1; // FAIL
|
rettv->vval.v_number = 1; // FAIL
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_curbuf) {
|
if (!is_curbuf) {
|
||||||
|
// Set "curbuf" to the buffer being changed. Then make sure there is a
|
||||||
|
// window for it to handle any side effects.
|
||||||
VIsual_active = false;
|
VIsual_active = false;
|
||||||
curbuf_save = curbuf;
|
|
||||||
curwin_save = curwin;
|
curwin_save = curwin;
|
||||||
curbuf = buf;
|
curbuf = buf;
|
||||||
find_win_for_curbuf();
|
find_win_for_curbuf(); // simplest: find existing window for "buf"
|
||||||
|
|
||||||
|
if (curwin->w_buffer != buf) {
|
||||||
|
// No existing window for this buffer. It is dangerous to have
|
||||||
|
// curwin->w_buffer differ from "curbuf", use the autocmd window.
|
||||||
|
curbuf = curwin->w_buffer;
|
||||||
|
aucmd_prepbuf(&aco, buf);
|
||||||
|
using_aco = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
linenr_T append_lnum;
|
linenr_T append_lnum;
|
||||||
@@ -193,8 +203,12 @@ static void set_buffer_lines(buf_T *buf, linenr_T lnum_arg, bool append, typval_
|
|||||||
|
|
||||||
done:
|
done:
|
||||||
if (!is_curbuf) {
|
if (!is_curbuf) {
|
||||||
curbuf = curbuf_save;
|
if (using_aco) {
|
||||||
curwin = curwin_save;
|
aucmd_restbuf(&aco);
|
||||||
|
} else {
|
||||||
|
curwin = curwin_save;
|
||||||
|
curbuf = curwin->w_buffer;
|
||||||
|
}
|
||||||
VIsual_active = save_VIsual_active;
|
VIsual_active = save_VIsual_active;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user