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
master
David Lawrence Ramsey 2005-11-05 17:35:44 +00:00
parent c3b3b9a28f
commit a0168ca896
11 changed files with 67 additions and 33 deletions

View File

@ -47,6 +47,13 @@ CVS code -
do_page_down(), do_para_end(), do_next_word(), do_prev_word(), do_page_down(), do_para_end(), do_next_word(), do_prev_word(),
do_up(), do_down(), do_scroll_down(), do_right(), do_mouse(), do_up(), do_down(), do_scroll_down(), do_right(), do_mouse(),
do_gotolinecolumn(), do_delete(), and find_paragraph(). (DLR) 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: - files.c:
read_file() read_file()
- Remove apparently unneeded logic to handle a case where - Remove apparently unneeded logic to handle a case where

View File

@ -6,7 +6,7 @@
.\" Public License for copying conditions. There is NO warranty. .\" Public License for copying conditions. There is NO warranty.
.\" .\"
.\" $Id$ .\" $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. .\" 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 should only need to use this option if they don't, as mouse support
won't work properly with this option enabled. won't work properly with this option enabled.
.TP .TP
.B \-L (\-\-nonewlines)
Don't add newlines to the ends of files.
.TP
.B \-N (\-\-noconvert) .B \-N (\-\-noconvert)
Disable automatic conversion of files from DOS/Mac format. Disable automatic conversion of files from DOS/Mac format.
.TP .TP

View File

@ -6,7 +6,7 @@
.\" Public License for copying conditions. There is NO warranty. .\" Public License for copying conditions. There is NO warranty.
.\" .\"
.\" $Id$ .\" $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. .\" Please adjust this date whenever revising the manpage.
.\" .\"
.SH NAME .SH NAME
@ -95,6 +95,9 @@ Don't follow symlinks when writing files.
.B set/unset nohelp .B set/unset nohelp
Don't display the help lists at the bottom of the screen. Don't display the help lists at the bottom of the screen.
.TP .TP
.B set/unset nonewlines
Don't add newlines to the ends of files.
.TP
.B set/unset nowrap .B set/unset nowrap
Don't wrap text at all. Don't wrap text at all.
.TP .TP

View File

@ -67,6 +67,9 @@
## Don't display the helpful shortcut lists at the bottom of the screen. ## Don't display the helpful shortcut lists at the bottom of the screen.
# set nohelp # set nohelp
## Don't add newlines to the ends of files.
# set nonewlines
## Don't wrap text at all. ## Don't wrap text at all.
# set nowrap # set nowrap
@ -330,7 +333,7 @@
## highlight possible errors and parameters ## highlight possible errors and parameters
# icolor brightwhite "^[[:space:]]*(set|unset|syntax|i?color).*$" # icolor brightwhite "^[[:space:]]*(set|unset|syntax|i?color).*$"
## set, unset and syntax ## 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)\>" # icolor green "^[[:space:]]*(set|unset|syntax)\>"
## colors ## colors
# icolor yellow "^[[:space:]]*i?color[[:space:]]*(bright)?(white|black|red|blue|green|yellow|magenta|cyan)?(,(white|black|red|blue|green|yellow|magenta|cyan))?\>" # icolor yellow "^[[:space:]]*i?color[[:space:]]*(bright)?(white|black|red|blue|green|yellow|magenta|cyan)?(,(white|black|red|blue|green|yellow|magenta|cyan))?\>"

View File

@ -9,7 +9,7 @@
@smallbook @smallbook
@set EDITION 0.1 @set EDITION 0.1
@set VERSION 1.3.9 @set VERSION 1.3.9
@set UPDATED 04 Nov 2005 @set UPDATED 05 Nov 2005
@dircategory Editors @dircategory Editors
@direntry @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 should only need to use this option if they don't, as mouse support
won't work properly with this option enabled. won't work properly with this option enabled.
@item -L, --nonewlines
Don't add newlines to the ends of files.
@item -N, --noconvert @item -N, --noconvert
Don't convert files from DOS/Mac format. Don't convert files from DOS/Mac format.

View File

