Commit 8cc6308f authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

Offering ^Q in the writeout menu to close and discard the current buffer

without saving it.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5509 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
parent 1bebe34b
Showing with 82 additions and 34 deletions
+82 -34
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> 2015-12-23 Mike Frysinger <vapier@gentoo.org>
* doc/syntax/autoconf.nanorc: Handle .m4 files too, add the "elif" * doc/syntax/autoconf.nanorc: Handle .m4 files too, add the "elif"
keyword, handle dnl comments better, and mark trailing whitespace. keyword, handle dnl comments better, and mark trailing whitespace.
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
.\" Documentation License along with this program. If not, see .\" Documentation License along with this program. If not, see
.\" <http://www.gnu.org/licenses/>. .\" <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. .\" Please adjust this date whenever revising the manpage.
.\" .\"
.SH NAME .SH NAME
...@@ -596,6 +596,11 @@ When writing a file, 'prepends' (writes at the beginning) instead of overwriting ...@@ -596,6 +596,11 @@ When writing a file, 'prepends' (writes at the beginning) instead of overwriting
.B backup .B backup
When writing a file, creates a backup of the current file. When writing a file, creates a backup of the current file.
.TP .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 .B firstfile
Goes to the first file when using the file browser (reading or writing files). Goes to the first file when using the file browser (reading or writing files).
.TP .TP
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
@smallbook @smallbook
@set EDITION 0.3 @set EDITION 0.3
@set VERSION 2.5.0 @set VERSION 2.5.1
@set UPDATED December 2015 @set UPDATED December 2015
@dircategory Editors @dircategory Editors
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
@titlepage @titlepage
@title GNU @code{nano} @title GNU @code{nano}
@subtitle a small and friendly text editor. @subtitle a small and friendly text editor.
@subtitle version 2.5.0 @subtitle version 2.5.1
@author Chris Allegretta @author Chris Allegretta
@page @page
...@@ -1159,6 +1159,11 @@ When writing a file, 'prepends' (writes at the beginning) instead of overwriting ...@@ -1159,6 +1159,11 @@ When writing a file, 'prepends' (writes at the beginning) instead of overwriting
@item backup @item backup
When writing a file, creates a backup of the current file. 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 @item tofiles
Starts the file browser, allowing to select a file from a list. Starts the file browser, allowing to select a file from a list.
......
...@@ -2211,11 +2211,11 @@ bool write_marked_file(const char *name, FILE *f_open, bool tmp, ...@@ -2211,11 +2211,11 @@ bool write_marked_file(const char *name, FILE *f_open, bool tmp,
#endif /* !NANO_TINY */ #endif /* !NANO_TINY */
/* Write the current file to disk. If the mark is on, write the current /* 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 * marked selection to disk. If exiting is TRUE, write the entire file
* regardless of whether the mark is on, and without prompting if the * to disk regardless of whether the mark is on, and without prompting if
* TEMP_FILE flag is set and the current file has a name. Return TRUE * the TEMP_FILE flag is set and the current file has a name. Return 0
* on success or FALSE on error. */ * on error, 1 on success, and 2 when the buffer is to be discarded. */
bool do_writeout(bool exiting) int do_writeout(bool exiting)
{ {
int i; int i;
append_type append = OVERWRITE; append_type append = OVERWRITE;
...@@ -2224,15 +2224,13 @@ bool do_writeout(bool exiting) ...@@ -2224,15 +2224,13 @@ bool do_writeout(bool exiting)
#ifndef DISABLE_EXTRA #ifndef DISABLE_EXTRA
static bool did_credits = FALSE; static bool did_credits = FALSE;
#endif #endif
bool retval = FALSE; bool result = FALSE;
if (exiting && openfile->filename[0] != '\0' && ISSET(TEMP_FILE)) { if (exiting && openfile->filename[0] != '\0' && ISSET(TEMP_FILE)) {
retval = write_file(openfile->filename, NULL, FALSE, OVERWRITE, result = write_file(openfile->filename, NULL, FALSE, OVERWRITE, FALSE);
FALSE);
/* Write succeeded. */ if (result)
if (retval) return 1; /* The write succeeded. */
return retval;
} }
ans = mallocstrcpy(NULL, ans = mallocstrcpy(NULL,
...@@ -2289,11 +2287,26 @@ bool do_writeout(bool exiting) ...@@ -2289,11 +2287,26 @@ bool do_writeout(bool exiting)
* encoded null), treat it as though it's blank. */ * encoded null), treat it as though it's blank. */
if (i < 0 || *answer == '\n') { if (i < 0 || *answer == '\n') {
statusbar(_("Cancelled")); statusbar(_("Cancelled"));
retval = FALSE;
break; break;
} else { } else {
functionptrtype func = func_from_key(&i); 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); ans = mallocstrcpy(ans, answer);
#ifndef DISABLE_BROWSER #ifndef DISABLE_BROWSER
...@@ -2347,7 +2360,6 @@ bool do_writeout(bool exiting) ...@@ -2347,7 +2360,6 @@ bool do_writeout(bool exiting)
strcasecmp(answer, "zzy") == 0) { strcasecmp(answer, "zzy") == 0) {
do_credits(); do_credits();
did_credits = TRUE; did_credits = TRUE;
retval = FALSE;
break; break;
} }
#endif #endif
...@@ -2431,7 +2443,7 @@ bool do_writeout(bool exiting) ...@@ -2431,7 +2443,7 @@ bool do_writeout(bool exiting)
* a separate file. If we're using restricted mode, this * a separate file. If we're using restricted mode, this
* function is disabled, since it allows reading from or * function is disabled, since it allows reading from or
* writing to files not specified on the command line. */ * writing to files not specified on the command line. */
retval = result =
#ifndef NANO_TINY #ifndef NANO_TINY
(!ISSET(RESTRICTED) && !exiting && openfile->mark_set) ? (!ISSET(RESTRICTED) && !exiting && openfile->mark_set) ?
write_marked_file(answer, NULL, FALSE, append) : write_marked_file(answer, NULL, FALSE, append) :
...@@ -2444,14 +2456,16 @@ bool do_writeout(bool exiting) ...@@ -2444,14 +2456,16 @@ bool do_writeout(bool exiting)
free(ans); free(ans);
return retval; return result ? 1 : 0;
} }
/* Write the current file to disk. If the mark is on, write the current /* Write the current buffer to disk, or discard it. */
* marked selection to disk. */
void do_writeout_void(void) 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(); display_main_list();
} }
......
...@@ -270,6 +270,9 @@ void prepend_void(void) ...@@ -270,6 +270,9 @@ void prepend_void(void)
void backup_file_void(void) void backup_file_void(void)
{ {
} }
void discard_buffer(void)
{
}
void new_buffer_void(void) void new_buffer_void(void)
{ {
} }
...@@ -632,6 +635,7 @@ void shortcut_init(void) ...@@ -632,6 +635,7 @@ void shortcut_init(void)
const char *nano_backup_msg = N_("Toggle backing up of the original file"); const char *nano_backup_msg = N_("Toggle backing up of the original file");
const char *nano_execute_msg = N_("Execute external command"); const char *nano_execute_msg = N_("Execute external command");
#endif #endif
const char *nano_discard_buffer_msg = N_("Close buffer without saving it");
#ifndef DISABLE_MULTIBUFFER #ifndef DISABLE_MULTIBUFFER
const char *nano_multibuffer_msg = N_("Toggle the use of a new buffer"); const char *nano_multibuffer_msg = N_("Toggle the use of a new buffer");
#endif #endif
...@@ -1006,6 +1010,9 @@ void shortcut_init(void) ...@@ -1006,6 +1010,9 @@ void shortcut_init(void)
N_("Last File"), IFSCHELP(nano_lastfile_msg), BLANKAFTER, VIEW); N_("Last File"), IFSCHELP(nano_lastfile_msg), BLANKAFTER, VIEW);
#endif #endif
add_to_funcs(discard_buffer, MWRITEFILE,
N_("Discard buffer"), IFSCHELP(nano_discard_buffer_msg), BLANKAFTER, NOVIEW);
#if !defined(NANO_TINY) && !defined(DISABLE_BROWSER) #if !defined(NANO_TINY) && !defined(DISABLE_BROWSER)
add_to_funcs(do_research, MBROWSER, add_to_funcs(do_research, MBROWSER,
whereis_next_tag, IFSCHELP(nano_whereis_next_msg), TOGETHER, VIEW); whereis_next_tag, IFSCHELP(nano_whereis_next_msg), TOGETHER, VIEW);
...@@ -1197,6 +1204,8 @@ void shortcut_init(void) ...@@ -1197,6 +1204,8 @@ void shortcut_init(void)
add_to_sclist(MBROWSER, "M-G", goto_dir_void, 0); add_to_sclist(MBROWSER, "M-G", goto_dir_void, 0);
add_to_sclist(MBROWSER, "F13", goto_dir_void, 0); add_to_sclist(MBROWSER, "F13", goto_dir_void, 0);
#endif #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-D", dos_format_void, 0);
add_to_sclist(MWRITEFILE, "M-M", mac_format_void, 0); add_to_sclist(MWRITEFILE, "M-M", mac_format_void, 0);
if (!ISSET(RESTRICTED)) { if (!ISSET(RESTRICTED)) {
...@@ -1333,6 +1342,8 @@ sc *strtosc(char *input) ...@@ -1333,6 +1342,8 @@ sc *strtosc(char *input)
s->scfunc = do_cancel; s->scfunc = do_cancel;
else if (!strcasecmp(input, "exit")) else if (!strcasecmp(input, "exit"))
s->scfunc = do_exit; s->scfunc = do_exit;
else if (!strcasecmp(input, "discardbuffer"))
s->scfunc = discard_buffer;
else if (!strcasecmp(input, "writeout")) else if (!strcasecmp(input, "writeout"))
s->scfunc = do_writeout_void; s->scfunc = do_writeout_void;
#ifndef NANO_TINY #ifndef NANO_TINY
......
...@@ -1146,23 +1146,27 @@ void do_exit(void) ...@@ -1146,23 +1146,27 @@ void do_exit(void)
/* If the user chose not to save, or if the user chose to save and /* If the user chose not to save, or if the user chose to save and
* the save succeeded, we're ready to exit. */ * 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 #ifndef NANO_TINY
if (ISSET(LOCKING) && openfile->lock_filename) /* If there is a lockfile, remove it. */
delete_lockfile(openfile->lock_filename); if (ISSET(LOCKING) && openfile->lock_filename)
delete_lockfile(openfile->lock_filename);
#endif #endif
#ifndef DISABLE_MULTIBUFFER #ifndef DISABLE_MULTIBUFFER
/* Exit only if there are no more open file buffers. */ /* If there are no more open file buffers, jump off a cliff. */
if (!close_buffer(FALSE)) if (!close_buffer(FALSE))
#endif #endif
finish(); finish();
/* If the user canceled, we go on. */
} else if (i != 1)
statusbar(_("Cancelled"));
display_main_list();
} }
/* Another placeholder for function mapping. */ /* Another placeholder for function mapping. */
......
...@@ -325,7 +325,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type ...@@ -325,7 +325,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type
bool write_marked_file(const char *name, FILE *f_open, bool tmp, bool write_marked_file(const char *name, FILE *f_open, bool tmp,
append_type append); append_type append);
#endif #endif
bool do_writeout(bool exiting); int do_writeout(bool exiting);
void do_writeout_void(void); void do_writeout_void(void);
#ifndef NANO_TINY #ifndef NANO_TINY
void do_savefile(void); void do_savefile(void);
...@@ -483,6 +483,7 @@ int more_space(void); ...@@ -483,6 +483,7 @@ int more_space(void);
int no_help(void); int no_help(void);
void no_current_file_name_warning(void); void no_current_file_name_warning(void);
void do_exit(void); void do_exit(void);
void close_and_go(void);
void signal_init(void); void signal_init(void);
RETSIGTYPE handle_hupterm(int signal); RETSIGTYPE handle_hupterm(int signal);
RETSIGTYPE do_suspend(int signal); RETSIGTYPE do_suspend(int signal);
...@@ -836,6 +837,7 @@ void mac_format_void(void); ...@@ -836,6 +837,7 @@ void mac_format_void(void);
void append_void(void); void append_void(void);
void prepend_void(void); void prepend_void(void);
void backup_file_void(void); void backup_file_void(void);
void discard_buffer(void);
void new_buffer_void(void); void new_buffer_void(void);
void backwards_void(void); void backwards_void(void);
void goto_dir_void(void); void goto_dir_void(void);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment