diff src/ex_docmd.c @ 34647:6b2efa2b2386 v9.1.0208

patch 9.1.0208: winfixbuf does not allow to re-edit current buffer Commit: https://github.com/vim/vim/commit/65e580bd5610465bb6b9c1a546b7a8d00c76aa47 Author: Colin Kennedy <colinvfx@gmail.com> Date: Tue Mar 26 18:29:30 2024 +0100 patch 9.1.0208: winfixbuf does not allow to re-edit current buffer 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: #14237 closes: #14286 Signed-off-by: Colin Kennedy <colinvfx@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Tue, 26 Mar 2024 18:45:03 +0100
parents ceee63c7f7aa
children 159d598e6781
line wrap: on
line diff
--- a/src/ex_docmd.c
+++ b/src/ex_docmd.c
@@ -461,6 +461,40 @@ restore_dbg_stuff(struct dbg_stuff *dsp)
 #endif
 
 /*
+ * 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 int
+is_other_file(int fnum, char_u *ffname)
+{
+  if (fnum != 0)
+  {
+    if (fnum == curbuf->b_fnum)
+      return FALSE;
+
+    return TRUE;
+  }
+
+  if (ffname == NULL)
+    return TRUE;
+
+  if (*ffname == NUL)
+    return FALSE;
+
+  // TODO: Need a reliable way to know whether a buffer is meant to live on-disk
+  // !curbuf->b_dev_valid is not always available (example: missing on Windows)
+  if (curbuf->b_sfname != NULL
+      && *curbuf->b_sfname != NUL)
+    // This occurs with unsaved buffers. In which case `ffname`
+    // actually corresponds to curbuf->b_sfname
+    return fnamecmp(ffname, curbuf->b_sfname) != 0;
+
+  return otherfile(ffname);
+}
+
+/*
  * do_exmode(): Repeatedly get commands for the "Ex" mode, until the ":vi"
  * command is given.
  */
@@ -7256,12 +7290,15 @@ ex_open(exarg_T *eap)
     static void
 ex_edit(exarg_T *eap)
 {
+    char_u *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;
 
     do_exedit(eap, NULL);