+2015-12-23 Benno Schulenberg <bensberg@justemail.net>
+ * src/files.c (do_writeout, do_writeout_void), src/global.c
+ (shortcut_init, strtosc), src/nano.c (do_exit, close_and_go),
+ doc/man/nanorc.5, doc/texinfo/nano.texi: In the writeout menu,
+ offer ^Q to close and discard the buffer without saving it. By
+ default, the key is bound only when --tempfile is in effect.
+
2015-12-23 Mike Frysinger <vapier@gentoo.org>
* doc/syntax/autoconf.nanorc: Handle .m4 files too, add the "elif"
keyword, handle dnl comments better, and mark trailing whitespace.
.\" Documentation License along with this program. If not, see
.\" <http://www.gnu.org/licenses/>.
.\"
-.TH NANORC 5 "version 2.5.0" "December 2015"
+.TH NANORC 5 "version 2.5.1" "December 2015"
.\" Please adjust this date whenever revising the manpage.
.\"
.SH NAME
.B backup
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
+is in effect.)
+.TP
.B firstfile
Goes to the first file when using the file browser (reading or writing files).
.TP
@smallbook
@set EDITION 0.3
-@set VERSION 2.5.0
+@set VERSION 2.5.1
@set UPDATED December 2015
@dircategory Editors
@titlepage
@title GNU @code{nano}
@subtitle a small and friendly text editor.
-@subtitle version 2.5.0
+@subtitle version 2.5.1
@author Chris Allegretta
@page
@item backup
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}
+is in effect.)
+
@item tofiles
Starts the file browser, allowing to select a file from a list.
#endif /* !NANO_TINY */
/* Write the current file to disk. If the mark is on, write the current
- * marked selection to disk. If exiting is TRUE, write the file to disk
- * regardless of whether the mark is on, and without prompting if the
- * TEMP_FILE flag is set and the current file has a name. Return TRUE
- * on success or FALSE on error. */
-bool do_writeout(bool exiting)
+ * marked selection to disk. If exiting is TRUE, write the entire file
+ * to disk regardless of whether the mark is on, and without prompting if
+ * the TEMP_FILE flag is set and the current file has a name. Return 0
+ * on error, 1 on success, and 2 when the buffer is to be discarded. */
+int do_writeout(bool exiting)
{
int i;
append_type append = OVERWRITE;
#ifndef DISABLE_EXTRA
static bool did_credits = FALSE;
#endif
- bool retval = FALSE;
+ bool result = FALSE;
if (exiting && openfile->filename[0] != '\0' && ISSET(TEMP_FILE)) {
- retval = write_file(openfile->filename, NULL, FALSE, OVERWRITE,
- FALSE);
+ result = write_file(openfile->filename, NULL, FALSE, OVERWRITE, FALSE);
- /* Write succeeded. */
- if (retval)
- return retval;
+ if (result)
+ return 1; /* The write succeeded. */
}
ans = mallocstrcpy(NULL,
* encoded null), treat it as though it's blank. */
if (i < 0 || *answer == '\n') {
statusbar(_("Cancelled"));
- retval = FALSE;
break;
} else {
functionptrtype func = func_from_key(&i);
+ /* Upon request, abandon the buffer, if user is sure. */
+ if (func == discard_buffer) {
+ if (openfile->modified)
+ i = do_yesno_prompt(FALSE,
+ _("Save modified buffer anyway ? "));
+ else
+ i = 0;
+
+ if (i == 0) {
+ free(ans);
+ return 2; /* Yes, discard the buffer. */
+ }
+ if (i < 0)
+ continue; /* The discard was cancelled. */
+ }
+
ans = mallocstrcpy(ans, answer);
#ifndef DISABLE_BROWSER
strcasecmp(answer, "zzy") == 0) {
do_credits();
did_credits = TRUE;
- retval = FALSE;
break;
}
#endif
* a separate file. If we're using restricted mode, this
* function is disabled, since it allows reading from or
* writing to files not specified on the command line. */
- retval =
+ result =
#ifndef NANO_TINY
(!ISSET(RESTRICTED) && !exiting && openfile->mark_set) ?
write_marked_file(answer, NULL, FALSE, append) :
free(ans);
- return retval;
+ return result ? 1 : 0;
}
-/* Write the current file to disk. If the mark is on, write the current
- * marked selection to disk. */
+/* Write the current buffer to disk, or discard it. */
void do_writeout_void(void)
{
- do_writeout(FALSE);
+ /* If the user chose to discard the buffer, close it. */
+ if (do_writeout(FALSE) == 2)
+ close_and_go();
+
display_main_list();
}
void backup_file_void(void)
{
}
+void discard_buffer(void)
+{
+}
void new_buffer_void(void)
{
}
const char *nano_backup_msg = N_("Toggle backing up of the original file");
const char *nano_execute_msg = N_("Execute external command");
#endif
+ const char *nano_discard_buffer_msg = N_("Close buffer without saving it");
#ifndef DISABLE_MULTIBUFFER
const char *nano_multibuffer_msg = N_("Toggle the use of a new buffer");
#endif
N_("Last File"), IFSCHELP(nano_lastfile_msg), BLANKAFTER, VIEW);
#endif
+ add_to_funcs(discard_buffer, MWRITEFILE,
+ N_("Discard buffer"), IFSCHELP(nano_discard_buffer_msg), BLANKAFTER, NOVIEW);
+
#if !defined(NANO_TINY) && !defined(DISABLE_BROWSER)
add_to_funcs(do_research, MBROWSER,
whereis_next_tag, IFSCHELP(nano_whereis_next_msg), TOGETHER, VIEW);
add_to_sclist(MBROWSER, "M-G", goto_dir_void, 0);
add_to_sclist(MBROWSER, "F13", goto_dir_void, 0);
#endif
+ if (ISSET(TEMP_FILE))
+ add_to_sclist(MWRITEFILE, "^Q", discard_buffer, 0);
add_to_sclist(MWRITEFILE, "M-D", dos_format_void, 0);
add_to_sclist(MWRITEFILE, "M-M", mac_format_void, 0);
if (!ISSET(RESTRICTED)) {
s->scfunc = do_cancel;
else if (!strcasecmp(input, "exit"))
s->scfunc = do_exit;
+ else if (!strcasecmp(input, "discardbuffer"))
+ s->scfunc = discard_buffer;
else if (!strcasecmp(input, "writeout"))
s->scfunc = do_writeout_void;
#ifndef NANO_TINY
/* 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))) {
+ if (i == 0 || (i == 1 && do_writeout(TRUE)))
+ close_and_go();
+ else if (i != 1)
+ statusbar(_("Cancelled"));
+ display_main_list();
+}
+
+/* Close the current buffer, and terminate nano if it was the last. */
+void close_and_go(void)
+{
#ifndef NANO_TINY
- if (ISSET(LOCKING) && openfile->lock_filename)
- delete_lockfile(openfile->lock_filename);
+ /* If there is a lockfile, remove it. */
+ if (ISSET(LOCKING) && openfile->lock_filename)
+ delete_lockfile(openfile->lock_filename);
#endif
-
#ifndef DISABLE_MULTIBUFFER
- /* Exit only if there are no more open file buffers. */
- if (!close_buffer(FALSE))
+ /* If there are no more open file buffers, jump off a cliff. */
+ if (!close_buffer(FALSE))
#endif
- finish();
- /* If the user canceled, we go on. */
- } else if (i != 1)
- statusbar(_("Cancelled"));
-
- display_main_list();
+ finish();
}
/* Another placeholder for function mapping. */
bool write_marked_file(const char *name, FILE *f_open, bool tmp,
append_type append);
#endif
-bool do_writeout(bool exiting);
+int do_writeout(bool exiting);
void do_writeout_void(void);
#ifndef NANO_TINY
void do_savefile(void);
int no_help(void);
void no_current_file_name_warning(void);
void do_exit(void);
+void close_and_go(void);
void signal_init(void);
RETSIGTYPE handle_hupterm(int signal);
RETSIGTYPE do_suspend(int signal);
void append_void(void);
void prepend_void(void);
void backup_file_void(void);
+void discard_buffer(void);
void new_buffer_void(void);
void backwards_void(void);
void goto_dir_void(void);