From 65e580bd5610465bb6b9c1a546b7a8d00c76aa47 Mon Sep 17 00:00:00 2001 From: Colin Kennedy Date: Tue, 26 Mar 2024 18:29:30 +0100 Subject: 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 Signed-off-by: Christian Brabandt --- src/ex_docmd.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'src/ex_docmd.c') 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 @@ -460,6 +460,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); -- cgit v1.2.3