Patch 8.2.2036
Problem:    Current buffer is messed up if creating a new buffer for the
            quickfix window fails.
Solution:   Check that creating the buffer succeeds. (closes #7352)
Files:      src/quickfix.c, src/testdir/test_quickfix.vim,
            src/testdir/dumps/Test_quickfix_window_fails.dump


*** ../vim-8.2.2035/src/quickfix.c      2020-11-14 13:15:20.062728413 +0100
--- src/quickfix.c      2020-11-23 20:12:35.198093818 +0100
***************
*** 4151,4163 ****
      if (qf_buf != NULL)
      {
        // Use the existing quickfix buffer
!       (void)do_ecmd(qf_buf->b_fnum, NULL, NULL, NULL, ECMD_ONE,
!               ECMD_HIDE + ECMD_OLDBUF, oldwin);
      }
      else
      {
        // Create a new quickfix buffer
!       (void)do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, oldwin);
  
        // save the number of the new buffer
        qi->qf_bufnr = curbuf->b_fnum;
--- 4151,4165 ----
      if (qf_buf != NULL)
      {
        // Use the existing quickfix buffer
!       if (do_ecmd(qf_buf->b_fnum, NULL, NULL, NULL, ECMD_ONE,
!                                     ECMD_HIDE + ECMD_OLDBUF, oldwin) == FAIL)
!           return FAIL;
      }
      else
      {
        // Create a new quickfix buffer
!       if (do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, ECMD_HIDE, oldwin) == FAIL)
!           return FAIL;
  
        // save the number of the new buffer
        qi->qf_bufnr = curbuf->b_fnum;
*** ../vim-8.2.2035/src/testdir/test_quickfix.vim       2020-11-14 
17:25:44.868329693 +0100
--- src/testdir/test_quickfix.vim       2020-11-23 20:11:36.690293522 +0100
***************
*** 5218,5221 ****
--- 5218,5256 ----
    cclose
  endfunc
  
+ " Test for very weird problem: autocommand causes a failure, resulting opening
+ " the quickfix window to fail. This still splits the window, but otherwise
+ " should not mess up buffers.
+ func Test_quickfix_window_fails_to_open()
+   CheckScreendump
+ 
+   let lines =<< trim END
+       anything
+       try
+         anything
+       endtry
+   END
+   call writefile(lines, 'XquickfixFails')
+ 
+   let lines =<< trim END
+       split XquickfixFails
+       silent vimgrep anything %
+       normal o
+       au BufLeave * ++once source XquickfixFails
+       " This will trigger the autocommand, which causes an error, what follows
+       " is aborted but the window was already split.
+       silent! cwindow
+   END
+   call writefile(lines, 'XtestWinFails')
+   let buf = RunVimInTerminal('-S XtestWinFails', #{rows: 13})
+   call VerifyScreenDump(buf, 'Test_quickfix_window_fails', {})
+ 
+   " clean up
+   call term_sendkeys(buf, ":bwipe!\<CR>")
+   call term_wait(buf)
+   call StopVimInTerminal(buf)
+   call delete('XtestWinFails')
+   call delete('XquickfixFails')
+ endfunc
+ 
  " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.2035/src/testdir/dumps/Test_quickfix_window_fails.dump   
2020-11-23 20:14:13.397762907 +0100
--- src/testdir/dumps/Test_quickfix_window_fails.dump   2020-11-23 
20:11:46.486260081 +0100
***************
*** 0 ****
--- 1,13 ----
+ |a+0&#ffffff0|n|y|t|h|i|n|g| @66
+ > @74
+ |t|r|y| @71
+ |X+3&&|q|u|i|c|k|f|i|x|F|a|i|l|s| |[|+|]| @38|2|,|0|-|1| @9|T|o|p
+ | +0&&@74
+ |t|r|y| @71
+ @2|a|n|y|t|h|i|n|g| @64
+ |X+1&&|q|u|i|c|k|f|i|x|F|a|i|l|s| |[|+|]| @38|2|,|0|-|1| @9|5|0|%
+ | +0&&@74
+ |~+0#4040ff13&| @73
+ |~| @73
+ |[+1#0000000&|N|o| |N|a|m|e|]| @47|0|,|0|-|1| @9|A|l@1
+ | +0&&@74
*** ../vim-8.2.2035/src/version.c       2020-11-23 18:14:51.276875903 +0100
--- src/version.c       2020-11-23 19:36:41.553757010 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2036,
  /**/

-- 
I have to exercise early in the morning before my brain
figures out what I'm doing.

 /// 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/202011231927.0ANJRioT1561061%40masaka.moolenaar.net.

Raspunde prin e-mail lui