diff options
author | Colin Kennedy <colinvfx@gmail.com> | 2024-03-27 08:22:33 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-27 16:22:33 +0800 |
commit | 61e25b7200a62d3f8c99ddd6196e124be6b6e3dc (patch) | |
tree | 0989367f86a04ed96e711e38d756caf31cc5ce7c /src | |
parent | 00e9c6955125fdbded208d4b5af59b94e96d7ea8 (diff) | |
download | rneovim-61e25b7200a62d3f8c99ddd6196e124be6b6e3dc.tar.gz rneovim-61e25b7200a62d3f8c99ddd6196e124be6b6e3dc.tar.bz2 rneovim-61e25b7200a62d3f8c99ddd6196e124be6b6e3dc.zip |
vim-patch:9.1.0208: winfixbuf does not allow to re-edit current buffer (#28054)
Problem: winfixbuf does not allow to re-edit current buffer
(Tim Pope, after v9.1.0147)
Solution: Explicitly allow :e even when 'winfixbuf' is set,
since it just re-loads the current buffer
(Colin Kennedy)
fixes: vim/vim#14237
closes: vim/vim#14286
https://github.com/vim/vim/commit/65e580bd5610465bb6b9c1a546b7a8d00c76aa47
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/ex_docmd.c | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 1009e25081..ee738d9e92 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -216,6 +216,38 @@ static void restore_dbg_stuff(struct dbg_stuff *dsp) current_exception = dsp->current_exception; } +/// Check if ffname differs from fnum. +/// fnum is a buffer number. 0 == current buffer, 1-or-more must be a valid buffer ID. +/// ffname is a full path to where a buffer lives on-disk or would live on-disk. +static bool is_other_file(int fnum, char *ffname) +{ + if (fnum != 0) { + if (fnum == curbuf->b_fnum) { + return false; + } + + return true; + } + + if (ffname == NULL) { + return true; + } + + if (*ffname == NUL) { + return false; + } + + if (!curbuf->file_id_valid + && curbuf->b_sfname != NULL + && *curbuf->b_sfname != NUL) { + // This occurs with unsaved buffers. In which case `ffname` + // actually corresponds to curbuf->b_sfname + return path_fnamecmp(ffname, curbuf->b_sfname) != 0; + } + + return otherfile(ffname); +} + /// Repeatedly get commands for Ex mode, until the ":vi" command is given. void do_exmode(void) { @@ -5371,11 +5403,13 @@ static void ex_find(exarg_T *eap) /// ":edit", ":badd", ":balt", ":visual". static void ex_edit(exarg_T *eap) { + char *ffname = eap->cmdidx == CMD_enew ? NULL : eap->arg; + // Exclude commands which keep the window's current buffer if (eap->cmdidx != CMD_badd && eap->cmdidx != CMD_balt // All other commands must obey 'winfixbuf' / ! rules - && !check_can_set_curbuf_forceit(eap->forceit)) { + && (is_other_file(0, ffname) && !check_can_set_curbuf_forceit(eap->forceit))) { return; } |