]> granicus.if.org Git - vim/commitdiff
patch 9.0.0272: BufReadCmd not triggered when loading a "nofile" buffer v9.0.0272
authorBram Moolenaar <Bram@vim.org>
Fri, 26 Aug 2022 10:55:01 +0000 (11:55 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 26 Aug 2022 10:55:01 +0000 (11:55 +0100)
Problem:    BufReadCmd not triggered when loading a "nofile" buffer. (Maxim
            Kim)
Solution:   Call readfile() but bail out before reading a file.
            (closes #10983)

src/buffer.c
src/fileio.c
src/testdir/test_autocmd.vim
src/version.c
src/vim.h

index 72868528120bb47fc3f801e9a77a174007b5644d..2c8169478cbfa926732f8610ec16e8d5e97dfbd6 100644 (file)
@@ -167,8 +167,9 @@ buffer_ensure_loaded(buf_T *buf)
 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                flags_arg)          // extra flags for readfile()
 {
+    int                flags = flags_arg;
     int                retval = OK;
     bufref_T   old_curbuf;
 #ifdef FEAT_SYN_HL
@@ -220,10 +221,13 @@ open_buffer(
     // 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
-           && !bt_quickfix(curbuf)
-           && !bt_nofilename(curbuf)
 #ifdef FEAT_NETBEANS_INTG
            && netbeansReadFile
 #endif
index 6d063a5ab754eda1a106dd554939b34f8853507b..1b30e0fed52b2a248b5fa3b2ffef3be5f4de5b91 100644 (file)
@@ -108,6 +108,7 @@ filemess(
  * 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,6 +310,9 @@ readfile(
 #endif
 
        curbuf->b_op_start = orig_start;
+
+       if (flags & READ_NOFILE)
+           return FAIL;
     }
 
     if ((shortmess(SHM_OVER) || curbuf->b_help) && p_verbose == 0)
index 6bbe48c0f2fbd225041a0e99199be801399bb398..c043a3531145470120037663db9d3cf59d2b55a0 100644 (file)
@@ -576,6 +576,18 @@ func Test_BufReadCmdHelpJump()
   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
index 59e36e4fa9994e17a1816f58c094409884c6f058..ff452da1f6565cd4552a969bed492d259614fd35 100644 (file)
@@ -723,6 +723,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    272,
 /**/
     271,
 /**/
index 9445fa2da94173867da3848cf05caa263288ef4e..05b663237d485698137ebfea6ae36ebfbf29e68f 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -1006,6 +1006,7 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
 #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