diff options
author | Sebastien Helleu <flashcode@flashtux.org> | 2013-12-15 13:45:40 +0100 |
---|---|---|
committer | Sebastien Helleu <flashcode@flashtux.org> | 2013-12-15 13:45:40 +0100 |
commit | d52d214448fa5db7167ee89b532f299af02aa10c (patch) | |
tree | 961430092a684d9a38fc48a787fcee67731857f6 /src | |
parent | 52cbd0b9217f2ea5f93c30bd1043cd4ad9fa494a (diff) | |
download | weechat-d52d214448fa5db7167ee89b532f299af02aa10c.zip |
core: add buffer property "highlight_tags_restrict", rename option irc.look.highlight_tags to irc.look.highlight_tags_restrict
The buffer property "highlight_tags" is renamed to "highlight_tags_restrict".
New behavior for buffer property "highlight_tags": force highlight on tags.
Option irc.look.highlight_tags is renamed to irc.look.highlight_tags_restrict.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/wee-infolist.c | 23 | ||||
-rw-r--r-- | src/core/wee-infolist.h | 2 | ||||
-rw-r--r-- | src/core/wee-upgrade.c | 19 | ||||
-rw-r--r-- | src/gui/gui-buffer.c | 102 | ||||
-rw-r--r-- | src/gui/gui-buffer.h | 14 | ||||
-rw-r--r-- | src/gui/gui-line.c | 44 | ||||
-rw-r--r-- | src/plugins/irc/irc-channel.c | 8 | ||||
-rw-r--r-- | src/plugins/irc/irc-config.c | 33 | ||||
-rw-r--r-- | src/plugins/irc/irc-config.h | 2 | ||||
-rw-r--r-- | src/plugins/irc/irc-server.c | 8 |
10 files changed, 200 insertions, 55 deletions
diff --git a/src/core/wee-infolist.c b/src/core/wee-infolist.c index c2aa0c6c6..3392ffeca 100644 --- a/src/core/wee-infolist.c +++ b/src/core/wee-infolist.c @@ -549,6 +549,29 @@ infolist_time (struct t_infolist *infolist, const char *var) } /* + * Searches for a variable in current infolist item. + */ + +struct t_infolist_var * +infolist_search_var (struct t_infolist *infolist, const char *var) +{ + struct t_infolist_var *ptr_var; + + if (!infolist || !infolist->ptr_item || !var || !var[0]) + return NULL; + + for (ptr_var = infolist->ptr_item->vars; ptr_var; + ptr_var = ptr_var->next_var) + { + if (string_strcasecmp (ptr_var->name, var) == 0) + return ptr_var; + } + + /* variable not found */ + return NULL; +} + +/* * Frees a variable in item. */ diff --git a/src/core/wee-infolist.h b/src/core/wee-infolist.h index 13a05eee5..772ac4a72 100644 --- a/src/core/wee-infolist.h +++ b/src/core/wee-infolist.h @@ -101,6 +101,8 @@ extern void *infolist_buffer (struct t_infolist *infolist, const char *var, int *size); extern time_t infolist_time (struct t_infolist *infolist, const char *var); +extern struct t_infolist_var *infolist_search_var (struct t_infolist *infolist, + const char *var); extern void infolist_free (struct t_infolist *infolist); extern void infolist_free_all_plugin (struct t_weechat_plugin *plugin); extern void infolist_print_log (); diff --git a/src/core/wee-upgrade.c b/src/core/wee-upgrade.c index 09af3d0b2..6c1c87477 100644 --- a/src/core/wee-upgrade.c +++ b/src/core/wee-upgrade.c @@ -521,8 +521,23 @@ upgrade_weechat_read_cb (void *data, infolist_string (infolist, "highlight_words")); gui_buffer_set_highlight_regex (upgrade_current_buffer, infolist_string (infolist, "highlight_regex")); - gui_buffer_set_highlight_tags (upgrade_current_buffer, - infolist_string (infolist, "highlight_tags")); + if (infolist_search_var (infolist, + "highlight_tags_restrict")) + { + /* WeeChat >= 0.4.3 */ + gui_buffer_set_highlight_tags_restrict (upgrade_current_buffer, + infolist_string (infolist, + "highlight_tags_restrict")); + gui_buffer_set_highlight_tags (upgrade_current_buffer, + infolist_string (infolist, + "highlight_tags")); + } + else + { + /* WeeChat <= 0.4.2 */ + gui_buffer_set_highlight_tags_restrict (upgrade_current_buffer, + infolist_string (infolist, "highlight_tags")); + } gui_buffer_set_hotlist_max_level_nicks (upgrade_current_buffer, infolist_string (infolist, "hotlist_max_level_nicks")); index = 0; diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c index c9e33e88e..1080996aa 100644 --- a/src/gui/gui-buffer.c +++ b/src/gui/gui-buffer.c @@ -88,8 +88,8 @@ char *gui_buffer_properties_get_integer[] = }; char *gui_buffer_properties_get_string[] = { "plugin", "name", "full_name", "short_name", "title", "input", - "text_search_input", "highlight_words", "highlight_regex", "highlight_tags", - "hotlist_max_level_nicks", + "text_search_input", "highlight_words", "highlight_regex", + "highlight_tags_restrict", "highlight_tags", "hotlist_max_level_nicks", NULL }; char *gui_buffer_properties_get_pointer[] = @@ -101,9 +101,9 @@ char *gui_buffer_properties_set[] = "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", "hotlist_max_level_nicks", "hotlist_max_level_nicks_add", - "hotlist_max_level_nicks_del", "input", "input_pos", - "input_get_unknown_commands", + "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", NULL }; @@ -643,6 +643,9 @@ gui_buffer_new (struct t_weechat_plugin *plugin, new_buffer->highlight_words = NULL; new_buffer->highlight_regex = NULL; new_buffer->highlight_regex_compiled = NULL; + new_buffer->highlight_tags_restrict = NULL; + new_buffer->highlight_tags_restrict_count = 0; + new_buffer->highlight_tags_restrict_array = NULL; new_buffer->highlight_tags = NULL; new_buffer->highlight_tags_count = 0; new_buffer->highlight_tags_array = NULL; @@ -1034,6 +1037,8 @@ gui_buffer_get_string (struct t_gui_buffer *buffer, const char *property) return buffer->highlight_words; else if (string_strcasecmp (property, "highlight_regex") == 0) return buffer->highlight_regex; + else if (string_strcasecmp (property, "highlight_tags_restrict") == 0) + return buffer->highlight_tags_restrict; else if (string_strcasecmp (property, "highlight_tags") == 0) return buffer->highlight_tags; else if (string_strcasecmp (property, "hotlist_max_level_nicks") == 0) @@ -1406,12 +1411,66 @@ gui_buffer_set_highlight_regex (struct t_gui_buffer *buffer, } /* + * Sets tags to restrict highlights for a buffer. + */ + +void +gui_buffer_set_highlight_tags_restrict (struct t_gui_buffer *buffer, + const char *new_tags) +{ + int i; + char **tags_array; + + if (buffer->highlight_tags_restrict) + { + free (buffer->highlight_tags_restrict); + buffer->highlight_tags_restrict = NULL; + } + if (buffer->highlight_tags_restrict_array) + { + for (i = 0; i < buffer->highlight_tags_restrict_count; i++) + { + string_free_split (buffer->highlight_tags_restrict_array[i]); + } + free (buffer->highlight_tags_restrict_array); + buffer->highlight_tags_restrict_array = NULL; + } + buffer->highlight_tags_restrict_count = 0; + + if (!new_tags) + return; + + buffer->highlight_tags_restrict = strdup (new_tags); + if (!buffer->highlight_tags_restrict) + return; + + tags_array = string_split (buffer->highlight_tags_restrict, ",", 0, 0, + &buffer->highlight_tags_restrict_count); + if (tags_array) + { + buffer->highlight_tags_restrict_array = + malloc (buffer->highlight_tags_restrict_count * + sizeof (*buffer->highlight_tags_restrict_array)); + if (buffer->highlight_tags_restrict_array) + { + for (i = 0; i < buffer->highlight_tags_restrict_count; i++) + { + buffer->highlight_tags_restrict_array[i] = string_split (tags_array[i], + "+", 0, 0, + NULL); + } + } + string_free_split (tags_array); + } +} + +/* * Sets highlight tags for a buffer. */ void gui_buffer_set_highlight_tags (struct t_gui_buffer *buffer, - const char *new_highlight_tags) + const char *new_tags) { int i; char **tags_array; @@ -1432,10 +1491,10 @@ gui_buffer_set_highlight_tags (struct t_gui_buffer *buffer, } buffer->highlight_tags_count = 0; - if (!new_highlight_tags) + if (!new_tags) return; - buffer->highlight_tags = strdup (new_highlight_tags); + buffer->highlight_tags = strdup (new_tags); if (!buffer->highlight_tags) return; @@ -1443,8 +1502,9 @@ gui_buffer_set_highlight_tags (struct t_gui_buffer *buffer, &buffer->highlight_tags_count); if (tags_array) { - buffer->highlight_tags_array = malloc (buffer->highlight_tags_count * - sizeof (*buffer->highlight_tags_array)); + buffer->highlight_tags_array = + malloc (buffer->highlight_tags_count * + sizeof (*buffer->highlight_tags_array)); if (buffer->highlight_tags_array) { for (i = 0; i < buffer->highlight_tags_count; i++) @@ -1751,6 +1811,10 @@ gui_buffer_set (struct t_gui_buffer *buffer, const char *property, { gui_buffer_set_highlight_regex (buffer, value); } + else if (string_strcasecmp (property, "highlight_tags_restrict") == 0) + { + gui_buffer_set_highlight_tags_restrict (buffer, value); + } else if (string_strcasecmp (property, "highlight_tags") == 0) { gui_buffer_set_highlight_tags (buffer, value); @@ -2486,6 +2550,16 @@ gui_buffer_close (struct t_gui_buffer *buffer) regfree (buffer->highlight_regex_compiled); free (buffer->highlight_regex_compiled); } + if (buffer->highlight_tags_restrict) + free (buffer->highlight_tags_restrict); + if (buffer->highlight_tags_restrict_array) + { + for (i = 0; i < buffer->highlight_tags_restrict_count; i++) + { + string_free_split (buffer->highlight_tags_restrict_array[i]); + } + free (buffer->highlight_tags_restrict_array); + } if (buffer->highlight_tags) free (buffer->highlight_tags); if (buffer->highlight_tags_array) @@ -3693,6 +3767,9 @@ gui_buffer_hdata_buffer_cb (void *data, const char *hdata_name) HDATA_VAR(struct t_gui_buffer, highlight_words, STRING, 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); + HDATA_VAR(struct t_gui_buffer, highlight_tags_restrict_count, INTEGER, 0, NULL, NULL); + HDATA_VAR(struct t_gui_buffer, highlight_tags_restrict_array, POINTER, 0, "highlight_tags_restrict_count", NULL); HDATA_VAR(struct t_gui_buffer, highlight_tags, STRING, 0, NULL, NULL); HDATA_VAR(struct t_gui_buffer, highlight_tags_count, INTEGER, 0, NULL, NULL); HDATA_VAR(struct t_gui_buffer, highlight_tags_array, POINTER, 0, "highlight_tags_count", NULL); @@ -3879,6 +3956,8 @@ gui_buffer_add_to_infolist (struct t_infolist *infolist, return 0; if (!infolist_new_var_pointer (ptr_item, "highlight_regex_compiled", buffer->highlight_regex_compiled)) return 0; + if (!infolist_new_var_string (ptr_item, "highlight_tags_restrict", buffer->highlight_tags_restrict)) + return 0; if (!infolist_new_var_string (ptr_item, "highlight_tags", buffer->highlight_tags)) return 0; if (!infolist_new_var_string (ptr_item, "hotlist_max_level_nicks", hashtable_get_string (buffer->hotlist_max_level_nicks, "keys_values"))) @@ -4081,6 +4160,9 @@ gui_buffer_print_log () 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); diff --git a/src/gui/gui-buffer.h b/src/gui/gui-buffer.h index 70ca1696b..1ab93f06d 100644 --- a/src/gui/gui-buffer.h +++ b/src/gui/gui-buffer.h @@ -177,10 +177,12 @@ 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_tags; /* tags to highlight */ - int highlight_tags_count; /* number of tags to highlight */ - /* (if 0, any tag is highlighted) */ - char ***highlight_tags_array; /* tags to highlight */ + 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 */ + char *highlight_tags; /* force highlight on these tags */ + int highlight_tags_count; /* number of highlight tags */ + char ***highlight_tags_array; /* array with highlight tags */ /* hotlist settings for buffer */ struct t_hashtable *hotlist_max_level_nicks; /* max hotlist level for */ @@ -263,8 +265,10 @@ extern void gui_buffer_set_highlight_words (struct t_gui_buffer *buffer, const char *new_highlight_words); extern void gui_buffer_set_highlight_regex (struct t_gui_buffer *buffer, const char *new_highlight_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, - const char *new_highlight_tags); + const char *new_tags); extern void gui_buffer_set_hotlist_max_level_nicks (struct t_gui_buffer *buffer, const char *new_hotlist_max_level_nicks); extern void gui_buffer_set_unread (struct t_gui_buffer *buffer); diff --git a/src/gui/gui-line.c b/src/gui/gui-line.c index f6e4d863f..4a2460c64 100644 --- a/src/gui/gui-line.c +++ b/src/gui/gui-line.c @@ -699,23 +699,15 @@ gui_line_has_highlight (struct t_gui_line *line) return 0; /* - * check if highlight is forced by a tag (with option highlight_tags) or - * disabled for line; also check if the line is an action message (for - * example tag "irc_action") and get pointer on the nick (tag "nick_xxx"), - * these info will be used later (see below) + * check if highlight is disabled for line; also check if the line is an + * action message (for example tag "irc_action") and get pointer on the nick + * (tag "nick_xxx"), these info will be used later (see below) */ no_highlight = 0; action = 0; ptr_nick = NULL; for (i = 0; i < line->data->tags_count; i++) { - if (config_highlight_tags - && gui_line_match_tags (line->data, - config_num_highlight_tags, - config_highlight_tags)) - { - return 1; - } if (strcmp (line->data->tags_array[i], GUI_CHAT_TAG_NO_HIGHLIGHT) == 0) no_highlight = 1; else if (strncmp (line->data->tags_array[i], "nick_", 5) == 0) @@ -734,14 +726,38 @@ gui_line_has_highlight (struct t_gui_line *line) 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; + } + + /* + * 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_count > 0) + if (line->data->buffer->highlight_tags_restrict_count > 0) { if (!gui_line_match_tags (line->data, - line->data->buffer->highlight_tags_count, - line->data->buffer->highlight_tags_array)) + line->data->buffer->highlight_tags_restrict_count, + line->data->buffer->highlight_tags_restrict_array)) return 0; } diff --git a/src/plugins/irc/irc-channel.c b/src/plugins/irc/irc-channel.c index f30696881..28a51e724 100644 --- a/src/plugins/irc/irc-channel.c +++ b/src/plugins/irc/irc-channel.c @@ -253,11 +253,11 @@ irc_channel_new (struct t_irc_server *server, int channel_type, (channel_type == IRC_CHANNEL_TYPE_CHANNEL) ? weechat_config_string (irc_config_look_highlight_channel) : weechat_config_string (irc_config_look_highlight_pv)); - if (weechat_config_string (irc_config_look_highlight_tags) - && weechat_config_string (irc_config_look_highlight_tags)[0]) + if (weechat_config_string (irc_config_look_highlight_tags_restrict) + && weechat_config_string (irc_config_look_highlight_tags_restrict)[0]) { - weechat_buffer_set (new_buffer, "highlight_tags", - weechat_config_string (irc_config_look_highlight_tags)); + weechat_buffer_set (new_buffer, "highlight_tags_restrict", + weechat_config_string (irc_config_look_highlight_tags_restrict)); } } diff --git a/src/plugins/irc/irc-config.c b/src/plugins/irc/irc-config.c index 49d06b575..6b3b1f818 100644 --- a/src/plugins/irc/irc-config.c +++ b/src/plugins/irc/irc-config.c @@ -69,7 +69,7 @@ struct t_config_option *irc_config_look_display_pv_back; struct t_config_option *irc_config_look_highlight_server; struct t_config_option *irc_config_look_highlight_channel; struct t_config_option *irc_config_look_highlight_pv; -struct t_config_option *irc_config_look_highlight_tags; +struct t_config_option *irc_config_look_highlight_tags_restrict; struct t_config_option *irc_config_look_item_away_message; struct t_config_option *irc_config_look_item_channel_modes_hide_key; struct t_config_option *irc_config_look_item_display_server; @@ -488,12 +488,12 @@ irc_config_change_look_item_nick_prefix (void *data, } /* - * Callback for changes on option "irc.look.highlight_tags". + * Callback for changes on option "irc.look.highlight_tags_restrict". */ void -irc_config_change_look_highlight_tags (void *data, - struct t_config_option *option) +irc_config_change_look_highlight_tags_restrict (void *data, + struct t_config_option *option) { struct t_irc_server *ptr_server; struct t_irc_channel *ptr_channel; @@ -507,16 +507,16 @@ irc_config_change_look_highlight_tags (void *data, { if (ptr_server->buffer) { - weechat_buffer_set (ptr_server->buffer, "highlight_tags", - weechat_config_string (irc_config_look_highlight_tags)); + weechat_buffer_set (ptr_server->buffer, "highlight_tags_restrict", + weechat_config_string (irc_config_look_highlight_tags_restrict)); } for (ptr_channel = ptr_server->channels; ptr_channel; ptr_channel = ptr_channel->next_channel) { if (ptr_channel->buffer) { - weechat_buffer_set (ptr_channel->buffer, "highlight_tags", - weechat_config_string (irc_config_look_highlight_tags)); + weechat_buffer_set (ptr_channel->buffer, "highlight_tags_restrict", + weechat_config_string (irc_config_look_highlight_tags_restrict)); } } } @@ -2343,14 +2343,17 @@ irc_config_init () "disables default highlight on nick, examples: \"$nick\", " "\"(?-i)$nick\""), NULL, 0, 0, "$nick", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL); - irc_config_look_highlight_tags = weechat_config_new_option ( - irc_config_file, ptr_section, - "highlight_tags", "string", - N_("comma separated list of tags for messages that may produce " - "highlight (usually any message from another user, not server " - "messages,..)"), + irc_config_look_highlight_tags_restrict = weechat_config_new_option ( + irc_config_file, ptr_section, + "highlight_tags_restrict", "string", + N_("restrict highlights to these tags on irc buffers (to have " + "highlight on user messages but not server messages); tags " + "must be separated by a comma and \"+\" can be used to make a " + "logical \"and\" between tags; tags can start or end with \"*\" " + "to match more than one tag; an empty value allows highlight on any " + "tag"), NULL, 0, 0, "irc_privmsg,irc_notice", NULL, 0, NULL, NULL, - &irc_config_change_look_highlight_tags, NULL, NULL, NULL); + &irc_config_change_look_highlight_tags_restrict, NULL, NULL, NULL); irc_config_look_item_away_message = weechat_config_new_option ( irc_config_file, ptr_section, "item_away_message", "boolean", diff --git a/src/plugins/irc/irc-config.h b/src/plugins/irc/irc-config.h index 6a0759455..0a5e13e0d 100644 --- a/src/plugins/irc/irc-config.h +++ b/src/plugins/irc/irc-config.h @@ -117,7 +117,7 @@ extern struct t_config_option *irc_config_look_display_pv_back; extern struct t_config_option *irc_config_look_highlight_server; extern struct t_config_option *irc_config_look_highlight_channel; extern struct t_config_option *irc_config_look_highlight_pv; -extern struct t_config_option *irc_config_look_highlight_tags; +extern struct t_config_option *irc_config_look_highlight_tags_restrict; extern struct t_config_option *irc_config_look_item_away_message; extern struct t_config_option *irc_config_look_item_channel_modes_hide_key; extern struct t_config_option *irc_config_look_item_display_server; diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c index 0f5055c80..0fb4815ff 100644 --- a/src/plugins/irc/irc-server.c +++ b/src/plugins/irc/irc-server.c @@ -3460,11 +3460,11 @@ irc_server_create_buffer (struct t_irc_server *server) /* set highlights settings on server buffer */ weechat_buffer_set (server->buffer, "highlight_words_add", weechat_config_string (irc_config_look_highlight_server)); - if (weechat_config_string (irc_config_look_highlight_tags) - && weechat_config_string (irc_config_look_highlight_tags)[0]) + if (weechat_config_string (irc_config_look_highlight_tags_restrict) + && weechat_config_string (irc_config_look_highlight_tags_restrict)[0]) { - weechat_buffer_set (server->buffer, "highlight_tags", - weechat_config_string (irc_config_look_highlight_tags)); + weechat_buffer_set (server->buffer, "highlight_tags_restrict", + weechat_config_string (irc_config_look_highlight_tags_restrict)); } irc_server_set_buffer_title (server); |