mirror of
				https://github.com/neovim/neovim.git
				synced 2025-10-26 12:27:24 +00:00 
			
		
		
		
	vim-patch:9.0.0272: BufReadCmd not triggered when loading a "nofile" buffer
Problem:    BufReadCmd not triggered when loading a "nofile" buffer. (Maxim
            Kim)
Solution:   Call readfile() but bail out before reading a file.
            (closes vim/vim#10983)
b1d2c8116c
			
			
This commit is contained in:
		| @@ -165,11 +165,12 @@ static int read_buffer(int read_stdin, exarg_T *eap, int flags) | |||||||
| /// | /// | ||||||
| /// @param read_stdin  read file from stdin | /// @param read_stdin  read file from stdin | ||||||
| /// @param eap  for forced 'ff' and 'fenc' or NULL | /// @param eap  for forced 'ff' and 'fenc' or NULL | ||||||
| /// @param flags  extra flags for readfile() | /// @param flags_arg  extra flags for readfile() | ||||||
| /// | /// | ||||||
| /// @return  FAIL for failure, OK otherwise. | /// @return  FAIL for failure, OK otherwise. | ||||||
| int open_buffer(int read_stdin, exarg_T *eap, int flags) | int open_buffer(int read_stdin, exarg_T *eap, int flags_arg) | ||||||
| { | { | ||||||
|  |   int flags = flags_arg; | ||||||
|   int retval = OK; |   int retval = OK; | ||||||
|   bufref_T old_curbuf; |   bufref_T old_curbuf; | ||||||
|   long old_tw = curbuf->b_p_tw; |   long old_tw = curbuf->b_p_tw; | ||||||
| @@ -224,8 +225,14 @@ int open_buffer(int read_stdin, exarg_T *eap, int flags) | |||||||
|   // mark cursor position as being invalid |   // mark cursor position as being invalid | ||||||
|   curwin->w_valid = 0; |   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. |   // Read the file if there is one. | ||||||
|   if (curbuf->b_ffname != NULL && !bt_quickfix(curbuf) && !bt_nofilename(curbuf)) { |   if (curbuf->b_ffname != NULL) { | ||||||
| #ifdef UNIX | #ifdef UNIX | ||||||
|     int save_bin = curbuf->b_p_bin; |     int save_bin = curbuf->b_p_bin; | ||||||
|     int perm; |     int perm; | ||||||
|   | |||||||
| @@ -167,6 +167,7 @@ void filemess(buf_T *buf, char_u *name, char_u *s, int attr) | |||||||
| /// READ_STDIN   read from stdin instead of a file | /// READ_STDIN   read from stdin instead of a file | ||||||
| /// READ_BUFFER  read from curbuf instead of a file (converting after reading | /// READ_BUFFER  read from curbuf instead of a file (converting after reading | ||||||
| ///              stdin) | ///              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_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_KEEP_UNDO  don't clear undo info or read it from a file | ||||||
| /// READ_FIFO    read from fifo/socket instead of a file | /// READ_FIFO    read from fifo/socket instead of a file | ||||||
| @@ -334,6 +335,10 @@ int readfile(char *fname, char *sfname, linenr_T from, linenr_T lines_to_skip, | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     curbuf->b_op_start = orig_start; |     curbuf->b_op_start = orig_start; | ||||||
|  |  | ||||||
|  |     if (flags & READ_NOFILE) { | ||||||
|  |       return FAIL; | ||||||
|  |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   if ((shortmess(SHM_OVER) || curbuf->b_help) && p_verbose == 0) { |   if ((shortmess(SHM_OVER) || curbuf->b_help) && p_verbose == 0) { | ||||||
|   | |||||||
| @@ -15,6 +15,7 @@ | |||||||
| #define READ_KEEP_UNDO  0x20    // keep undo info | #define READ_KEEP_UNDO  0x20    // keep undo info | ||||||
| #define READ_FIFO       0x40    // read from fifo or socket | #define READ_FIFO       0x40    // read from fifo or socket | ||||||
| #define READ_NOWINENTER 0x80    // do not trigger BufWinEnter | #define READ_NOWINENTER 0x80    // do not trigger BufWinEnter | ||||||
|  | #define READ_NOFILE     0x100   // do not read a file, do trigger BufReadCmd | ||||||
|  |  | ||||||
| #define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) | #define READ_STRING(x, y) (char_u *)read_string((x), (size_t)(y)) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -493,6 +493,18 @@ func Test_BufReadCmdHelpJump() | |||||||
|   au! BufReadCmd |   au! BufReadCmd | ||||||
| endfunc | 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() | func Test_augroup_deleted() | ||||||
|   " This caused a crash before E936 was introduced |   " This caused a crash before E936 was introduced | ||||||
|   augroup x |   augroup x | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 zeertzjq
					zeertzjq