diff --git a/ChangeLog b/ChangeLog index dd0bb43101b9b5f451fcc209fe94d5f7fe1eb97a..50dd3bfc886fa5225eb5904928d6ff6d0fe41bd4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +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> * 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 fbbe11cba8c330cc929378b8318f3ac08bc49b62..cf81d6c713913a444714fc30d51d778a429ee913 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 d635f02cf207b40c8843f43952dd5b52c18be40d..7132e2936a78f512b047e4569276a90c2cf001d8 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 55e330bb7fc773029e652f61efe3ba4378b8f595..cbe3b74ddcf00f08b2fa9ad770b25962c9aee001 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 4e28e7a10f230905aea61944d78b476428de5e34..31bff59a0673640530bfedc326f847896616a193 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 a55862240272d3d0648274788efbae490debf59c..5aae59f1bb94620344538863329fa6d485f3551f 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);