Patch 9.0.0272 (after 9.0.0261)
Problem: BufReadCmd not triggered when loading a "nofile" buffer. (Maxim
Kim)
Solution: Call readfile() but bail out before reading a file.
(closes #10983)
Files: src/buffer.c, src/fileio.c, src/vim.h,
src/testdir/test_autocmd.vim
*** ../vim-9.0.0271/src/buffer.c 2022-08-25 16:16:41.554729493 +0100
--- src/buffer.c 2022-08-26 11:43:32.938922612 +0100
***************
*** 167,174 ****
open_buffer(
int read_stdin, // read file from stdin
exarg_T *eap, // for forced 'ff' and 'fenc' or NULL
! int flags) // extra flags for readfile()
{
int retval = OK;
bufref_T old_curbuf;
#ifdef FEAT_SYN_HL
--- 167,175 ----
open_buffer(
int read_stdin, // read file from stdin
exarg_T *eap, // for forced 'ff' and 'fenc' or NULL
! int flags_arg) // extra flags for readfile()
{
+ int flags = flags_arg;
int retval = OK;
bufref_T old_curbuf;
#ifdef FEAT_SYN_HL
***************
*** 220,229 ****
// mark cursor position as being invalid
curwin->w_valid = 0;
// Read the file if there is one.
if (curbuf->b_ffname != NULL
- && !bt_quickfix(curbuf)
- && !bt_nofilename(curbuf)
#ifdef FEAT_NETBEANS_INTG
&& netbeansReadFile
#endif
--- 221,233 ----
// mark cursor position as being invalid
curwin->w_valid = 0;
+ // A buffer without an actual file should not use the buffer name to read a
+ // file.
+ if (bt_quickfix(curbuf) || bt_nofilename(curbuf))
+ flags |= READ_NOFILE;
+
// Read the file if there is one.
if (curbuf->b_ffname != NULL
#ifdef FEAT_NETBEANS_INTG
&& netbeansReadFile
#endif
*** ../vim-9.0.0271/src/fileio.c 2022-08-25 15:11:11.400084545 +0100
--- src/fileio.c 2022-08-26 11:45:40.774793909 +0100
***************
*** 108,113 ****
--- 108,114 ----
* READ_STDIN read from stdin instead of a file
* READ_BUFFER read from curbuf instead of a file (converting after reading
* stdin)
+ * READ_NOFILE do not read a file, only trigger BufReadCmd
* READ_DUMMY read into a dummy buffer (to check if file contents changed)
* READ_KEEP_UNDO don't clear undo info or read it from a file
* READ_FIFO read from fifo/socket instead of a file
***************
*** 309,314 ****
--- 310,318 ----
#endif
curbuf->b_op_start = orig_start;
+
+ if (flags & READ_NOFILE)
+ return FAIL;
}
if ((shortmess(SHM_OVER) || curbuf->b_help) && p_verbose == 0)
*** ../vim-9.0.0271/src/vim.h 2022-08-15 15:54:45.710375583 +0100
--- src/vim.h 2022-08-26 11:44:14.046881148 +0100
***************
*** 1006,1011 ****
--- 1006,1012 ----
#define READ_KEEP_UNDO 0x20 // keep undo info
#define READ_FIFO 0x40 // read from fifo or socket
#define READ_NOWINENTER 0x80 // do not trigger BufWinEnter
+ #define READ_NOFILE 0x100 // do not read a file, do trigger BufReadCmd
// Values for change_indent()
#define INDENT_SET 1 // set indent
*** ../vim-9.0.0271/src/testdir/test_autocmd.vim 2022-07-27 15:23:32.272483068 +0100
--- src/testdir/test_autocmd.vim 2022-08-26 11:52:13.401662244 +0100
***************
*** 576,581 ****
--- 576,593 ----
au! BufReadCmd
endfunc
+ " BufReadCmd is triggered for a "nofile" buffer
+ func Test_BufReadCmdNofile()
+ new somefile
+ set buftype=nofile
+ au BufReadCmd somefile call setline(1, 'triggered')
+ edit
+ call assert_equal('triggered', getline(1))
+
+ au! BufReadCmd
+ bwipe!
+ endfunc
+
func Test_augroup_deleted()
" This caused a crash before E936 was introduced
augroup x
*** ../vim-9.0.0271/src/version.c 2022-08-26 10:33:49.066709861 +0100
--- src/version.c 2022-08-26 11:53:49.245371734 +0100
***************
*** 725,726 ****
--- 725,728 ----
{ /* Add new patch number below this line */
+ /**/
+ 272,
/**/
--
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us. (Calvin)
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///