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
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
- 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:
##
## 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
void color_update(void)
{
const syntaxtype *tmpsyntax;
- colortype *tmpcolor;
+ colortype *tmpcolor, *defcolor = NULL;
assert(openfile != NULL);
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);
}
}
+ /* 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
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;