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
Этот коммит содержится в:
родитель
eab0fd808c
Коммит
179b1bad87
@ -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:
|
||||
|
@ -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
|
||||
|
16
src/color.c
16
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
|
||||
|
@ -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;
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user