From: Benno Schulenberg Date: Fri, 26 Feb 2016 16:08:21 +0000 (+0000) Subject: Looking for the default syntax only when all else failed -- X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=812f986f2ed9a91a2f9c930e512ce96b9779ff07;p=nano.git Looking for the default syntax only when all else failed -- foregoing a small, complicating optimization. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5684 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- 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;