comparison src/buffer.c @ 11959:91a26b7a4119 v8.0.0860

patch 8.0.0860: side effects when channel appends to a buffer commit https://github.com/vim/vim/commit/6b7355a30ddd294c19cd9be924d487d592ccfae1 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Aug 4 21:37:54 2017 +0200 patch 8.0.0860: side effects when channel appends to a buffer 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)
author Christian Brabandt <cb@256bit.org>
date Fri, 04 Aug 2017 21:45:04 +0200
parents bc0fee081e1e
children d4ffc3dc9fb0
comparison
equal deleted inserted replaced
11958:052270a67371 11959:91a26b7a4119
5792 if (buf->b_fname == NULL) 5792 if (buf->b_fname == NULL)
5793 return (char_u *)_("[No Name]"); 5793 return (char_u *)_("[No Name]");
5794 return NULL; 5794 return NULL;
5795 } 5795 }
5796 5796
5797 #if defined(FEAT_JOB_CHANNEL) \
5798 || defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) \
5799 || defined(PROTO)
5800 # define SWITCH_TO_WIN
5801
5802 /*
5803 * Find a window that contains "buf" and switch to it.
5804 * If there is no such window, use the current window and change "curbuf".
5805 * Caller must initialize save_curbuf to NULL.
5806 * restore_win_for_buf() MUST be called later!
5807 */
5808 void
5809 switch_to_win_for_buf(
5810 buf_T *buf,
5811 win_T **save_curwinp,
5812 tabpage_T **save_curtabp,
5813 bufref_T *save_curbuf)
5814 {
5815 win_T *wp;
5816 tabpage_T *tp;
5817
5818 if (find_win_for_buf(buf, &wp, &tp) == FAIL)
5819 switch_buffer(save_curbuf, buf);
5820 else if (switch_win(save_curwinp, save_curtabp, wp, tp, TRUE) == FAIL)
5821 {
5822 restore_win(*save_curwinp, *save_curtabp, TRUE);
5823 switch_buffer(save_curbuf, buf);
5824 }
5825 }
5826
5827 void
5828 restore_win_for_buf(
5829 win_T *save_curwin,
5830 tabpage_T *save_curtab,
5831 bufref_T *save_curbuf)
5832 {
5833 if (save_curbuf->br_buf == NULL)
5834 restore_win(save_curwin, save_curtab, TRUE);
5835 else
5836 restore_buffer(save_curbuf);
5837 }
5838 #endif
5839
5797 #if (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ 5840 #if (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \
5798 || defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) \ 5841 || defined(SWITCH_TO_WIN) \
5799 || defined(PROTO) 5842 || defined(PROTO)
5800 /* 5843 /*
5801 * Find a window for buffer "buf". 5844 * Find a window for buffer "buf".
5802 * If found OK is returned and "wp" and "tp" are set to the window and tabpage. 5845 * If found OK is returned and "wp" and "tp" are set to the window and tabpage.
5803 * If not found FAIL is returned. 5846 * If not found FAIL is returned.