From: Benno Schulenberg Date: Sat, 25 Jul 2015 19:25:50 +0000 (+0000) Subject: Adding a new bindable function that writes a file to disk without X-Git-Tag: v2.5.0~144 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=ee7b0956789c6c43f2073ecb9c2864d777b5b398;p=nano.git 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 --- diff --git a/ChangeLog b/ChangeLog index dd0bb431..50dd3bfc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2015-07-25 Benno Schulenberg + * 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 * doc/man/{nano.1,nanorc.5}, doc/texinfo/nano.texi: Add deprecation notices for the options 'set const', 'set poslog' and '--poslog'. diff --git a/doc/man/nanorc.5 b/doc/man/nanorc.5 index fbbe11cb..cf81d6c7 100644 --- a/doc/man/nanorc.5 +++ b/doc/man/nanorc.5 @@ -380,7 +380,10 @@ Cancels the current command. Exits from the program (or from the help viewer or the file browser). .TP .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 .B insert Inserts a file into the current buffer (at the current cursor position), diff --git a/doc/texinfo/nano.texi b/doc/texinfo/nano.texi index d635f02c..7132e293 100644 --- a/doc/texinfo/nano.texi +++ b/doc/texinfo/nano.texi @@ -950,7 +950,10 @@ Cancels the current command. Exits from the program (or from the help viewer or the file browser). @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 Inserts a file into the current buffer (at the current cursor position), diff --git a/src/files.c b/src/files.c index 55e330bb..cbe3b74d 100644 --- a/src/files.c +++ b/src/files.c @@ -2459,6 +2459,17 @@ void do_writeout_void(void) 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 * convert ~user/ and ~/ notation. */ char *real_dir_from_tilde(const char *buf) diff --git a/src/global.c b/src/global.c index 4e28e7a1..31bff59a 100644 --- a/src/global.c +++ b/src/global.c @@ -601,6 +601,7 @@ void shortcut_init(void) const char *nano_suspend_msg = N_("Suspend the editor (if suspend is enabled)"); #ifndef NANO_TINY + const char *nano_savefile_msg = N_("Save file without prompting"); const char *nano_case_msg = N_("Toggle the case sensitivity of the search"); const char *nano_reverse_msg = @@ -911,6 +912,11 @@ void shortcut_init(void) add_to_funcs(do_suspend_void, MMAIN, 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 add_to_funcs(get_history_older_void, (MWHEREIS|MREPLACE|MREPLACEWITH|MWHEREISFILE), @@ -1299,6 +1305,10 @@ sc *strtosc(char *input) s->scfunc = do_exit; else if (!strcasecmp(input, "writeout")) s->scfunc = do_writeout_void; +#ifndef NANO_TINY + else if (!strcasecmp(input, "savefile")) + s->scfunc = do_savefile; +#endif else if (!strcasecmp(input, "insert")) s->scfunc = do_insertfile_void; else if (!strcasecmp(input, "whereis")) diff --git a/src/proto.h b/src/proto.h index a5586224..5aae59f1 100644 --- a/src/proto.h +++ b/src/proto.h @@ -321,6 +321,9 @@ bool write_marked_file(const char *name, FILE *f_open, bool tmp, #endif bool do_writeout(bool exiting); void do_writeout_void(void); +#ifndef NANO_TINY +void do_savefile(void); +#endif char *real_dir_from_tilde(const char *buf); #if !defined(DISABLE_TABCOMP) || !defined(DISABLE_BROWSER) int diralphasort(const void *va, const void *vb);