]> jfr.im git - irc/weechat/weechat.git/commitdiff
api: add support of priority in function hook_line (closes #1821)
authorSébastien Helleu <redacted>
Fri, 16 Sep 2022 19:05:51 +0000 (21:05 +0200)
committerSébastien Helleu <redacted>
Fri, 16 Sep 2022 19:05:51 +0000 (21:05 +0200)
ChangeLog.adoc
doc/en/weechat_plugin_api.en.adoc
doc/fr/weechat_plugin_api.fr.adoc
doc/it/weechat_plugin_api.it.adoc
doc/ja/weechat_plugin_api.ja.adoc
doc/sr/weechat_plugin_api.sr.adoc
src/core/hook/wee-hook-line.c
src/core/wee-hook.c

index 2faad0b0df5d6588914a1155c6aae5f5747022d7..a18744c914feec0096c0e02256c261c38b859ef2 100644 (file)
@@ -25,6 +25,7 @@ New features::
   * api: rename function string_build_with_split_string to string_rebuild_split_string, add arguments "index_start" and "index_end"
   * api: add info "uptime_current"
   * api: add function crypto_hash_file
+  * api: add support of priority in function hook_line (issue #1821)
   * buflist: add variable `${hotlist_priority_number}` (integer version of `${hotlist_priority}`)
   * irc: display SETNAME command in channels and private buffers, add options irc.color.message_setname and irc.look.smart_filter_setname (issue #1805)
   * irc: add option irc.look.display_pv_nick_change
index 04dd75835429e1f20cc24df5ed2a269362c8d26c..aba955d284a6c42839c752f76dc9f2b1064a11ee 100644 (file)
@@ -8808,10 +8808,16 @@ C examples:
 [source,c]
 ----
 /* hook modifier with priority = 2000 */
+/* high priority: called before other modifier calbacks */
 weechat_hook_modifier ("2000|input_text_display", &modifier_cb, NULL, NULL);
 
 /* hook two signals with priority = 3000 */
+/* high priority: called before other signal callbacks */
 weechat_hook_signal ("3000|quit;upgrade", &signal_cb, NULL, NULL);
+
+/* hook lines printed in formatted buffers with priority = 500 */
+/* low priority: called after other line callbacks */
+weechat_hook_line ("500|formatted", "*", NULL, &line_cb, NULL, NULL);
 ----
 
 Following hook types allow priority:
@@ -8819,6 +8825,7 @@ Following hook types allow priority:
 * <<_hook_command,command>>
 * <<_hook_completion,completion>>
 * <<_hook_command_run,command_run>>
+* <<_hook_line,line>>
 * <<_hook_signal,signal>>
 * <<_hook_hsignal,hsignal>>
 * <<_hook_config,config>>
@@ -9967,7 +9974,7 @@ hook = weechat.hook_connect("", "my.server.org", 1234, 1, 0, "",
 
 ==== hook_line
 
-_WeeChat ≥ 2.3._
+_WeeChat ≥ 2.3, updated in 3.7._
 
 Hook a line to be printed in a buffer.
 
@@ -10001,7 +10008,8 @@ struct t_hook *weechat_hook_line (const char *buffer_type,
 Arguments:
 
 * _buffer_type_: catch lines on the given buffer type (if NULL or empty string,
-  _formatted_ is the default):
+  _formatted_ is the default)
+  (a priority is allowed before the buffer type, see note about <<hook_priority,priority>>):
 ** _formatted_: catch lines on formatted buffers only (default)
 ** _free_: catch lines on buffers with free content only
 ** _*_: catch lines on all buffer types
index ac7909fc3f366b03143c646a1fdc7fea0cd26854..c078f0444902434547d6327e672a9e151c255363 100644 (file)
@@ -8949,10 +8949,16 @@ Exemples en C :
 [source,c]
 ----
 /* accrocher un modificateur avec priorité = 2000 */
+/* haute priorité : appelé avant les autres fonctions de rappel "modifier" */
 weechat_hook_modifier ("2000|input_text_display", &modifier_cb, NULL, NULL);
 
 /* accrocher deux signaux avec priorité = 3000 */
+/* haute priorité : appelé avant les autres fonctions de rappel "signal" */
 weechat_hook_signal ("3000|quit;upgrade", &signal_cb, NULL, NULL);
+
+/* accrocher les lignes affichées dans les tampons formatés avec priorité = 500 */
+/* basse priorité : appelé après les autres fonctions de rappel "line" */
+weechat_hook_line ("500|formatted", "*", NULL, &line_cb, NULL, NULL);
 ----
 
 Les types de "hooks" suivants autorisent une priorité :
@@ -8960,6 +8966,7 @@ Les types de "hooks" suivants autorisent une priorité :
 * <<_hook_command,command>>
 * <<_hook_completion,completion>>
 * <<_hook_command_run,command_run>>
+* <<_hook_line,line>>
 * <<_hook_signal,signal>>
 * <<_hook_hsignal,hsignal>>
 * <<_hook_config,config>>
@@ -10154,7 +10161,7 @@ hook = weechat.hook_connect("", "my.server.org", 1234, 1, 0, "",
 
 ==== hook_line
 
-_WeeChat ≥ 2.3._
+_WeeChat ≥ 2.3, mis à jour dans la 3.7._
 
 Intercepter une ligne sur le point d'être affichée dans un tampon.
 
@@ -10170,8 +10177,8 @@ appelés dans cet ordre :
   "hook").
 
 [NOTE]
-The "line" hook is the only one among these three hooks that can work on
-buffers with free content.
+Le "hook" "line" est le seul parmi ces trois "hooks" qui peut fonctionner sur
+un tampon avec contenu libre.
 
 Prototype :
 
@@ -10190,7 +10197,8 @@ struct t_hook *weechat_hook_line (const char *buffer_type,
 Paramètres :
 
 * _buffer_type_ : intercepter les lignes affichées sur ce type de tampon
-  (si NULL ou chaîne vide, _formatted_ est utilisé par défaut) :
+  (si NULL ou chaîne vide, _formatted_ est utilisé par défaut)
+  (une priorité est autorisée avant le type de tampon, voir la note sur la <<hook_priority,priorité>>) :
 ** _formatted_ : intercepter les lignes sur un tampon avec contenu formaté
    seulement (par défaut)
 ** _free_ : intercepter les lignes sur un tampon avec contenu libre seulement
index 0a5787cfe15e6517defb72633e1b1cf49eace245..7eec59dd404535e12fcb04118b8a8b4c73d70b5b 100644 (file)
@@ -9098,10 +9098,16 @@ C examples:
 [source,c]
 ----
 /* hook per il modificatore con priorità = 2000 */
+/* high priority: called before other modifier calbacks */
 weechat_hook_modifier ("2000|input_text_display", &modifier_cb, NULL, NULL);
 
 /* hook two signals with priority = 3000 */
+/* high priority: called before other signal callbacks */
 weechat_hook_signal ("3000|quit;upgrade", &signal_cb, NULL, NULL);
+
+/* hook lines printed in formatted buffers with priority = 500 */
+/* low priority: called after other line callbacks */
+weechat_hook_line ("500|formatted", "*", NULL, &line_cb, NULL, NULL);
 ----
 
 I tipi di hook che seguono consentono la priorità:
@@ -9109,6 +9115,7 @@ I tipi di hook che seguono consentono la priorità:
 * <<_hook_command,command>>
 * <<_hook_completion,completion>>
 * <<_hook_command_run,command_run>>
+* <<_hook_line,line>>
 * <<_hook_signal,signal>>
 * <<_hook_hsignal,hsignal>>
 * <<_hook_config,config>>
@@ -10294,7 +10301,7 @@ hook = weechat.hook_connect("", "my.server.org", 1234, 1, 0, "",
 // TRANSLATION MISSING
 ==== hook_line
 
-_WeeChat ≥ 2.3._
+_WeeChat ≥ 2.3, updated in 3.7._
 
 Hook a line to be printed in a buffer.
 
@@ -10328,7 +10335,8 @@ struct t_hook *weechat_hook_line (const char *buffer_type,
 Argomenti:
 
 * _buffer_type_: catch lines on the given buffer type (if NULL or empty string,
-  _formatted_ is the default):
+  _formatted_ is the default)
+  (a priority is allowed before the buffer type, see note about <<hook_priority,priority>>):
 ** _formatted_: catch lines on formatted buffers only (default)
 ** _free_: catch lines on buffers with free content only
 ** _*_: catch lines on all buffer types
index 7b42259da77bbafb6684dff93e7f282f3062b14f..4f3506b16a5f56ea7a9116f361ca68216887fadb 100644 (file)
@@ -8841,10 +8841,16 @@ C examples:
 [source,c]
 ----
 /* hook modifier with priority = 2000 */
+/* high priority: called before other modifier calbacks */
 weechat_hook_modifier ("2000|input_text_display", &modifier_cb, NULL, NULL);
 
 /* hook two signals with priority = 3000 */
+/* high priority: called before other signal callbacks */
 weechat_hook_signal ("3000|quit;upgrade", &signal_cb, NULL, NULL);
+
+/* hook lines printed in formatted buffers with priority = 500 */
+/* low priority: called after other line callbacks */
+weechat_hook_line ("500|formatted", "*", NULL, &line_cb, NULL, NULL);
 ----
 
 以下のフック型に対して優先度を設定できます:
@@ -8852,6 +8858,7 @@ weechat_hook_signal ("3000|quit;upgrade", &signal_cb, NULL, NULL);
 * <<_hook_command,command>>
 * <<_hook_completion,completion>>
 * <<_hook_command_run,command_run>>
+* <<_hook_line,line>>
 * <<_hook_signal,signal>>
 * <<_hook_hsignal,hsignal>>
 * <<_hook_config,config>>
@@ -10010,7 +10017,8 @@ hook = weechat.hook_connect("", "my.server.org", 1234, 1, 0, "",
 
 ==== hook_line
 
-_WeeChat バージョン 2.3 以上で利用可_
+// TRANSLATION MISSING
+_WeeChat ≥ 2.3, updated in 3.7._
 
 バッファに対する行表示をフックする。
 
@@ -10044,7 +10052,8 @@ struct t_hook *weechat_hook_line (const char *buffer_type,
 引数:
 
 * _buffer_type_: ここで指定したバッファ型の行をフックします (NULL または空文字列の場合、
-  _formatted_ を指定したことになります):
+  _formatted_ を指定したことになります)
+  (a priority is allowed before the buffer type, see note about <<hook_priority,priority>>):
 ** _formatted_: フォーマット済み内容バッファの行のみをフックします (デフォルト)
 ** _free_: 自由内容バッファの行のみをフックします
 ** _*_: すべてのバッファの行をフックします
index 057c206e72a70842716c336f6cb0ae238c9f6a73..65eecfc33544a51184f32352add795816e7563e4 100644 (file)
@@ -8545,10 +8545,16 @@ C examples:
 [source,c]
 ----
 /* модификатор кука са приоритетом = 2000 */
+/* high priority: called before other modifier calbacks */
 weechat_hook_modifier ("2000|input_text_display", &modifier_cb, NULL, NULL);
 
 /* hook two signals with priority = 3000 */
+/* high priority: called before other signal callbacks */
 weechat_hook_signal ("3000|quit;upgrade", &signal_cb, NULL, NULL);
+
+/* hook lines printed in formatted buffers with priority = 500 */
+/* low priority: called after other line callbacks */
+weechat_hook_line ("500|formatted", "*", NULL, &line_cb, NULL, NULL);
 ----
 
 Приоритет дозвољавају следећи типови кука:
@@ -8556,6 +8562,7 @@ weechat_hook_signal ("3000|quit;upgrade", &signal_cb, NULL, NULL);
 * <<_hook_command,command>>
 * <<_hook_completion,completion>>
 * <<_hook_command_run,command_run>>
+* <<_hook_line,line>>
 * <<_hook_signal,signal>>
 * <<_hook_hsignal,hsignal>>
 * <<_hook_config,config>>
@@ -9632,7 +9639,8 @@ hook = weechat.hook_connect("", "my.server.org", 1234, 1, 0, "",
 
 ==== hook_line
 
-_WeeChat ≥ 2.3._
+// TRANSLATION MISSING
+_WeeChat ≥ 2.3, updated in 3.7._
 
 Качи се на линију која треба да се испише у бафер.
 
@@ -9661,7 +9669,9 @@ struct t_hook *weechat_hook_line (const char *buffer_type,
 
 Аргументи:
 
-* _buffer_type_: хвата линије у наведеном типу бафера (ако је NULL или празан стринг, подразумева се _formatted_):
+// TRANSLATION MISSING
+* _buffer_type_: хвата линије у наведеном типу бафера (ако је NULL или празан стринг, подразумева се _formatted_)
+  (a priority is allowed before the buffer type, see note about <<hook_priority,приоритетима>>):
 ** _formatted_: хвата линије само у форматираним баферима (подразумевано)
 ** _free_: хвата линије само у баферима са слободним садржајем
 ** _*_: хвата линије у баферима свих типова
index 00bd7f138b97e367871d37af4797c76149816a85..366c9bf2e63087dd3c96d32ee51bc30421b6b7cb 100644 (file)
@@ -71,6 +71,8 @@ hook_line (struct t_weechat_plugin *plugin, const char *buffer_type,
 {
     struct t_hook *new_hook;
     struct t_hook_line *new_hook_line;
+    int priority;
+    const char *ptr_buffer_type;
 
     if (!callback)
         return NULL;
@@ -85,17 +87,18 @@ hook_line (struct t_weechat_plugin *plugin, const char *buffer_type,
         return NULL;
     }
 
-    hook_init_data (new_hook, plugin, HOOK_TYPE_LINE, HOOK_PRIORITY_DEFAULT,
+    hook_get_priority_and_name (buffer_type, &priority, &ptr_buffer_type);
+    hook_init_data (new_hook, plugin, HOOK_TYPE_LINE, priority,
                     callback_pointer, callback_data);
 
     new_hook->hook_data = new_hook_line;
     new_hook_line->callback = callback;
-    if (!buffer_type || !buffer_type[0])
+    if (!ptr_buffer_type || !ptr_buffer_type[0])
         new_hook_line->buffer_type = GUI_BUFFER_TYPE_DEFAULT;
-    else if (strcmp (buffer_type, "*") == 0)
+    else if (strcmp (ptr_buffer_type, "*") == 0)
         new_hook_line->buffer_type = -1;
     else
-        new_hook_line->buffer_type = gui_buffer_search_type (buffer_type);
+        new_hook_line->buffer_type = gui_buffer_search_type (ptr_buffer_type);
     new_hook_line->buffers = string_split (
         (buffer_name && buffer_name[0]) ? buffer_name : "*",
         ",",
index 04b1acc2efa9e5df6c88743617d823af71da3a20..b50a664e71ce93699895b0f80690498b16453000 100644 (file)
@@ -362,6 +362,9 @@ hook_get_priority_and_name (const char *string,
     if (name)
         *name = string;
 
+    if (!string)
+        return;
+
     pos = strchr (string, '|');
     if (pos)
     {