From 3df1d70bb56be1ecd3304c5eb7c8ead12e792489 Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Tue, 1 Jan 2013 17:26:50 +0100 Subject: [PATCH] aspell: add signal "aspell_suggest" (sent when new suggestions are displayed) --- ChangeLog | 1 + doc/en/weechat_plugin_api.en.txt | 5 ++++ doc/fr/weechat_plugin_api.fr.txt | 5 ++++ doc/it/weechat_plugin_api.it.txt | 6 +++++ src/plugins/aspell/weechat-aspell-bar-item.c | 11 ++++++--- src/plugins/aspell/weechat-aspell.c | 25 +++++++++++++++++--- 6 files changed, 47 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0dfecd958..cc20b00c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -61,6 +61,7 @@ Version 0.4.0 (under dev!) hook_connect (task #11205) * alias: give higher priority to aliases (2000) so that they take precedence over an existing command +* aspell: add signal "aspell_suggest" (sent when new suggestions are displayed) * aspell: add bar items "aspell_dict" (dictionary used on current buffer) and "aspell_suggest" (suggestions for misspelled word at cursor), add option aspell.check.suggestions (task #12061) diff --git a/doc/en/weechat_plugin_api.en.txt b/doc/en/weechat_plugin_api.en.txt index 4b0a663e1..1186f9ec7 100644 --- a/doc/en/weechat_plugin_api.en.txt +++ b/doc/en/weechat_plugin_api.en.txt @@ -7513,6 +7513,11 @@ Arguments: |======================================== | Plugin | Signal | Arguments | Description +| aspell | aspell_suggest + + (_new in version 0.4.0_) | + pointer: buffer | + new suggestions for a misspelled word + | guile | guile_script_loaded + (_new in version 0.3.9_) | string: path to script | diff --git a/doc/fr/weechat_plugin_api.fr.txt b/doc/fr/weechat_plugin_api.fr.txt index e1a5df460..7b59a7e16 100644 --- a/doc/fr/weechat_plugin_api.fr.txt +++ b/doc/fr/weechat_plugin_api.fr.txt @@ -7626,6 +7626,11 @@ Paramètres : |======================================== | Extension | Signal | Paramètres | Description +| aspell | aspell_suggest + + (_nouveau dans la version 0.4.0_) | + pointeur : tampon | + nouvelles suggestions pour un mot mal orthographié + | guile | guile_script_loaded + (_nouveau dans la version 0.3.9_) | chaîne: chemin vers le script | diff --git a/doc/it/weechat_plugin_api.it.txt b/doc/it/weechat_plugin_api.it.txt index 6415725ca..380d13e86 100644 --- a/doc/it/weechat_plugin_api.it.txt +++ b/doc/it/weechat_plugin_api.it.txt @@ -7554,6 +7554,12 @@ Argomenti: |======================================== | Plugin | Segnale | Argomenti | Descrizione +// TRANSLATION MISSING +| aspell | aspell_suggest + + (_novità nella versione 0.4.0_) | + pointer: buffer | + new suggestions for a misspelled word + // TRANSLATION MISSING | guile | guile_script_loaded + (_novità nella versione 0.3.9_) | diff --git a/src/plugins/aspell/weechat-aspell-bar-item.c b/src/plugins/aspell/weechat-aspell-bar-item.c index 5201846b0..e0e12e7ef 100644 --- a/src/plugins/aspell/weechat-aspell-bar-item.c +++ b/src/plugins/aspell/weechat-aspell-bar-item.c @@ -68,7 +68,7 @@ weechat_aspell_bar_item_suggest (void *data, struct t_gui_bar_item *item, { struct t_gui_buffer *buffer; const char *suggestions; - char str_delim[128], *suggestions2; + char str_delim[128], *pos, *suggestions2; /* make C compiler happy */ (void) data; @@ -87,14 +87,19 @@ weechat_aspell_bar_item_suggest (void *data, struct t_gui_bar_item *item, "localvar_aspell_suggest"); if (suggestions) { + pos = strchr (suggestions, ':'); + if (pos) + pos++; + else + pos = suggestions; snprintf (str_delim, sizeof (str_delim), "%s/%s", weechat_color ("bar_delim"), weechat_color ("bar_fg")); - suggestions2 = weechat_string_replace (suggestions, "/", str_delim); + suggestions2 = weechat_string_replace (pos, "/", str_delim); if (suggestions2) return suggestions2; - return strdup (suggestions); + return strdup (pos); } } diff --git a/src/plugins/aspell/weechat-aspell.c b/src/plugins/aspell/weechat-aspell.c index b302dc491..702500b96 100644 --- a/src/plugins/aspell/weechat-aspell.c +++ b/src/plugins/aspell/weechat-aspell.c @@ -747,6 +747,7 @@ weechat_aspell_modifier_cb (void *data, const char *modifier, struct t_gui_buffer *buffer; char *result, *ptr_string, *pos_space, *ptr_end, save_end; char *word_for_suggestions, *old_suggestions, *suggestions; + char *word_and_suggestions; const char *color_normal, *color_error, *ptr_suggestions; int buffer_has_changed, utf8_char_int, char_size; int length, index_result, length_word, word_ok; @@ -987,8 +988,21 @@ weechat_aspell_modifier_cb (void *data, const char *modifier, suggestions = weechat_aspell_get_suggestions (word_for_suggestions); if (suggestions) { - weechat_buffer_set (buffer, "localvar_set_aspell_suggest", - suggestions); + length = strlen (word_for_suggestions) + 1 /* ":" */ + + strlen (suggestions) + 1; + word_and_suggestions = malloc (length); + if (word_and_suggestions) + { + snprintf (word_and_suggestions, length, "%s:%s", + word_for_suggestions, suggestions); + weechat_buffer_set (buffer, "localvar_set_aspell_suggest", + word_and_suggestions); + free (word_and_suggestions); + } + else + { + weechat_buffer_set (buffer, "localvar_del_aspell_suggest", ""); + } free (suggestions); } else @@ -1002,7 +1016,10 @@ weechat_aspell_modifier_cb (void *data, const char *modifier, weechat_buffer_set (buffer, "localvar_del_aspell_suggest", ""); } - /* if suggestions have changed, update the bar item */ + /* + * if suggestions have changed, update the bar item + * and send signal "aspell_suggest" + */ ptr_suggestions = weechat_buffer_get_string (buffer, "localvar_aspell_suggest"); if ((old_suggestions && !ptr_suggestions) @@ -1011,6 +1028,8 @@ weechat_aspell_modifier_cb (void *data, const char *modifier, && (strcmp (old_suggestions, ptr_suggestions) != 0))) { weechat_bar_item_update ("aspell_suggest"); + weechat_hook_signal_send ("aspell_suggest", + WEECHAT_HOOK_SIGNAL_POINTER, buffer); } if (old_suggestions) free (old_suggestions);