summaryrefslogtreecommitdiffstats
path: root/src/ex_docmd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ex_docmd.c')
-rw-r--r--src/ex_docmd.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/ex_docmd.c b/src/ex_docmd.c
index 21ba0d5bc3..981d270dc7 100644
--- 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);