From 6799bc69a6573567d068c66af75546ca4dc412c3 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Wed, 29 Sep 2021 14:51:22 +0200 Subject: [PATCH] tweaks: adjust three parameters -- two were mistaken, one superfluous The calls of write_file() in do_spell() and do_formatter() write out a temporary file -- such a file does not have an 'openfile' record, so setting 'annotate' to TRUE was pointless. Using the correct value for this parameter allows dropping two conditions in write_file(). And when 'exiting' is TRUE and --save-on-exit is in effect, it is slightly wasteful to stat() the written file and store the info in its 'openfile' record as the buffer will be closed directly after. So, now the only place where 'annotate' is TRUE is when writing out the full buffer to a normally named file. --- src/files.c | 6 +++--- src/text.c | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/files.c b/src/files.c index e91b8367..b6fc9822 100644 --- a/src/files.c +++ b/src/files.c @@ -1983,7 +1983,7 @@ bool write_file(const char *name, FILE *thefile, bool normal, } /* When having written an entire buffer, update some administrivia. */ - if (annotate && method == OVERWRITE && normal) { + if (annotate && method == OVERWRITE) { /* If the filename was changed, write a new lockfile when needed, * and check whether it means a different syntax gets used. */ if (strcmp(openfile->filename, realname) != 0) { @@ -2030,7 +2030,7 @@ bool write_file(const char *name, FILE *thefile, bool normal, } #ifndef NANO_TINY - if (ISSET(MINIBAR) && LINES > 1 && annotate && normal) + if (ISSET(MINIBAR) && LINES > 1 && annotate) report_size = TRUE; else #endif @@ -2302,7 +2302,7 @@ int do_writeout(bool exiting, bool withprompt) free(given); if (choice == 1) return write_file(openfile->filename, NULL, - TRUE, OVERWRITE, TRUE); + TRUE, OVERWRITE, FALSE); else if (choice == 0) return 2; else diff --git a/src/text.c b/src/text.c index 5983cb60..1a892eed 100644 --- a/src/text.c +++ b/src/text.c @@ -2502,7 +2502,7 @@ void do_spell(void) okay = write_marked_file(temp_name, stream, FALSE, OVERWRITE); else #endif - okay = write_file(temp_name, stream, FALSE, OVERWRITE, TRUE); + okay = write_file(temp_name, stream, FALSE, OVERWRITE, FALSE); if (!okay) { statusline(ALERT, _("Error writing temp file: %s"), strerror(errno)); @@ -2903,7 +2903,7 @@ void do_formatter(void) temp_name = safe_tempfile(&stream); if (temp_name != NULL) - okay = write_file(temp_name, stream, FALSE, OVERWRITE, TRUE); + okay = write_file(temp_name, stream, FALSE, OVERWRITE, FALSE); if (!okay) { statusline(ALERT, _("Error writing temp file: %s"), strerror(errno));