add support for case insensitive expression matching when using color

syntax highlighting, via the "icolor" directive, and add it to those
regexes that can use it (ported from Brand Huntsman's old patch)


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2774 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
David Lawrence Ramsey 2005-06-27 03:07:10 +00:00
parent a899ab185f
commit 23555f29ba
5 changed files with 41 additions and 19 deletions

View File

@ -114,6 +114,11 @@ CVS code -
NANO_SMALL is defined. Changes to usage(), main(), NANO_SMALL is defined. Changes to usage(), main(),
statusbar(), nanorc.sample, nano.1, and nanorc.5. (DLR, statusbar(), nanorc.sample, nano.1, and nanorc.5. (DLR,
suggested by CHAO Wei-Lun) suggested by CHAO Wei-Lun)
- Add support for case insensitive expression matching when
using color syntax highlighting, via the "icolor" directive,
and add it to those regexes that can use it. Changes to
parse_colors(), parse_rcfile(), nanorc.sample, and nanorc.5.
(Brand Huntsman, minor tweaks by DLR)
- chars.c: - chars.c:
make_mbstring() make_mbstring()
- Change erroneous ENABLE_EXTRA #ifdef to NANO_EXTRA to fix a - Change erroneous ENABLE_EXTRA #ifdef to NANO_EXTRA to fix a

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.8" "June 17, 2005" .TH NANORC 5 "version 1.3.8" "June 26, 2005"
.\" Please adjust this date whenever revising the manpage. .\" Please adjust this date whenever revising the manpage.
.\" .\"
.SH NAME .SH NAME
@ -28,8 +28,8 @@ During startup, \fBnano\fP will first read its system-wide settings from
.SH OPTIONS .SH OPTIONS
The configuration file accepts a series of "set" and "unset" commands, The configuration file accepts a series of "set" and "unset" commands,
which can be used to configure nano on startup without using the which can be used to configure nano on startup without using the
command-line options. Additionally, the "syntax" and "color" keywords command-line options. Additionally, the "syntax", "color", and "icolor"
are used to define syntax highlighting rules for different text keywords are used to define syntax highlighting rules for different text
patterns. GNU nano will read one command per line. patterns. GNU nano will read one command per line.
Options in rcfiles take precedence over nano's defaults, and command Options in rcfiles take precedence over nano's defaults, and command
@ -170,8 +170,8 @@ spaces. They must be single-column characters.
.B syntax "\fIstr\fP" ["\fIfileregex\fP" ... ] .B syntax "\fIstr\fP" ["\fIfileregex\fP" ... ]
Defines a syntax named \fIstr\fP which can be activated via the \fB-Y\fP Defines a syntax named \fIstr\fP which can be activated via the \fB-Y\fP
flag, or will be automatically activated if the current filename matches flag, or will be automatically activated if the current filename matches
\fIfileregex\fP. All following \fBcolor\fP statements will apply to \fIfileregex\fP. All following \fBcolor\fP and \fBicolor\fP statements
\fIsyntax\fP until a new syntax is defined. will apply to \fIsyntax\fP until a new syntax is defined.
.TP .TP
.B color \fIfgcolor\fP,\fIbgcolor\fP "\fIregex\fP" ... .B color \fIfgcolor\fP,\fIbgcolor\fP "\fIregex\fP" ...
For the currently defined syntax, display all expressions matching For the currently defined syntax, display all expressions matching
@ -183,6 +183,9 @@ stronger color highlight for the foreground. If your terminal supports
transparency, not specifying a \fIbgcolor\fP tells \fBnano\fP to attempt transparency, not specifying a \fIbgcolor\fP tells \fBnano\fP to attempt
to use a transparent background. to use a transparent background.
.TP .TP
.B icolor \fIfgcolor\fP,\fIbgcolor\fP "\fIregex\fP" ...
Same as above, except that the expression matching is case insensitive.
.TP
.B color \fIfgcolor\fP,\fIbgcolor\fP start="\fIsr\fP" end="\fIer\fP" .B color \fIfgcolor\fP,\fIbgcolor\fP start="\fIsr\fP" end="\fIer\fP"
Display expressions which start with \fIsr\fP and end with \fIer\fP Display expressions which start with \fIsr\fP and end with \fIer\fP
with foreground color \fIfgcolor\fP and background color \fIbgcolor\fP, with foreground color \fIfgcolor\fP and background color \fIbgcolor\fP,
@ -190,6 +193,9 @@ at least one of which must be specified. This allows syntax
highlighting to span multiple lines. Note that all subsequent instances highlighting to span multiple lines. Note that all subsequent instances
of \fIsr\fP after an initial \fIsr\fP is found will be highlighted until of \fIsr\fP after an initial \fIsr\fP is found will be highlighted until
the first instance of \fIer\fP. the first instance of \fIer\fP.
.TP
.B icolor \fIfgcolor\fP,\fIbgcolor\fP start="\fIsr\fP" end="\fIer\fP"
Same as above, except that the expression matching is case insensitive.
.SH FILES .SH FILES
.TP .TP

View File

@ -142,9 +142,17 @@
# set whitespace " " # set whitespace " "
## Color setup ## Color setup
##
## Format: ## Format:
##
## syntax "short description" ["filename regex" ...] ## syntax "short description" ["filename regex" ...]
##
## color foreground,background "regex" ["regex"...] ## color foreground,background "regex" ["regex"...]
## or
## icolor foreground,background "regex" ["regex"...]
##
## "color" will do case sensitive matches, while "icolor" will do case
## insensitive matches.
## ##
## Legal colors: white, black, red, blue, green, yellow, magenta, cyan. ## Legal colors: white, black, red, blue, green, yellow, magenta, cyan.
## You may use the prefix "bright" to mean a stronger color highlight ## You may use the prefix "bright" to mean a stronger color highlight
@ -280,7 +288,7 @@
# color brightgreen "\.(data|subsection|text)" # color brightgreen "\.(data|subsection|text)"
# color green "\.(align|file|globl|global|hidden|section|size|type|weak)" # color green "\.(align|file|globl|global|hidden|section|size|type|weak)"
# color brightyellow "\.(ascii|asciz|byte|double|float|hword|int|long|short|single|struct|word)" # color brightyellow "\.(ascii|asciz|byte|double|float|hword|int|long|short|single|struct|word)"
# color brightred "^[[:space:]]*[._A-Za-z0-9]*:" # icolor brightred "^[[:space:]]*[._A-Z0-9]*:"
# color brightcyan "^[[:space:]]*#[[:space:]]*(define|undef|include|ifn?def|endif|elif|else|if|warning|error)" # color brightcyan "^[[:space:]]*#[[:space:]]*(define|undef|include|ifn?def|endif|elif|else|if|warning|error)"
## Highlight strings (note: VERY resource intensive) ## Highlight strings (note: VERY resource intensive)
# color brightyellow "<[^= ]*>" ""(\\.|[^\"])*"" # color brightyellow "<[^= ]*>" ""(\\.|[^\"])*""
@ -293,14 +301,14 @@
## ##
# syntax "nanorc" "(\.|/|)nanorc$" # syntax "nanorc" "(\.|/|)nanorc$"
## highlight possible errors and parameters ## highlight possible errors and parameters
# color brightwhite "^[[:space:]]*(set|unset|syntax|color).*$" # icolor brightwhite "^[[:space:]]*(set|unset|syntax|i?color).*$"
## set, unset and syntax ## set, unset and syntax
# color 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:]]+(regexp|smarthome|smooth|speller|suspend|tabsize|tabstospaces|tempfile|view|whitespace)\>" # 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:]]+(regexp|smarthome|smooth|speller|suspend|tabsize|tabstospaces|tempfile|view|whitespace)\>"
# color green "^[[:space:]]*(set|unset|syntax)\>" # icolor green "^[[:space:]]*(set|unset|syntax)\>"
## colors ## colors
# color yellow "^[[:space:]]*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))?\>"
# color magenta "^[[:space:]]*color\>" "\<(start|end)=" # icolor magenta "^[[:space:]]*i?color\>" "\<(start|end)="
## strings ## strings
# color white "\"(\\.|[^\"])*\"" # icolor white "\"(\\.|[^\"])*\""
## comments ## comments
# color blue "[[:space:]]*#.*$" # icolor blue "[[:space:]]*#.*$"

View File

@ -492,7 +492,7 @@ int color_to_int(const char *colorname, bool *bright);
char *parse_next_regex(char *ptr); char *parse_next_regex(char *ptr);
bool nregcomp(regex_t *preg, const char *regex, int eflags); bool nregcomp(regex_t *preg, const char *regex, int eflags);
void parse_syntax(char *ptr); void parse_syntax(char *ptr);
void parse_colors(char *ptr); void parse_colors(char *ptr, bool icase);
#endif /* ENABLE_COLOR */ #endif /* ENABLE_COLOR */
void parse_rcfile(FILE *rcstream); void parse_rcfile(FILE *rcstream);
void do_rcfile(void); void do_rcfile(void);

View File

@ -341,8 +341,9 @@ void parse_syntax(char *ptr)
} }
} }
/* Parse the color stuff into the colorstrings array. */ /* Parse the color stuff into the colorstrings array. If icase is TRUE,
void parse_colors(char *ptr) * treat the color stuff as case insensitive. */
void parse_colors(char *ptr, bool icase)
{ {
int fg, bg; int fg, bg;
bool bright = FALSE, no_fgcolor = FALSE; bool bright = FALSE, no_fgcolor = FALSE;
@ -429,7 +430,7 @@ void parse_colors(char *ptr)
if (ptr == NULL) if (ptr == NULL)
break; break;
if (nregcomp(&newcolor->start, fgstr, 0)) { if (nregcomp(&newcolor->start, fgstr, icase ? REG_ICASE : 0)) {
free(newcolor); free(newcolor);
cancelled = TRUE; cancelled = TRUE;
} else { } else {
@ -479,7 +480,7 @@ void parse_colors(char *ptr)
continue; continue;
newcolor->end = (regex_t *)nmalloc(sizeof(regex_t)); newcolor->end = (regex_t *)nmalloc(sizeof(regex_t));
if (nregcomp(newcolor->end, fgstr, 0)) { if (nregcomp(newcolor->end, fgstr, icase ? REG_ICASE : 0)) {
free(newcolor->end); free(newcolor->end);
newcolor->end = NULL; newcolor->end = NULL;
} }
@ -525,7 +526,9 @@ void parse_rcfile(FILE *rcstream)
else if (strcasecmp(keyword, "syntax") == 0) else if (strcasecmp(keyword, "syntax") == 0)
parse_syntax(ptr); parse_syntax(ptr);
else if (strcasecmp(keyword, "color") == 0) else if (strcasecmp(keyword, "color") == 0)
parse_colors(ptr); parse_colors(ptr, FALSE);
else if (strcasecmp(keyword, "icolor") == 0)
parse_colors(ptr, TRUE);
#endif /* ENABLE_COLOR */ #endif /* ENABLE_COLOR */
else else
rcfile_error(N_("Command %s not understood"), keyword); rcfile_error(N_("Command %s not understood"), keyword);