@ -508,11 +508,11 @@ void read_file(FILE *f, const char *filename)
openfile->totsize += get_totsize(openfile->fileage, openfile->totsize += get_totsize(openfile->fileage,
openfile->filebot); openfile->filebot);
/* If text has been added to the magicline (i.e, a file that doesn't /* If the NO_NEWLINES flag isn't set, and text has been added to
* end in a newline has been inserted at the end of the current * the magicline (i.e, a file that doesn't end in a newline has been
* buffer), add a new magicline, and move the current line down to * inserted at the end of the current buffer), add a new magicline,
* it. */ * and move the current line down to it. */
if (openfile->filebot->data[0] != '\0') { if (!ISSET(NO_NEWLINES) && openfile->filebot->data[0] != '\0') {
new_magicline(); new_magicline();
openfile->current = openfile->filebot; openfile->current = openfile->filebot;
openfile->current_x = 0; openfile->current_x = 0;
@ -1608,7 +1608,7 @@ int write_marked_file(const char *name, FILE *f_open, bool tmp,
int retval = -1; int retval = -1;
bool old_modified = openfile->modified; bool old_modified = openfile->modified;
/* write_file() unsets the modified flag. */ /* write_file() unsets the modified flag. */
bool added_magicline; bool added_magicline = FALSE;
/* Whether we added a magicline after filebot. */ /* Whether we added a magicline after filebot. */
filestruct *top, *bot; filestruct *top, *bot;
size_t top_x, bot_x; 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); (const filestruct **)&bot, &bot_x, NULL);
filepart = partition_filestruct(top, top_x, bot, bot_x); filepart = partition_filestruct(top, top_x, bot, bot_x);
/* If the line at filebot is blank, treat it as the magicline and /* Handle the magicline if the NO_NEWLINES flag isn't set. If the
* hence the end of the file. Otherwise, add a magicline and treat * line at filebot is blank, treat it as the magicline and hence the
* it as the end of the file. */ * end of the file. Otherwise, add a magicline and treat it as the
if ((added_magicline = (openfile->filebot->data[0] != '\0'))) * end of the file. */
if (!ISSET(NO_NEWLINES) &&
(added_magicline = (openfile->filebot->data[0] != '\0')))
new_magicline(); new_magicline();
retval = write_file(name, f_open, tmp, append, TRUE); retval = write_file(name, f_open, tmp, append, TRUE);
/* If we added a magicline, remove it now. */ /* If the NO_NEWLINES flag isn't set, and we added a magicline,
if (added_magicline) * remove it now. */
if (!ISSET(NO_NEWLINES) && added_magicline)
remove_magicline(); remove_magicline();
/* Unpartition the filestruct so that it contains all the text /* Unpartition the filestruct so that it contains all the text

View File

@ -387,8 +387,9 @@ void move_to_filestruct(filestruct **file_top, filestruct **file_bot,
* partition. */ * partition. */
renumber(top_save); renumber(top_save);
/* If the text doesn't end with a magicline, add a new magicline. */ /* If the NO_NEWLINES flag isn't set, and the text doesn't end with
if (openfile->filebot->data[0] != '\0') * a magicline, add a new magicline. */
if (!ISSET(NO_NEWLINES) && openfile->filebot->data[0] != '\0')
new_magicline(); new_magicline();
} }
@ -447,8 +448,9 @@ void copy_from_filestruct(filestruct *file_top, filestruct *file_bot)
* partition. */ * partition. */
renumber(top_save); renumber(top_save);
/* If the text doesn't end with a magicline, add a new magicline. */ /* If the NO_NEWLINES flag isn't set, and the text doesn't end with
if (openfile->filebot->data[0] != '\0') * a magicline, add a new magicline. */
if (!ISSET(NO_NEWLINES) && openfile->filebot->data[0] != '\0')
new_magicline(); new_magicline();
} }
@ -745,6 +747,8 @@ void usage(void)
#endif #endif
print1opt("-K", "--rebindkeypad", print1opt("-K", "--rebindkeypad",
N_("Fix numeric keypad key confusion problem")); N_("Fix numeric keypad key confusion problem"));
print1opt("-L", "--nonewlines",
N_("Don't add newlines to the ends of files"));
#ifndef NANO_SMALL #ifndef NANO_SMALL
print1opt("-N", "--noconvert", print1opt("-N", "--noconvert",
N_("Don't convert files from DOS/Mac format")); 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)) if (!allow_cntrls && is_cntrl_mbchar(output + i - char_buf_len))
continue; continue;
/* When a character is inserted on the current magicline, it /* If the NO_NEWLINES flag isn't set, when a character is
* means we need a new one! */ * added to the magicline, it means we need a new magicline! */
if (openfile->filebot == openfile->current) if (!ISSET(NO_NEWLINES) && openfile->filebot ==
openfile->current)
new_magicline(); new_magicline();
/* More dangerousness fun =) */ /* More dangerousness fun =) */
@ -1570,6 +1575,7 @@ int main(int argc, char **argv)
{"ignorercfiles", 0, NULL, 'I'}, {"ignorercfiles", 0, NULL, 'I'},
#endif #endif
{"rebindkeypad", 0, NULL, 'K'}, {"rebindkeypad", 0, NULL, 'K'},
{"nonewlines", 0, NULL, 'L'},
{"morespace", 0, NULL, 'O'}, {"morespace", 0, NULL, 'O'},
#ifndef DISABLE_JUSTIFY #ifndef DISABLE_JUSTIFY
{"quotestr", 1, NULL, 'Q'}, {"quotestr", 1, NULL, 'Q'},
@ -1653,11 +1659,11 @@ int main(int argc, char **argv)
while ((optchr = while ((optchr =
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
getopt_long(argc, argv, 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) long_options, NULL)
#else #else
getopt(argc, argv, getopt(argc, argv,
"h?ABC:EFHIKNOQ:RST:UVWY:abcdefgijklmo:pr:s:tvwxz") "h?ABC:EFHIKLNOQ:RST:UVWY:abcdefgijklmo:pr:s:tvwxz")
#endif #endif
) != -1) { ) != -1) {
switch (optchr) { switch (optchr) {
@ -1701,6 +1707,9 @@ int main(int argc, char **argv)
case 'K': case 'K':
SET(REBIND_KEYPAD); SET(REBIND_KEYPAD);
break; break;
case 'L':
SET(NO_NEWLINES);
break;
#ifndef NANO_SMALL #ifndef NANO_SMALL
case 'N': case 'N':
SET(NO_CONVERT); SET(NO_CONVERT);

View File

@ -320,7 +320,8 @@ typedef struct rcoption {
#define TABS_TO_SPACES (1<<27) #define TABS_TO_SPACES (1<<27)
#define QUICK_BLANK (1<<28) #define QUICK_BLANK (1<<28)
#define WORD_BOUNDS (1<<29) #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. */ /* Control key sequences. Changing these would be very, very bad. */
#define NANO_CONTROL_SPACE 0 #define NANO_CONTROL_SPACE 0

View File

@ -51,6 +51,7 @@ const static rcoption rcopts[] = {
{"morespace", MORE_SPACE}, {"morespace", MORE_SPACE},
{"nofollow", NOFOLLOW_SYMLINKS}, {"nofollow", NOFOLLOW_SYMLINKS},
{"nohelp", NO_HELP}, {"nohelp", NO_HELP},
{"nonewlines", NO_NEWLINES},
#ifndef DISABLE_WRAPPING #ifndef DISABLE_WRAPPING
{"nowrap", NO_WRAP}, {"nowrap", NO_WRAP},
#endif #endif

View File

@ -844,8 +844,9 @@ ssize_t do_replace_loop(const char *needle, const filestruct
} }
#endif #endif
/* If text has been added to the magicline, make a new magicline. */ /* If the NO_NEWLINES flag isn't set, and text has been added to the
if (openfile->filebot->data[0] != '\0') * magicline, make a new magicline. */
if (!ISSET(NO_NEWLINES) && openfile->filebot->data[0] != '\0')
new_magicline(); new_magicline();
return numreplaced; return numreplaced;

View File

@ -129,11 +129,11 @@ void do_delete(void)
wrap_reset(); wrap_reset();
#endif #endif
/* If text has been added to the magicline as a result of /* If the NO_NEWLINES flag isn't set, and text has been added to
* deleting at the end of the line before filebot, add a new * the magicline as a result of deleting at the end of the line
* magicline. */ * before filebot, add a new magicline. */
if (openfile->current == openfile->filebot && if (!ISSET(NO_NEWLINES) && openfile->current ==
openfile->current->data[0] != '\0') openfile->filebot && openfile->current->data[0] != '\0')
new_magicline(); new_magicline();
} else } else
return; return;