From 70cbbda87cbd19972fd79ec23e5ff4f908d8746f Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Tue, 4 Aug 2015 18:49:57 +0000 Subject: [PATCH] Adding the option --unix (and 'set unix'), to save a file by default in Unix format. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5342 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 5 +++++ doc/man/nano.1 | 5 +++++ doc/man/nanorc.5 | 5 +++++ doc/syntax/nanorc.nanorc | 2 +- doc/texinfo/nano.texi | 11 +++++++++++ src/files.c | 3 +++ src/nano.c | 8 ++++++-- src/nano.h | 3 ++- src/rcfile.c | 1 + 9 files changed, 39 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index d6e4a5d3..325de767 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2015-08-04 Benno Schulenberg + * src/nano.c (main), src/files.c (read_file), src/rcfile.c, + doc/man/nano.1, doc/man/nanorc.5, doc/texinfo/nano.texi: Add + the option --unix, to save a file by default in Unix format. + 2015-08-03 Benno Schulenberg * src/rcfile.c (parse_binding): Check the value of shortcut->toggle only if it actually is a toggle. Found with valgrind. diff --git a/doc/man/nano.1 b/doc/man/nano.1 index 4e786141..6e778a89 100644 --- a/doc/man/nano.1 +++ b/doc/man/nano.1 @@ -222,6 +222,11 @@ Use this alternative spell checker command. Always save a changed buffer without prompting. Same as Pico's \fB\-t\fP option. .TP +.BR \-u ", " \-\-unix +Save a file by default in Unix format. This overrides nano's +default behavior of saving a file in the format that it had. +(This option has no effect when you also use \fB\-\-noconvert\fR.) +.TP .BR \-v ", " \-\-view View-file (read-only) mode. .TP diff --git a/doc/man/nanorc.5 b/doc/man/nanorc.5 index 80e566b9..d794ea81 100644 --- a/doc/man/nanorc.5 +++ b/doc/man/nanorc.5 @@ -242,6 +242,11 @@ Valid color names for foreground and background are: .BR white , \ black , \ red , \ blue , \ green , \ yellow , \ magenta ", and " cyan . And either "\fIfgcolor\fR" or ",\fIbgcolor\fR" may be left out. .TP +.B set unix +Save a file by default in Unix format. This overrides nano's +default behavior of saving a file in the format that it had. +(This option has no effect when you also use \fBset noconvert\fR.) +.TP .B set view Disallow file modification. .TP diff --git a/doc/syntax/nanorc.nanorc b/doc/syntax/nanorc.nanorc index 8846cf6f..5741d573 100644 --- a/doc/syntax/nanorc.nanorc +++ b/doc/syntax/nanorc.nanorc @@ -6,7 +6,7 @@ syntax "nanorc" "\.?nanorc$" icolor brightred "^[[:space:]]*((un)?(bind|set)|include|syntax|header|magic|linter|i?color|extendsyntax).*$" # Keywords -icolor brightgreen "^[[:space:]]*(set|unset)[[:space:]]+(allow_insecure_backup|autoindent|backup|backwards|boldtext|casesensitive|const(antshow)?|cut|fill|historylog|locking|morespace|mouse|multibuffer|noconvert|nofollow|nohelp|nonewlines|nowrap|pos(ition)?log|preserve|quickblank|quiet|rebinddelete|rebindkeypad|regexp|smarthome|smooth|softwrap|suspend|tabsize|tabstospaces|tempfile|view|wordbounds)\>" +icolor brightgreen "^[[:space:]]*(set|unset)[[:space:]]+(allow_insecure_backup|autoindent|backup|backwards|boldtext|casesensitive|const(antshow)?|cut|fill|historylog|locking|morespace|mouse|multibuffer|noconvert|nofollow|nohelp|nonewlines|nowrap|pos(ition)?log|preserve|quickblank|quiet|rebinddelete|rebindkeypad|regexp|smarthome|smooth|softwrap|suspend|tabsize|tabstospaces|tempfile|unix|view|wordbounds)\>" icolor yellow "^[[:space:]]*set[[:space:]]+(functioncolor|keycolor|statuscolor|titlecolor)[[: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|operatingdir|punct|quotestr|speller|statuscolor|titlecolor|whitespace)[[:space:]]+" icolor brightgreen "^[[:space:]]*bind[[:space:]]+((\^|M-)([[:alpha:]]|space|[]]|[0-9_=+{}|;:'\",./<>\?-])|F([1-9]|1[0-6])|Ins|Del)[[:space:]]+[[:alpha:]]+[[:space:]]+(all|main|search|replace(2|with)?|gotoline|writeout|insert|ext(ernal)?cmd|help|spell|linter|browser|whereisfile|gotodir)+[[:space:]]*$" diff --git a/doc/texinfo/nano.texi b/doc/texinfo/nano.texi index 0b250fbb..c2f5b52b 100644 --- a/doc/texinfo/nano.texi +++ b/doc/texinfo/nano.texi @@ -325,6 +325,12 @@ Don't ask whether or not to save the current contents of the file when exiting, assume yes. This is most useful when using @command{nano} as the composer of a mailer program. +@item -u +@item --unix +Save a file by default in Unix format. This overrides nano's ++default behavior of saving a file in the format that it had. +(This option has no effect when you also use @code{--noconvert}.) + @item -v @itemx --view Don't allow the contents of the file to be altered. Note that this @@ -799,6 +805,11 @@ Valid color names for foreground and background are: white, black, red, blue, green, yellow, magenta, and cyan. And either @var{fgcolor} or @var{,bgcolor} may be left out. +@item set unix +Save a file by default in Unix format. This overrides nano's +default behavior of saving a file in the format that it had. +(This option has no effect when you also use @code{set noconvert}.) + @item set view Disallow file modification. diff --git a/src/files.c b/src/files.c index 0a1f445d..2c929c04 100644 --- a/src/files.c +++ b/src/files.c @@ -908,6 +908,9 @@ void read_file(FILE *f, int fd, const char *filename, bool undoable, bool checkw statusbar(P_("Read %lu line (Warning: No write permission)", "Read %lu lines (Warning: No write permission)", (unsigned long)num_lines), (unsigned long)num_lines); + + if (ISSET(MAKE_IT_UNIX)) + openfile->fmt = NIX_FILE; } /* Open the file (and decide if it exists). If newfie is TRUE, display diff --git a/src/nano.c b/src/nano.c index aff1ba57..e95b9a98 100644 --- a/src/nano.c +++ b/src/nano.c @@ -2168,6 +2168,7 @@ int main(int argc, char **argv) {"speller", 1, NULL, 's'}, #endif {"tempfile", 0, NULL, 't'}, + {"unix", 0, NULL, 'u'}, {"view", 0, NULL, 'v'}, #ifndef DISABLE_WRAPPING {"nowrap", 0, NULL, 'w'}, @@ -2228,11 +2229,11 @@ int main(int argc, char **argv) while ((optchr = #ifdef HAVE_GETOPT_LONG getopt_long(argc, argv, - "ABC:DEFGHIKLNOPQ:RST:UVWY:abcdefghijklmno:pqr:s:tvwxz$", + "ABC:DEFGHIKLNOPQ:RST:UVWY:abcdefghijklmno:pqr:s:tuvwxz$", long_options, NULL) #else getopt(argc, argv, - "ABC:DEFGHIKLNOPQ:RST:UVWY:abcdefghijklmno:pqr:s:tvwxz$") + "ABC:DEFGHIKLNOPQ:RST:UVWY:abcdefghijklmno:pqr:s:tuvwxz$") #endif ) != -1) { switch (optchr) { @@ -2396,6 +2397,9 @@ int main(int argc, char **argv) case 't': SET(TEMP_FILE); break; + case 'u': + SET(MAKE_IT_UNIX); + break; case 'v': SET(VIEW_MODE); break; diff --git a/src/nano.h b/src/nano.h index 851e7dbc..2fb93990 100644 --- a/src/nano.h +++ b/src/nano.h @@ -531,7 +531,8 @@ enum SOFTWRAP, POS_HISTORY, LOCKING, - NOREAD_MODE + NOREAD_MODE, + MAKE_IT_UNIX }; /* Flags for the menus in which a given function should be present. */ diff --git a/src/rcfile.c b/src/rcfile.c index 6b0f1691..12da051c 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -82,6 +82,7 @@ static const rcoption rcopts[] = { {"suspend", SUSPEND}, {"tabsize", 0}, {"tempfile", TEMP_FILE}, + {"unix", MAKE_IT_UNIX}, {"view", VIEW_MODE}, #ifndef NANO_TINY {"allow_insecure_backup", INSECURE_BACKUP}, -- 2.39.5