port over more of Brand Huntsman's old patch: a color syntax specified
on the command line will now override the syntax associated with the current file extension git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2951 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
ab73dd4816
commit
6135bf3f6b
|
@ -51,7 +51,9 @@ CVS code -
|
||||||
color_to_short()), and parse_colors(). (DLR)
|
color_to_short()), and parse_colors(). (DLR)
|
||||||
- Change color handling to save only the extension and color
|
- Change color handling to save only the extension and color
|
||||||
regex strings constantly, and to actually compile them on an
|
regex strings constantly, and to actually compile them on an
|
||||||
as-needed basis. Changes to update_color(),
|
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(),
|
||||||
thanks_for_all_the_fish(), nregcomp(), parse_syntax(), and
|
thanks_for_all_the_fish(), nregcomp(), parse_syntax(), and
|
||||||
parse_colors(). (Brand Huntsman and DLR)
|
parse_colors(). (Brand Huntsman and DLR)
|
||||||
- Various other color fixes. Handle unspecified foreground
|
- Various other color fixes. Handle unspecified foreground
|
||||||
|
|
74
src/color.c
74
src/color.c
|
@ -113,40 +113,9 @@ void color_update(void)
|
||||||
assert(openfile != NULL);
|
assert(openfile != NULL);
|
||||||
|
|
||||||
openfile->colorstrings = NULL;
|
openfile->colorstrings = NULL;
|
||||||
for (tmpsyntax = syntaxes; tmpsyntax != NULL;
|
|
||||||
tmpsyntax = tmpsyntax->next) {
|
|
||||||
exttype *e;
|
|
||||||
|
|
||||||
for (e = tmpsyntax->extensions; e != NULL; e = e->next) {
|
/* If we specified a syntax override string, use it. */
|
||||||
bool not_compiled = (e->ext == NULL);
|
if (syntaxstr != NULL) {
|
||||||
|
|
||||||
/* e->ext_regex has already been checked for validity
|
|
||||||
* elsewhere. Compile its specified regex if we haven't
|
|
||||||
* already. */
|
|
||||||
if (not_compiled) {
|
|
||||||
e->ext = (regex_t *)nmalloc(sizeof(regex_t));
|
|
||||||
regcomp(e->ext, e->ext_regex, REG_EXTENDED);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Set colorstrings if we matched the extension regex. */
|
|
||||||
if (regexec(e->ext, openfile->filename, 0, NULL, 0) == 0)
|
|
||||||
openfile->colorstrings = tmpsyntax->color;
|
|
||||||
|
|
||||||
if (openfile->colorstrings != NULL)
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* Decompile e->ext_regex's specified regex if we aren't
|
|
||||||
* going to use it. */
|
|
||||||
if (not_compiled) {
|
|
||||||
regfree(e->ext);
|
|
||||||
free(e->ext);
|
|
||||||
e->ext = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If we haven't found a match, use the override string. */
|
|
||||||
if (openfile->colorstrings == NULL && syntaxstr != NULL) {
|
|
||||||
for (tmpsyntax = syntaxes; tmpsyntax != NULL;
|
for (tmpsyntax = syntaxes; tmpsyntax != NULL;
|
||||||
tmpsyntax = tmpsyntax->next) {
|
tmpsyntax = tmpsyntax->next) {
|
||||||
if (mbstrcasecmp(tmpsyntax->desc, syntaxstr) == 0)
|
if (mbstrcasecmp(tmpsyntax->desc, syntaxstr) == 0)
|
||||||
|
@ -157,6 +126,45 @@ void color_update(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If we didn't specify a syntax override string, or if we did and
|
||||||
|
* there was no syntax by that name, get the syntax based on the
|
||||||
|
* file extension. */
|
||||||
|
if (openfile->colorstrings == NULL) {
|
||||||
|
for (tmpsyntax = syntaxes; tmpsyntax != NULL;
|
||||||
|
tmpsyntax = tmpsyntax->next) {
|
||||||
|
exttype *e;
|
||||||
|
|
||||||
|
for (e = tmpsyntax->extensions; e != NULL; e = e->next) {
|
||||||
|
bool not_compiled = (e->ext == NULL);
|
||||||
|
|
||||||
|
/* e->ext_regex has already been checked for validity
|
||||||
|
* elsewhere. Compile its specified regex if we haven't
|
||||||
|
* already. */
|
||||||
|
if (not_compiled) {
|
||||||
|
e->ext = (regex_t *)nmalloc(sizeof(regex_t));
|
||||||
|
regcomp(e->ext, e->ext_regex, REG_EXTENDED);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set colorstrings if we matched the extension
|
||||||
|
* regex. */
|
||||||
|
if (regexec(e->ext, openfile->filename, 0, NULL,
|
||||||
|
0) == 0)
|
||||||
|
openfile->colorstrings = tmpsyntax->color;
|
||||||
|
|
||||||
|
if (openfile->colorstrings != NULL)
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Decompile e->ext_regex's specified regex if we aren't
|
||||||
|
* going to use it. */
|
||||||
|
if (not_compiled) {
|
||||||
|
regfree(e->ext);
|
||||||
|
free(e->ext);
|
||||||
|
e->ext = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (tmpcolor = openfile->colorstrings; tmpcolor != NULL;
|
for (tmpcolor = openfile->colorstrings; tmpcolor != NULL;
|
||||||
tmpcolor = tmpcolor->next) {
|
tmpcolor = tmpcolor->next) {
|
||||||
/* tmpcolor->start_regex and tmpcolor->end_regex have already
|
/* tmpcolor->start_regex and tmpcolor->end_regex have already
|
||||||
|
|
Loading…
Reference in New Issue