1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-04 00:33:13 +02:00

core: expand buffer local variables in evaluation of expressions (command /eval and function "string_eval_expression" in plugin API)

This commit is contained in:
Sebastien Helleu
2012-11-02 15:40:15 +01:00
parent f7b53fe6aa
commit 4d436e3ac6
18 changed files with 64 additions and 34 deletions
+2 -1
View File
@@ -230,7 +230,8 @@ To force a string comparison, add double quotes around each expression, for exam
Some variables are replaced in expression, using the format ${variable}, variable can be, by order of prioity :
1. the name of an option (file.section.option)
2. a hdata name/variable (the value is automatically converted to string), by default "window" and "buffer" point to current window/buffer.
2. the name of a local variable in buffer
3. a hdata name/variable (the value is automatically converted to string), by default "window" and "buffer" point to current window/buffer.
Format for hdata can be one of following:
hdata.var1.var2...: start with a hdata (pointer must be known), and ask variables one after one (other hdata can be followed)
hdata(list).var1.var2...: start with a hdata using a list, for example:
+2 -1
View File
@@ -230,7 +230,8 @@ To force a string comparison, add double quotes around each expression, for exam
Some variables are replaced in expression, using the format ${variable}, variable can be, by order of prioity :
1. the name of an option (file.section.option)
2. a hdata name/variable (the value is automatically converted to string), by default "window" and "buffer" point to current window/buffer.
2. the name of a local variable in buffer
3. a hdata name/variable (the value is automatically converted to string), by default "window" and "buffer" point to current window/buffer.
Format for hdata can be one of following:
hdata.var1.var2...: start with a hdata (pointer must be known), and ask variables one after one (other hdata can be followed)
hdata(list).var1.var2...: start with a hdata using a list, for example:
+2 -1
View File
@@ -230,7 +230,8 @@ Pour forcer une comparaison de chaînes, ajoutez des guillemets autour de chaque
Des variables sont remplacées dans l'expression, en utilisant le format ${variable}, la variable pouvant être, par ordre de priorité :
1. le nom d'une option (fichier.section.option)
2. le nom d'un hdata/variable (la valeur est automatiquement convertie en chaîne), par défaut "window" et "buffer" pointent vers la fenêtre et le tampon courants.
2. le nom d'une variable locale du tampon
3. le nom d'un hdata/variable (la valeur est automatiquement convertie en chaîne), par défaut "window" et "buffer" pointent vers la fenêtre et le tampon courants.
Le format du hdata peut être le suivant :
hdata.var1.var2...: démarrer avec un hdata (le pointeur doit être connu), et demander les variables l'une après l'autre (d'autres hdata peuvent être suivis)
hdata(list).var1.var2...: démarrer avec un hdata en utlisant une liste, par exemple :
+2 -1
View File
@@ -230,7 +230,8 @@ To force a string comparison, add double quotes around each expression, for exam
Some variables are replaced in expression, using the format ${variable}, variable can be, by order of prioity :
1. the name of an option (file.section.option)
2. a hdata name/variable (the value is automatically converted to string), by default "window" and "buffer" point to current window/buffer.
2. the name of a local variable in buffer
3. a hdata name/variable (the value is automatically converted to string), by default "window" and "buffer" point to current window/buffer.
Format for hdata can be one of following:
hdata.var1.var2...: start with a hdata (pointer must be known), and ask variables one after one (other hdata can be followed)
hdata(list).var1.var2...: start with a hdata using a list, for example:
+2 -1
View File
@@ -230,7 +230,8 @@ To force a string comparison, add double quotes around each expression, for exam
Some variables are replaced in expression, using the format ${variable}, variable can be, by order of prioity :
1. the name of an option (file.section.option)
2. a hdata name/variable (the value is automatically converted to string), by default "window" and "buffer" point to current window/buffer.
2. the name of a local variable in buffer
3. a hdata name/variable (the value is automatically converted to string), by default "window" and "buffer" point to current window/buffer.
Format for hdata can be one of following:
hdata.var1.var2...: start with a hdata (pointer must be known), and ask variables one after one (other hdata can be followed)
hdata(list).var1.var2...: start with a hdata using a list, for example:
+3 -2
View File
@@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.4.0-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2012-11-02 08:59+0100\n"
"POT-Creation-Date: 2012-11-02 15:35+0100\n"
"PO-Revision-Date: 2012-09-29 11:42+0200\n"
"Last-Translator: Jiri Golembiovsky <golemj@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@@ -1227,7 +1227,8 @@ msgid ""
"Some variables are replaced in expression, using the format ${variable}, "
"variable can be, by order of prioity :\n"
" 1. the name of an option (file.section.option)\n"
" 2. a hdata name/variable (the value is automatically converted to string), "
" 2. the name of a local variable in buffer\n"
" 3. a hdata name/variable (the value is automatically converted to string), "
"by default \"window\" and \"buffer\" point to current window/buffer.\n"
"Format for hdata can be one of following:\n"
" hdata.var1.var2...: start with a hdata (pointer must be known), and ask "
+3 -2
View File
@@ -23,7 +23,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.3.7-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2012-11-02 08:59+0100\n"
"POT-Creation-Date: 2012-11-02 15:35+0100\n"
"PO-Revision-Date: 2012-10-19 17:57+0100\n"
"Last-Translator: Nils Görs <weechatter@arcor.de>\n"
"Language-Team: German <weechatter@arcor.de>\n"
@@ -1286,7 +1286,8 @@ msgid ""
"Some variables are replaced in expression, using the format ${variable}, "
"variable can be, by order of prioity :\n"
" 1. the name of an option (file.section.option)\n"
" 2. a hdata name/variable (the value is automatically converted to string), "
" 2. the name of a local variable in buffer\n"
" 3. a hdata name/variable (the value is automatically converted to string), "
"by default \"window\" and \"buffer\" point to current window/buffer.\n"
"Format for hdata can be one of following:\n"
" hdata.var1.var2...: start with a hdata (pointer must be known), and ask "
+3 -2
View File
@@ -22,7 +22,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.4.0-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2012-11-02 08:59+0100\n"
"POT-Creation-Date: 2012-11-02 15:35+0100\n"
"PO-Revision-Date: 2012-09-29 11:42+0200\n"
"Last-Translator: Elián Hanisch <lambdae2@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@@ -1263,7 +1263,8 @@ msgid ""
"Some variables are replaced in expression, using the format ${variable}, "
"variable can be, by order of prioity :\n"
" 1. the name of an option (file.section.option)\n"
" 2. a hdata name/variable (the value is automatically converted to string), "
" 2. the name of a local variable in buffer\n"
" 3. a hdata name/variable (the value is automatically converted to string), "
"by default \"window\" and \"buffer\" point to current window/buffer.\n"
"Format for hdata can be one of following:\n"
" hdata.var1.var2...: start with a hdata (pointer must be known), and ask "
+6 -4
View File
@@ -21,8 +21,8 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.4.0-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2012-11-02 08:59+0100\n"
"PO-Revision-Date: 2012-10-27 12:51+0200\n"
"POT-Creation-Date: 2012-11-02 15:35+0100\n"
"PO-Revision-Date: 2012-11-02 15:35+0100\n"
"Last-Translator: Sebastien Helleu <flashcode@flashtux.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
"Language: French\n"
@@ -1263,7 +1263,8 @@ msgid ""
"Some variables are replaced in expression, using the format ${variable}, "
"variable can be, by order of prioity :\n"
" 1. the name of an option (file.section.option)\n"
" 2. a hdata name/variable (the value is automatically converted to string), "
" 2. the name of a local variable in buffer\n"
" 3. a hdata name/variable (the value is automatically converted to string), "
"by default \"window\" and \"buffer\" point to current window/buffer.\n"
"Format for hdata can be one of following:\n"
" hdata.var1.var2...: start with a hdata (pointer must be known), and ask "
@@ -1320,7 +1321,8 @@ msgstr ""
"Des variables sont remplacées dans l'expression, en utilisant le format "
"${variable}, la variable pouvant être, par ordre de priorité :\n"
" 1. le nom d'une option (fichier.section.option)\n"
" 2. le nom d'un hdata/variable (la valeur est automatiquement convertie en "
" 2. le nom d'une variable locale du tampon\n"
" 3. le nom d'un hdata/variable (la valeur est automatiquement convertie en "
"chaîne), par défaut \"window\" et \"buffer\" pointent vers la fenêtre et le "
"tampon courants.\n"
"Le format du hdata peut être le suivant :\n"
+3 -2
View File
@@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.4.0-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2012-11-02 08:59+0100\n"
"POT-Creation-Date: 2012-11-02 15:35+0100\n"
"PO-Revision-Date: 2012-09-29 11:42+0200\n"
"Last-Translator: Andras Voroskoi <voroskoi@frugalware.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@@ -1165,7 +1165,8 @@ msgid ""
"Some variables are replaced in expression, using the format ${variable}, "
"variable can be, by order of prioity :\n"
" 1. the name of an option (file.section.option)\n"
" 2. a hdata name/variable (the value is automatically converted to string), "
" 2. the name of a local variable in buffer\n"
" 3. a hdata name/variable (the value is automatically converted to string), "
"by default \"window\" and \"buffer\" point to current window/buffer.\n"
"Format for hdata can be one of following:\n"
" hdata.var1.var2...: start with a hdata (pointer must be known), and ask "
+3 -2
View File
@@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.4.0-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2012-11-02 08:59+0100\n"
"POT-Creation-Date: 2012-11-02 15:35+0100\n"
"PO-Revision-Date: 2012-09-29 11:42+0200\n"
"Last-Translator: Marco Paolone <marcopaolone@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@@ -1252,7 +1252,8 @@ msgid ""
"Some variables are replaced in expression, using the format ${variable}, "
"variable can be, by order of prioity :\n"
" 1. the name of an option (file.section.option)\n"
" 2. a hdata name/variable (the value is automatically converted to string), "
" 2. the name of a local variable in buffer\n"
" 3. a hdata name/variable (the value is automatically converted to string), "
"by default \"window\" and \"buffer\" point to current window/buffer.\n"
"Format for hdata can be one of following:\n"
" hdata.var1.var2...: start with a hdata (pointer must be known), and ask "
+3 -2
View File
@@ -20,7 +20,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.4.0-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2012-11-02 08:59+0100\n"
"POT-Creation-Date: 2012-11-02 15:35+0100\n"
"PO-Revision-Date: 2012-09-29 11:42+0200\n"
"Last-Translator: AYANOKOUZI, Ryuunosuke <i38w7i3@yahoo.co.jp>\n"
"Language-Team: Japanese <https://github.com/l/WeeChat>\n"
@@ -1238,7 +1238,8 @@ msgid ""
"Some variables are replaced in expression, using the format ${variable}, "
"variable can be, by order of prioity :\n"
" 1. the name of an option (file.section.option)\n"
" 2. a hdata name/variable (the value is automatically converted to string), "
" 2. the name of a local variable in buffer\n"
" 3. a hdata name/variable (the value is automatically converted to string), "
"by default \"window\" and \"buffer\" point to current window/buffer.\n"
"Format for hdata can be one of following:\n"
" hdata.var1.var2...: start with a hdata (pointer must be known), and ask "
+3 -2
View File
@@ -21,7 +21,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.4.0-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2012-11-02 08:59+0100\n"
"POT-Creation-Date: 2012-11-02 15:35+0100\n"
"PO-Revision-Date: 2012-09-29 11:42+0200\n"
"Last-Translator: Krzysztof Korościk <soltys@szluug.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@@ -1259,7 +1259,8 @@ msgid ""
"Some variables are replaced in expression, using the format ${variable}, "
"variable can be, by order of prioity :\n"
" 1. the name of an option (file.section.option)\n"
" 2. a hdata name/variable (the value is automatically converted to string), "
" 2. the name of a local variable in buffer\n"
" 3. a hdata name/variable (the value is automatically converted to string), "
"by default \"window\" and \"buffer\" point to current window/buffer.\n"
"Format for hdata can be one of following:\n"
" hdata.var1.var2...: start with a hdata (pointer must be known), and ask "
+3 -2
View File
@@ -21,7 +21,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.4.0-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2012-11-02 08:59+0100\n"
"POT-Creation-Date: 2012-11-02 15:35+0100\n"
"PO-Revision-Date: 2012-09-29 11:43+0200\n"
"Last-Translator: Sergio Durigan Junior <sergiosdj@gmail.com>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@@ -1294,7 +1294,8 @@ msgid ""
"Some variables are replaced in expression, using the format ${variable}, "
"variable can be, by order of prioity :\n"
" 1. the name of an option (file.section.option)\n"
" 2. a hdata name/variable (the value is automatically converted to string), "
" 2. the name of a local variable in buffer\n"
" 3. a hdata name/variable (the value is automatically converted to string), "
"by default \"window\" and \"buffer\" point to current window/buffer.\n"
"Format for hdata can be one of following:\n"
" hdata.var1.var2...: start with a hdata (pointer must be known), and ask "
+3 -2
View File
@@ -21,7 +21,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WeeChat 0.4.0-dev\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2012-11-02 08:59+0100\n"
"POT-Creation-Date: 2012-11-02 15:35+0100\n"
"PO-Revision-Date: 2012-09-29 11:43+0200\n"
"Last-Translator: Aleksey V Zapparov AKA ixti <ixti@member.fsf.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\n"
@@ -1183,7 +1183,8 @@ msgid ""
"Some variables are replaced in expression, using the format ${variable}, "
"variable can be, by order of prioity :\n"
" 1. the name of an option (file.section.option)\n"
" 2. a hdata name/variable (the value is automatically converted to string), "
" 2. the name of a local variable in buffer\n"
" 3. a hdata name/variable (the value is automatically converted to string), "
"by default \"window\" and \"buffer\" point to current window/buffer.\n"
"Format for hdata can be one of following:\n"
" hdata.var1.var2...: start with a hdata (pointer must be known), and ask "
+3 -2
View File
@@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: flashcode@flashtux.org\n"
"POT-Creation-Date: 2012-11-02 08:59+0100\n"
"POT-Creation-Date: 2012-11-02 15:35+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -1025,7 +1025,8 @@ msgid ""
"Some variables are replaced in expression, using the format ${variable}, "
"variable can be, by order of prioity :\n"
" 1. the name of an option (file.section.option)\n"
" 2. a hdata name/variable (the value is automatically converted to string), "
" 2. the name of a local variable in buffer\n"
" 3. a hdata name/variable (the value is automatically converted to string), "
"by default \"window\" and \"buffer\" point to current window/buffer.\n"
"Format for hdata can be one of following:\n"
" hdata.var1.var2...: start with a hdata (pointer must be known), and ask "
+2 -1
View File
@@ -5796,7 +5796,8 @@ command_init ()
"Some variables are replaced in expression, using the "
"format ${variable}, variable can be, by order of prioity :\n"
" 1. the name of an option (file.section.option)\n"
" 2. a hdata name/variable (the value is automatically "
" 2. the name of a local variable in buffer\n"
" 3. a hdata name/variable (the value is automatically "
"converted to string), by default \"window\" and \"buffer\" "
"point to current window/buffer.\n"
"Format for hdata can be one of following:\n"
+16 -4
View File
@@ -36,6 +36,7 @@
#include "wee-hdata.h"
#include "wee-hook.h"
#include "wee-string.h"
#include "../gui/gui-buffer.h"
#include "../gui/gui-color.h"
#include "../gui/gui-window.h"
#include "../plugins/plugin.h"
@@ -212,7 +213,8 @@ end:
* by order of priority:
* 1. an extra variable (from hashtable "extra_vars")
* 2. an name of option (file.section.option)
* 3. a hdata name/variable
* 3. a buffer local variable
* 4. a hdata name/variable
* Examples:
* option: ${weechat.look.scroll_amount}
* hdata : ${window.buffer.full_name}
@@ -224,6 +226,7 @@ eval_replace_vars_cb (void *data, const char *text)
{
struct t_hashtable *pointers, *extra_vars;
struct t_config_option *ptr_option;
struct t_gui_buffer *ptr_buffer;
char str_value[64], *value, *pos, *pos1, *pos2, *hdata_name, *list_name;
char *tmp;
const char *ptr_value;
@@ -233,12 +236,12 @@ eval_replace_vars_cb (void *data, const char *text)
pointers = (struct t_hashtable *)(((void **)data)[0]);
extra_vars = (struct t_hashtable *)(((void **)data)[1]);
/* first look for var in hashtable "extra_vars" */
/* 1. look for var in hashtable "extra_vars" */
ptr_value = hashtable_get (extra_vars, text);
if (ptr_value)
return strdup (ptr_value);
/* look for name of option: if found, return this value */
/* 2. look for name of option: if found, return this value */
config_file_search_with_string (text, NULL, NULL, &ptr_option, NULL);
if (ptr_option)
{
@@ -261,7 +264,16 @@ eval_replace_vars_cb (void *data, const char *text)
}
}
/* look for hdata */
/* 3. look for local variable in buffer */
ptr_buffer = hashtable_get (pointers, "buffer");
if (ptr_buffer)
{
ptr_value = hashtable_get (ptr_buffer->local_variables, text);
if (ptr_value)
return strdup (ptr_value);
}
/* 4. look for hdata */
value = NULL;
hdata_name = NULL;
list_name = NULL;