From: David Lawrence Ramsey Date: Mon, 1 Aug 2005 04:23:29 +0000 (+0000) Subject: more color updates: add a "default" syntax that takes no extensions for X-Git-Tag: v1.3.9~87 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=179b1bad873e55df5339f610a6104e8a7f8998ac;p=nano.git more color updates: add a "default" syntax that takes no extensions for those files that don't match any other syntax's extensions (ported from Brand Huntsman's old patch, but modified to work with a syntax named "default" instead of requiring a "default-syntax" keyword, and to fit into the existing color architecture) git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2959 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- diff --git a/ChangeLog b/ChangeLog index d41657ee..875e3bab 100644 --- a/ChangeLog +++ b/ChangeLog @@ -53,7 +53,9 @@ CVS code - regex strings constantly, and to actually compile them on an as-needed basis. Also, make a color syntax specified on the command line override the syntax associated with the current - file extension. Changes to update_color(), + file extension, and add a "default" syntax that takes no + extensions for those files that don't match any other + syntax's extensions. Changes to update_color(), thanks_for_all_the_fish(), nregcomp(), parse_syntax(), and parse_colors(). (Brand Huntsman and DLR) - Various other color fixes. Handle unspecified foreground @@ -285,6 +287,7 @@ CVS code - - doc/nanorc.sample: - Add regexes for Bourne shell scripts. (Mike Frysinger, minor tweaks by DLR) + - Explain how the "default" syntax works. (DLR) - doc/man/fr/nano.1, doc/man/fr/nanorc.1: - Updated translation by Jean-Philippe GĂ©rard. - src/Makefile.am: diff --git a/doc/nanorc.sample b/doc/nanorc.sample index 7a0b5ad5..4226275b 100644 --- a/doc/nanorc.sample +++ b/doc/nanorc.sample @@ -147,12 +147,16 @@ ## ## syntax "short description" ["filename regex" ...] ## +## (The syntax "default" is reserved: it takes no filename regexes, and +## applies to files that don't match any other syntax's filename +## regexes.) +## ## color foreground,background "regex" ["regex"...] ## or ## icolor foreground,background "regex" ["regex"...] ## -## "color" will do case sensitive matches, while "icolor" will do case -## insensitive matches. +## ("color" will do case sensitive matches, while "icolor" will do case +## insensitive matches.) ## ## Legal colors: white, black, red, blue, green, yellow, magenta, cyan. ## You may use the prefix "bright" to mean a stronger color highlight diff --git a/src/color.c b/src/color.c index c74ee905..658a81da 100644 --- a/src/color.c +++ b/src/color.c @@ -108,7 +108,7 @@ void color_init(void) void color_update(void) { const syntaxtype *tmpsyntax; - colortype *tmpcolor; + colortype *tmpcolor, *defcolor = NULL; assert(openfile != NULL); @@ -134,6 +134,15 @@ void color_update(void) tmpsyntax = tmpsyntax->next) { exttype *e; + /* If this is the default syntax, it has no associated + * extensions. (We've checked for this and for duplicate + * syntax names elsewhere.) Skip over it here, but keep + * track of its color regexes. */ + if (mbstrcasecmp(tmpsyntax->desc, "default") == 0) { + defcolor = syntaxes->color; + continue; + } + for (e = tmpsyntax->extensions; e != NULL; e = e->next) { bool not_compiled = (e->ext == NULL); @@ -165,6 +174,11 @@ void color_update(void) } } + /* If we didn't get a syntax based on the file extension, and we + * have a default syntax, use it. */ + if (openfile->colorstrings == NULL && defcolor != NULL) + openfile->colorstrings = defcolor; + for (tmpcolor = openfile->colorstrings; tmpcolor != NULL; tmpcolor = tmpcolor->next) { /* tmpcolor->start_regex and tmpcolor->end_regex have already diff --git a/src/rcfile.c b/src/rcfile.c index 14f70162..2f0f9801 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -322,6 +322,12 @@ void parse_syntax(char *ptr) fprintf(stderr, "Starting a new syntax type: \"%s\"\n", nameptr); #endif + /* The default syntax should have no associated extensions. */ + if (mbstrcasecmp(endsyntax->desc, "default") == 0 && *ptr != '\0') { + rcfile_error(N_("The default syntax must take no extensions")); + return; + } + /* Now load the extensions into their part of the struct. */ while (*ptr != '\0') { exttype *newext;