options: add -O/--bookstyle to make leading whitespace mean new paragraph

Before version 2.9.8, nano would consider any line that started with
leading whitespace as the beginning of a new paragraph, and would thus
be unable to justify an indented piece of text (unless autoindent was
switched on).  I thought that this was too limiting and changed the
way nano detects and parses paragraphs.  It works fine in texts where
paragraphs occupy multiple lines, but breaks down for paragraphs of
a single line: nano merges those with adjoining lines.

Now, when -O or --bookstyle or 'set bookstyle' is used, nano will again
consider a line that begins with whitespace as the start of a paragraph
-- when 'autoindent' is OFF.

This addresses https://savannah.gnu.org/bugs/?57402.
Indirectly-reported-by: Sébastien Desreux <seb@h-k.fr>
Also-reported-by: Bill Kendrick <nbs@sonic.net>
master
Benno Schulenberg 2019-12-18 17:19:04 +01:00
parent 331bd7662e
commit 712f68c697
4 changed files with 14 additions and 2 deletions

View File

@ -543,7 +543,8 @@ enum
BREAK_LONG_LINES,
JUMPY_SCROLLING,
EMPTY_LINE,
INDICATOR
INDICATOR,
BOOKSTYLE
};
/* Flags for the menus in which a given function should be present. */

View File

@ -541,6 +541,8 @@ void usage(void)
#ifndef NANO_TINY
print_opt("-N", "--noconvert",
N_("Don't convert files from DOS/Mac format"));
print_opt("-O", "--bookstyle",
N_("Leading whitespace means new paragraph"));
#endif
#ifdef ENABLE_HISTORIES
if (!ISSET(RESTRICTED))
@ -1737,6 +1739,7 @@ int main(int argc, char **argv)
{"guidestripe", 1, NULL, 'J'},
{"nonewlines", 0, NULL, 'L'},
{"noconvert", 0, NULL, 'N'},
{"bookstyle", 0, NULL, 'O'},
{"positionlog", 0, NULL, 'P'},
{"softwrap", 0, NULL, 'S'},
{"wordbounds", 0, NULL, 'W'},
@ -1803,7 +1806,7 @@ int main(int argc, char **argv)
if (*(tail(argv[0])) == 'r')
SET(RESTRICTED);
while ((optchr = getopt_long(argc, argv, "ABC:DEFGHIJ:KLMNPQ:RST:UVWX:Y:Z"
while ((optchr = getopt_long(argc, argv, "ABC:DEFGHIJ:KLMNOPQ:RST:UVWX:Y:Z"
"abcdef:ghijklmno:pqr:s:tuvwxyz$", long_options, NULL)) != -1) {
switch (optchr) {
#ifndef NANO_TINY
@ -1871,6 +1874,9 @@ int main(int argc, char **argv)
case 'N':
SET(NO_CONVERT);
break;
case 'O':
SET(BOOKSTYLE);
break;
#endif
#ifdef ENABLE_HISTORIES
case 'P':

View File

@ -103,6 +103,7 @@ static const rcoption rcopts[] = {
{"autoindent", AUTOINDENT},
{"backup", MAKE_BACKUP},
{"backupdir", 0},
{"bookstyle", BOOKSTYLE},
{"cutfromcursor", CUT_FROM_CURSOR},
{"guidestripe", 0},
{"indicator", INDICATOR},

View File

@ -1510,6 +1510,10 @@ bool begpar(const linestruct *const line, int depth)
if (line->data[quot_len + indent_len] == '\0')
return FALSE;
/* When requested, treat a line that starts with whitespace as a BOP. */
if (ISSET(BOOKSTYLE) && !ISSET(AUTOINDENT) && is_blank_char(line->data))
return TRUE;
/* If the quote part of the preceding line differs, this is a BOP. */
if (quot_len != quote_length(line->prev->data) ||
strncmp(line->data, line->prev->data, quot_len) != 0)