Patch 8.2.0302
Problem:    Setting 'term' may cause error in TermChanged autocommand.
Solution:   Use aucmd_prepbuf() to switch to the buffer where the autocommand
            is to be executed. (closes #5682)
Files:      src/term.c, src/testdir/test_autocmd.vim


*** ../vim-8.2.0301/src/term.c  2020-02-15 23:06:40.826770264 +0100
--- src/term.c  2020-02-22 22:16:06.379929420 +0100
***************
*** 2071,2091 ****
        check_map_keycodes();   // check mappings for terminal codes used
  
        {
!           bufref_T    old_curbuf;
  
            /*
             * Execute the TermChanged autocommands for each buffer that is
             * loaded.
             */
!           set_bufref(&old_curbuf, curbuf);
!           FOR_ALL_BUFFERS(curbuf)
            {
                if (curbuf->b_ml.ml_mfp != NULL)
                    apply_autocmds(EVENT_TERMCHANGED, NULL, NULL, FALSE,
                                                                      curbuf);
            }
-           if (bufref_valid(&old_curbuf))
-               curbuf = old_curbuf.br_buf;
        }
      }
  
--- 2071,2094 ----
        check_map_keycodes();   // check mappings for terminal codes used
  
        {
!           buf_T       *buf;
!           aco_save_T  aco;
  
            /*
             * Execute the TermChanged autocommands for each buffer that is
             * loaded.
             */
!           FOR_ALL_BUFFERS(buf)
            {
                if (curbuf->b_ml.ml_mfp != NULL)
+               {
+                   aucmd_prepbuf(&aco, buf);
                    apply_autocmds(EVENT_TERMCHANGED, NULL, NULL, FALSE,
                                                                      curbuf);
+                   // restore curwin/curbuf and a few other things
+                   aucmd_restbuf(&aco);
+               }
            }
        }
      }
  
*** ../vim-8.2.0301/src/testdir/test_autocmd.vim        2020-02-18 
21:54:36.982093690 +0100
--- src/testdir/test_autocmd.vim        2020-02-22 22:15:19.048090983 +0100
***************
*** 2382,2385 ****
--- 2382,2405 ----
    augroup! FileChangedROTest
  endfunc
  
+ func LogACmd()
+   call add(g:logged, line('$'))
+ endfunc
+ 
+ func Test_TermChanged()
+   enew!
+   tabnew
+   call setline(1, ['a', 'b', 'c', 'd'])
+   $
+   au TermChanged * call LogACmd()
+   let g:logged = []
+   let term_save = &term
+   set term=xterm
+   call assert_equal([1, 4], g:logged)
+ 
+   au! TermChanged
+   let &term = term_save
+   bwipe!
+ endfunc
+ 
  " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.0301/src/version.c       2020-02-22 21:21:23.698595570 +0100
--- src/version.c       2020-02-22 22:09:37.445280046 +0100
***************
*** 740,741 ****
--- 740,743 ----
  {   /* Add new patch number below this line */
+ /**/
+     302,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
95. Only communication in your household is through email.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            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/202002222146.01MLkS4G025206%40masaka.moolenaar.net.

Raspunde prin e-mail lui