Commit ee7b0956 authored by Benno Schulenberg's avatar Benno Schulenberg
Browse files

Adding a new bindable function that writes a file to disk without

first asking for its name.  Patch was suggested by Seiya Nuta.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5318 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
parent 25c775af
Showing with 38 additions and 2 deletions
+38 -2
2015-07-25 Benno Schulenberg <bensberg@justemail.net>
* src/global.c (shortcut_init, strtosc), src/files.c (savefile),
doc/man/nanorc.5, doc/texinfo/nano.texi: Add a new bindable function,
'savefile', which writes a file to disk without first asking for its
name. This implements Savannah patch #8208 submitted by Seiya Nuta.
2015-07-23 Benno Schulenberg <bensberg@justemail.net> 2015-07-23 Benno Schulenberg <bensberg@justemail.net>
* doc/man/{nano.1,nanorc.5}, doc/texinfo/nano.texi: Add deprecation * doc/man/{nano.1,nanorc.5}, doc/texinfo/nano.texi: Add deprecation
notices for the options 'set const', 'set poslog' and '--poslog'. notices for the options 'set const', 'set poslog' and '--poslog'.
......
...@@ -380,7 +380,10 @@ Cancels the current command. ...@@ -380,7 +380,10 @@ Cancels the current command.
Exits from the program (or from the help viewer or the file browser). Exits from the program (or from the help viewer or the file browser).
.TP .TP
.B writeout .B writeout
Writes the current buffer to disk. Writes the current buffer to disk, asking for a name.
.TP
.B savefile
Writes the current file to disk without prompting or warning.
.TP .TP
.B insert .B insert
Inserts a file into the current buffer (at the current cursor position), Inserts a file into the current buffer (at the current cursor position),
......
...@@ -950,7 +950,10 @@ Cancels the current command. ...@@ -950,7 +950,10 @@ Cancels the current command.
Exits from the program (or from the help viewer or the file browser). Exits from the program (or from the help viewer or the file browser).
@item writeout @item writeout
Writes the current buffer to disk. Writes the current buffer to disk, asking for a name.
@item savefile
Writes the current file to disk without prompting or warning.
@item insert @item insert
Inserts a file into the current buffer (at the current cursor position), Inserts a file into the current buffer (at the current cursor position),
......
...@@ -2459,6 +2459,17 @@ void do_writeout_void(void) ...@@ -2459,6 +2459,17 @@ void do_writeout_void(void)
display_main_list(); display_main_list();
} }
#ifndef NANO_TINY
/* If it has a name, write the current file to disk without prompting. */
void do_savefile(void)
{
if (openfile->filename[0] != '\0')
write_file(openfile->filename, NULL, FALSE, OVERWRITE, FALSE);
else
do_writeout_void();
}
#endif
/* Return a malloc()ed string containing the actual directory, used to /* Return a malloc()ed string containing the actual directory, used to
* convert ~user/ and ~/ notation. */ * convert ~user/ and ~/ notation. */
char *real_dir_from_tilde(const char *buf) char *real_dir_from_tilde(const char *buf)
......
...@@ -601,6 +601,7 @@ void shortcut_init(void) ...@@ -601,6 +601,7 @@ void shortcut_init(void)
const char *nano_suspend_msg = const char *nano_suspend_msg =
N_("Suspend the editor (if suspend is enabled)"); N_("Suspend the editor (if suspend is enabled)");
#ifndef NANO_TINY #ifndef NANO_TINY
const char *nano_savefile_msg = N_("Save file without prompting");
const char *nano_case_msg = const char *nano_case_msg =
N_("Toggle the case sensitivity of the search"); N_("Toggle the case sensitivity of the search");
const char *nano_reverse_msg = const char *nano_reverse_msg =
...@@ -911,6 +912,11 @@ void shortcut_init(void) ...@@ -911,6 +912,11 @@ void shortcut_init(void)
add_to_funcs(do_suspend_void, MMAIN, add_to_funcs(do_suspend_void, MMAIN,
N_("Suspend"), IFSCHELP(nano_suspend_msg), BLANKAFTER, VIEW); N_("Suspend"), IFSCHELP(nano_suspend_msg), BLANKAFTER, VIEW);
#ifndef NANO_TINY
add_to_funcs(do_savefile, MMAIN,
N_("Save"), IFSCHELP(nano_savefile_msg), BLANKAFTER, NOVIEW);
#endif
#ifndef DISABLE_HISTORIES #ifndef DISABLE_HISTORIES
add_to_funcs(get_history_older_void, add_to_funcs(get_history_older_void,
(MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE), (MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE),
...@@ -1299,6 +1305,10 @@ sc *strtosc(char *input) ...@@ -1299,6 +1305,10 @@ sc *strtosc(char *input)
s->scfunc = do_exit; s->scfunc = do_exit;
else if (!strcasecmp(input, "writeout")) else if (!strcasecmp(input, "writeout"))
s->scfunc = do_writeout_void; s->scfunc = do_writeout_void;
#ifndef NANO_TINY
else if (!strcasecmp(input, "savefile"))
s->scfunc = do_savefile;
#endif
else if (!strcasecmp(input, "insert")) else if (!strcasecmp(input, "insert"))
s->scfunc = do_insertfile_void; s->scfunc = do_insertfile_void;
else if (!strcasecmp(input, "whereis")) else if (!strcasecmp(input, "whereis"))
......
...@@ -321,6 +321,9 @@ bool write_marked_file(const char *name, FILE *f_open, bool tmp, ...@@ -321,6 +321,9 @@ bool write_marked_file(const char *name, FILE *f_open, bool tmp,
#endif #endif
bool do_writeout(bool exiting); bool do_writeout(bool exiting);
void do_writeout_void(void); void do_writeout_void(void);
#ifndef NANO_TINY
void do_savefile(void);
#endif
char *real_dir_from_tilde(const char *buf); char *real_dir_from_tilde(const char *buf);
#if !defined(DISABLE_TABCOMP) || !defined(DISABLE_BROWSER) #if !defined(DISABLE_TABCOMP) || !defined(DISABLE_BROWSER)
int diralphasort(const void *va, const void *vb); int diralphasort(const void *va, const void *vb);
......
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