From 2c62b07d2b0e87c6d61a178410dc1e08b7f3826b Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Sat, 29 May 2004 16:38:57 +0000 Subject: [PATCH] allow the changing of closing punctuation and closing brackets (used in justification) via the rcfile git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1783 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 4 ++++ doc/man/nanorc.5 | 9 +++++++++ doc/nanorc.sample | 14 +++++++++++++- src/global.c | 5 +++++ src/nano.c | 8 ++++++-- src/proto.h | 2 ++ src/rcfile.c | 35 +++++++++++++++++++++++++++-------- 7 files changed, 66 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index cfb47012..9ab2643a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -101,6 +101,9 @@ CVS code - "whitespace". This is disabled if nanorc support is disabled or if we're in tiny mode. (Mike Frysinger; minor changes and adaptations by DLR) + - Add the ability to change the closing punctuation and closing + brackets used to control justification, via the rcfile + entries "punct" and "brackets". (DLR) - files.c: add_open_file() - Rearrange the NANO_SMALL #ifdef so that the code to set the @@ -374,6 +377,7 @@ CVS code - - Document the smart home key option. (DLR) - Document the whitespace option. (DLR, adapted from documentation by Mike Frysinger) + - Document the punct and brackets options. (DLR) - nano.texi: - Fix toggle inaccuracies: Meta-L now toggles line wrapping, and Meta-< and Meta-> aren't toggles. (DLR) diff --git a/doc/man/nanorc.5 b/doc/man/nanorc.5 index 69a2e015..dcbee33e 100644 --- a/doc/man/nanorc.5 +++ b/doc/man/nanorc.5 @@ -50,6 +50,10 @@ Create backup files in \fBset backupdir "\fIdirectory\fP"\fP Set the directory where \fBnano\fP puts the backup files if file backups are enabled. +\fBset brackets "\fIstring\fP"\fP +Set the characters treated as closing brackets. They cannot contain +tabs or spaces. Only closing punctuation, optionally followed by +closing brackets, can end sentences. .TP \fBset/unset const\fP Constantly display the cursor position in the status bar. @@ -90,6 +94,11 @@ feature is turned off. \fBset/unset preserve\fP Preserve the XON and XOFF keys (^Q and ^S). .TP +\fBset punct "\fIstring\fP"\fP +Set the characters treated as closing punctuation. They cannot contain +tabs or spaces. Only closing punctuation, optionally followed by +closing brackets, can end sentences. +.TP \fBset quotestr "\fIstring\fP"\fP The email-quote string, used to justify email-quoted paragraphs. This is an "extended regular expression" if your system supports them, diff --git a/doc/nanorc.sample b/doc/nanorc.sample index f7a79608..058223af 100644 --- a/doc/nanorc.sample +++ b/doc/nanorc.sample @@ -17,6 +17,12 @@ ## The directory to put the backup files in. # set backupdir "" +## The characters treated as closing brackets. They cannot contain tabs +## or spaces. Only closing punctuation, optionally followed by closing +## brackets, can end sentences. +## +# set brackets "'")}]>" + ## Constantly display the cursor position in the status bar. # set const @@ -64,6 +70,12 @@ ## Preserve the XON and XOFF keys (^Q and ^S). # set preserve +## The characters treated as closing punctuation. They cannot contain +## tabs or spaces. Only closing punctuation, optionally followed by +## closing brackets, can end sentences. +## +# set punct ".?!" + ## The email-quote string, used to justify email-quoted paragraphs. ## This is an extended regular expression if your system supports them, ## otherwise a literal string. Default: @@ -219,7 +231,7 @@ ## highlight possible errors and parameters #color brightwhite "^ *(set|unset|syntax|color).*$" ## set, unset and syntax -#color cyan "^ *(set|unset) +(autoindent|backup|backupdir|const|cut|fill|historylog|mouse|multibuffer|noconvert|nofollow|nohelp|nowrap|operatingdir|preserve|quotestr|rebinddelete|regexp|smarthome|smooth|speller|suspend|tabsize|tempfile|view|whitespace)" +#color cyan "^ *(set|unset) +(autoindent|backup|backupdir|brackets|const|cut|fill|historylog|mouse|multibuffer|noconvert|nofollow|nohelp|nowrap|operatingdir|preserve|punct|quotestr|rebinddelete|regexp|smarthome|smooth|speller|suspend|tabsize|tempfile|view|whitespace)" #color green "^ *(set|unset|syntax)\>" ## colors #color yellow "^ *color +(bright)?(white|black|red|blue|green|yellow|magenta|cyan)(,(white|black|red|blue|green|yellow|magenta|cyan))?\>" diff --git a/src/global.c b/src/global.c index 465a65c7..9b0334b5 100644 --- a/src/global.c +++ b/src/global.c @@ -67,6 +67,11 @@ openfilestruct *open_files = NULL; /* The list of open files */ #endif #ifndef DISABLE_JUSTIFY +char *punct = NULL; /* Closing punctuation that can end + sentences. */ +char *brackets = NULL; /* Closing brackets that can follow + closing punctuation and can end + sentences. */ char *quotestr = NULL; /* Quote string. The default value is set in main(). */ #endif diff --git a/src/nano.c b/src/nano.c index 62bc1307..e8addff0 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1902,8 +1902,6 @@ size_t indent_length(const char *line) * line[skip + 1] must not be whitespace. */ void justify_format(filestruct *line, size_t skip) { - const char *punct = ".?!"; - const char *brackets = "'\")}]>"; char *back, *front; /* These four asserts are assumptions about the input data. */ @@ -3392,6 +3390,12 @@ int main(int argc, char *argv[]) #endif #ifndef DISABLE_JUSTIFY + if (punct == NULL) + punct = mallocstrcpy(punct, ".?!"); + + if (brackets == NULL) + brackets = mallocstrcpy(brackets, "'\")}]>"); + if (quotestr == NULL) #ifdef HAVE_REGEX_H quotestr = mallocstrcpy(NULL, "^([ \t]*[|>:}#])+"); diff --git a/src/proto.h b/src/proto.h index f4cf99bc..e38ae641 100644 --- a/src/proto.h +++ b/src/proto.h @@ -47,6 +47,8 @@ extern int search_offscreen; extern int currslen; #ifndef DISABLE_JUSTIFY +extern char *punct; +extern char *brackets; extern char *quotestr; #endif diff --git a/src/rcfile.c b/src/rcfile.c index b30c62a8..0dbad5fb 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -43,6 +43,9 @@ const static rcoption rcopts[] = { {"autoindent", AUTOINDENT}, {"backup", BACKUP_FILE}, {"backupdir", 0}, +#endif +#ifndef DISABLE_JUSTIFY + {"brackets", 0}, #endif {"const", CONSTUPDATE}, #ifndef NANO_SMALL @@ -73,6 +76,7 @@ const static rcoption rcopts[] = { #endif {"preserve", PRESERVE}, #ifndef DISABLE_JUSTIFY + {"punct", 0}, {"quotestr", 0}, #endif {"rebinddelete", REBIND_DELETE}, @@ -152,12 +156,12 @@ char *parse_next_word(char *ptr) } /* The keywords operatingdir, backupdir, fill, tabsize, speller, - * quotestr, and whitespace take an argument when set. Among these, - * operatingdir, backupdir, speller, quotestr, and whitespace have to - * allow tabs and spaces in the argument. Thus, if the next word starts - * with a ", we say it ends with the last " of the line. Otherwise, the - * word is interpreted as usual. That is so the arguments can contain - * "s too. */ + * punct, brackets, quotestr, and whitespace take an argument when set. + * Among these, operatingdir, backupdir, speller, punct, brackets, + * quotestr, and whitespace have to allow tabs and spaces in the + * argument. Thus, if the next word starts with a ", we say it ends + * with the last " of the line. Otherwise, the word is interpreted as + * usual. That is so the arguments can contain "s too. */ char *parse_argument(char *ptr) { const char *ptr_bak = ptr; @@ -545,6 +549,8 @@ void parse_rcfile(FILE *rcstream) || !strcasecmp(rcopts[i].name, "fill") #endif #ifndef DISABLE_JUSTIFY + || !strcasecmp(rcopts[i].name, "punct") + || !strcasecmp(rcopts[i].name, "brackets") || !strcasecmp(rcopts[i].name, "quotestr") #endif #ifndef NANO_SMALL @@ -589,9 +595,22 @@ void parse_rcfile(FILE *rcstream) } else #endif #ifndef DISABLE_JUSTIFY - if (!strcasecmp(rcopts[i].name, "quotestr")) + if (!strcasecmp(rcopts[i].name, "punct")) { + punct = mallocstrcpy(NULL, option); + if (strchr(punct, '\t') != NULL || strchr(punct, ' ') != NULL) { + rcfile_error(_("Non-tab and non-space characters required")); + free(punct); + punct = NULL; + } + } else if (!strcasecmp(rcopts[i].name, "brackets")) { + brackets = mallocstrcpy(NULL, option); + if (strchr(brackets, '\t') != NULL || strchr(brackets, ' ') != NULL) { + rcfile_error(_("Non-tab and non-space characters required")); + free(brackets); + brackets = NULL; + } + } else if (!strcasecmp(rcopts[i].name, "quotestr")) quotestr = mallocstrcpy(NULL, option); - else #endif #ifndef NANO_SMALL if (!strcasecmp(rcopts[i].name, "backupdir")) -- 2.39.5