From 1759b1f0041850c70c26d67be2b930964251d7a6 Mon Sep 17 00:00:00 2001 From: Emmanuel Bouthenot Date: Thu, 28 Sep 2006 13:30:54 +0000 Subject: [PATCH] minor improvements on aspell plugin : + spellchecking is now available on commands like /me, /away, /query, ... + do not colorize urls : words begining with http(s)://, ftp(s)://, fish://, file://, etc + do not colorize words begining with '#' (channels) , '/' (commands), '-' (command option) --- src/plugins/aspell/weechat-aspell.c | 82 +++++++++++++++++---- src/plugins/aspell/weechat-aspell.h | 25 +++++++ weechat/src/plugins/aspell/weechat-aspell.c | 82 +++++++++++++++++---- weechat/src/plugins/aspell/weechat-aspell.h | 25 +++++++ 4 files changed, 184 insertions(+), 30 deletions(-) diff --git a/src/plugins/aspell/weechat-aspell.c b/src/plugins/aspell/weechat-aspell.c index 984f4c55e..a0ef8e163 100644 --- a/src/plugins/aspell/weechat-aspell.c +++ b/src/plugins/aspell/weechat-aspell.c @@ -1180,6 +1180,39 @@ weechat_aspell_is_simili_number (char *word) return ret; } +/* + * weechat_aspell_is_url : + * detect if a word is an url + */ +int +weechat_aspell_is_url (char *word) +{ + int ret; + + ret = 0; + if (strncasecmp(word, "http://", 7) == 0 + || strncasecmp(word, "https://", 8) == 0 + || strncasecmp(word, "ftp://", 6) == 0 + || strncasecmp(word, "tftp://", 7) == 0 + || strncasecmp(word, "ftps://", 7) == 0 + || strncasecmp(word, "ssh://", 6) == 0 + || strncasecmp(word, "fish://", 7) == 0 + || strncasecmp(word, "dict://", 7) == 0 + || strncasecmp(word, "ldap://", 7) == 0 + || strncasecmp(word, "file://", 7) == 0 + || strncasecmp(word, "telnet://", 9) == 0 + || strncasecmp(word, "gopher://", 9) == 0 + || strncasecmp(word, "irc://", 6) == 0 + || strncasecmp(word, "ircs://", 7) == 0 + || strncasecmp(word, "irc6://", 7) == 0 + || strncasecmp(word, "irc6s://", 8) == 0 + || strncasecmp(word, "cvs://", 6) == 0 + || strncasecmp(word, "svn://", 6) == 0 + || strncasecmp(word, "svn+ssh://", 10) == 0) + ret = 1; + return ret; +} + /* * weechat_aspell_keyb_check : handler to check spelling on input line */ @@ -1189,6 +1222,8 @@ weechat_aspell_keyb_check (t_weechat_plugin *p, int argc, char **argv, { char *server, *channel; aspell_config_t *c; + cmds_keep_t *cmd; + int keep_cmd_found; char *input, *ptr_input, *pos_space, *clword; int count, offset; @@ -1225,40 +1260,57 @@ weechat_aspell_keyb_check (t_weechat_plugin *p, int argc, char **argv, if (!input[0]) return PLUGIN_RC_OK; - + if (input[0] == '/') - return PLUGIN_RC_OK; + { + keep_cmd_found = 0; + for(cmd = cmd_tokeep; cmd->cmd; ++cmd) + { + if (strncasecmp (input, cmd->cmd, cmd->len) == 0) { + keep_cmd_found = 1; + break; + } + } + if (keep_cmd_found == 0) + return PLUGIN_RC_OK; + } count = 0; ptr_input = input; weechat_aspell_plugin->input_color (weechat_aspell_plugin, 0, 0, 0); while (ptr_input && ptr_input[0]) - { + { pos_space = strchr (ptr_input, ' '); if (pos_space) pos_space[0] = '\0'; - clword = weechat_aspell_clean_word (ptr_input, &offset); - if (clword) + if (ptr_input[0] != '/' && ptr_input[0] != '-' && ptr_input[0] != '#') { - if ( (int) strlen (clword) >= aspell_plugin_options.word_size) + clword = weechat_aspell_clean_word (ptr_input, &offset); + if (clword) { - if (!weechat_aspell_is_simili_number (clword)) + if ( (int) strlen (clword) >= aspell_plugin_options.word_size) { - if (!weechat_aspell_nick_in_channel (clword, server, channel)) + if (!weechat_aspell_is_url (clword)) { - if (aspell_speller_check (c->speller->speller, clword, -1) != 1) + if (!weechat_aspell_is_simili_number (clword)) { - if (count == 0) - weechat_aspell_plugin->input_color (weechat_aspell_plugin, 0, 0, 0); - weechat_aspell_plugin->input_color (weechat_aspell_plugin, aspell_plugin_options.color, - ptr_input - input + offset, strlen (clword)); - count++; + if (!weechat_aspell_nick_in_channel (clword, server, channel)) + { + if (aspell_speller_check (c->speller->speller, clword, -1) != 1) + { + if (count == 0) + weechat_aspell_plugin->input_color (weechat_aspell_plugin, 0, 0, 0); + weechat_aspell_plugin->input_color (weechat_aspell_plugin, aspell_plugin_options.color, + ptr_input - input + offset, strlen (clword)); + count++; + } + } } } } + free (clword); } - free (clword); } if (pos_space) diff --git a/src/plugins/aspell/weechat-aspell.h b/src/plugins/aspell/weechat-aspell.h index 99193b0f2..156ac5384 100644 --- a/src/plugins/aspell/weechat-aspell.h +++ b/src/plugins/aspell/weechat-aspell.h @@ -78,6 +78,12 @@ typedef struct iso_countries_t char *name; } iso_countries_t; +typedef struct cmds_keep_t +{ + char *cmd; + int len; +} cmds_keep_t; + /* aspell supported langs 2006-05-27 */ iso_langs_t langs_avail[] = { @@ -178,4 +184,23 @@ iso_countries_t countries_avail[] = { NULL, NULL} }; +/* internal or irc commands to be use with spellchecking */ +cmds_keep_t cmd_tokeep[] = +{ + { "/builtin ", 9 }, + { "/ame " , 5 }, + { "/amsg " , 6 }, + { "/away " , 6 }, + { "/cycle " , 7 }, + { "/kick " , 6 }, + { "/kickban " , 9 }, + { "/me " , 4 }, + { "/notice " , 8 }, + { "/part " , 6 }, + { "/query " , 7 }, + { "/quit " , 6 }, + { "/topic " , 7 }, + { NULL, 0} +}; + #endif /* WEECHAT_ASPELL__H */ diff --git a/weechat/src/plugins/aspell/weechat-aspell.c b/weechat/src/plugins/aspell/weechat-aspell.c index 984f4c55e..a0ef8e163 100644 --- a/weechat/src/plugins/aspell/weechat-aspell.c +++ b/weechat/src/plugins/aspell/weechat-aspell.c @@ -1180,6 +1180,39 @@ weechat_aspell_is_simili_number (char *word) return ret; } +/* + * weechat_aspell_is_url : + * detect if a word is an url + */ +int +weechat_aspell_is_url (char *word) +{ + int ret; + + ret = 0; + if (strncasecmp(word, "http://", 7) == 0 + || strncasecmp(word, "https://", 8) == 0 + || strncasecmp(word, "ftp://", 6) == 0 + || strncasecmp(word, "tftp://", 7) == 0 + || strncasecmp(word, "ftps://", 7) == 0 + || strncasecmp(word, "ssh://", 6) == 0 + || strncasecmp(word, "fish://", 7) == 0 + || strncasecmp(word, "dict://", 7) == 0 + || strncasecmp(word, "ldap://", 7) == 0 + || strncasecmp(word, "file://", 7) == 0 + || strncasecmp(word, "telnet://", 9) == 0 + || strncasecmp(word, "gopher://", 9) == 0 + || strncasecmp(word, "irc://", 6) == 0 + || strncasecmp(word, "ircs://", 7) == 0 + || strncasecmp(word, "irc6://", 7) == 0 + || strncasecmp(word, "irc6s://", 8) == 0 + || strncasecmp(word, "cvs://", 6) == 0 + || strncasecmp(word, "svn://", 6) == 0 + || strncasecmp(word, "svn+ssh://", 10) == 0) + ret = 1; + return ret; +} + /* * weechat_aspell_keyb_check : handler to check spelling on input line */ @@ -1189,6 +1222,8 @@ weechat_aspell_keyb_check (t_weechat_plugin *p, int argc, char **argv, { char *server, *channel; aspell_config_t *c; + cmds_keep_t *cmd; + int keep_cmd_found; char *input, *ptr_input, *pos_space, *clword; int count, offset; @@ -1225,40 +1260,57 @@ weechat_aspell_keyb_check (t_weechat_plugin *p, int argc, char **argv, if (!input[0]) return PLUGIN_RC_OK; - + if (input[0] == '/') - return PLUGIN_RC_OK; + { + keep_cmd_found = 0; + for(cmd = cmd_tokeep; cmd->cmd; ++cmd) + { + if (strncasecmp (input, cmd->cmd, cmd->len) == 0) { + keep_cmd_found = 1; + break; + } + } + if (keep_cmd_found == 0) + return PLUGIN_RC_OK; + } count = 0; ptr_input = input; weechat_aspell_plugin->input_color (weechat_aspell_plugin, 0, 0, 0); while (ptr_input && ptr_input[0]) - { + { pos_space = strchr (ptr_input, ' '); if (pos_space) pos_space[0] = '\0'; - clword = weechat_aspell_clean_word (ptr_input, &offset); - if (clword) + if (ptr_input[0] != '/' && ptr_input[0] != '-' && ptr_input[0] != '#') { - if ( (int) strlen (clword) >= aspell_plugin_options.word_size) + clword = weechat_aspell_clean_word (ptr_input, &offset); + if (clword) { - if (!weechat_aspell_is_simili_number (clword)) + if ( (int) strlen (clword) >= aspell_plugin_options.word_size) { - if (!weechat_aspell_nick_in_channel (clword, server, channel)) + if (!weechat_aspell_is_url (clword)) { - if (aspell_speller_check (c->speller->speller, clword, -1) != 1) + if (!weechat_aspell_is_simili_number (clword)) { - if (count == 0) - weechat_aspell_plugin->input_color (weechat_aspell_plugin, 0, 0, 0); - weechat_aspell_plugin->input_color (weechat_aspell_plugin, aspell_plugin_options.color, - ptr_input - input + offset, strlen (clword)); - count++; + if (!weechat_aspell_nick_in_channel (clword, server, channel)) + { + if (aspell_speller_check (c->speller->speller, clword, -1) != 1) + { + if (count == 0) + weechat_aspell_plugin->input_color (weechat_aspell_plugin, 0, 0, 0); + weechat_aspell_plugin->input_color (weechat_aspell_plugin, aspell_plugin_options.color, + ptr_input - input + offset, strlen (clword)); + count++; + } + } } } } + free (clword); } - free (clword); } if (pos_space) diff --git a/weechat/src/plugins/aspell/weechat-aspell.h b/weechat/src/plugins/aspell/weechat-aspell.h index 99193b0f2..156ac5384 100644 --- a/weechat/src/plugins/aspell/weechat-aspell.h +++ b/weechat/src/plugins/aspell/weechat-aspell.h @@ -78,6 +78,12 @@ typedef struct iso_countries_t char *name; } iso_countries_t; +typedef struct cmds_keep_t +{ + char *cmd; + int len; +} cmds_keep_t; + /* aspell supported langs 2006-05-27 */ iso_langs_t langs_avail[] = { @@ -178,4 +184,23 @@ iso_countries_t countries_avail[] = { NULL, NULL} }; +/* internal or irc commands to be use with spellchecking */ +cmds_keep_t cmd_tokeep[] = +{ + { "/builtin ", 9 }, + { "/ame " , 5 }, + { "/amsg " , 6 }, + { "/away " , 6 }, + { "/cycle " , 7 }, + { "/kick " , 6 }, + { "/kickban " , 9 }, + { "/me " , 4 }, + { "/notice " , 8 }, + { "/part " , 6 }, + { "/query " , 7 }, + { "/quit " , 6 }, + { "/topic " , 7 }, + { NULL, 0} +}; + #endif /* WEECHAT_ASPELL__H */