tweaks: rename a function, to better describe what it does

Its major function is to find an applicable syntax, if there is any.
And if the syntax hasn't been used before, to prime its color pairs.

Also, reshuffle a line to be able to elide an #ifdef.
master
Benno Schulenberg 2020-04-28 16:32:04 +02:00
parent b97da1dfe4
commit bc4240dda5
5 changed files with 10 additions and 14 deletions

View File

@ -163,8 +163,9 @@ bool found_in_list(regexlisttype *head, const char *shibboleth)
return FALSE;
}
/* Update the color information based on the current filename and content. */
void color_update(void)
/* Find a syntax that applies to the current buffer, based upon filename
* or buffer content, and load and prime this syntax when needed. */
void find_and_prime_applicable_syntax(void)
{
syntaxtype *sntx = NULL;

View File

@ -466,10 +466,9 @@ bool open_buffer(const char *filename, bool new_one)
}
#ifdef ENABLE_COLOR
/* If we're loading into a new buffer, update the colors to account
* for it, if applicable. */
/* If a new buffer was opened, check whether a syntax can be applied. */
if (new_one)
color_update();
find_and_prime_applicable_syntax();
#endif
free(realname);
return TRUE;
@ -1963,16 +1962,12 @@ bool write_file(const char *name, FILE *thefile, bool tmp,
openfile->lock_filename = do_lockfile(realname, FALSE);
}
#endif
openfile->filename = mallocstrcpy(openfile->filename, realname);
#ifdef ENABLE_COLOR
const char *oldname, *newname;
oldname = openfile->syntax ? openfile->syntax->name : "";
#endif
openfile->filename = mallocstrcpy(openfile->filename, realname);
#ifdef ENABLE_COLOR
/* See if the applicable syntax has changed. */
color_update();
find_and_prime_applicable_syntax();
newname = openfile->syntax ? openfile->syntax->name : "";
/* If the syntax changed, discard and recompute the multidata. */

View File

@ -88,7 +88,7 @@ void wrap_help_text_into_buffer(void)
remove_magicline();
#ifdef ENABLE_COLOR
color_update();
find_and_prime_applicable_syntax();
#endif
prepare_for_display();

View File

@ -853,7 +853,7 @@ bool scoop_stdin(void)
make_new_buffer();
read_file(stream, 0, "stdin", TRUE);
#ifdef ENABLE_COLOR
color_update();
find_and_prime_applicable_syntax();
#endif
/* Restore the original ^C handler. */

View File

@ -244,7 +244,7 @@ bool is_valid_unicode(wchar_t wc);
#ifdef ENABLE_COLOR
void set_colorpairs(void);
void color_init(void);
void color_update(void);
void find_and_prime_applicable_syntax(void);
void set_up_multicache(linestruct *line);
void check_the_multis(linestruct *line);
void precalc_multicolorinfo(void);