Mercurial > vim
comparison src/channel.c @ 22210:d6f6f9fed7d7 v8.2.1654
patch 8.2.1654: when job writes to hidden buffer current window is wrong
Commit: https://github.com/vim/vim/commit/ad9ec5e79916d206fd7677b77e36485c47ae534f
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Sep 10 21:25:45 2020 +0200
patch 8.2.1654: when job writes to hidden buffer current window is wrong
Problem: When job writes to hidden buffer current window has display
errors. (Johnny McArthur)
Solution: Use aucmd_prepbuf() instead of switch_to_win_for_buf().
(closes #6925)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 10 Sep 2020 21:30:03 +0200 |
parents | 2cc0de1e05a6 |
children | a5bda73bc640 |
comparison
equal
deleted
inserted
replaced
22209:825fb261b141 | 22210:d6f6f9fed7d7 |
---|---|
2617 } | 2617 } |
2618 | 2618 |
2619 static void | 2619 static void |
2620 append_to_buffer(buf_T *buffer, char_u *msg, channel_T *channel, ch_part_T part) | 2620 append_to_buffer(buf_T *buffer, char_u *msg, channel_T *channel, ch_part_T part) |
2621 { | 2621 { |
2622 bufref_T save_curbuf = {NULL, 0, 0}; | 2622 aco_save_T aco; |
2623 win_T *save_curwin = NULL; | |
2624 tabpage_T *save_curtab = NULL; | |
2625 linenr_T lnum = buffer->b_ml.ml_line_count; | 2623 linenr_T lnum = buffer->b_ml.ml_line_count; |
2626 int save_write_to = buffer->b_write_to_channel; | 2624 int save_write_to = buffer->b_write_to_channel; |
2627 chanpart_T *ch_part = &channel->ch_part[part]; | 2625 chanpart_T *ch_part = &channel->ch_part[part]; |
2628 int save_p_ma = buffer->b_p_ma; | 2626 int save_p_ma = buffer->b_p_ma; |
2629 int empty = (buffer->b_ml.ml_flags & ML_EMPTY) ? 1 : 0; | 2627 int empty = (buffer->b_ml.ml_flags & ML_EMPTY) ? 1 : 0; |
2645 --lnum; | 2643 --lnum; |
2646 buffer->b_write_to_channel = FALSE; | 2644 buffer->b_write_to_channel = FALSE; |
2647 } | 2645 } |
2648 | 2646 |
2649 // Append to the buffer | 2647 // Append to the buffer |
2650 ch_log(channel, "appending line %d to buffer", (int)lnum + 1 - empty); | 2648 ch_log(channel, "appending line %d to buffer %s", |
2649 (int)lnum + 1 - empty, buffer->b_fname); | |
2651 | 2650 |
2652 buffer->b_p_ma = TRUE; | 2651 buffer->b_p_ma = TRUE; |
2653 | 2652 |
2654 // Save curbuf/curwin/curtab and make "buffer" the current buffer. | 2653 // set curbuf to be our buf, temporarily |
2655 switch_to_win_for_buf(buffer, &save_curwin, &save_curtab, &save_curbuf); | 2654 aucmd_prepbuf(&aco, buffer); |
2656 | 2655 |
2657 u_sync(TRUE); | 2656 u_sync(TRUE); |
2658 // ignore undo failure, undo is not very useful here | 2657 // ignore undo failure, undo is not very useful here |
2659 vim_ignored = u_save(lnum - empty, lnum + 1); | 2658 vim_ignored = u_save(lnum - empty, lnum + 1); |
2660 | 2659 |
2666 } | 2665 } |
2667 else | 2666 else |
2668 ml_append(lnum, msg, 0, FALSE); | 2667 ml_append(lnum, msg, 0, FALSE); |
2669 appended_lines_mark(lnum, 1L); | 2668 appended_lines_mark(lnum, 1L); |
2670 | 2669 |
2671 // Restore curbuf/curwin/curtab | 2670 // reset notion of buffer |
2672 restore_win_for_buf(save_curwin, save_curtab, &save_curbuf); | 2671 aucmd_restbuf(&aco); |
2673 | 2672 |
2674 if (ch_part->ch_nomodifiable) | 2673 if (ch_part->ch_nomodifiable) |
2675 buffer->b_p_ma = FALSE; | 2674 buffer->b_p_ma = FALSE; |
2676 else | 2675 else |
2677 buffer->b_p_ma = save_p_ma; | 2676 buffer->b_p_ma = save_p_ma; |
2691 | 2690 |
2692 // If the cursor is at or above the new line, move it one line | 2691 // If the cursor is at or above the new line, move it one line |
2693 // down. If the topline is outdated update it now. | 2692 // down. If the topline is outdated update it now. |
2694 if (move_cursor || wp->w_topline > buffer->b_ml.ml_line_count) | 2693 if (move_cursor || wp->w_topline > buffer->b_ml.ml_line_count) |
2695 { | 2694 { |
2695 win_T *save_curwin = curwin; | |
2696 | |
2696 if (move_cursor) | 2697 if (move_cursor) |
2697 ++wp->w_cursor.lnum; | 2698 ++wp->w_cursor.lnum; |
2698 save_curwin = curwin; | |
2699 curwin = wp; | 2699 curwin = wp; |
2700 curbuf = curwin->w_buffer; | 2700 curbuf = curwin->w_buffer; |
2701 scroll_cursor_bot(0, FALSE); | 2701 scroll_cursor_bot(0, FALSE); |
2702 curwin = save_curwin; | 2702 curwin = save_curwin; |
2703 curbuf = curwin->w_buffer; | 2703 curbuf = curwin->w_buffer; |