From 1ecf8333a50697db46cbc18f4ae644433a841bab Mon Sep 17 00:00:00 2001 From: Piotr Henryk Dabrowski Date: Sat, 7 Apr 2018 01:40:04 +0200 Subject: [PATCH] options: new --nofilename/-f command line option added Added option preventing Nano from prompting for a new file name when the file name is known. Useful for temporary files. Also applies to ^O. Unlike --tempfile/-t, it will still prompt for confirmation when exiting with changes. Signed-off-by: Piotr Henryk Dabrowski --- doc/nano.1 | 5 ++++- doc/nano.texi | 5 ++++- src/files.c | 2 +- src/nano.c | 12 +++++++++--- src/nano.h | 3 ++- src/rcfile.c | 1 + 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/doc/nano.1 b/doc/nano.1 index f25a07ef..23df019e 100644 --- a/doc/nano.1 +++ b/doc/nano.1 @@ -179,6 +179,9 @@ Interpret the Delete key differently so that both Backspace and Delete work properly. You should only need to use this option if Backspace acts like Delete on your system. .TP +.BR \-f ", " \-\-nofilename +Do not ask for a new filename when saving. +.TP .BR \-g ", " \-\-showcursor Make the cursor visible in the file browser, putting it on the highlighted item. Useful for braille users. @@ -261,7 +264,7 @@ continuing it over multiple screen lines. Since this option last when using other options (e.g.\& 'nano \-wS$') or pass it separately (e.g.\& 'nano \-wS \-$'). .TP -.BR \-b ", " \-e ", " \-f ", " \-j +.BR \-b ", " \-e ", " \-j Ignored, for compatibility with Pico. .SH TOGGLES diff --git a/doc/nano.texi b/doc/nano.texi index c73cedbb..d18afd9f 100644 --- a/doc/nano.texi +++ b/doc/nano.texi @@ -288,6 +288,10 @@ Interpret the Delete key differently so that both Backspace and Delete work properly. You should only need to use this option if Backspace acts like Delete on your system. address@hidden -f address@hidden --nofilename +Do not ask for a new filename when saving. + @item -g @itemx --showcursor Make the cursor visible in the file browser, putting it on the @@ -408,7 +412,6 @@ separately (e.g.@: @code{nano -wS -$}). @item -b @itemx -e address@hidden -f @itemx -j Ignored, for compatibility with Pico. diff --git a/src/files.c b/src/files.c index c32fce1b..324b19b5 100644 --- a/src/files.c +++ b/src/files.c @@ -2264,7 +2264,7 @@ int do_writeout(bool exiting, bool withprompt) void do_writeout_void(void) { /* If the user chose to discard the buffer, close it. */ - if (do_writeout(FALSE, TRUE) == 2) + if (do_writeout(FALSE, !ISSET(NO_FILENAME)) == 2) close_and_go(); } diff --git a/src/nano.c b/src/nano.c index 955ec4ca..bb1334a3 100644 --- a/src/nano.c +++ b/src/nano.c @@ -849,6 +849,8 @@ void usage(void) print_opt("-c", "--constantshow", N_("Constantly show cursor position")); print_opt("-d", "--rebinddelete", N_("Fix Backspace/Delete confusion problem")); + print_opt("-f", "--nofilename", + N_("Do not ask for a new filename when saving")); #ifdef ENABLE_BROWSER if (!ISSET(RESTRICTED)) print_opt("-g", "--showcursor", N_("Show cursor in file browser")); @@ -1034,7 +1036,8 @@ void version(void) /* If the current file buffer has been modified, and the TEMP_FILE flag * isn't set, ask whether or not to save the file buffer. If the * TEMP_FILE flag is set and the current file has a name, save it - * unconditionally. Then, if more than one file buffer is open, close + * unconditionally. If the NO_FILENAME flag is set, do not prompt for + * a new file name. Then, if more than one file buffer is open, close * the current file buffer and switch to the next one. If only one file * buffer is open, exit from nano. */ void do_exit(void) @@ -1066,7 +1069,7 @@ void do_exit(void) /* If the user chose not to save, or if the user chose to save and * the save succeeded, we're ready to exit. */ - if (i == 0 || (i == 1 && do_writeout(TRUE, TRUE) > 0)) + if (i == 0 || (i == 1 && do_writeout(TRUE, !ISSET(NO_FILENAME)) > 0)) close_and_go(); else if (i != 1) statusbar(_("Cancelled")); @@ -1950,6 +1953,7 @@ int main(int argc, char **argv) #endif {"constantshow", 0, NULL, 'c'}, {"rebinddelete", 0, NULL, 'd'}, + {"nofilename", 0, NULL, 'f'}, #ifdef ENABLE_BROWSER {"showcursor", 0, NULL, 'g'}, #endif @@ -2058,7 +2062,6 @@ int main(int argc, char **argv) switch (optchr) { case 'b': case 'e': - case 'f': case 'j': /* Pico compatibility flags. */ break; @@ -2175,6 +2178,9 @@ int main(int argc, char **argv) case 'd': SET(REBIND_DELETE); break; + case 'f': + SET(NO_FILENAME); + break; case 'g': SET(SHOW_CURSOR); break; diff --git a/src/nano.h b/src/nano.h index 17a52369..8942ec04 100644 --- a/src/nano.h +++ b/src/nano.h @@ -543,7 +543,8 @@ enum SHOW_CURSOR, LINE_NUMBERS, NO_PAUSES, - AT_BLANKS + AT_BLANKS, + NO_FILENAME }; /* Flags for the menus in which a given function should be present. */ diff --git a/src/rcfile.c b/src/rcfile.c index eb4e2c6f..8a376d62 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -57,6 +57,7 @@ static const rcoption rcopts[] = { {"multibuffer", MULTIBUFFER}, #endif {"nohelp", NO_HELP}, + {"nofilename", NO_FILENAME}, {"nonewlines", NO_NEWLINES}, {"nopauses", NO_PAUSES}, #ifdef ENABLE_WRAPPING -- 2.14.1