From 5e9cb26331b05eeda092aafa5ccc91c4cdb56947 Mon Sep 17 00:00:00 2001 From: op Date: Tue, 3 Mar 2026 15:17:29 +0000 Subject: [PATCH] improve the "No changes need to be saved" check Instead of checking for the BFCHG flag in buffsave(), bubble it up to filesave(), which is the interactive function. This avoids prompting for a filepath for e.g. when attempting to save the *scratch* buffer. The only other place where buffsave() is called, anycb in buffer.c is already guarding for a set file name and the BFCHG flag. Initial diff from Han Boetes (hboetes at gmail), tweaked by me. --- usr.bin/mg/file.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/usr.bin/mg/file.c b/usr.bin/mg/file.c index b01e8181cc1..6f1e3d50386 100644 --- a/usr.bin/mg/file.c +++ b/usr.bin/mg/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.104 2024/04/23 13:34:50 jsg Exp $ */ +/* $OpenBSD: file.c,v 1.105 2026/03/03 15:17:29 op Exp $ */ /* This file is in the public domain. */ @@ -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();