Patch 9.0.0910
Problem:    Setting lines in another buffer may not work well.
Solution:   Make sure the buffer being changed has a window. (issue #11558)
Files:      src/evalbuffer.c


*** ../vim-9.0.0909/src/evalbuffer.c    2022-11-06 22:25:59.111977620 +0000
--- src/evalbuffer.c    2022-11-19 13:44:11.499338895 +0000
***************
*** 137,150 ****
      listitem_T        *li = NULL;
      long      added = 0;
      linenr_T  append_lnum;
-     buf_T     *curbuf_save = NULL;
      win_T     *curwin_save = NULL;
!     int               is_curbuf = buf == curbuf;
      int               save_VIsual_active = VIsual_active;
  
      // 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
      // loaded.
      if (buf == NULL || (!is_curbuf && buf->b_ml.ml_mfp == NULL) || lnum < 1)
      {
        rettv->vval.v_number = 1;       // FAIL
--- 137,151 ----
      listitem_T        *li = NULL;
      long      added = 0;
      linenr_T  append_lnum;
      win_T     *curwin_save = NULL;
!     aco_save_T        aco;
!     int               using_aco = FALSE;
      int               save_VIsual_active = VIsual_active;
  
      // 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
      // loaded.
+     int is_curbuf = buf == curbuf;
      if (buf == NULL || (!is_curbuf && buf->b_ml.ml_mfp == NULL) || lnum < 1)
      {
        rettv->vval.v_number = 1;       // FAIL
***************
*** 155,165 ****
  
      if (!is_curbuf)
      {
        VIsual_active = FALSE;
-       curbuf_save = curbuf;
        curwin_save = curwin;
        curbuf = buf;
!       find_win_for_curbuf();
      }
  
      if (append)
--- 156,176 ----
  
      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;
        curwin_save = curwin;
        curbuf = buf;
!       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;
!       }
      }
  
      if (append)
***************
*** 262,269 ****
  done:
      if (!is_curbuf)
      {
!       curbuf = curbuf_save;
!       curwin = curwin_save;
        VIsual_active = save_VIsual_active;
      }
  }
--- 273,287 ----
  done:
      if (!is_curbuf)
      {
!       if (using_aco)
!       {
!           aucmd_restbuf(&aco);
!       }
!       else
!       {
!           curwin = curwin_save;
!           curbuf = curwin->w_buffer;
!       }
        VIsual_active = save_VIsual_active;
      }
  }
*** ../vim-9.0.0909/src/version.c       2022-11-19 13:14:05.741367062 +0000
--- src/version.c       2022-11-19 13:42:33.543207101 +0000
***************
*** 697,698 ****
--- 697,700 ----
  {   /* Add new patch number below this line */
+ /**/
+     910,
  /**/

-- 
Bare feet magnetize sharp metal objects so they point upward from the
floor -- especially in the dark.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20221119140012.38B701C12B2%40moolenaar.net.

Raspunde prin e-mail lui