From: "Omar Polo" Subject: Re: mg: Don't try to save *scratch* when there are no changes. To: Han Boetes Cc: tech@openbsd.org Date: Mon, 02 Mar 2026 21:50:49 +0100 Hello, Han Boetes wrote: > Hello all, > > If you open mg without argument and hit C-x C-s, mg tries to save *scratch*, whilst emacs says: (No changes need to be saved) agreed, if the file is not marked as changed, save-buffer should be a no-op. (there's write-file for "forcing" the write) > The patch below fixes this minor compatibility issue. looks fine, but upon a closer look I realized that the similar check in buffsave() is now redundant. there are only two callers: - filesave() which we are modifying, and - anycb() (in buffer.c) which attempts to write all buffers, but it already has the (*bp->b_fname) != 0 and the BFCHG flag check to guard it. so, while we're here, I'd propose to also remove the BFCHG check from buffsave(), effectively "bubbling it up" to filesave(). what do you think? diff /home/op/w/mg path + /home/op/w/mg commit - 5c635afccf74b1d7ea58bf5a07f9ea69f1fcf56d blob - b01e8181cc1ecce617f04131c43e3795823fd409 file + file.c --- file.c +++ file.c @@ -565,6 +565,11 @@ static int makebackup = TRUE; int filesave(int f, int n) { + if ((curbp->b_flag & BFCHG) == 0) { + ewprintf("(No changes need to be saved)"); + return (TRUE); + } + if (curbp->b_fname[0] == '\0') return (filewrite(f, n)); else @@ -572,8 +577,7 @@ filesave(int f, int n) } /* - * Save the contents of the buffer argument into its associated file. Do - * nothing if there have been no changes (is this a bug, or a feature?). + * Save the contents of the buffer argument into its associated file. * Error if there is no remembered file name. If this is the first write * since the read or visit, then a backup copy of the file is made. * Allow user to select whether or not to make backup files by looking at @@ -585,12 +589,6 @@ buffsave(struct buffer *bp) int s; FILE *ffp; - /* return, no changes */ - if ((bp->b_flag & BFCHG) == 0) { - ewprintf("(No changes need to be saved)"); - return (TRUE); - } - /* must have a name */ if (bp->b_fname[0] == '\0') { dobeep();