From 9105c3ba1f988c2d0103318c827f5bbd7ecbadd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Thu, 16 Aug 2018 22:47:47 +0200 Subject: [PATCH] trigger: allow creation of temporary variables with the regex --- ChangeLog.adoc | 1 + doc/de/weechat_user.de.adoc | 7 ++++++- doc/en/weechat_user.en.adoc | 6 +++++- doc/fr/weechat_user.fr.adoc | 6 +++++- doc/it/weechat_user.it.adoc | 7 ++++++- doc/ja/weechat_user.ja.adoc | 7 ++++++- doc/pl/weechat_user.pl.adoc | 7 ++++++- src/plugins/trigger/trigger-callback.c | 5 +++-- 8 files changed, 38 insertions(+), 8 deletions(-) diff --git a/ChangeLog.adoc b/ChangeLog.adoc index 837f572fec0..6ae7ae3d96c 100644 --- a/ChangeLog.adoc +++ b/ChangeLog.adoc @@ -22,6 +22,7 @@ New features:: * core: allow partial buffer name in command /buffer close (issue #1226) * api: add function hook_line + * trigger: allow creation of temporary variables with the regex Bug fixes:: diff --git a/doc/de/weechat_user.de.adoc b/doc/de/weechat_user.de.adoc index efb55f7211a..15ed8b2ebd6 100644 --- a/doc/de/weechat_user.de.adoc +++ b/doc/de/weechat_user.de.adoc @@ -3797,7 +3797,12 @@ ${tg_displayed} && (${tg_highlight} || ${tg_msg_pv}) Reguläre Ausdrücke werden verwendet um Variablen in einem Callback Hashtable zu ändern. Das Format ist: "/regex/replace" oder "/regex/replace/var" (wobei _var_ eine -Variable eines Hashtable darstellt). + +Variable eines Hashtable darstellt). + +// TRANSLATION MISSING +If _var_ does not exist in the hashtable, it is created automatically with an +empty value. This allows to create custom temporary variables. + Sollte _var_ nicht näher spezifiziert sein, wird die Standard-Variable genutzt, welche abhängig von dem genutzten Hook ist: diff --git a/doc/en/weechat_user.en.adoc b/doc/en/weechat_user.en.adoc index 38b992d0f1d..d92df6c8fce 100644 --- a/doc/en/weechat_user.en.adoc +++ b/doc/en/weechat_user.en.adoc @@ -3711,7 +3711,11 @@ ${tg_displayed} && (${tg_highlight} || ${tg_msg_pv}) The regular expression is used to change variables in callback hashtable. The format is: "/regex/replace" or "/regex/replace/var" (where _var_ is a -variable of the hashtable). + +variable of the hashtable). + +If _var_ does not exist in the hashtable, it is created automatically with an +empty value. This allows to create custom temporary variables. + If _var_ is not specified, the default variable is used, it depends on hook type: diff --git a/doc/fr/weechat_user.fr.adoc b/doc/fr/weechat_user.fr.adoc index d4404559a6e..883511987ca 100644 --- a/doc/fr/weechat_user.fr.adoc +++ b/doc/fr/weechat_user.fr.adoc @@ -3830,7 +3830,11 @@ L'expression régulière est utilisée pour modifier des variables dans la table de hachage de la fonction de rappel. Le format est : "/regex/remplacement" ou "/regex/remplacement/var" (où _var_ est -une variable de la table de hachage). + +une variable de la table de hachage). + +Si _var_ n'existe pas dans la table de hachage, elle est automatiquement créée +avec une valeur vide. Cela permet de créer des variables temporaires. + Si _var_ n'est pas spécifiée, la variable par défaut est utilisée, elle dépend du type de hook : diff --git a/doc/it/weechat_user.it.adoc b/doc/it/weechat_user.it.adoc index 3d842ebc93c..62952150ea7 100644 --- a/doc/it/weechat_user.it.adoc +++ b/doc/it/weechat_user.it.adoc @@ -3971,7 +3971,12 @@ ${tg_displayed} && (${tg_highlight} || ${tg_msg_pv}) The regular expression is used to change variables in callback hashtable. The format is: "/regex/replace" or "/regex/replace/var" (where _var_ is a -variable of the hashtable). + +variable of the hashtable). + +// TRANSLATION MISSING +If _var_ does not exist in the hashtable, it is created automatically with an +empty value. This allows to create custom temporary variables. + If _var_ is not specified, the default variable is used, it depends on hook type: diff --git a/doc/ja/weechat_user.ja.adoc b/doc/ja/weechat_user.ja.adoc index e6a03c937b7..6521a3c60b6 100644 --- a/doc/ja/weechat_user.ja.adoc +++ b/doc/ja/weechat_user.ja.adoc @@ -3707,7 +3707,12 @@ ${tg_displayed} && (${tg_highlight} || ${tg_msg_pv}) 正規表現はコールバックハッシュテーブル内の変数を変更するために使われます。 書式: "/regex/replace" または "/regex/replace/var" (ここで -_var_ はハッシュテーブルの変数)。 + +_var_ はハッシュテーブルの変数)。 + +// TRANSLATION MISSING +If _var_ does not exist in the hashtable, it is created automatically with an +empty value. This allows to create custom temporary variables. + _var_ が指定されなかった場合、デフォルト変数を使います、これはフックの種類に依存します: diff --git a/doc/pl/weechat_user.pl.adoc b/doc/pl/weechat_user.pl.adoc index e8e216ccc1f..97ae5003610 100644 --- a/doc/pl/weechat_user.pl.adoc +++ b/doc/pl/weechat_user.pl.adoc @@ -3741,7 +3741,12 @@ ${tg_displayed} && (${tg_highlight} || ${tg_msg_pv}) Wyrażenia regularne są używane do zmiany zmiennych w tablicy hashy callbacka. Format: "/wyrażenie/zamień" lub "/wyrażenie/zamień/zmienna" (gdzie _zmienna_ to -zmienna tablicy hashy). + +zmienna tablicy hashy). + +// TRANSLATION MISSING +If _var_ does not exist in the hashtable, it is created automatically with an +empty value. This allows to create custom temporary variables. + Jeśli _zmienna_ nie zostanie podana, użyta zostanie domyślna zmienna, zależy ona od typu uchwytu: diff --git a/src/plugins/trigger/trigger-callback.c b/src/plugins/trigger/trigger-callback.c index 88454ac504d..d77f15a7ded 100644 --- a/src/plugins/trigger/trigger-callback.c +++ b/src/plugins/trigger/trigger-callback.c @@ -277,9 +277,10 @@ trigger_callback_replace_regex (struct t_trigger *trigger, { weechat_printf_date_tags (trigger_buffer, 0, "no_trigger", "\t regex %d (%s): %s", - i + 1, ptr_key, _("empty variable")); + i + 1, ptr_key, _("creating variable")); } - continue; + weechat_hashtable_set (extra_vars, ptr_key, ""); + ptr_value = weechat_hashtable_get (extra_vars, ptr_key); } weechat_hashtable_set (pointers, "regex", trigger->regex[i].regex);