mirror of
https://github.com/weechat/weechat.git
synced 2026-07-09 03:03:12 +02:00
core: add option weechat.look.highlight_disable_regex and buffer property "highlight_disable_regex" (closes #1798)
This commit is contained in:
@@ -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;
|
||||
@@ -912,6 +914,43 @@ config_change_emphasized_attributes (const void *pointer, void *data,
|
||||
gui_window_ask_refresh (1);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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,
|
||||
|
||||
+99
-27
@@ -106,12 +106,14 @@ char *gui_buffer_properties_get_integer[] =
|
||||
};
|
||||
char *gui_buffer_properties_get_string[] =
|
||||
{ "plugin", "name", "full_name", "old_full_name", "short_name", "title",
|
||||
"input", "text_search_input", "highlight_words", "highlight_regex",
|
||||
"highlight_tags_restrict", "highlight_tags", "hotlist_max_level_nicks",
|
||||
"input", "text_search_input", "highlight_words", "highlight_disable_regex",
|
||||
"highlight_regex", "highlight_tags_restrict", "highlight_tags",
|
||||
"hotlist_max_level_nicks",
|
||||
NULL
|
||||
};
|
||||
char *gui_buffer_properties_get_pointer[] =
|
||||
{ "plugin", "text_search_regex_compiled", "highlight_regex_compiled",
|
||||
{ "plugin", "text_search_regex_compiled", "highlight_disable_regex_compiled",
|
||||
"highlight_regex_compiled",
|
||||
NULL
|
||||
};
|
||||
char *gui_buffer_properties_set[] =
|
||||
@@ -119,10 +121,11 @@ char *gui_buffer_properties_set[] =
|
||||
"clear", "filter", "number", "name", "short_name", "type", "notify", "title",
|
||||
"time_for_each_line", "nicklist", "nicklist_case_sensitive",
|
||||
"nicklist_display_groups", "highlight_words", "highlight_words_add",
|
||||
"highlight_words_del", "highlight_regex", "highlight_tags_restrict",
|
||||
"highlight_tags", "hotlist_max_level_nicks", "hotlist_max_level_nicks_add",
|
||||
"hotlist_max_level_nicks_del", "input", "input_pos",
|
||||
"input_get_unknown_commands", "input_get_empty", "input_multiline",
|
||||
"highlight_words_del", "highlight_disable_regex", "highlight_regex",
|
||||
"highlight_tags_restrict", "highlight_tags", "hotlist_max_level_nicks",
|
||||
"hotlist_max_level_nicks_add", "hotlist_max_level_nicks_del",
|
||||
"input", "input_pos", "input_get_unknown_commands", "input_get_empty",
|
||||
"input_multiline",
|
||||
NULL
|
||||
};
|
||||
|
||||
@@ -800,6 +803,8 @@ gui_buffer_new_props (struct t_weechat_plugin *plugin,
|
||||
|
||||
/* highlight */
|
||||
new_buffer->highlight_words = NULL;
|
||||
new_buffer->highlight_disable_regex = NULL;
|
||||
new_buffer->highlight_disable_regex_compiled = NULL;
|
||||
new_buffer->highlight_regex = NULL;
|
||||
new_buffer->highlight_regex_compiled = NULL;
|
||||
new_buffer->highlight_tags_restrict = NULL;
|
||||
@@ -1310,6 +1315,8 @@ gui_buffer_get_string (struct t_gui_buffer *buffer, const char *property)
|
||||
return buffer->text_search_input;
|
||||
else if (string_strcasecmp (property, "highlight_words") == 0)
|
||||
return buffer->highlight_words;
|
||||
else if (string_strcasecmp (property, "highlight_disable_regex") == 0)
|
||||
return buffer->highlight_disable_regex;
|
||||
else if (string_strcasecmp (property, "highlight_regex") == 0)
|
||||
return buffer->highlight_regex;
|
||||
else if (string_strcasecmp (property, "highlight_tags_restrict") == 0)
|
||||
@@ -1343,6 +1350,8 @@ gui_buffer_get_pointer (struct t_gui_buffer *buffer, const char *property)
|
||||
return buffer->plugin;
|
||||
else if (string_strcasecmp (property, "text_search_regex_compiled") == 0)
|
||||
return buffer->text_search_regex_compiled;
|
||||
else if (string_strcasecmp (property, "highlight_disable_regex_compiled") == 0)
|
||||
return buffer->highlight_disable_regex_compiled;
|
||||
else if (string_strcasecmp (property, "highlight_regex_compiled") == 0)
|
||||
return buffer->highlight_regex_compiled;
|
||||
|
||||
@@ -1737,13 +1746,57 @@ gui_buffer_remove_highlight_words (struct t_gui_buffer *buffer,
|
||||
string_free_split (remove_words);
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets highlight disable regex for a buffer.
|
||||
*/
|
||||
|
||||
void
|
||||
gui_buffer_set_highlight_disable_regex (struct t_gui_buffer *buffer,
|
||||
const char *new_regex)
|
||||
{
|
||||
if (!buffer)
|
||||
return;
|
||||
|
||||
if (buffer->highlight_disable_regex)
|
||||
{
|
||||
free (buffer->highlight_disable_regex);
|
||||
buffer->highlight_disable_regex = NULL;
|
||||
}
|
||||
if (buffer->highlight_disable_regex_compiled)
|
||||
{
|
||||
regfree (buffer->highlight_disable_regex_compiled);
|
||||
free (buffer->highlight_disable_regex_compiled);
|
||||
buffer->highlight_disable_regex_compiled = NULL;
|
||||
}
|
||||
|
||||
if (new_regex && new_regex[0])
|
||||
{
|
||||
buffer->highlight_disable_regex = strdup (new_regex);
|
||||
if (buffer->highlight_disable_regex)
|
||||
{
|
||||
buffer->highlight_disable_regex_compiled =
|
||||
malloc (sizeof (*buffer->highlight_disable_regex_compiled));
|
||||
if (buffer->highlight_disable_regex_compiled)
|
||||
{
|
||||
if (string_regcomp (buffer->highlight_disable_regex_compiled,
|
||||
buffer->highlight_disable_regex,
|
||||
REG_EXTENDED | REG_ICASE) != 0)
|
||||
{
|
||||
free (buffer->highlight_disable_regex_compiled);
|
||||
buffer->highlight_disable_regex_compiled = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets highlight regex for a buffer.
|
||||
*/
|
||||
|
||||
void
|
||||
gui_buffer_set_highlight_regex (struct t_gui_buffer *buffer,
|
||||
const char *new_highlight_regex)
|
||||
const char *new_regex)
|
||||
{
|
||||
if (!buffer)
|
||||
return;
|
||||
@@ -1760,9 +1813,9 @@ gui_buffer_set_highlight_regex (struct t_gui_buffer *buffer,
|
||||
buffer->highlight_regex_compiled = NULL;
|
||||
}
|
||||
|
||||
if (new_highlight_regex && new_highlight_regex[0])
|
||||
if (new_regex && new_regex[0])
|
||||
{
|
||||
buffer->highlight_regex = strdup (new_highlight_regex);
|
||||
buffer->highlight_regex = strdup (new_regex);
|
||||
if (buffer->highlight_regex)
|
||||
{
|
||||
buffer->highlight_regex_compiled =
|
||||
@@ -2234,6 +2287,10 @@ gui_buffer_set (struct t_gui_buffer *buffer, const char *property,
|
||||
{
|
||||
gui_buffer_remove_highlight_words (buffer, value);
|
||||
}
|
||||
else if (string_strcasecmp (property, "highlight_disable_regex") == 0)
|
||||
{
|
||||
gui_buffer_set_highlight_disable_regex (buffer, value);
|
||||
}
|
||||
else if (string_strcasecmp (property, "highlight_regex") == 0)
|
||||
{
|
||||
gui_buffer_set_highlight_regex (buffer, value);
|
||||
@@ -3034,6 +3091,13 @@ gui_buffer_close (struct t_gui_buffer *buffer)
|
||||
}
|
||||
if (buffer->highlight_words)
|
||||
free (buffer->highlight_words);
|
||||
if (buffer->highlight_disable_regex)
|
||||
free (buffer->highlight_disable_regex);
|
||||
if (buffer->highlight_disable_regex_compiled)
|
||||
{
|
||||
regfree (buffer->highlight_disable_regex_compiled);
|
||||
free (buffer->highlight_disable_regex_compiled);
|
||||
}
|
||||
if (buffer->highlight_regex)
|
||||
free (buffer->highlight_regex);
|
||||
if (buffer->highlight_regex_compiled)
|
||||
@@ -4430,6 +4494,8 @@ gui_buffer_hdata_buffer_cb (const void *pointer, void *data,
|
||||
HDATA_VAR(struct t_gui_buffer, text_search_found, INTEGER, 0, NULL, NULL);
|
||||
HDATA_VAR(struct t_gui_buffer, text_search_input, STRING, 0, NULL, NULL);
|
||||
HDATA_VAR(struct t_gui_buffer, highlight_words, STRING, 0, NULL, NULL);
|
||||
HDATA_VAR(struct t_gui_buffer, highlight_disable_regex, STRING, 0, NULL, NULL);
|
||||
HDATA_VAR(struct t_gui_buffer, highlight_disable_regex_compiled, POINTER, 0, NULL, NULL);
|
||||
HDATA_VAR(struct t_gui_buffer, highlight_regex, STRING, 0, NULL, NULL);
|
||||
HDATA_VAR(struct t_gui_buffer, highlight_regex_compiled, POINTER, 0, NULL, NULL);
|
||||
HDATA_VAR(struct t_gui_buffer, highlight_tags_restrict, STRING, 0, NULL, NULL);
|
||||
@@ -4642,6 +4708,10 @@ gui_buffer_add_to_infolist (struct t_infolist *infolist,
|
||||
return 0;
|
||||
if (!infolist_new_var_string (ptr_item, "highlight_words", buffer->highlight_words))
|
||||
return 0;
|
||||
if (!infolist_new_var_string (ptr_item, "highlight_disable_regex", buffer->highlight_disable_regex))
|
||||
return 0;
|
||||
if (!infolist_new_var_pointer (ptr_item, "highlight_disable_regex_compiled", buffer->highlight_disable_regex_compiled))
|
||||
return 0;
|
||||
if (!infolist_new_var_string (ptr_item, "highlight_regex", buffer->highlight_regex))
|
||||
return 0;
|
||||
if (!infolist_new_var_pointer (ptr_item, "highlight_regex_compiled", buffer->highlight_regex_compiled))
|
||||
@@ -4851,27 +4921,29 @@ gui_buffer_print_log ()
|
||||
num, ptr_undo, ptr_undo->data, ptr_undo->pos);
|
||||
num++;
|
||||
}
|
||||
log_printf (" completion. . . . . . . : 0x%lx", ptr_buffer->completion);
|
||||
log_printf (" completion. . . . . . . . . . . : 0x%lx", ptr_buffer->completion);
|
||||
log_printf (" history . . . . . . . . : 0x%lx", ptr_buffer->history);
|
||||
log_printf (" last_history. . . . . . : 0x%lx", ptr_buffer->last_history);
|
||||
log_printf (" ptr_history . . . . . . : 0x%lx", ptr_buffer->ptr_history);
|
||||
log_printf (" num_history . . . . . . : %d", ptr_buffer->num_history);
|
||||
log_printf (" text_search . . . . . . : %d", ptr_buffer->text_search);
|
||||
log_printf (" text_search_exact . . . : %d", ptr_buffer->text_search_exact);
|
||||
log_printf (" text_search_regex . . . : %d", ptr_buffer->text_search_regex);
|
||||
log_printf (" text_search_regex_compiled: 0x%lx", ptr_buffer->text_search_regex_compiled);
|
||||
log_printf (" text_search_where . . . : %d", ptr_buffer->text_search_where);
|
||||
log_printf (" text_search_found . . . : %d", ptr_buffer->text_search_found);
|
||||
log_printf (" text_search_input . . . : '%s'", ptr_buffer->text_search_input);
|
||||
log_printf (" highlight_words . . . . : '%s'", ptr_buffer->highlight_words);
|
||||
log_printf (" highlight_regex . . . . : '%s'", ptr_buffer->highlight_regex);
|
||||
log_printf (" highlight_regex_compiled: 0x%lx", ptr_buffer->highlight_regex_compiled);
|
||||
log_printf (" highlight_tags_restrict. . . : '%s'", ptr_buffer->highlight_tags_restrict);
|
||||
log_printf (" highlight_tags_restrict_count: %d", ptr_buffer->highlight_tags_restrict_count);
|
||||
log_printf (" highlight_tags_restrict_array: 0x%lx", ptr_buffer->highlight_tags_restrict_array);
|
||||
log_printf (" highlight_tags. . . . . : '%s'", ptr_buffer->highlight_tags);
|
||||
log_printf (" highlight_tags_count. . : %d", ptr_buffer->highlight_tags_count);
|
||||
log_printf (" highlight_tags_array. . : 0x%lx", ptr_buffer->highlight_tags_array);
|
||||
log_printf (" text_search . . . . . . . . . . : %d", ptr_buffer->text_search);
|
||||
log_printf (" text_search_exact . . . . . . . : %d", ptr_buffer->text_search_exact);
|
||||
log_printf (" text_search_regex . . . . . . . : %d", ptr_buffer->text_search_regex);
|
||||
log_printf (" text_search_regex_compiled. . . : 0x%lx", ptr_buffer->text_search_regex_compiled);
|
||||
log_printf (" text_search_where . . . . . . . : %d", ptr_buffer->text_search_where);
|
||||
log_printf (" text_search_found . . . . . . . : %d", ptr_buffer->text_search_found);
|
||||
log_printf (" text_search_input . . . . . . . : '%s'", ptr_buffer->text_search_input);
|
||||
log_printf (" highlight_words . . . . . . . . : '%s'", ptr_buffer->highlight_words);
|
||||
log_printf (" highlight_disable_regex . . . . : '%s'", ptr_buffer->highlight_disable_regex);
|
||||
log_printf (" highlight_disable_regex_compiled: 0x%lx", ptr_buffer->highlight_disable_regex_compiled);
|
||||
log_printf (" highlight_regex . . . . . . . . : '%s'", ptr_buffer->highlight_regex);
|
||||
log_printf (" highlight_regex_compiled. . . . : 0x%lx", ptr_buffer->highlight_regex_compiled);
|
||||
log_printf (" highlight_tags_restrict . . . . : '%s'", ptr_buffer->highlight_tags_restrict);
|
||||
log_printf (" highlight_tags_restrict_count . : %d", ptr_buffer->highlight_tags_restrict_count);
|
||||
log_printf (" highlight_tags_restrict_array . : 0x%lx", ptr_buffer->highlight_tags_restrict_array);
|
||||
log_printf (" highlight_tags. . . . . . . . . : '%s'", ptr_buffer->highlight_tags);
|
||||
log_printf (" highlight_tags_count. . . . . . : %d", ptr_buffer->highlight_tags_count);
|
||||
log_printf (" highlight_tags_array. . . . . . : 0x%lx", ptr_buffer->highlight_tags_array);
|
||||
log_printf (" hotlist . . . . . . . . : 0x%lx", ptr_buffer->hotlist);
|
||||
log_printf (" hotlist_removed . . . . : 0x%lx", ptr_buffer->hotlist_removed);
|
||||
log_printf (" keys. . . . . . . . . . : 0x%lx", ptr_buffer->keys);
|
||||
|
||||
@@ -199,6 +199,8 @@ struct t_gui_buffer
|
||||
char *highlight_words; /* list of words to highlight */
|
||||
char *highlight_regex; /* regex for highlight */
|
||||
regex_t *highlight_regex_compiled; /* compiled regex */
|
||||
char *highlight_disable_regex; /* regex for disabling highlight */
|
||||
regex_t *highlight_disable_regex_compiled; /* compiled regex */
|
||||
char *highlight_tags_restrict; /* restrict highlight to these tags */
|
||||
int highlight_tags_restrict_count; /* number of restricted tags */
|
||||
char ***highlight_tags_restrict_array; /* array with restricted tags */
|
||||
@@ -316,8 +318,10 @@ extern void gui_buffer_set_title (struct t_gui_buffer *buffer,
|
||||
const char *new_title);
|
||||
extern void gui_buffer_set_highlight_words (struct t_gui_buffer *buffer,
|
||||
const char *new_highlight_words);
|
||||
extern void gui_buffer_set_highlight_disable_regex (struct t_gui_buffer *buffer,
|
||||
const char *new_regex);
|
||||
extern void gui_buffer_set_highlight_regex (struct t_gui_buffer *buffer,
|
||||
const char *new_highlight_regex);
|
||||
const char *new_regex);
|
||||
extern void gui_buffer_set_highlight_tags_restrict (struct t_gui_buffer *buffer,
|
||||
const char *new_tags);
|
||||
extern void gui_buffer_set_highlight_tags (struct t_gui_buffer *buffer,
|
||||
|
||||
+104
-55
@@ -27,6 +27,7 @@
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <regex.h>
|
||||
|
||||
#include "../core/weechat.h"
|
||||
#include "../core/wee-config.h"
|
||||
@@ -861,9 +862,18 @@ gui_line_get_nick_tag (struct t_gui_line *line)
|
||||
int
|
||||
gui_line_has_highlight (struct t_gui_line *line)
|
||||
{
|
||||
int rc, i, no_highlight, action, length;
|
||||
int rc, rc_regex, i, no_highlight, action, length;
|
||||
char *msg_no_color, *ptr_msg_no_color, *highlight_words;
|
||||
const char *ptr_nick;
|
||||
regmatch_t regex_match;
|
||||
|
||||
rc = 0;
|
||||
|
||||
/* remove color codes from line message */
|
||||
msg_no_color = gui_color_decode (line->data->message, NULL);
|
||||
if (!msg_no_color)
|
||||
return 0;
|
||||
ptr_msg_no_color = msg_no_color;
|
||||
|
||||
/*
|
||||
* highlights are disabled on this buffer? (special value "-" means that
|
||||
@@ -871,7 +881,10 @@ gui_line_has_highlight (struct t_gui_line *line)
|
||||
*/
|
||||
if (line->data->buffer->highlight_words
|
||||
&& (strcmp (line->data->buffer->highlight_words, "-") == 0))
|
||||
return 0;
|
||||
{
|
||||
rc = 0;
|
||||
goto end;
|
||||
}
|
||||
|
||||
/*
|
||||
* check if highlight is disabled for line; also check if the line is an
|
||||
@@ -898,50 +911,11 @@ gui_line_has_highlight (struct t_gui_line *line)
|
||||
}
|
||||
}
|
||||
if (no_highlight)
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* check if highlight is forced by a tag
|
||||
* (with global option "weechat.look.highlight_tags")
|
||||
*/
|
||||
if (config_highlight_tags
|
||||
&& gui_line_match_tags (line->data,
|
||||
config_num_highlight_tags,
|
||||
config_highlight_tags))
|
||||
{
|
||||
return 1;
|
||||
rc = 0;
|
||||
goto end;
|
||||
}
|
||||
|
||||
/*
|
||||
* check if highlight is forced by a tag
|
||||
* (with buffer property "highlight_tags")
|
||||
*/
|
||||
if (line->data->buffer->highlight_tags
|
||||
&& gui_line_match_tags (line->data,
|
||||
line->data->buffer->highlight_tags_count,
|
||||
line->data->buffer->highlight_tags_array))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* check that line matches highlight tags, if any (if no tag is specified,
|
||||
* then any tag is allowed)
|
||||
*/
|
||||
if (line->data->buffer->highlight_tags_restrict_count > 0)
|
||||
{
|
||||
if (!gui_line_match_tags (line->data,
|
||||
line->data->buffer->highlight_tags_restrict_count,
|
||||
line->data->buffer->highlight_tags_restrict_array))
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* remove color codes from line message */
|
||||
msg_no_color = gui_color_decode (line->data->message, NULL);
|
||||
if (!msg_no_color)
|
||||
return 0;
|
||||
ptr_msg_no_color = msg_no_color;
|
||||
|
||||
/*
|
||||
* if the line is an action message and that we know the nick, we skip
|
||||
* the nick if it is at beginning of message (to not highlight an action
|
||||
@@ -963,6 +937,77 @@ gui_line_has_highlight (struct t_gui_line *line)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* check if highlight is disabled by a regex
|
||||
* (with global option "weechat.look.highlight_disable_regex")
|
||||
*/
|
||||
if (config_highlight_disable_regex)
|
||||
{
|
||||
rc_regex = regexec (config_highlight_disable_regex,
|
||||
ptr_msg_no_color, 1, ®ex_match, 0);
|
||||
if ((rc_regex == 0) && (regex_match.rm_so >= 0) && (regex_match.rm_eo > 0))
|
||||
{
|
||||
rc = 0;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* check if highlight is disabled by a regex
|
||||
* (with buffer property "highlight_disable_regex")
|
||||
*/
|
||||
if (line->data->buffer->highlight_disable_regex_compiled)
|
||||
{
|
||||
rc_regex = regexec (line->data->buffer->highlight_disable_regex_compiled,
|
||||
ptr_msg_no_color, 1, ®ex_match, 0);
|
||||
if ((rc_regex == 0) && (regex_match.rm_so >= 0) && (regex_match.rm_eo > 0))
|
||||
{
|
||||
rc = 0;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* check if highlight is forced by a tag
|
||||
* (with global option "weechat.look.highlight_tags")
|
||||
*/
|
||||
if (config_highlight_tags
|
||||
&& gui_line_match_tags (line->data,
|
||||
config_num_highlight_tags,
|
||||
config_highlight_tags))
|
||||
{
|
||||
rc = 1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
/*
|
||||
* check if highlight is forced by a tag
|
||||
* (with buffer property "highlight_tags")
|
||||
*/
|
||||
if (line->data->buffer->highlight_tags
|
||||
&& gui_line_match_tags (line->data,
|
||||
line->data->buffer->highlight_tags_count,
|
||||
line->data->buffer->highlight_tags_array))
|
||||
{
|
||||
rc = 1;
|
||||
goto end;
|
||||
}
|
||||
|
||||
/*
|
||||
* check that line matches highlight tags, if any (if no tag is specified,
|
||||
* then any tag is allowed)
|
||||
*/
|
||||
if (line->data->buffer->highlight_tags_restrict_count > 0)
|
||||
{
|
||||
if (!gui_line_match_tags (line->data,
|
||||
line->data->buffer->highlight_tags_restrict_count,
|
||||
line->data->buffer->highlight_tags_restrict_array))
|
||||
{
|
||||
rc = 0;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* there is highlight on line if one of buffer highlight words matches line
|
||||
* or one of global highlight words matches line
|
||||
@@ -974,30 +1019,34 @@ gui_line_has_highlight (struct t_gui_line *line)
|
||||
highlight_words : line->data->buffer->highlight_words);
|
||||
if (highlight_words)
|
||||
free (highlight_words);
|
||||
if (rc)
|
||||
goto end;
|
||||
|
||||
if (!rc)
|
||||
{
|
||||
highlight_words = gui_buffer_string_replace_local_var (line->data->buffer,
|
||||
CONFIG_STRING(config_look_highlight));
|
||||
rc = string_has_highlight (ptr_msg_no_color,
|
||||
(highlight_words) ?
|
||||
highlight_words : CONFIG_STRING(config_look_highlight));
|
||||
if (highlight_words)
|
||||
free (highlight_words);
|
||||
}
|
||||
highlight_words = gui_buffer_string_replace_local_var (line->data->buffer,
|
||||
CONFIG_STRING(config_look_highlight));
|
||||
rc = string_has_highlight (ptr_msg_no_color,
|
||||
(highlight_words) ?
|
||||
highlight_words : CONFIG_STRING(config_look_highlight));
|
||||
if (highlight_words)
|
||||
free (highlight_words);
|
||||
if (rc)
|
||||
goto end;
|
||||
|
||||
if (!rc && config_highlight_regex)
|
||||
if (config_highlight_regex)
|
||||
{
|
||||
rc = string_has_highlight_regex_compiled (ptr_msg_no_color,
|
||||
config_highlight_regex);
|
||||
}
|
||||
if (rc)
|
||||
goto end;
|
||||
|
||||
if (!rc && line->data->buffer->highlight_regex_compiled)
|
||||
if (line->data->buffer->highlight_regex_compiled)
|
||||
{
|
||||
rc = string_has_highlight_regex_compiled (ptr_msg_no_color,
|
||||
line->data->buffer->highlight_regex_compiled);
|
||||
}
|
||||
|
||||
end:
|
||||
free (msg_no_color);
|
||||
|
||||
return rc;
|
||||
|
||||
Reference in New Issue
Block a user