nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit bc4240dda5ef0c956b302ddc62e904a1767490d7
parent b97da1dfe41ad2fc8396fb038d300f4d9b7594df
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Tue, 28 Apr 2020 16:32:04 +0200

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.

Diffstat:
Msrc/color.c | 5+++--
Msrc/files.c | 13++++---------
Msrc/help.c | 2+-
Msrc/nano.c | 2+-
Msrc/proto.h | 2+-
5 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/src/color.c b/src/color.c @@ -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; diff --git a/src/files.c b/src/files.c @@ -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. */ diff --git a/src/help.c b/src/help.c @@ -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(); diff --git a/src/nano.c b/src/nano.c @@ -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. */ diff --git a/src/proto.h b/src/proto.h @@ -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);