From fec8a1d1224fb3255213fc0f52ea8e00449f966b Mon Sep 17 00:00:00 2001 From: Sebastien Helleu Date: Fri, 4 Jan 2013 18:41:27 +0100 Subject: [PATCH] aspell: ignore self and remote nicks in private buffers --- ChangeLog | 3 +- src/plugins/aspell/weechat-aspell.c | 57 ++++++++++++++++------------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index cc20b00c1..7a9b5ad6e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,7 @@ WeeChat ChangeLog ================= Sébastien Helleu -v0.4.0-rc1, 2013-01-01 +v0.4.0-rc1, 2013-01-04 Version 0.4.0 (under dev!) @@ -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: ignore self and remote nicks in private buffers * 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 diff --git a/src/plugins/aspell/weechat-aspell.c b/src/plugins/aspell/weechat-aspell.c index 702500b96..039c4fa9d 100644 --- a/src/plugins/aspell/weechat-aspell.c +++ b/src/plugins/aspell/weechat-aspell.c @@ -630,41 +630,48 @@ weechat_aspell_string_is_simili_number (const char *word) int weechat_aspell_check_word (struct t_gui_buffer *buffer, const char *word) { + const char *buffer_type, *buffer_nick, *buffer_channel; struct t_aspell_speller *ptr_speller; - int rc; - rc = 0; /* word too small? then do not check word */ if ((weechat_config_integer (weechat_aspell_config_check_word_min_length) > 0) && ((int)strlen (word) < weechat_config_integer (weechat_aspell_config_check_word_min_length))) - rc = 1; - else + return 1; + + /* word is a number? then do not check word */ + if (weechat_aspell_string_is_simili_number (word)) + return 1; + + /* word is a nick of nicklist on this buffer? then do not check word */ + if (weechat_nicklist_search_nick (buffer, NULL, word)) + return 1; + + /* for "private" buffers, ignore self and remote nicks */ + buffer_type = weechat_buffer_get_string (buffer, "localvar_type"); + if (buffer_type && (strcmp (buffer_type, "private") == 0)) { - /* word is a number? then do not check word */ - if (weechat_aspell_string_is_simili_number (word)) - rc = 1; - else + /* check seld nick */ + buffer_nick = weechat_buffer_get_string (buffer, "localvar_nick"); + if (buffer_nick && (weechat_strcasecmp (buffer_nick, word) == 0)) + return 1; + /* check remote nick */ + buffer_channel = weechat_buffer_get_string (buffer, "localvar_channel"); + if (buffer_channel && (weechat_strcasecmp (buffer_channel, word) == 0)) + return 1; + } + + /* check word with all spellers for this buffer (order is important) */ + for (ptr_speller = weechat_aspell_spellers; ptr_speller; + ptr_speller = ptr_speller->next_speller) + { + if (aspell_speller_check (ptr_speller->speller, word, -1) == 1) { - /* word is a nick of nicklist on this buffer? then do not check word */ - if (weechat_nicklist_search_nick (buffer, NULL, word)) - rc = 1; - else - { - /* check word with all spellers for this buffer (order is important) */ - for (ptr_speller = weechat_aspell_spellers; ptr_speller; - ptr_speller = ptr_speller->next_speller) - { - if (aspell_speller_check (ptr_speller->speller, word, -1) == 1) - { - rc = 1; - break; - } - } - } + return 1; } } - return rc; + /* misspelled word! */ + return 0; } /*