mirror of
https://github.com/weechat/weechat.git
synced 2026-07-05 17:23:15 +02:00
core: add support of flags in regular expressions and highlight options, add irc options to customize/disable default nick highlight (task #11128)
New functions in C plugin API:
- string_regex_flags
- string_regcomp
New irc options:
- irc.look.highlight_server
- irc.look.highlight_channel
- irc.look.highlight_pv
Regex flags are supported in following options/commands:
- option weechat.look.highlight
- option weechat.look.highlight_regex
- options irc.look.highlight_{server|channel|pv}
- option relay.network.allowed_ips
- core command /filter
- irc command /list
- irc command /ignore
- rmodifier command /rmodifier
This commit is contained in:
@@ -229,7 +229,10 @@ irc_channel_new (struct t_irc_server *server, int channel_type,
|
||||
}
|
||||
|
||||
/* set highlights settings on channel buffer */
|
||||
weechat_buffer_set(new_buffer, "highlight_words_add", "$nick");
|
||||
weechat_buffer_set(new_buffer, "highlight_words_add",
|
||||
(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])
|
||||
{
|
||||
|
||||
@@ -2245,8 +2245,8 @@ irc_command_list (void *data, struct t_gui_buffer *buffer, int argc,
|
||||
ptr_server->cmd_list_regexp = malloc (sizeof (*ptr_server->cmd_list_regexp));
|
||||
if (ptr_server->cmd_list_regexp)
|
||||
{
|
||||
if ((ret = regcomp (ptr_server->cmd_list_regexp, ptr_regex,
|
||||
REG_NOSUB | REG_ICASE | REG_EXTENDED)) != 0)
|
||||
if ((ret = weechat_string_regcomp (ptr_server->cmd_list_regexp, ptr_regex,
|
||||
REG_EXTENDED | REG_ICASE | REG_NOSUB)) != 0)
|
||||
{
|
||||
regerror (ret, ptr_server->cmd_list_regexp,
|
||||
buf, sizeof(buf));
|
||||
@@ -4946,6 +4946,8 @@ irc_command_init ()
|
||||
"is working\n"
|
||||
" channel: channel name where ignore is "
|
||||
"working\n\n"
|
||||
"Note: the regular expression can start with "
|
||||
"\"(?-i)\" to become case sensitive.\n\n"
|
||||
"Examples:\n"
|
||||
" ignore nick \"toto\" everywhere:\n"
|
||||
" /ignore add toto\n"
|
||||
@@ -5029,7 +5031,8 @@ irc_command_init ()
|
||||
N_("channel: channel to list\n"
|
||||
" server: server name\n"
|
||||
" regex: regular expression used to filter "
|
||||
"results\n\n"
|
||||
"results (case insensitive, can start by \"(?-i)\" "
|
||||
"to become case sensitive)\n\n"
|
||||
"Examples:\n"
|
||||
" list all channels on server (can be very slow "
|
||||
"on large networks):\n"
|
||||
|
||||
@@ -80,6 +80,9 @@ struct t_config_option *irc_config_look_item_channel_modes_hide_key;
|
||||
struct t_config_option *irc_config_look_item_nick_modes;
|
||||
struct t_config_option *irc_config_look_item_nick_prefix;
|
||||
struct t_config_option *irc_config_look_hide_nickserv_pwd;
|
||||
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_item_display_server;
|
||||
struct t_config_option *irc_config_look_msgbuffer_fallback;
|
||||
@@ -2183,6 +2186,42 @@ irc_config_init ()
|
||||
"hide_nickserv_pwd", "boolean",
|
||||
N_("hide password displayed by nickserv"),
|
||||
NULL, 0, 0, "on", NULL, 0, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
irc_config_look_highlight_server = weechat_config_new_option (
|
||||
irc_config_file, ptr_section,
|
||||
"highlight_server", "string",
|
||||
N_("comma separated list of words to highlight in server buffers "
|
||||
"(case insensitive, use \"(?-i)\" at beginning of words to "
|
||||
"make them case sensitive; special variables $nick, $channel and "
|
||||
"$server are replaced by their value), these words are added to "
|
||||
"buffer local variable \"highlight_words\" only when buffer is "
|
||||
"created (it does not affect current buffers), an empty string "
|
||||
"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_channel = weechat_config_new_option (
|
||||
irc_config_file, ptr_section,
|
||||
"highlight_channel", "string",
|
||||
N_("comma separated list of words to highlight in channel buffers "
|
||||
"(case insensitive, use \"(?-i)\" at beginning of words to "
|
||||
"make them case sensitive; special variables $nick, $channel and "
|
||||
"$server are replaced by their value), these words are added to "
|
||||
"buffer local variable \"highlight_words\" only when buffer is "
|
||||
"created (it does not affect current buffers), an empty string "
|
||||
"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_pv = weechat_config_new_option (
|
||||
irc_config_file, ptr_section,
|
||||
"highlight_pv", "string",
|
||||
N_("comma separated list of words to highlight in private buffers "
|
||||
"(case insensitive, use \"(?-i)\" at beginning of words to "
|
||||
"make them case sensitive; special variables $nick, $channel and "
|
||||
"$server are replaced by their value), these words are added to "
|
||||
"buffer local variable \"highlight_words\" only when buffer is "
|
||||
"created (it does not affect current buffers), an empty string "
|
||||
"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",
|
||||
|
||||
@@ -105,6 +105,9 @@ extern struct t_config_option *irc_config_look_item_channel_modes_hide_key;
|
||||
extern struct t_config_option *irc_config_look_item_nick_modes;
|
||||
extern struct t_config_option *irc_config_look_item_nick_prefix;
|
||||
extern struct t_config_option *irc_config_look_hide_nickserv_pwd;
|
||||
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_item_display_server;
|
||||
extern struct t_config_option *irc_config_look_msgbuffer_fallback;
|
||||
|
||||
@@ -146,7 +146,8 @@ irc_ignore_new (const char *mask, const char *server, const char *channel)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (regcomp (regex, complete_mask, REG_NOSUB | REG_ICASE | REG_EXTENDED) != 0)
|
||||
if (weechat_string_regcomp (regex, complete_mask,
|
||||
REG_EXTENDED | REG_ICASE | REG_NOSUB) != 0)
|
||||
{
|
||||
free (regex);
|
||||
free (complete_mask);
|
||||
|
||||
@@ -3010,7 +3010,8 @@ irc_server_create_buffer (struct t_irc_server *server)
|
||||
weechat_buffer_set (server->buffer, "input_get_unknown_commands", "1");
|
||||
|
||||
/* set highlights settings on server buffer */
|
||||
weechat_buffer_set (server->buffer, "highlight_words_add", "$nick");
|
||||
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])
|
||||
{
|
||||
|
||||
@@ -505,9 +505,11 @@ plugin_load (const char *filename, int argc, char **argv)
|
||||
new_plugin->string_expand_home = &string_expand_home;
|
||||
new_plugin->string_remove_quotes = &string_remove_quotes;
|
||||
new_plugin->string_strip = &string_strip;
|
||||
new_plugin->string_mask_to_regex = &string_mask_to_regex;
|
||||
new_plugin->string_regex_flags = &string_regex_flags;
|
||||
new_plugin->string_regcomp = &string_regcomp;
|
||||
new_plugin->string_has_highlight = &string_has_highlight;
|
||||
new_plugin->string_has_highlight_regex = &string_has_highlight_regex;
|
||||
new_plugin->string_mask_to_regex = &string_mask_to_regex;
|
||||
new_plugin->string_split = &string_split;
|
||||
new_plugin->string_free_split = &string_free_split;
|
||||
new_plugin->string_build_with_split_string = &string_build_with_split_string;
|
||||
|
||||
@@ -104,7 +104,9 @@ relay_config_change_network_allowed_ips (void *data,
|
||||
relay_config_regex_allowed_ips = malloc (sizeof (*relay_config_regex_allowed_ips));
|
||||
if (relay_config_regex_allowed_ips)
|
||||
{
|
||||
if (regcomp (relay_config_regex_allowed_ips, allowed_ips, REG_EXTENDED) != 0)
|
||||
if (weechat_string_regcomp (relay_config_regex_allowed_ips,
|
||||
allowed_ips,
|
||||
REG_EXTENDED | REG_ICASE) != 0)
|
||||
{
|
||||
free (relay_config_regex_allowed_ips);
|
||||
relay_config_regex_allowed_ips = NULL;
|
||||
@@ -416,7 +418,8 @@ relay_config_init ()
|
||||
relay_config_network_allowed_ips = weechat_config_new_option (
|
||||
relay_config_file, ptr_section,
|
||||
"allowed_ips", "string",
|
||||
N_("regular expression with IPs allowed to use relay, example: "
|
||||
N_("regular expression with IPs allowed to use relay (case insensitive, "
|
||||
"use \"(?-i)\" at beginning to make it case sensitive), example: "
|
||||
"\"^(123.45.67.89|192.160.*)$\""),
|
||||
NULL, 0, 0, "", NULL, 0, NULL, NULL,
|
||||
&relay_config_change_network_allowed_ips, NULL, NULL, NULL);
|
||||
|
||||
@@ -246,7 +246,8 @@ rmodifier_command_init ()
|
||||
" groups: action on groups found: comma separated "
|
||||
"list of groups (from 1 to 9) with optional \"*\" "
|
||||
"after number to hide group\n"
|
||||
" regex: regular expression\n"
|
||||
" regex: regular expression (case insensitive, "
|
||||
"can start by \"(?-i)\" to become case sensitive)\n"
|
||||
" del: delete a rmodifier\n"
|
||||
" -all: delete all rmodifiers\n"
|
||||
" default: restore default rmodifiers\n\n"
|
||||
|
||||
@@ -271,8 +271,8 @@ rmodifier_new (const char *name, const char *modifiers, const char *str_regex,
|
||||
if (!regex)
|
||||
return NULL;
|
||||
|
||||
if (regcomp (regex, str_regex,
|
||||
REG_EXTENDED | REG_ICASE) != 0)
|
||||
if (weechat_string_regcomp (regex, str_regex,
|
||||
REG_EXTENDED | REG_ICASE) != 0)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
_("%s%s: error compiling regular expression \"%s\""),
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#define __WEECHAT_WEECHAT_PLUGIN_H 1
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <regex.h>
|
||||
|
||||
struct t_config_option;
|
||||
struct t_gui_window;
|
||||
@@ -46,7 +47,7 @@ struct timeval;
|
||||
*/
|
||||
|
||||
/* API version (used to check that plugin has same API and can be loaded) */
|
||||
#define WEECHAT_PLUGIN_API_VERSION "20120112-01"
|
||||
#define WEECHAT_PLUGIN_API_VERSION "20120122-01"
|
||||
|
||||
/* macros for defining plugin infos */
|
||||
#define WEECHAT_PLUGIN_NAME(__name) \
|
||||
@@ -225,10 +226,13 @@ struct t_weechat_plugin
|
||||
char *(*string_remove_quotes) (const char *string, const char *quotes);
|
||||
char *(*string_strip) (const char *string, int left, int right,
|
||||
const char *chars);
|
||||
char *(*string_mask_to_regex) (const char *mask);
|
||||
const char *(*string_regex_flags) (const char *regex, int default_flags,
|
||||
int *flags);
|
||||
int (*string_regcomp) (regex_t *preg, const char *regex, int default_flags);
|
||||
int (*string_has_highlight) (const char *string,
|
||||
const char *highlight_words);
|
||||
int (*string_has_highlight_regex) (const char *string, const char *regex);
|
||||
char *(*string_mask_to_regex) (const char *mask);
|
||||
char **(*string_split) (const char *string, const char *separators,
|
||||
int keep_eol, int num_items_max, int *num_items);
|
||||
void (*string_free_split) (char **split_string);
|
||||
@@ -939,12 +943,17 @@ extern int weechat_plugin_end (struct t_weechat_plugin *plugin);
|
||||
weechat_plugin->string_remove_quotes(__string, __quotes)
|
||||
#define weechat_string_strip(__string, __left, __right, __chars) \
|
||||
weechat_plugin->string_strip(__string, __left, __right, __chars)
|
||||
#define weechat_string_mask_to_regex(__mask) \
|
||||
weechat_plugin->string_mask_to_regex(__mask)
|
||||
#define weechat_string_regex_flags(__regex, __default_flags, __flags) \
|
||||
weechat_plugin->string_regex_flags(__regex, __default_flags, \
|
||||
__flags)
|
||||
#define weechat_string_regcomp(__preg, __regex, __default_flags) \
|
||||
weechat_plugin->string_regcomp(__preg, __regex, __default_flags)
|
||||
#define weechat_string_has_highlight(__string, __highlight_words) \
|
||||
weechat_plugin->string_has_highlight(__string, __highlight_words)
|
||||
#define weechat_string_has_highlight_regex(__string, __regex) \
|
||||
weechat_plugin->string_has_highlight_regex(__string, __regex)
|
||||
#define weechat_string_mask_to_regex(__mask) \
|
||||
weechat_plugin->string_mask_to_regex(__mask)
|
||||
#define weechat_string_split(__string, __separator, __eol, __max, \
|
||||
__num_items) \
|
||||
weechat_plugin->string_split(__string, __separator, __eol, \
|
||||
|
||||
Reference in New Issue
Block a user