diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2022-07-24 22:29:07 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2022-07-24 22:43:48 +0200 |
commit | 68ad24f2df0ace9788da801137dacf43b7fe806a (patch) | |
tree | d0fa35877ef78fa2931393a15cc91235354134a0 /src/core | |
parent | 1796634d83b90eeb97ede6c238e4092aca948304 (diff) | |
download | weechat-68ad24f2df0ace9788da801137dacf43b7fe806a.zip |
core: add option weechat.look.highlight_disable_regex and buffer property "highlight_disable_regex" (closes #1798)
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/wee-config.c | 62 | ||||
-rw-r--r-- | src/core/wee-config.h | 2 | ||||
-rw-r--r-- | src/core/wee-upgrade.c | 2 |
3 files changed, 66 insertions, 0 deletions
diff --git a/src/core/wee-config.c b/src/core/wee-config.c index 071cbfe91..8b1cdb556 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -121,6 +121,7 @@ struct t_config_option *config_look_day_change_message_2dates; struct t_config_option *config_look_eat_newline_glitch; struct t_config_option *config_look_emphasized_attributes; struct t_config_option *config_look_highlight; +struct t_config_option *config_look_highlight_disable_regex; struct t_config_option *config_look_highlight_regex; struct t_config_option *config_look_highlight_tags; struct t_config_option *config_look_hotlist_add_conditions; @@ -321,6 +322,7 @@ int config_length_prefix_same_nick_middle = 0; struct t_hook *config_day_change_timer = NULL; int config_day_change_old_day = -1; int config_emphasized_attributes = 0; +regex_t *config_highlight_disable_regex = NULL; regex_t *config_highlight_regex = NULL; char ***config_highlight_tags = NULL; int config_num_highlight_tags = 0; @@ -913,6 +915,43 @@ config_change_emphasized_attributes (const void *pointer, void *data, } /* + * Callback for changes on option "weechat.look.highlight_disable_regex". + */ + +void +config_change_highlight_disable_regex (const void *pointer, void *data, + struct t_config_option *option) +{ + /* make C compiler happy */ + (void) pointer; + (void) data; + (void) option; + + if (config_highlight_disable_regex) + { + regfree (config_highlight_disable_regex); + free (config_highlight_disable_regex); + config_highlight_disable_regex = NULL; + } + + if (CONFIG_STRING(config_look_highlight_disable_regex) + && CONFIG_STRING(config_look_highlight_disable_regex)[0]) + { + config_highlight_disable_regex = malloc (sizeof (*config_highlight_disable_regex)); + if (config_highlight_disable_regex) + { + if (string_regcomp (config_highlight_disable_regex, + CONFIG_STRING(config_look_highlight_disable_regex), + REG_EXTENDED | REG_ICASE) != 0) + { + free (config_highlight_disable_regex); + config_highlight_disable_regex = NULL; + } + } + } +} + +/* * Callback for changes on option "weechat.look.highlight_regex". */ @@ -3035,6 +3074,20 @@ config_weechat_init_options () "example: \"test,(?-i)*toto*,flash*\""), NULL, 0, 0, "", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL); + config_look_highlight_disable_regex = config_file_new_option ( + weechat_config_file, ptr_section, + "highlight_disable_regex", "string", + N_("POSIX extended regular expression used to prevent any highlight " + "from a message: this option has higher priority over other " + "highlight options (if the string is found in the message, the " + "highlight is disabled and the other options are ignored), " + "regular expression is case insensitive (use \"(?-i)\" at beginning " + "to make it case sensitive), examples: " + "\"<flash.*>\", \"(?-i)<Flash.*>\""), + NULL, 0, 0, "", NULL, 0, + NULL, NULL, NULL, + &config_change_highlight_disable_regex, NULL, NULL, + NULL, NULL, NULL); config_look_highlight_regex = config_file_new_option ( weechat_config_file, ptr_section, "highlight_regex", "string", @@ -4876,6 +4929,8 @@ config_weechat_init () &config_day_change_timer_cb, NULL, NULL); } + if (!config_highlight_disable_regex) + config_change_highlight_disable_regex (NULL, NULL, NULL); if (!config_highlight_regex) config_change_highlight_regex (NULL, NULL, NULL); if (!config_highlight_tags) @@ -4937,6 +4992,13 @@ config_weechat_free () { config_file_free (weechat_config_file); + if (config_highlight_disable_regex) + { + regfree (config_highlight_disable_regex); + free (config_highlight_disable_regex); + config_highlight_disable_regex = NULL; + } + if (config_highlight_regex) { regfree (config_highlight_regex); diff --git a/src/core/wee-config.h b/src/core/wee-config.h index 0feec6c42..38017e294 100644 --- a/src/core/wee-config.h +++ b/src/core/wee-config.h @@ -173,6 +173,7 @@ extern struct t_config_option *config_look_day_change_message_2dates; extern struct t_config_option *config_look_eat_newline_glitch; extern struct t_config_option *config_look_emphasized_attributes; extern struct t_config_option *config_look_highlight; +extern struct t_config_option *config_look_highlight_disable_regex; extern struct t_config_option *config_look_highlight_regex; extern struct t_config_option *config_look_highlight_tags; extern struct t_config_option *config_look_hotlist_add_conditions; @@ -357,6 +358,7 @@ extern int config_length_nick_prefix_suffix; extern int config_length_prefix_same_nick; extern int config_length_prefix_same_nick_middle; extern int config_emphasized_attributes; +extern regex_t *config_highlight_disable_regex; extern regex_t *config_highlight_regex; extern char ***config_highlight_tags; extern int config_num_highlight_tags; diff --git a/src/core/wee-upgrade.c b/src/core/wee-upgrade.c index 48c859416..404c98797 100644 --- a/src/core/wee-upgrade.c +++ b/src/core/wee-upgrade.c @@ -557,6 +557,8 @@ upgrade_weechat_read_buffer (struct t_infolist *infolist) /* highlight options */ gui_buffer_set_highlight_words ( ptr_buffer, infolist_string (infolist, "highlight_words")); + gui_buffer_set_highlight_disable_regex ( + ptr_buffer, infolist_string (infolist, "highlight_disable_regex")); gui_buffer_set_highlight_regex ( ptr_buffer, infolist_string (infolist, "highlight_regex")); if (infolist_search_var (infolist, |