diff --git a/ChangeLog b/ChangeLog index 2e035206..5048fc69 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ * doc/man/nanorc.5, doc/texinfo/nano.texi, doc/syntax/nanorc.nanorc, doc/nanorc.sample.in: Correct the description of 'justifytrim', add it to the Info document, sort it, and tweak a wording. + * src/color.c (color_update): Look for a default syntax only when + all else failed -- forego the small, complicating optimization. GNU nano 2.5.3 - 2016.02.25 diff --git a/src/color.c b/src/color.c index 849e26e4..31fba417 100644 --- a/src/color.c +++ b/src/color.c @@ -153,8 +153,7 @@ void nfreeregex(regex_t **r) void color_update(void) { syntaxtype *tmpsyntax; - syntaxtype *defsyntax = NULL; - colortype *tmpcolor, *defcolor = NULL; + colortype *tmpcolor; regexlisttype *e; assert(openfile != NULL); @@ -210,15 +209,6 @@ void color_update(void) for (tmpsyntax = syntaxes; tmpsyntax != NULL; tmpsyntax = tmpsyntax->next) { - /* If this is the default syntax, it has no associated - * extensions, which we've checked for elsewhere. Skip over - * it here, but keep track of its color regexes. */ - if (strcmp(tmpsyntax->desc, "default") == 0) { - defsyntax = tmpsyntax; - defcolor = tmpsyntax->color; - continue; - } - for (e = tmpsyntax->extensions; e != NULL; e = e->next) { bool not_compiled = (e->ext == NULL); @@ -342,11 +332,16 @@ void color_update(void) #endif /* HAVE_LIBMAGIC */ } - /* If we didn't find any syntax yet, and we do have a default one, - * use it. */ - if (openfile->colorstrings == NULL && defcolor != NULL) { - openfile->syntax = defsyntax; - openfile->colorstrings = defcolor; + /* If we didn't find any syntax yet, see if there is a default one. */ + if (openfile->colorstrings == NULL) { + for (tmpsyntax = syntaxes; tmpsyntax != NULL; + tmpsyntax = tmpsyntax->next) { + if (strcmp(tmpsyntax->desc, "default") == 0) { + openfile->syntax = tmpsyntax; + openfile->colorstrings = tmpsyntax->color; + break; + } + } } for (tmpcolor = openfile->colorstrings; tmpcolor != NULL;