options: rename --tempfile to --saveonexit, to be far clearer

A long option should describe what it does, not vaguely hint at it.

Also, in several places of nano's code we deal with actual temp files,
and then having a flag called TEMP_FILE that doesn't have anything to
do with temp files is somewhat confusing.
This commit is contained in:
Benno Schulenberg 2020-04-30 17:25:48 +02:00
parent af062af490
commit d4ee6a2b53
10 changed files with 35 additions and 32 deletions

View File

@ -291,7 +291,7 @@ The default value is \-8.
Use this command to perform spell checking and correcting, instead of
using the built-in corrector that calls \fBhunspell\fR or GNU \fBspell\fR.
.TP
.BR \-t ", " \-\-tempfile
.BR \-t ", " \-\-saveonexit
Save a changed buffer without prompting (when exiting with \fB^X\fR).
.TP
.BR \-u ", " \-\-unix

View File

@ -411,10 +411,10 @@ corrector, which requires either @command{hunspell} or GNU @command{spell}
to be installed.
@item -t
@itemx --tempfile
Don't ask whether to save a modified buffer when exiting with @kbd{^X}, but
assume yes. This option is useful when @command{nano} is used as the
composer of a mailer program.
@itemx --saveonexit
Save a changed buffer without prompting (when exiting with @kbd{^X}).
This can be handy when @command{nano} is used as the composer of an
email program.
@item -u
@item --unix
@ -1476,7 +1476,7 @@ When writing a file, creates a backup of the current file.
@item discardbuffer
When about to write a file, discard the current buffer without saving.
(This function is bound by default only when option @option{--tempfile}
(This function is bound by default only when option @option{--saveonexit}
is in effect.)
@item browser

View File

@ -247,6 +247,9 @@ system either Backspace acts like Delete or Delete acts like Backspace.
Do regular-expression searches by default.
Regular expressions in \fBnano\fR are of the extended type (ERE).
.TP
.B set saveonexit
Save a changed buffer automatically on exit (\fB^X\fR); don't prompt.
.TP
.B set selectedcolor \fIfgcolor\fR,\fIbgcolor\fR
Specify the color combination to use for selected text.
See \fBset titlecolor\fR for more details.
@ -293,9 +296,6 @@ greater than 0. The default value is \fB8\fR.
.B set tabstospaces
Convert typed tabs to spaces.
.TP
.B set tempfile
Save automatically on exit, don't prompt.
.TP
.B set titlecolor \fIfgcolor\fR,\fIbgcolor\fR
Specify the color combination to use for the title bar.
Valid names for the foreground and background colors are:
@ -796,7 +796,7 @@ When writing a file, creates a backup of the current file.
.TP
.B discardbuffer
When about to write a file, discard the current buffer without saving.
(This function is bound by default only when option \fB\-\-tempfile\fR
(This function is bound by default only when option \fB\-\-saveonexit\fR
is in effect.)
.TP
.B browser

View File

@ -130,6 +130,10 @@
## Regular expressions are of the extended type (ERE).
# set regexp
## Save a changed buffer automatically on exit; don't prompt.
# set saveonexit
## (The old form of this option, 'set tempfile', is deprecated.)
## Put the cursor on the highlighted item in the file browser, and show
## the cursor in the help viewer; useful for people who use a braille
## display and people with poor vision.
@ -159,9 +163,6 @@
## Convert typed tabs to spaces.
# set tabstospaces
## Save automatically on exit; don't prompt.
# set tempfile
## Snip whitespace at the end of lines when justifying or hard-wrapping.
# set trimblanks

View File

@ -2060,7 +2060,7 @@ bool write_marked_file(const char *name, FILE *stream, bool tmp,
/* Write the current file to disk. If the mark is on, write the current
* marked selection to disk. If exiting is TRUE, write the entire file
* to disk regardless of whether the mark is on. Do not ask for a name
* when withprompt is FALSE nor when the TEMP_FILE flag is set and the
* when withprompt is FALSE nor when the SAVE_ON_EXIT flag is set and the
* file already has a name. Return 0 on error, 1 on success, and 2 when
* the buffer is to be discarded. */
int do_writeout(bool exiting, bool withprompt)
@ -2113,7 +2113,7 @@ int do_writeout(bool exiting, bool withprompt)
present_path = mallocstrcpy(present_path, "./");
/* When we shouldn't prompt, use the existing filename. */
if ((!withprompt || (ISSET(TEMP_FILE) && exiting)) &&
if ((!withprompt || (ISSET(SAVE_ON_EXIT) && exiting)) &&
openfile->filename[0] != '\0')
answer = mallocstrcpy(answer, openfile->filename);
else {
@ -2184,7 +2184,7 @@ int do_writeout(bool exiting, bool withprompt)
* "zzy" as the filename to save under (hence "xyzzy"), and
* this is the first time we've done this, show an Easter
* egg. Display the credits. */
if (!did_credits && exiting && !ISSET(TEMP_FILE) &&
if (!did_credits && exiting && !ISSET(SAVE_ON_EXIT) &&
strcasecmp(answer, "zzy") == 0) {
if (LINES > 5 && COLS > 31) {
do_credits();
@ -2273,7 +2273,7 @@ int do_writeout(bool exiting, bool withprompt)
/* When in tool mode and not called by 'savefile',
* overwrite the file right here when requested. */
if (ISSET(TEMP_FILE) && withprompt) {
if (ISSET(SAVE_ON_EXIT) && withprompt) {
free(given);
if (choice == 1)
return write_file(openfile->filename, NULL,

View File

@ -482,7 +482,7 @@ size_t shown_entries_for(int menu)
item = item->next;
}
/* When --tempfile is not used, widen the grid of the WriteOut menu. */
/* When --saveonexit is not used, widen the grid of the WriteOut menu. */
if (menu == MWRITEFILE && first_sc_for(menu, discard_buffer) == NULL)
count--;
@ -1390,7 +1390,7 @@ void shortcut_init(void)
add_to_sclist(MBROWSER, "^_", 0, goto_dir, 0);
add_to_sclist(MBROWSER, "M-G", 0, goto_dir, 0);
#endif
if (ISSET(TEMP_FILE) && !ISSET(PRESERVE))
if (ISSET(SAVE_ON_EXIT) && !ISSET(PRESERVE))
add_to_sclist(MWRITEFILE, "^Q", 0, discard_buffer, 0);
#ifndef NANO_TINY
add_to_sclist(MWRITEFILE, "M-D", 0, dos_format_void, 0);

View File

@ -570,7 +570,7 @@ void usage(void)
print_opt(_("-s <prog>"), _("--speller=<prog>"),
N_("Enable alternate speller"));
#endif
print_opt("-t", "--tempfile", N_("Auto save on exit, don't prompt"));
print_opt("-t", "--saveonexit", N_("Save changes on exit, don't prompt"));
#ifndef NANO_TINY
print_opt("-u", "--unix", N_("Save a file by default in Unix format"));
#endif
@ -719,9 +719,9 @@ void version(void)
printf("\n");
}
/* 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
/* If the current file buffer has been modified, and the SAVE_ON_EXIT
* flag isn't set, ask whether or not to save the file buffer. If the
* SAVE_ON_EXIT flag is set and the current file has a name, save it
* unconditionally. 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. */
@ -733,15 +733,15 @@ void do_exit(void)
* save. */
if (!openfile->modified)
choice = 0;
/* If the TEMP_FILE flag is set and the current file has a name,
/* If the SAVE_ON_EXIT flag is set and the current file has a name,
* pretend the user chose to save. */
else if (openfile->filename[0] != '\0' && ISSET(TEMP_FILE))
else if (openfile->filename[0] != '\0' && ISSET(SAVE_ON_EXIT))
choice = 1;
/* Otherwise, ask the user whether or not to save. */
else {
/* If the TEMP_FILE flag is set, and the current file doesn't
/* If the SAVE_ON_EXIT flag is set, and the current file doesn't
* have a name, warn the user before prompting for a name. */
if (ISSET(TEMP_FILE))
if (ISSET(SAVE_ON_EXIT))
warn_and_shortly_pause(_("No file name"));
choice = do_yesno_prompt(FALSE, _("Save modified buffer? "));
@ -1709,7 +1709,8 @@ int main(int argc, char **argv)
#ifdef ENABLE_SPELLER
{"speller", 1, NULL, 's'},
#endif
{"tempfile", 0, NULL, 't'},
{"saveonexit", 0, NULL, 't'},
{"tempfile", 0, NULL, 't'}, /* Deprecated; remove in 2022. */
{"view", 0, NULL, 'v'},
#ifdef ENABLE_WRAPPING
{"nowrap", 0, NULL, 'w'},
@ -1992,7 +1993,7 @@ int main(int argc, char **argv)
break;
#endif
case 't':
SET(TEMP_FILE);
SET(SAVE_ON_EXIT);
break;
#ifndef NANO_TINY
case 'u':

View File

@ -504,7 +504,7 @@ enum
VIEW_MODE,
USE_MOUSE,
USE_REGEXP,
TEMP_FILE,
SAVE_ON_EXIT,
CUT_FROM_CURSOR,
BACKWARDS_SEARCH,
MULTIBUFFER,

View File

@ -86,13 +86,14 @@ static const rcoption rcopts[] = {
{"rawsequences", RAW_SEQUENCES},
{"rebinddelete", REBIND_DELETE},
{"regexp", USE_REGEXP},
{"saveonexit", SAVE_ON_EXIT},
#ifdef ENABLE_SPELLER
{"speller", 0},
#endif
{"suspend", SUSPENDABLE}, /* Deprecated; remove in 2022. */
{"suspendable", SUSPENDABLE},
{"tabsize", 0},
{"tempfile", TEMP_FILE},
{"tempfile", SAVE_ON_EXIT}, /* Deprecated; remove in 2022. */
{"view", VIEW_MODE},
#ifndef NANO_TINY
{"afterends", AFTER_ENDS},

View File

@ -7,7 +7,7 @@ comment "#"
color brightred ".*"
# Keywords
color brightgreen "^[[:space:]]*(set|unset)[[:space:]]+(afterends|allow_insecure_backup|atblanks|autoindent|backup|backwards|boldtext|breaklonglines|casesensitive|constantshow|cutfromcursor|emptyline|finalnewline|historylog|jumpyscrolling|linenumbers|locking|morespace|mouse|multibuffer|noconvert|nohelp|nopauses|nonewlines|nowrap|positionlog|preserve|quickblank|quiet|rawsequences|rebinddelete|regexp|showcursor|smarthome|smooth|softwrap|suspendable|tabstospaces|tempfile|trimblanks|unix|view|wordbounds|zap)\>"
color brightgreen "^[[:space:]]*(set|unset)[[:space:]]+(afterends|allow_insecure_backup|atblanks|autoindent|backup|backwards|boldtext|breaklonglines|casesensitive|constantshow|cutfromcursor|emptyline|finalnewline|historylog|jumpyscrolling|linenumbers|locking|morespace|mouse|multibuffer|noconvert|nohelp|nopauses|nonewlines|nowrap|positionlog|preserve|quickblank|quiet|rawsequences|rebinddelete|regexp|saveonexit|showcursor|smarthome|smooth|softwrap|suspendable|tabstospaces|trimblanks|unix|view|wordbounds|zap)\>"
color yellow "^[[:space:]]*set[[:space:]]+((error|function|key|number|selected|status|stripe|title)color)[[:space:]]+(bright)?(white|black|red|blue|green|yellow|magenta|cyan|normal)?(,(white|black|red|blue|green|yellow|magenta|cyan|normal))?\>"
color brightgreen "^[[:space:]]*set[[:space:]]+(backupdir|brackets|errorcolor|functioncolor|keycolor|matchbrackets|numbercolor|operatingdir|punct|quotestr|selectedcolor|speller|statuscolor|stripecolor|titlecolor|whitespace|wordchars)[[:space:]]+"
color brightgreen "^[[:space:]]*set[[:space:]]+(fill[[:space:]]+-?[[:digit:]]+|(guidestripe|tabsize)[[:space:]]+[1-9][0-9]*)\>"