From 4e9aa928f63f1e7be856b8127b8d0d1dee8941b1 Mon Sep 17 00:00:00 2001
From: Rishabh Dave <rishabhddave@gmail.com>
Date: Sat, 15 Jul 2017 23:33:43 +0530
Subject: [PATCH] new feature: provide an option to suppress creation of
 ".save" files

Provide an option to prevent dumping of buffer into the ".save" files.
This can be done by passing "-Z" or "--nodotsave" as an argument or by
writing "set nodotsave" in nanorc.

This fulfills https://savannah.gnu.org/bugs/?30749.

Signed-off-by: Rishabh Dave <rishabhddave@gmail.com>
Requested-by: Ren Lawrence <renlawrence@gmail.com>
---
 src/nano.c           | 9 +++++++--
 src/nano.h           | 1 +
 src/rcfile.c         | 1 +
 syntax/nanorc.nanorc | 2 +-
 4 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/src/nano.c b/src/nano.c
index 2560105..ac76bce 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -641,7 +641,7 @@ void die_save_file(const char *die_filename, struct stat *die_stat)
     /* If we're using restricted mode, don't write any emergency backup
      * files, since that would allow reading from or writing to files
      * not specified on the command line. */
-    if (ISSET(RESTRICTED))
+    if (ISSET(RESTRICTED) || ISSET(NO_DOTSAVE))
 	return;
 
     /* If we can't save, we have really bad problems, but we might as
@@ -846,6 +846,7 @@ void usage(void)
     print_opt(_("-X <str>"), _("--wordchars=<str>"),
 	N_("Which other characters are word parts"));
 #endif
+    print_opt("-Z", "--nodotsave", N_("Do not create \".save\" file"));
 #ifndef DISABLE_COLOR
     if (!ISSET(RESTRICTED))
 	print_opt(_("-Y <name>"), _("--syntax=<name>"),
@@ -1931,6 +1932,7 @@ int main(int argc, char **argv)
 #ifndef DISABLE_COLOR
 	{"syntax", 1, NULL, 'Y'},
 #endif
+	{"nodotsave", 0, NULL, 'Z'},
 	{"constantshow", 0, NULL, 'c'},
 	{"rebinddelete", 0, NULL, 'd'},
 #ifdef ENABLE_BROWSER
@@ -2025,7 +2027,7 @@ int main(int argc, char **argv)
 
     while ((optchr =
 	getopt_long(argc, argv,
-		"ABC:DEFGHIKLNOPQ:RST:UVWX:Y:abcdefghijklmno:pqr:s:tuvwxz$",
+		"ABC:DEFGHIKLNOPQ:RST:UVWX:Y:Zabcdefghijklmno:pqr:s:tuvwxz$",
 		long_options, NULL)) != -1) {
 	switch (optchr) {
 	    case 'b':
@@ -2131,6 +2133,9 @@ int main(int argc, char **argv)
 		syntaxstr = mallocstrcpy(syntaxstr, optarg);
 		break;
 #endif
+	    case 'Z':
+		SET(NO_DOTSAVE);
+		break;
 #ifndef NANO_TINY
 	    case 'a':
 		SET(AT_BLANKS);
diff --git a/src/nano.h b/src/nano.h
index 2c1aef2..1cd05a2 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -520,6 +520,7 @@ enum
     SHOW_CURSOR,
     LINE_NUMBERS,
     NO_PAUSES,
+    NO_DOTSAVE,
     AT_BLANKS
 };
 
diff --git a/src/rcfile.c b/src/rcfile.c
index 95fe88a..c9f4926 100644
--- a/src/rcfile.c
+++ b/src/rcfile.c
@@ -60,6 +60,7 @@ static const rcoption rcopts[] = {
     {"multibuffer", MULTIBUFFER},
 #endif
     {"nohelp", NO_HELP},
+    {"nodotsave", NO_DOTSAVE},
     {"nonewlines", NO_NEWLINES},
     {"nopauses", NO_PAUSES},
 #ifndef DISABLE_WRAPPING
diff --git a/syntax/nanorc.nanorc b/syntax/nanorc.nanorc
index ac1fa4c..7bce6f9 100644
--- a/syntax/nanorc.nanorc
+++ b/syntax/nanorc.nanorc
@@ -7,7 +7,7 @@ comment "#"
 icolor brightred "^[[:space:]]*((un)?(bind|set)|include|syntax|header|magic|comment|linter|formatter|i?color|extendsyntax).*$"
 
 # Keywords
-icolor brightgreen "^[[:space:]]*(set|unset)[[:space:]]+(allow_insecure_backup|atblanks|autoindent|backup|backwards|boldtext|casesensitive|constantshow|cutfromcursor|fill[[:space:]]+-?[[:digit:]]+|historylog|justifytrim|linenumbers|locking|morespace|mouse|multibuffer|noconvert|nohelp|nopauses|nonewlines|nowrap|positionlog|preserve|quickblank|quiet|rebinddelete|rebindkeypad|regexp|showcursor|smarthome|smooth|softwrap|suspend|tabsize[[:space:]]+[1-9][0-9]*|tabstospaces|tempfile|unix|view|wordbounds)\>"
+icolor brightgreen "^[[:space:]]*(set|unset)[[:space:]]+(allow_insecure_backup|atblanks|autoindent|backup|backwards|boldtext|casesensitive|constantshow|cutfromcursor|fill[[:space:]]+-?[[:digit:]]+|historylog|justifytrim|linenumbers|locking|morespace|mouse|multibuffer|noconvert|nodotsave|nohelp|nopauses|nonewlines|nowrap|positionlog|preserve|quickblank|quiet|rebinddelete|rebindkeypad|regexp|showcursor|smarthome|smooth|softwrap|suspend|tabsize[[:space:]]+[1-9][0-9]*|tabstospaces|tempfile|unix|view|wordbounds)\>"
 icolor yellow "^[[:space:]]*set[[:space:]]+((function|key|number|status|title)color)[[:space:]]+(bright)?(white|black|red|blue|green|yellow|magenta|cyan)?(,(white|black|red|blue|green|yellow|magenta|cyan))?\>"
 icolor brightgreen "^[[:space:]]*set[[:space:]]+(backupdir|brackets|functioncolor|keycolor|matchbrackets|numbercolor|operatingdir|punct|quotestr|speller|statuscolor|titlecolor|whitespace|wordchars)[[:space:]]+"
 icolor brightgreen "^[[:space:]]*bind[[:space:]]+((\^([[:alpha:]]|[]0-9\^_]|Space)|M-([[:alpha:]]|[]!"#$%&'()*+,./0-9:;<=>?@\^_`{|}~-]|Space))|F([1-9]|1[0-6])|Ins|Del)[[:space:]]+[[:alpha:]]+[[:space:]]+(all|main|search|replace(with)?|gotoline|writeout|insert|ext(ernal)?cmd|help|spell|linter|browser|whereisfile|gotodir)([[:space:]]+#|[[:space:]]*$)"
-- 
2.9.4

