summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog.adoc1
-rw-r--r--doc/en/weechat_plugin_api.en.adoc8
-rw-r--r--doc/fr/weechat_plugin_api.fr.adoc8
-rw-r--r--doc/it/weechat_plugin_api.it.adoc10
-rw-r--r--doc/ja/weechat_plugin_api.ja.adoc11
-rw-r--r--doc/sr/weechat_plugin_api.sr.adoc11
-rw-r--r--src/gui/gui-buffer.c10
-rw-r--r--tests/unit/gui/test-gui-buffer.cpp9
8 files changed, 53 insertions, 15 deletions
diff --git a/ChangeLog.adoc b/ChangeLog.adoc
index 9ce6ed2cf..35c5859db 100644
--- a/ChangeLog.adoc
+++ b/ChangeLog.adoc
@@ -22,6 +22,7 @@ New features::
* core: add option `-s` in command `/command` to execute multiple commands separated by semicolons
* core: allow case insensitive search of partial buffer name with `(?i)name` in command `/buffer`
* core: use function util_strftimeval in evaluation of expression `date:xxx`
+ * api: allow search by buffer id in function buffer_search (issue #2081)
* api: add modifier "color_decode" to decode WeeChat colors with a replacement string
* api: use whole replacement string instead of first char in function string_remove_color
* api: add functions config_option_get_{string|pointer} and config_{boolean|integer|string|color|enum}_inherited in scripting API
diff --git a/doc/en/weechat_plugin_api.en.adoc b/doc/en/weechat_plugin_api.en.adoc
index 9a3b67636..847034a3d 100644
--- a/doc/en/weechat_plugin_api.en.adoc
+++ b/doc/en/weechat_plugin_api.en.adoc
@@ -14291,9 +14291,9 @@ weechat.prnt(weechat.current_buffer(), "Text on current buffer")
==== buffer_search
-_Updated in 1.0._
+_Updated in 1.0, 4.3.0._
-Search a buffer by plugin and/or name.
+Search a buffer by plugin/name, full name or unique identifier (`id`).
Prototype:
@@ -14305,10 +14305,11 @@ struct t_gui_buffer *weechat_buffer_search (const char *plugin,
Arguments:
-* _plugin_: name of plugin, following special value is allowed:
+* _plugin_: name of plugin, following special values are allowed:
** `+==+`: the name used is the buffer full name (for example:
`irc.libera.#weechat` instead of `libera.#weechat`)
_(WeeChat ≥ 1.0)_
+** `+==id+`: the name used is the buffer unique identifier (`id`) _(WeeChat ≥ 4.3.0)_
* _name_: name of buffer, if it is NULL or empty string, the current buffer is
returned (buffer displayed by current window); if the name starts with
`(?i)`, the search is case insensitive _(WeeChat ≥ 1.0)_
@@ -14323,6 +14324,7 @@ C examples:
----
struct t_gui_buffer *buffer1 = weechat_buffer_search ("irc", "libera.#weechat");
struct t_gui_buffer *buffer2 = weechat_buffer_search ("==", "irc.libera.#test"); /* WeeChat ≥ 1.0 */
+struct t_gui_buffer *buffer3 = weechat_buffer_search ("==id", "1709797810942688"); /* WeeChat ≥ 4.3.0 */
----
Script (Python):
diff --git a/doc/fr/weechat_plugin_api.fr.adoc b/doc/fr/weechat_plugin_api.fr.adoc
index 18d18b049..fcb51f3d3 100644
--- a/doc/fr/weechat_plugin_api.fr.adoc
+++ b/doc/fr/weechat_plugin_api.fr.adoc
@@ -14607,9 +14607,9 @@ weechat.prnt(weechat.current_buffer(), "Texte sur le tampon courant")
==== buffer_search
-_Mis à jour dans la 1.0._
+_Mis à jour dans la 1.0, 4.3.0._
-Rechercher un tampon par l'extension et/ou le nom.
+Rechercher un tampon par l'extension/nom, nom complet ou identifiant unique (`id`).
Prototype :
@@ -14621,10 +14621,11 @@ struct t_gui_buffer *weechat_buffer_search (const char *plugin,
Paramètres :
-* _plugin_ : nom de l'extension, la valeur spéciale suivante est autorisée :
+* _plugin_ : nom de l'extension, les valeurs spéciales suivantes sont autorisées :
** `+==+` : le nom utilisé est le nom complet du tampon (par exemple :
`irc.libera.#weechat` au lieu de `libera.#weechat`)
_(WeeChat ≥ 1.0)_
+** `+==id+` : le nom utilisé est l'identifiant unique du tampon (`id`) _(WeeChat ≥ 4.3.0)_
* _name_ : nom du tampon, si c'est NULL ou une chaîne vide, le tampon courant
est retourné (tampon affiché par la fenêtre courante); si le nom commence par
`(?i)`, la recherche est insensible à la casse _(WeeChat ≥ 1.0)_
@@ -14639,6 +14640,7 @@ Exemples en C :
----
struct t_gui_buffer *buffer1 = weechat_buffer_search ("irc", "libera.#weechat");
struct t_gui_buffer *buffer2 = weechat_buffer_search ("==", "irc.libera.#test"); /* WeeChat ≥ 1.0 */
+struct t_gui_buffer *buffer3 = weechat_buffer_search ("==id", "1709797810942688"); /* WeeChat ≥ 4.3.0 */
----
Script (Python) :
diff --git a/doc/it/weechat_plugin_api.it.adoc b/doc/it/weechat_plugin_api.it.adoc
index ba611b731..ab928cc64 100644
--- a/doc/it/weechat_plugin_api.it.adoc
+++ b/doc/it/weechat_plugin_api.it.adoc
@@ -14948,9 +14948,10 @@ weechat.prnt(weechat.current_buffer(), "Testo sul buffer corrente")
==== buffer_search
// TRANSLATION MISSING
-_Updated in 1.0._
+_Updated in 1.0, 4.3.0._
-Cerca un buffer tramite plugin e/o nome.
+// TRANSLATION MISSING
+Search a buffer by plugin/name, full name or unique identifier (`id`).
Prototipo:
@@ -14963,11 +14964,13 @@ struct t_gui_buffer *weechat_buffer_search (const char *plugin,
Argomenti:
// TRANSLATION MISSING
-* _plugin_: name of plugin, following special value is allowed:
+* _plugin_: name of plugin, following special values are allowed:
** `+==+`: the name used is the buffer full name (for example:
`irc.libera.#weechat` instead of `libera.#weechat`)
_(WeeChat ≥ 1.0)_
// TRANSLATION MISSING
+** `+==id+`: the name used is the buffer unique identifier (`id`) _(WeeChat ≥ 4.3.0)_
+// TRANSLATION MISSING
* _name_: name of buffer, if it is NULL or empty string, the current buffer is
returned (buffer displayed by current window); if the name starts with
`(?i)`, the search is case insensitive _(WeeChat ≥ 1.0)_
@@ -14982,6 +14985,7 @@ Esempio in C:
----
struct t_gui_buffer *buffer1 = weechat_buffer_search ("irc", "libera.#weechat");
struct t_gui_buffer *buffer2 = weechat_buffer_search ("==", "irc.libera.#test"); /* WeeChat ≥ 1.0 */
+struct t_gui_buffer *buffer3 = weechat_buffer_search ("==id", "1709797810942688"); /* WeeChat ≥ 4.3.0 */
----
Script (Python):
diff --git a/doc/ja/weechat_plugin_api.ja.adoc b/doc/ja/weechat_plugin_api.ja.adoc
index 6c6461782..e4e1677b1 100644
--- a/doc/ja/weechat_plugin_api.ja.adoc
+++ b/doc/ja/weechat_plugin_api.ja.adoc
@@ -14495,9 +14495,10 @@ weechat.prnt(weechat.current_buffer(), "Text on current buffer")
==== buffer_search
-_WeeChat バージョン 1.0 で更新。_
+_WeeChat バージョン 1.0, 4.3.0 で更新。_
-プラグインおよび名前でバッファを検索。
+// TRANSLATION MISSING
+Search a buffer by plugin/name, full name or unique identifier (`id`).
プロトタイプ:
@@ -14509,10 +14510,13 @@ struct t_gui_buffer *weechat_buffer_search (const char *plugin,
引数:
-* _plugin_: プラグインの名前、以下の特殊値を使うことができます:
+// TRANSLATION MISSING
+* _plugin_: name of plugin, following special values are allowed:
** `+==+`: name 引数でバッファの完全な名前を使う (例:
`libera.#weechat` ではなく `irc.libera.#weechat`)
_(WeeChat バージョン 1.0 以上で利用可)_
+// TRANSLATION MISSING
+** `+==id+`: the name used is the buffer unique identifier (`id`) _(WeeChat ≥ 4.3.0)_
* _name_: バッファの名前、NULL または空文字列の場合、現在のバッファ
(現在のウィンドウに表示されているバッファ) を返す; 名前が `(?i)`
で始まる場合、検索は大文字小文字を区別せずに検索 _(WeeChat バージョン 1.0 以上で利用可)_
@@ -14527,6 +14531,7 @@ C 言語での使用例:
----
struct t_gui_buffer *buffer1 = weechat_buffer_search ("irc", "libera.#weechat");
struct t_gui_buffer *buffer2 = weechat_buffer_search ("==", "irc.libera.#test"); /* WeeChat バージョン 1.0 以上で利用可 */
+struct t_gui_buffer *buffer3 = weechat_buffer_search ("==id", "1709797810942688"); /* WeeChat バージョン 4.3.0 以上で利用可 */
----
スクリプト (Python) での使用例:
diff --git a/doc/sr/weechat_plugin_api.sr.adoc b/doc/sr/weechat_plugin_api.sr.adoc
index 10bf970a6..3aaecc754 100644
--- a/doc/sr/weechat_plugin_api.sr.adoc
+++ b/doc/sr/weechat_plugin_api.sr.adoc
@@ -13882,9 +13882,10 @@ weechat.prnt(weechat.current_buffer(), "Текст у текућем бафер
==== buffer_search
-_Ажурирано у верзији 1.0._
+_Ажурирано у верзији 1.0, 4.3.0._
-Тражи бафер по додатку и/или имену.
+// TRANSLATION MISSING
+Search a buffer by plugin/name, full name or unique identifier (`id`).
Прототип:
@@ -13896,8 +13897,11 @@ struct t_gui_buffer *weechat_buffer_search (const char *plugin,
Аргументи:
-* _plugin_: име додатка, дозвољене су следеће специјалне вредности:
+// TRANSLATION MISSING
+* _plugin_: name of plugin, following special values are allowed:
** `+==+`: име које се користи је пуно име бафера (на пример: `irc.libera.#weechat` уместо `libera.#weechat`) _(WeeChat ≥ 1.0)_
+// TRANSLATION MISSING
+** `+==id+`: the name used is the buffer unique identifier (`id`) _(WeeChat ≥ 4.3.0)_
* _name_: име бафера, ако је NULL или празан стринг, враћа се текући бафер (бафер који се приказује у текућем прозору); ако име почиње са `(?i)`, претрага не прави разлику у величини слова _(WeeChat ≥ 1.0)_
Повратна вредност:
@@ -13910,6 +13914,7 @@ C примери:
----
struct t_gui_buffer *buffer1 = weechat_buffer_search ("irc", "libera.#weechat");
struct t_gui_buffer *buffer2 = weechat_buffer_search ("==", "irc.libera.#test"); /* WeeChat ≥ 1.0 */
+struct t_gui_buffer *buffer3 = weechat_buffer_search ("==id", "1709797810942688"); /* WeeChat ≥ 4.3.0 */
----
Скрипта (Python):
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c
index 5d3fa475c..0b0c5e8c3 100644
--- a/src/gui/gui-buffer.c
+++ b/src/gui/gui-buffer.c
@@ -2924,6 +2924,7 @@ gui_buffer_search_by_full_name (const char *full_name)
* Searches for a buffer by plugin and name, full name or id.
*
* If plugin is "==", the name is used to search by full name.
+ * If plugin is "==id", the name is used to search by id (which must be numeric).
*/
struct t_gui_buffer *
@@ -2931,6 +2932,8 @@ gui_buffer_search (const char *plugin, const char *name)
{
struct t_gui_buffer *ptr_buffer;
int plugin_match, plugin_case_sensitive, name_case_sensitive;
+ long long id;
+ char *error;
if (!name || !name[0])
return gui_current_window->buffer;
@@ -2938,6 +2941,13 @@ gui_buffer_search (const char *plugin, const char *name)
if (plugin && (strcmp (plugin, "==") == 0))
return gui_buffer_search_by_full_name (name);
+ if (plugin && (strcmp (plugin, "==id") == 0))
+ {
+ error = NULL;
+ id = strtoll (name, &error, 10);
+ return (error && !error[0]) ? gui_buffer_search_by_id (id) : NULL;
+ }
+
plugin_case_sensitive = 1;
name_case_sensitive = 1;
diff --git a/tests/unit/gui/test-gui-buffer.cpp b/tests/unit/gui/test-gui-buffer.cpp
index 1c4e1131b..60e3f1adc 100644
--- a/tests/unit/gui/test-gui-buffer.cpp
+++ b/tests/unit/gui/test-gui-buffer.cpp
@@ -1375,6 +1375,7 @@ TEST(GuiBuffer, SearchByFullName)
TEST(GuiBuffer, Search)
{
struct t_gui_buffer *buffer;
+ char str_id[128];
buffer = gui_buffer_new (NULL, TEST_BUFFER_NAME,
NULL, NULL, NULL,
@@ -1388,12 +1389,20 @@ TEST(GuiBuffer, Search)
POINTERS_EQUAL(gui_buffers, gui_buffer_search ("==", NULL));
POINTERS_EQUAL(gui_buffers, gui_buffer_search ("==", ""));
POINTERS_EQUAL(NULL, gui_buffer_search ("==", "(?i)"));
+ POINTERS_EQUAL(gui_buffers, gui_buffer_search ("==id", NULL));
+ POINTERS_EQUAL(gui_buffers, gui_buffer_search ("==id", ""));
POINTERS_EQUAL(NULL, gui_buffer_search ("==", "xxx"));
POINTERS_EQUAL(NULL, gui_buffer_search ("==", "weechat"));
POINTERS_EQUAL(gui_buffers, gui_buffer_search ("==", "core.weechat"));
POINTERS_EQUAL(buffer, gui_buffer_search ("==", "core." TEST_BUFFER_NAME));
+ POINTERS_EQUAL(NULL, gui_buffer_search ("==id", "xxx"));
+ POINTERS_EQUAL(NULL, gui_buffer_search ("==id", "-1"));
+ POINTERS_EQUAL(NULL, gui_buffer_search ("==id", "0"));
+ snprintf (str_id, sizeof (str_id), "%lld", gui_buffers->id);
+ POINTERS_EQUAL(gui_buffers, gui_buffer_search ("==id", str_id));
+
POINTERS_EQUAL(gui_buffers, gui_buffer_search ("", ""));
POINTERS_EQUAL(gui_buffers, gui_buffer_search ("", "(?i)"));