summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2010-04-03 19:11:02 +0200
committerSebastien Helleu <flashcode@flashtux.org>2010-04-03 19:11:02 +0200
commit96f49f39e0fb41e50b416fea9891d15fa2333a8e (patch)
tree88533b2e9740a1a08dae985ca980430623f1cb8a
parent187381f1d1fce9120efada0075e075a087655f3a (diff)
downloadweechat-96f49f39e0fb41e50b416fea9891d15fa2333a8e.zip
Add or remove highlight words in a buffer with "highlight_words_add" and "highlight_words_del" (for buffer_set)
-rw-r--r--doc/en/weechat_plugin_api.en.txt7
-rw-r--r--doc/fr/weechat_plugin_api.fr.txt8
-rw-r--r--doc/it/weechat_plugin_api.it.txt7
-rw-r--r--src/gui/gui-buffer.c151
4 files changed, 173 insertions, 0 deletions
diff --git a/doc/en/weechat_plugin_api.en.txt b/doc/en/weechat_plugin_api.en.txt
index 87afffec9..dcd484407 100644
--- a/doc/en/weechat_plugin_api.en.txt
+++ b/doc/en/weechat_plugin_api.en.txt
@@ -7066,6 +7066,13 @@ Arguments:
separated list of words to highlight in this buffer, for example:
"abc,def,ghi"
+| highlight_words_add | comma separated list of words |
+ comma separated list of words to highlight in this buffer, these words are
+ added to existing highlighted words in buffer
+
+| highlight_words_del | comma separated list of words |
+ comma separated list of words to remove from highlighted words on buffer
+
| highlight_tags | comma separated list of tags |
comma separated list of tags to highlight in this buffer
diff --git a/doc/fr/weechat_plugin_api.fr.txt b/doc/fr/weechat_plugin_api.fr.txt
index a664b3915..6ec5d0c93 100644
--- a/doc/fr/weechat_plugin_api.fr.txt
+++ b/doc/fr/weechat_plugin_api.fr.txt
@@ -7168,6 +7168,14 @@ Paramètres :
une liste de mots à mettre en valeur dans ce tampon, par exemple :
"abc,def,ghi"
+| highlight_words_add | liste de mots séparés par des virgules |
+ liste de mots à mettre en valeur dans ce tampon, ces mots sont ajoutés aux
+ mots existants pour le tampon
+
+| highlight_words_del | liste de mots séparés par des virgules |
+ liste de mots à supprimer de la liste des mots à mettre en valeur dans ce
+ tampon
+
| highlight_tags | liste d'étiquettes ("tags") séparées par des virgules |
liste d'étiquettes ("tags") à mettre en valeur pour ce tampon
diff --git a/doc/it/weechat_plugin_api.it.txt b/doc/it/weechat_plugin_api.it.txt
index d62ec15d2..6f72f3c59 100644
--- a/doc/it/weechat_plugin_api.it.txt
+++ b/doc/it/weechat_plugin_api.it.txt
@@ -7138,6 +7138,13 @@ Argomenti:
separated list of words to highlight in this buffer, for example:
"abc,def,ghi"
+| highlight_words_add | comma separated list of words |
+ comma separated list of words to highlight in this buffer, these words are
+ added to existing highlighted words in buffer
+
+| highlight_words_del | comma separated list of words |
+ comma separated list of words to remove from highlighted words on buffer
+
| highlight_tags | comma separated list of tags |
comma separated list of tags to highlight in this buffer
diff --git a/src/gui/gui-buffer.c b/src/gui/gui-buffer.c
index 52da85b27..d1912585c 100644
--- a/src/gui/gui-buffer.c
+++ b/src/gui/gui-buffer.c
@@ -36,6 +36,7 @@
#include "../core/wee-config.h"
#include "../core/wee-hook.h"
#include "../core/wee-infolist.h"
+#include "../core/wee-list.h"
#include "../core/wee-log.h"
#include "../core/wee-string.h"
#include "../core/wee-utf8.h"
@@ -955,6 +956,148 @@ gui_buffer_set_highlight_words (struct t_gui_buffer *buffer,
}
/*
+ * gui_buffer_set_highlight_words_list: set highlight words for a buffer with a
+ * list
+ */
+
+void
+gui_buffer_set_highlight_words_list (struct t_gui_buffer *buffer,
+ struct t_weelist *list)
+{
+ struct t_weelist_item *ptr_list_item;
+ int length;
+ const char *ptr_string;
+ char *words;
+
+ /* compute length */
+ length = 0;
+ for (ptr_list_item = weelist_get (list, 0); ptr_list_item;
+ ptr_list_item = weelist_next (ptr_list_item))
+ {
+ ptr_string = weelist_string (ptr_list_item);
+ if (ptr_string)
+ length += strlen (ptr_string) + 1;
+ }
+ length += 2; /* '\n' + '\0' */
+
+ /* allocate memory */
+ words = malloc (length);
+ if (!words)
+ return;
+
+ /* build string */
+ words[0] = '\0';
+ for (ptr_list_item = weelist_get (list, 0); ptr_list_item;
+ ptr_list_item = weelist_next (ptr_list_item))
+ {
+ ptr_string = weelist_string (ptr_list_item);
+ if (ptr_string)
+ {
+ strcat (words, ptr_string);
+ if (weelist_next (ptr_list_item))
+ strcat (words, ",");
+ }
+ }
+
+ gui_buffer_set_highlight_words (buffer, words);
+}
+
+/*
+ * gui_buffer_add_highlight_words: add highlight words for a buffer
+ */
+
+void
+gui_buffer_add_highlight_words (struct t_gui_buffer *buffer,
+ const char *words_to_add)
+{
+ char **current_words, **add_words;
+ int current_count, add_count, i;
+ struct t_weelist *list;
+
+ if (!words_to_add)
+ return;
+
+ list = weelist_new ();
+ if (!list)
+ return;
+
+ current_words = string_split (buffer->highlight_words, ",", 0, 0,
+ &current_count);
+ add_words = string_split (words_to_add, ",", 0, 0,
+ &add_count);
+
+ for (i = 0; i < current_count; i++)
+ {
+ if (!weelist_search (list, current_words[i]))
+ weelist_add (list, current_words[i], WEECHAT_LIST_POS_END, NULL);
+ }
+ for (i = 0; i < add_count; i++)
+ {
+ if (!weelist_search (list, add_words[i]))
+ weelist_add (list, add_words[i], WEECHAT_LIST_POS_END, NULL);
+ }
+
+ gui_buffer_set_highlight_words_list (buffer, list);
+
+ weelist_free (list);
+
+ if (current_words)
+ string_free_split (current_words);
+ if (add_words)
+ string_free_split (add_words);
+}
+
+/*
+ * gui_buffer_remove_highlight_words: remove highlight words in a buffer
+ */
+
+void
+gui_buffer_remove_highlight_words (struct t_gui_buffer *buffer,
+ const char *words_to_remove)
+{
+ char **current_words, **remove_words;
+ int current_count, remove_count, i, j, to_remove;
+ struct t_weelist *list;
+
+ if (!words_to_remove)
+ return;
+
+ list = weelist_new ();
+ if (!list)
+ return;
+
+ current_words = string_split (buffer->highlight_words, ",", 0, 0,
+ &current_count);
+ remove_words = string_split (words_to_remove, ",", 0, 0,
+ &remove_count);
+
+ for (i = 0; i < current_count; i++)
+ {
+ /* search if word is to be removed or not */
+ to_remove = 0;
+ for (j = 0; j < remove_count; j++)
+ {
+ if (strcmp (current_words[i], remove_words[j]) == 0)
+ {
+ to_remove = 1;
+ break;
+ }
+ }
+ if (!to_remove)
+ weelist_add (list, current_words[i], WEECHAT_LIST_POS_END, NULL);
+ }
+
+ gui_buffer_set_highlight_words_list (buffer, list);
+
+ weelist_free (list);
+
+ if (current_words)
+ string_free_split (current_words);
+ if (remove_words)
+ string_free_split (remove_words);
+}
+
+/*
* gui_buffer_set_highlight_tags: set highlight tags for a buffer
*/
@@ -1147,6 +1290,14 @@ gui_buffer_set (struct t_gui_buffer *buffer, const char *property,
{
gui_buffer_set_highlight_words (buffer, value);
}
+ else if (string_strcasecmp (property, "highlight_words_add") == 0)
+ {
+ gui_buffer_add_highlight_words (buffer, value);
+ }
+ else if (string_strcasecmp (property, "highlight_words_del") == 0)
+ {
+ gui_buffer_remove_highlight_words (buffer, value);
+ }
else if (string_strcasecmp (property, "highlight_tags") == 0)
{
gui_buffer_set_highlight_tags (buffer, value);