nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit a0168ca89653d95a411b71bf9b6ae44dc71d54e3
parent c3b3b9a28f8ce2fd4c69400466d42c74ee94e5bc
Author: David Lawrence Ramsey <pooka109@gmail.com>
Date:   Sat,  5 Nov 2005 17:35:44 +0000

add new -L/--nonewlines command line option, and new "nonewlines" rcfile
option, to control whether nano adds magiclines to the ends of files


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3091 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

Diffstat:
MChangeLog | 7+++++++
Mdoc/man/nano.1 | 5++++-
Mdoc/man/nanorc.5 | 5++++-
Mdoc/nanorc.sample | 5++++-
Mdoc/texinfo/nano.texi | 5++++-
Msrc/files.c | 27+++++++++++++++------------
Msrc/nano.c | 27++++++++++++++++++---------
Msrc/nano.h | 3++-
Msrc/rcfile.c | 1+
Msrc/search.c | 5+++--
Msrc/text.c | 10+++++-----
11 files changed, 67 insertions(+), 33 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -47,6 +47,13 @@ CVS code - do_page_down(), do_para_end(), do_next_word(), do_prev_word(), do_up(), do_down(), do_scroll_down(), do_right(), do_mouse(), do_gotolinecolumn(), do_delete(), and find_paragraph(). (DLR) + - Add new -L/--nonewlines command line option, and new + "nonewlines" rcfile option, to control whether nano adds + magiclines to the ends of files. Changes to read_file(), + write_marked_file(), move_to_filestruct(), + copy_from_filestruct(), usage(), do_output(), main(), + do_replace_loop(), do_delete(), nano.1, nanorc.5, nano.texi, + and nanorc.sample. (DLR, suggested by re2823@Safe-mail.net) - files.c: read_file() - Remove apparently unneeded logic to handle a case where diff --git a/doc/man/nano.1 b/doc/man/nano.1 @@ -6,7 +6,7 @@ .\" Public License for copying conditions. There is NO warranty. .\" .\" $Id$ -.TH NANO 1 "version 1.3.9" "September 27, 2005" +.TH NANO 1 "version 1.3.9" "November 5, 2005" .\" Please adjust this date whenever revising the manpage. .\" @@ -73,6 +73,9 @@ Interpret the numeric keypad keys so that they all work properly. You should only need to use this option if they don't, as mouse support won't work properly with this option enabled. .TP +.B \-L (\-\-nonewlines) +Don't add newlines to the ends of files. +.TP .B \-N (\-\-noconvert) Disable automatic conversion of files from DOS/Mac format. .TP diff --git a/doc/man/nanorc.5 b/doc/man/nanorc.5 @@ -6,7 +6,7 @@ .\" Public License for copying conditions. There is NO warranty. .\" .\" $Id$ -.TH NANORC 5 "version 1.3.9" "September 27, 2005" +.TH NANORC 5 "version 1.3.9" "November 5, 2005" .\" Please adjust this date whenever revising the manpage. .\" .SH NAME @@ -95,6 +95,9 @@ Don't follow symlinks when writing files. .B set/unset nohelp Don't display the help lists at the bottom of the screen. .TP +.B set/unset nonewlines +Don't add newlines to the ends of files. +.TP .B set/unset nowrap Don't wrap text at all. .TP diff --git a/doc/nanorc.sample b/doc/nanorc.sample @@ -67,6 +67,9 @@ ## Don't display the helpful shortcut lists at the bottom of the screen. # set nohelp +## Don't add newlines to the ends of files. +# set nonewlines + ## Don't wrap text at all. # set nowrap @@ -330,7 +333,7 @@ ## highlight possible errors and parameters # icolor brightwhite "^[[:space:]]*(set|unset|syntax|i?color).*$" ## set, unset and syntax -# icolor cyan "^[[:space:]]*(set|unset)[[:space:]]+(autoindent|backup|backupdir|backwards|brackets|casesensitive|const|cut|fill|historylog|morespace|mouse|multibuffer|noconvert|nofollow|nohelp|nowrap|operatingdir|preserve|punct|quickblank|quotestr|rebinddelete)\>" "^[[:space:]]*(set|unset)[[:space:]]+(rebindkeypad|regexp|smarthome|smooth|speller|suspend|tabsize|tabstospaces|tempfile|view|whitespace|wordbounds)\>" +# icolor cyan "^[[:space:]]*(set|unset)[[:space:]]+(autoindent|backup|backupdir|backwards|brackets|casesensitive|const|cut|fill|historylog|morespace|mouse|multibuffer|noconvert|nofollow|nohelp|nonewlines|nowrap|operatingdir|preserve|punct|quickblank)\>" "^[[:space:]]*(set|unset)[[:space:]]+(quotestr|rebinddelete|rebindkeypad|regexp|smarthome|smooth|speller|suspend|tabsize|tabstospaces|tempfile|view|whitespace|wordbounds)\>" # icolor green "^[[:space:]]*(set|unset|syntax)\>" ## colors # icolor yellow "^[[:space:]]*i?color[[:space:]]*(bright)?(white|black|red|blue|green|yellow|magenta|cyan)?(,(white|black|red|blue|green|yellow|magenta|cyan))?\>" diff --git a/doc/texinfo/nano.texi b/doc/texinfo/nano.texi @@ -9,7 +9,7 @@ @smallbook @set EDITION 0.1 @set VERSION 1.3.9 -@set UPDATED 04 Nov 2005 +@set UPDATED 05 Nov 2005 @dircategory Editors @direntry @@ -143,6 +143,9 @@ Interpret the numeric keypad keys so that they all work properly. You should only need to use this option if they don't, as mouse support won't work properly with this option enabled. +@item -L, --nonewlines +Don't add newlines to the ends of files. + @item -N, --noconvert Don't convert files from DOS/Mac format. diff --git a/src/files.c b/src/files.c @@ -508,11 +508,11 @@ void read_file(FILE *f, const char *filename) openfile->totsize += get_totsize(openfile->fileage, openfile->filebot); - /* If text has been added to the magicline (i.e, a file that doesn't - * end in a newline has been inserted at the end of the current - * buffer), add a new magicline, and move the current line down to - * it. */ - if (openfile->filebot->data[0] != '\0') { + /* If the NO_NEWLINES flag isn't set, and text has been added to + * the magicline (i.e, a file that doesn't end in a newline has been + * inserted at the end of the current buffer), add a new magicline, + * and move the current line down to it. */ + if (!ISSET(NO_NEWLINES) && openfile->filebot->data[0] != '\0') { new_magicline(); openfile->current = openfile->filebot; openfile->current_x = 0; @@ -1608,7 +1608,7 @@ int write_marked_file(const char *name, FILE *f_open, bool tmp, int retval = -1; bool old_modified = openfile->modified; /* write_file() unsets the modified flag. */ - bool added_magicline; + bool added_magicline = FALSE; /* Whether we added a magicline after filebot. */ filestruct *top, *bot; size_t top_x, bot_x; @@ -1621,16 +1621,19 @@ int write_marked_file(const char *name, FILE *f_open, bool tmp, (const filestruct **)&bot, &bot_x, NULL); filepart = partition_filestruct(top, top_x, bot, bot_x); - /* If the line at filebot is blank, treat it as the magicline and - * hence the end of the file. Otherwise, add a magicline and treat - * it as the end of the file. */ - if ((added_magicline = (openfile->filebot->data[0] != '\0'))) + /* Handle the magicline if the NO_NEWLINES flag isn't set. If the + * line at filebot is blank, treat it as the magicline and hence the + * end of the file. Otherwise, add a magicline and treat it as the + * end of the file. */ + if (!ISSET(NO_NEWLINES) && + (added_magicline = (openfile->filebot->data[0] != '\0'))) new_magicline(); retval = write_file(name, f_open, tmp, append, TRUE); - /* If we added a magicline, remove it now. */ - if (added_magicline) + /* If the NO_NEWLINES flag isn't set, and we added a magicline, + * remove it now. */ + if (!ISSET(NO_NEWLINES) && added_magicline) remove_magicline(); /* Unpartition the filestruct so that it contains all the text diff --git a/src/nano.c b/src/nano.c @@ -387,8 +387,9 @@ void move_to_filestruct(filestruct **file_top, filestruct **file_bot, * partition. */ renumber(top_save); - /* If the text doesn't end with a magicline, add a new magicline. */ - if (openfile->filebot->data[0] != '\0') + /* If the NO_NEWLINES flag isn't set, and the text doesn't end with + * a magicline, add a new magicline. */ + if (!ISSET(NO_NEWLINES) && openfile->filebot->data[0] != '\0') new_magicline(); } @@ -447,8 +448,9 @@ void copy_from_filestruct(filestruct *file_top, filestruct *file_bot) * partition. */ renumber(top_save); - /* If the text doesn't end with a magicline, add a new magicline. */ - if (openfile->filebot->data[0] != '\0') + /* If the NO_NEWLINES flag isn't set, and the text doesn't end with + * a magicline, add a new magicline. */ + if (!ISSET(NO_NEWLINES) && openfile->filebot->data[0] != '\0') new_magicline(); } @@ -745,6 +747,8 @@ void usage(void) #endif print1opt("-K", "--rebindkeypad", N_("Fix numeric keypad key confusion problem")); + print1opt("-L", "--nonewlines", + N_("Don't add newlines to the ends of files")); #ifndef NANO_SMALL print1opt("-N", "--noconvert", N_("Don't convert files from DOS/Mac format")); @@ -1481,9 +1485,10 @@ void do_output(char *output, size_t output_len, bool allow_cntrls) if (!allow_cntrls && is_cntrl_mbchar(output + i - char_buf_len)) continue; - /* When a character is inserted on the current magicline, it - * means we need a new one! */ - if (openfile->filebot == openfile->current) + /* If the NO_NEWLINES flag isn't set, when a character is + * added to the magicline, it means we need a new magicline! */ + if (!ISSET(NO_NEWLINES) && openfile->filebot == + openfile->current) new_magicline(); /* More dangerousness fun =) */ @@ -1570,6 +1575,7 @@ int main(int argc, char **argv) {"ignorercfiles", 0, NULL, 'I'}, #endif {"rebindkeypad", 0, NULL, 'K'}, + {"nonewlines", 0, NULL, 'L'}, {"morespace", 0, NULL, 'O'}, #ifndef DISABLE_JUSTIFY {"quotestr", 1, NULL, 'Q'}, @@ -1653,11 +1659,11 @@ int main(int argc, char **argv) while ((optchr = #ifdef HAVE_GETOPT_LONG getopt_long(argc, argv, - "h?ABC:EFHIKNOQ:RST:UVWY:abcdefgijklmo:pr:s:tvwxz", + "h?ABC:EFHIKLNOQ:RST:UVWY:abcdefgijklmo:pr:s:tvwxz", long_options, NULL) #else getopt(argc, argv, - "h?ABC:EFHIKNOQ:RST:UVWY:abcdefgijklmo:pr:s:tvwxz") + "h?ABC:EFHIKLNOQ:RST:UVWY:abcdefgijklmo:pr:s:tvwxz") #endif ) != -1) { switch (optchr) { @@ -1701,6 +1707,9 @@ int main(int argc, char **argv) case 'K': SET(REBIND_KEYPAD); break; + case 'L': + SET(NO_NEWLINES); + break; #ifndef NANO_SMALL case 'N': SET(NO_CONVERT); diff --git a/src/nano.h b/src/nano.h @@ -320,7 +320,8 @@ typedef struct rcoption { #define TABS_TO_SPACES (1<<27) #define QUICK_BLANK (1<<28) #define WORD_BOUNDS (1<<29) -#define USE_UTF8 (1<<30) +#define NO_NEWLINES (1<<30) +#define USE_UTF8 (1<<31) /* Control key sequences. Changing these would be very, very bad. */ #define NANO_CONTROL_SPACE 0 diff --git a/src/rcfile.c b/src/rcfile.c @@ -51,6 +51,7 @@ const static rcoption rcopts[] = { {"morespace", MORE_SPACE}, {"nofollow", NOFOLLOW_SYMLINKS}, {"nohelp", NO_HELP}, + {"nonewlines", NO_NEWLINES}, #ifndef DISABLE_WRAPPING {"nowrap", NO_WRAP}, #endif diff --git a/src/search.c b/src/search.c @@ -844,8 +844,9 @@ ssize_t do_replace_loop(const char *needle, const filestruct } #endif - /* If text has been added to the magicline, make a new magicline. */ - if (openfile->filebot->data[0] != '\0') + /* If the NO_NEWLINES flag isn't set, and text has been added to the + * magicline, make a new magicline. */ + if (!ISSET(NO_NEWLINES) && openfile->filebot->data[0] != '\0') new_magicline(); return numreplaced; diff --git a/src/text.c b/src/text.c @@ -129,11 +129,11 @@ void do_delete(void) wrap_reset(); #endif - /* If text has been added to the magicline as a result of - * deleting at the end of the line before filebot, add a new - * magicline. */ - if (openfile->current == openfile->filebot && - openfile->current->data[0] != '\0') + /* If the NO_NEWLINES flag isn't set, and text has been added to + * the magicline as a result of deleting at the end of the line + * before filebot, add a new magicline. */ + if (!ISSET(NO_NEWLINES) && openfile->current == + openfile->filebot && openfile->current->data[0] != '\0') new_magicline(); } else return;