From 8dc23863c5375ac349822672955d8dd67d00708c Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Fri, 16 Jul 2010 19:45:14 +0200 Subject: [PATCH] Use '!' to reverse a regex in a filter (to keep lines matching regex and hide other lines) --- ChangeLog | 4 +++- po/cs.po | 12 +++++++++--- po/de.po | 12 +++++++++--- po/es.po | 12 +++++++++--- po/fr.po | 23 ++++++++++++++++------- po/hu.po | 11 ++++++++--- po/it.po | 12 +++++++++--- po/pl.po | 12 +++++++++--- po/ru.po | 11 ++++++++--- po/weechat.pot | 11 ++++++++--- src/core/wee-command.c | 12 ++++++++---- src/gui/gui-filter.c | 31 +++++++++++++++++++++++-------- 12 files changed, 119 insertions(+), 44 deletions(-) diff --git a/ChangeLog b/ChangeLog index 85c34ba9c..354587609 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,12 +1,14 @@ WeeChat ChangeLog ================= Sébastien Helleu -v0.3.3-dev, 2010-07-12 +v0.3.3-dev, 2010-07-16 Version 0.3.3 (under dev!) -------------------------- +* core: use '!' to reverse a regex in a filter (to keep lines matching regex + and hide other lines) * core: add keys for undo/redo changes on command line (default: ctrl/alt + underscore) (task #9483) * core: add new option weechat.look.align_end_of_lines diff --git a/po/cs.po b/po/cs.po index 2a197071d..05ac4f84f 100644 --- a/po/cs.po +++ b/po/cs.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.3-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-07-11 12:14+0200\n" +"POT-Creation-Date: 2010-07-16 15:42+0200\n" "PO-Revision-Date: 2010-06-20 21:24+0200\n" "Last-Translator: Jiri Golembiovsky \n" "Language-Team: weechat-dev \n" @@ -1040,6 +1040,7 @@ msgstr "" "[list] | [enable|disable|toggle [name]] | [add jméno plugin.buffer tags " "regex] | [del name|-all]" +#, fuzzy msgid "" " list: list all filters\n" " enable: enable filters (filters are enabled by default)\n" @@ -1053,8 +1054,11 @@ msgid "" "buffers)\n" " tags: comma separated list of tags, for example: \"irc_join," "irc_part,irc_quit\"\n" -" regex: regular expression to search in line (use \\t to separate " -"prefix from message, special chars like '|' must be escaped: '\\|')\n" +" regex: regular expression to search in line\n" +" - use '\\t' to separate prefix from message, special chars " +"like '|' must be escaped: '\\|'\n" +" - if regex starts with '!', then matching result is reversed " +"(use '\\!' to start with '!')\n" "\n" "The default key alt+'=' toggles filtering on/off.\n" "\n" @@ -1074,6 +1078,8 @@ msgid "" " /filter add nicks * irc_366 *\n" " filter nick \"toto\" on IRC channel #weechat:\n" " /filter add toto irc.freenode.#weechat * toto\\t\n" +" keep only nick \"titi\" on IRC channel #test:\n" +" /filter add titi irc.freenode.#test * !titi\\t\n" " filter lines containing word \"spam\":\n" " /filter add filterspam * * spam\n" " filter lines containing \"weechat sucks\" on IRC channel #weechat:\n" diff --git a/po/de.po b/po/de.po index ae3d950ca..500f2a622 100644 --- a/po/de.po +++ b/po/de.po @@ -22,7 +22,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.3-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-07-15 08:32+0200\n" +"POT-Creation-Date: 2010-07-16 15:42+0200\n" "PO-Revision-Date: 2010-07-12 11:04+0100\n" "Last-Translator: Nils G.\n" "Language-Team: weechat-dev \n" @@ -1062,6 +1062,7 @@ msgstr "" "[list] | [enable|disable|toggle [name]] | [add name plugin.buffer tags " "regex] | [del name|-all]" +#, fuzzy msgid "" " list: list all filters\n" " enable: enable filters (filters are enabled by default)\n" @@ -1075,8 +1076,11 @@ msgid "" "buffers)\n" " tags: comma separated list of tags, for example: \"irc_join," "irc_part,irc_quit\"\n" -" regex: regular expression to search in line (use \\t to separate " -"prefix from message, special chars like '|' must be escaped: '\\|')\n" +" regex: regular expression to search in line\n" +" - use '\\t' to separate prefix from message, special chars " +"like '|' must be escaped: '\\|'\n" +" - if regex starts with '!', then matching result is reversed " +"(use '\\!' to start with '!')\n" "\n" "The default key alt+'=' toggles filtering on/off.\n" "\n" @@ -1096,6 +1100,8 @@ msgid "" " /filter add nicks * irc_366 *\n" " filter nick \"toto\" on IRC channel #weechat:\n" " /filter add toto irc.freenode.#weechat * toto\\t\n" +" keep only nick \"titi\" on IRC channel #test:\n" +" /filter add titi irc.freenode.#test * !titi\\t\n" " filter lines containing word \"spam\":\n" " /filter add filterspam * * spam\n" " filter lines containing \"weechat sucks\" on IRC channel #weechat:\n" diff --git a/po/es.po b/po/es.po index 5443f226f..22d597087 100644 --- a/po/es.po +++ b/po/es.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.3-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-07-11 12:14+0200\n" +"POT-Creation-Date: 2010-07-16 15:42+0200\n" "PO-Revision-Date: 2010-06-20 21:24+0200\n" "Last-Translator: Elián Hanisch \n" "Language-Team: weechat-dev \n" @@ -1046,6 +1046,7 @@ msgstr "" "[list] | [enable|disable|toggle [nombre]] | [add nombre plugin.buffer " "etiquetas regex] | [del nombre|-all]" +#, fuzzy msgid "" " list: list all filters\n" " enable: enable filters (filters are enabled by default)\n" @@ -1059,8 +1060,11 @@ msgid "" "buffers)\n" " tags: comma separated list of tags, for example: \"irc_join," "irc_part,irc_quit\"\n" -" regex: regular expression to search in line (use \\t to separate " -"prefix from message, special chars like '|' must be escaped: '\\|')\n" +" regex: regular expression to search in line\n" +" - use '\\t' to separate prefix from message, special chars " +"like '|' must be escaped: '\\|'\n" +" - if regex starts with '!', then matching result is reversed " +"(use '\\!' to start with '!')\n" "\n" "The default key alt+'=' toggles filtering on/off.\n" "\n" @@ -1080,6 +1084,8 @@ msgid "" " /filter add nicks * irc_366 *\n" " filter nick \"toto\" on IRC channel #weechat:\n" " /filter add toto irc.freenode.#weechat * toto\\t\n" +" keep only nick \"titi\" on IRC channel #test:\n" +" /filter add titi irc.freenode.#test * !titi\\t\n" " filter lines containing word \"spam\":\n" " /filter add filterspam * * spam\n" " filter lines containing \"weechat sucks\" on IRC channel #weechat:\n" diff --git a/po/fr.po b/po/fr.po index 4292ece8c..c0ed2f7dd 100644 --- a/po/fr.po +++ b/po/fr.po @@ -21,8 +21,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.3-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-07-11 12:14+0200\n" -"PO-Revision-Date: 2010-07-10 09:31+0200\n" +"POT-Creation-Date: 2010-07-16 15:42+0200\n" +"PO-Revision-Date: 2010-07-16 14:57+0200\n" "Last-Translator: Sebastien Helleu \n" "Language-Team: weechat-dev \n" "Language: French\n" @@ -1063,8 +1063,11 @@ msgid "" "buffers)\n" " tags: comma separated list of tags, for example: \"irc_join," "irc_part,irc_quit\"\n" -" regex: regular expression to search in line (use \\t to separate " -"prefix from message, special chars like '|' must be escaped: '\\|')\n" +" regex: regular expression to search in line\n" +" - use '\\t' to separate prefix from message, special chars " +"like '|' must be escaped: '\\|'\n" +" - if regex starts with '!', then matching result is reversed " +"(use '\\!' to start with '!')\n" "\n" "The default key alt+'=' toggles filtering on/off.\n" "\n" @@ -1084,6 +1087,8 @@ msgid "" " /filter add nicks * irc_366 *\n" " filter nick \"toto\" on IRC channel #weechat:\n" " /filter add toto irc.freenode.#weechat * toto\\t\n" +" keep only nick \"titi\" on IRC channel #test:\n" +" /filter add titi irc.freenode.#test * !titi\\t\n" " filter lines containing word \"spam\":\n" " /filter add filterspam * * spam\n" " filter lines containing \"weechat sucks\" on IRC channel #weechat:\n" @@ -1101,9 +1106,11 @@ msgstr "" "tous les tampons)\n" " tags: liste de tags, séparés par des virgules, par exemple: " "\"irc_join,irc_part,irc_quit\"\n" -" regex: expressoin régulière à rechercher dans la ligne (utiliser " -"\\t pour séparer le préfixe du message, les caractères spéciaux comme '|' " -"doivent être échappés: '\\|')\n" +" regex: expression régulière à rechercher dans la ligne\n" +" - utiliser '\\t' pour séparer le préfixe du message, les " +"caractères spéciaux comme '|' doivent être échappés: '\\|'\n" +" - si l'expression régulière commence par '!' alors le " +"résultat est inversé (utiliser '\\!' pour démarrer par '!')\n" "\n" "La touche par défaut alt+'=' active/désactive le filtrage.\n" "\n" @@ -1123,6 +1130,8 @@ msgstr "" " /filter add nicks * irc_366 *\n" " filtrer le pseudo \"toto\" sur le canal IRC #weechat:\n" " /filter add toto irc.freenode.#weechat * toto\\t\n" +" garder uniquement le pseudo \"titi\" sur le canal IRC #test:\n" +" /filter add titi irc.freenode.#test * !titi\\t\n" " filtrer les lignes contenant le mot \"spam\":\n" " /filter add filtrespam * * spam\n" " filtrer les lignes contenant \"weechat sucks\" sur le canal IRC #weechat:\n" diff --git a/po/hu.po b/po/hu.po index 819cbb5c2..9b7e7a36e 100644 --- a/po/hu.po +++ b/po/hu.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.3-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-07-11 12:14+0200\n" +"POT-Creation-Date: 2010-07-16 15:42+0200\n" "PO-Revision-Date: 2010-06-20 21:24+0200\n" "Last-Translator: Andras Voroskoi \n" "Language-Team: weechat-dev \n" @@ -1030,8 +1030,11 @@ msgid "" "buffers)\n" " tags: comma separated list of tags, for example: \"irc_join," "irc_part,irc_quit\"\n" -" regex: regular expression to search in line (use \\t to separate " -"prefix from message, special chars like '|' must be escaped: '\\|')\n" +" regex: regular expression to search in line\n" +" - use '\\t' to separate prefix from message, special chars " +"like '|' must be escaped: '\\|'\n" +" - if regex starts with '!', then matching result is reversed " +"(use '\\!' to start with '!')\n" "\n" "The default key alt+'=' toggles filtering on/off.\n" "\n" @@ -1051,6 +1054,8 @@ msgid "" " /filter add nicks * irc_366 *\n" " filter nick \"toto\" on IRC channel #weechat:\n" " /filter add toto irc.freenode.#weechat * toto\\t\n" +" keep only nick \"titi\" on IRC channel #test:\n" +" /filter add titi irc.freenode.#test * !titi\\t\n" " filter lines containing word \"spam\":\n" " /filter add filterspam * * spam\n" " filter lines containing \"weechat sucks\" on IRC channel #weechat:\n" diff --git a/po/it.po b/po/it.po index 3a5e4a43e..c19f95477 100644 --- a/po/it.po +++ b/po/it.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: Weechat 0.3.3-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-07-11 12:14+0200\n" +"POT-Creation-Date: 2010-07-16 15:42+0200\n" "PO-Revision-Date: 2010-06-20 21:24+0200\n" "Last-Translator: Marco Paolone \n" "Language-Team: weechat-dev \n" @@ -1039,6 +1039,7 @@ msgstr "" "[list] | [enable|disable|toggle [nome]] | [add nome plugin.buffer tag regex] " "| [del nome|-all]" +#, fuzzy msgid "" " list: list all filters\n" " enable: enable filters (filters are enabled by default)\n" @@ -1052,8 +1053,11 @@ msgid "" "buffers)\n" " tags: comma separated list of tags, for example: \"irc_join," "irc_part,irc_quit\"\n" -" regex: regular expression to search in line (use \\t to separate " -"prefix from message, special chars like '|' must be escaped: '\\|')\n" +" regex: regular expression to search in line\n" +" - use '\\t' to separate prefix from message, special chars " +"like '|' must be escaped: '\\|'\n" +" - if regex starts with '!', then matching result is reversed " +"(use '\\!' to start with '!')\n" "\n" "The default key alt+'=' toggles filtering on/off.\n" "\n" @@ -1073,6 +1077,8 @@ msgid "" " /filter add nicks * irc_366 *\n" " filter nick \"toto\" on IRC channel #weechat:\n" " /filter add toto irc.freenode.#weechat * toto\\t\n" +" keep only nick \"titi\" on IRC channel #test:\n" +" /filter add titi irc.freenode.#test * !titi\\t\n" " filter lines containing word \"spam\":\n" " /filter add filterspam * * spam\n" " filter lines containing \"weechat sucks\" on IRC channel #weechat:\n" diff --git a/po/pl.po b/po/pl.po index 2abe36cfa..2299b7abf 100644 --- a/po/pl.po +++ b/po/pl.po @@ -21,7 +21,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.3-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-07-11 12:14+0200\n" +"POT-Creation-Date: 2010-07-16 15:42+0200\n" "PO-Revision-Date: 2010-06-20 21:25+0200\n" "Last-Translator: B.J. Stobiecki \n" "Language-Team: weechat-dev \n" @@ -1052,6 +1052,7 @@ msgstr "" "[list] | [enable|disable|toggle [nazwa]] | [add nazwa wtyczka.bufor tagi " "regex] | [del nazwa|-all]" +#, fuzzy msgid "" " list: list all filters\n" " enable: enable filters (filters are enabled by default)\n" @@ -1065,8 +1066,11 @@ msgid "" "buffers)\n" " tags: comma separated list of tags, for example: \"irc_join," "irc_part,irc_quit\"\n" -" regex: regular expression to search in line (use \\t to separate " -"prefix from message, special chars like '|' must be escaped: '\\|')\n" +" regex: regular expression to search in line\n" +" - use '\\t' to separate prefix from message, special chars " +"like '|' must be escaped: '\\|'\n" +" - if regex starts with '!', then matching result is reversed " +"(use '\\!' to start with '!')\n" "\n" "The default key alt+'=' toggles filtering on/off.\n" "\n" @@ -1086,6 +1090,8 @@ msgid "" " /filter add nicks * irc_366 *\n" " filter nick \"toto\" on IRC channel #weechat:\n" " /filter add toto irc.freenode.#weechat * toto\\t\n" +" keep only nick \"titi\" on IRC channel #test:\n" +" /filter add titi irc.freenode.#test * !titi\\t\n" " filter lines containing word \"spam\":\n" " /filter add filterspam * * spam\n" " filter lines containing \"weechat sucks\" on IRC channel #weechat:\n" diff --git a/po/ru.po b/po/ru.po index cf5e9f651..b2008fe0f 100644 --- a/po/ru.po +++ b/po/ru.po @@ -20,7 +20,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat 0.3.3-dev\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-07-11 12:14+0200\n" +"POT-Creation-Date: 2010-07-16 15:42+0200\n" "PO-Revision-Date: 2010-06-20 21:25+0200\n" "Last-Translator: Pavel Shevchuk \n" "Language-Team: weechat-dev \n" @@ -1038,8 +1038,11 @@ msgid "" "buffers)\n" " tags: comma separated list of tags, for example: \"irc_join," "irc_part,irc_quit\"\n" -" regex: regular expression to search in line (use \\t to separate " -"prefix from message, special chars like '|' must be escaped: '\\|')\n" +" regex: regular expression to search in line\n" +" - use '\\t' to separate prefix from message, special chars " +"like '|' must be escaped: '\\|'\n" +" - if regex starts with '!', then matching result is reversed " +"(use '\\!' to start with '!')\n" "\n" "The default key alt+'=' toggles filtering on/off.\n" "\n" @@ -1059,6 +1062,8 @@ msgid "" " /filter add nicks * irc_366 *\n" " filter nick \"toto\" on IRC channel #weechat:\n" " /filter add toto irc.freenode.#weechat * toto\\t\n" +" keep only nick \"titi\" on IRC channel #test:\n" +" /filter add titi irc.freenode.#test * !titi\\t\n" " filter lines containing word \"spam\":\n" " /filter add filterspam * * spam\n" " filter lines containing \"weechat sucks\" on IRC channel #weechat:\n" diff --git a/po/weechat.pot b/po/weechat.pot index c304fc122..a6ccb2f21 100644 --- a/po/weechat.pot +++ b/po/weechat.pot @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2010-07-11 12:14+0200\n" +"POT-Creation-Date: 2010-07-16 15:42+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -888,8 +888,11 @@ msgid "" "buffers)\n" " tags: comma separated list of tags, for example: \"irc_join," "irc_part,irc_quit\"\n" -" regex: regular expression to search in line (use \\t to separate " -"prefix from message, special chars like '|' must be escaped: '\\|')\n" +" regex: regular expression to search in line\n" +" - use '\\t' to separate prefix from message, special chars " +"like '|' must be escaped: '\\|'\n" +" - if regex starts with '!', then matching result is reversed " +"(use '\\!' to start with '!')\n" "\n" "The default key alt+'=' toggles filtering on/off.\n" "\n" @@ -909,6 +912,8 @@ msgid "" " /filter add nicks * irc_366 *\n" " filter nick \"toto\" on IRC channel #weechat:\n" " /filter add toto irc.freenode.#weechat * toto\\t\n" +" keep only nick \"titi\" on IRC channel #test:\n" +" /filter add titi irc.freenode.#test * !titi\\t\n" " filter lines containing word \"spam\":\n" " /filter add filterspam * * spam\n" " filter lines containing \"weechat sucks\" on IRC channel #weechat:\n" diff --git a/src/core/wee-command.c b/src/core/wee-command.c index abd55d9c9..5409256ca 100644 --- a/src/core/wee-command.c +++ b/src/core/wee-command.c @@ -1239,7 +1239,7 @@ command_filter (void *data, struct t_gui_buffer *buffer, { if (argc > 2) { - /* enable a filter */ + /* disable a filter */ ptr_filter = gui_filter_search_by_name (argv[2]); if (ptr_filter) { @@ -4605,9 +4605,11 @@ command_init () "(\"*\" for all buffers)\n" " tags: comma separated list of tags, for " "example: \"irc_join,irc_part,irc_quit\"\n" - " regex: regular expression to search in " - "line (use \\t to separate prefix from message, special " - "chars like '|' must be escaped: '\\|')\n\n" + " regex: regular expression to search in line\n" + " - use '\\t' to separate prefix from message, special " + "chars like '|' must be escaped: '\\|'\n" + " - if regex starts with '!', then matching " + "result is reversed (use '\\!' to start with '!')\n\n" "The default key alt+'=' toggles filtering on/off.\n\n" "Tags most commonly used:\n" " no_filter, no_highlight, log0..log9 (log level),\n" @@ -4624,6 +4626,8 @@ command_init () " /filter add nicks * irc_366 *\n" " filter nick \"toto\" on IRC channel #weechat:\n" " /filter add toto irc.freenode.#weechat * toto\\t\n" + " keep only nick \"titi\" on IRC channel #test:\n" + " /filter add titi irc.freenode.#test * !titi\\t\n" " filter lines containing word \"spam\":\n" " /filter add filterspam * * spam\n" " filter lines containing \"weechat sucks\" on IRC " diff --git a/src/gui/gui-filter.c b/src/gui/gui-filter.c index 2c79d8bb1..8ad74154c 100644 --- a/src/gui/gui-filter.c +++ b/src/gui/gui-filter.c @@ -76,6 +76,7 @@ gui_filter_check_line (struct t_gui_buffer *buffer, struct t_gui_line *line) { struct t_gui_filter *ptr_filter; const char *buffer_plugin_name; + int rc; /* line is always displayed if filters are disabled */ if (!gui_filters_enabled) @@ -103,12 +104,18 @@ gui_filter_check_line (struct t_gui_buffer *buffer, struct t_gui_line *line) ptr_filter->tags_array))) { /* check line with regex */ + rc = 1; if (!ptr_filter->regex_prefix && !ptr_filter->regex_message) - return 0; - + rc = 0; if (gui_line_match_regex (line, ptr_filter->regex_prefix, ptr_filter->regex_message)) + { + rc = 0; + } + if (ptr_filter->regex && (ptr_filter->regex[0] == '!')) + rc ^= 1; + if (rc == 0) return 0; } } @@ -291,28 +298,36 @@ gui_filter_new (int enabled, const char *name, const char *buffer_name, struct t_gui_filter *new_filter; regex_t *regex1, *regex2; char *pos_tab, *pos_point, *regex_prefix; - const char *pos_regex_message; - + const char *ptr_start_regex, *pos_regex_message; + if (!name || !buffer_name || !tags || !regex) return NULL; if (gui_filter_search_by_name (name)) return NULL; + ptr_start_regex = regex; + if ((ptr_start_regex[0] == '!') + || ((ptr_start_regex[0] == '\\') && (ptr_start_regex[1] == '!'))) + { + ptr_start_regex++; + } + regex1 = NULL; regex2 = NULL; - if (strcmp (regex, "*") != 0) + if (strcmp (ptr_start_regex, "*") != 0) { - pos_tab = strstr (regex, "\\t"); + pos_tab = strstr (ptr_start_regex, "\\t"); if (pos_tab) { - regex_prefix = string_strndup (regex, pos_tab - regex); + regex_prefix = string_strndup (ptr_start_regex, + pos_tab - ptr_start_regex); pos_regex_message = pos_tab + 2; } else { regex_prefix = NULL; - pos_regex_message = regex; + pos_regex_message = ptr_start_regex; } if (regex_prefix)