summaryrefslogtreecommitdiff
path: root/src/channel.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2017-08-04 21:37:54 +0200
committerBram Moolenaar <Bram@vim.org>2017-08-04 21:37:54 +0200
commit6b7355a30ddd294c19cd9be924d487d592ccfae1 (patch)
tree94c51538082a4ffe2c0306e6b7422607be5e3696 /src/channel.c
parent8e5eece8c5f22a2235edeb743d06253f6c54cfdc (diff)
downloadvim-git-6b7355a30ddd294c19cd9be924d487d592ccfae1.tar.gz
patch 8.0.0860: side effects when channel appends to a bufferv8.0.0860
Problem: There may be side effects when a channel appends to a buffer that is not the current buffer. Solution: Properly switch to another buffer before appending. (Yasuhiro Matsumoto, closes #1926, closes #1937)
Diffstat (limited to 'src/channel.c')
-rw-r--r--src/channel.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/src/channel.c b/src/channel.c
index c511f22ed..b19f08992 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -2284,7 +2284,9 @@ invoke_one_time_callback(
static void
append_to_buffer(buf_T *buffer, char_u *msg, channel_T *channel, ch_part_T part)
{
- buf_T *save_curbuf = curbuf;
+ bufref_T save_curbuf = {NULL, 0, 0};
+ win_T *save_curwin = NULL;
+ tabpage_T *save_curtab = NULL;
linenr_T lnum = buffer->b_ml.ml_line_count;
int save_write_to = buffer->b_write_to_channel;
chanpart_T *ch_part = &channel->ch_part[part];
@@ -2313,8 +2315,10 @@ append_to_buffer(buf_T *buffer, char_u *msg, channel_T *channel, ch_part_T part)
ch_log(channel, "appending line %d to buffer", (int)lnum + 1 - empty);
buffer->b_p_ma = TRUE;
- curbuf = buffer;
- curwin->w_buffer = curbuf;
+
+ /* Save curbuf/curwin/curtab and make "buffer" the current buffer. */
+ switch_to_win_for_buf(buffer, &save_curwin, &save_curtab, &save_curbuf);
+
u_sync(TRUE);
/* ignore undo failure, undo is not very useful here */
ignored = u_save(lnum - empty, lnum + 1);
@@ -2328,8 +2332,10 @@ append_to_buffer(buf_T *buffer, char_u *msg, channel_T *channel, ch_part_T part)
else
ml_append(lnum, msg, 0, FALSE);
appended_lines_mark(lnum, 1L);
- curbuf = save_curbuf;
- curwin->w_buffer = curbuf;
+
+ /* Restore curbuf/curwin/curtab */
+ restore_win_for_buf(save_curwin, save_curtab, &save_curbuf);
+
if (ch_part->ch_nomodifiable)
buffer->b_p_ma = FALSE;
else
@@ -2338,7 +2344,6 @@ append_to_buffer(buf_T *buffer, char_u *msg, channel_T *channel, ch_part_T part)
if (buffer->b_nwindows > 0)
{
win_T *wp;
- win_T *save_curwin;
FOR_ALL_WINDOWS(wp)
{