summaryrefslogtreecommitdiffstats
path: root/src/buffer.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/buffer.c
parent8e5eece8c5f22a2235edeb743d06253f6c54cfdc (diff)
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/buffer.c')
-rw-r--r--src/buffer.c45
1 files changed, 44 insertions, 1 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 181145d42c..369eec7098 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -5794,9 +5794,52 @@ buf_spname(buf_T *buf)
return NULL;
}
-#if (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \
+#if defined(FEAT_JOB_CHANNEL) \
|| defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) \
|| defined(PROTO)
+# define SWITCH_TO_WIN
+
+/*
+ * Find a window that contains "buf" and switch to it.
+ * If there is no such window, use the current window and change "curbuf".
+ * Caller must initialize save_curbuf to NULL.
+ * restore_win_for_buf() MUST be called later!
+ */
+ void
+switch_to_win_for_buf(
+ buf_T *buf,
+ win_T **save_curwinp,
+ tabpage_T **save_curtabp,
+ bufref_T *save_curbuf)
+{
+ win_T *wp;
+ tabpage_T *tp;
+
+ if (find_win_for_buf(buf, &wp, &tp) == FAIL)
+ switch_buffer(save_curbuf, buf);
+ else if (switch_win(save_curwinp, save_curtabp, wp, tp, TRUE) == FAIL)
+ {
+ restore_win(*save_curwinp, *save_curtabp, TRUE);
+ switch_buffer(save_curbuf, buf);
+ }
+}
+
+ void
+restore_win_for_buf(
+ win_T *save_curwin,
+ tabpage_T *save_curtab,
+ bufref_T *save_curbuf)
+{
+ if (save_curbuf->br_buf == NULL)
+ restore_win(save_curwin, save_curtab, TRUE);
+ else
+ restore_buffer(save_curbuf);
+}
+#endif
+
+#if (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \
+ || defined(SWITCH_TO_WIN) \
+ || defined(PROTO)
/*
* Find a window for buffer "buf".
* If found OK is returned and "wp" and "tp" are set to the window and tabpage.