diff options
| author | Tom Wesley | 2014-06-10 19:24:09 +0100 |
|---|---|---|
| committer | Tom Wesley | 2014-06-10 19:24:09 +0100 |
| commit | 37a10e7d08390547c9771953110d83212f0d62b4 (patch) | |
| tree | 624f0b00f86066b13d8301e78cb13b20538a2e4b /scripts | |
| parent | 5cdd2be80b0111edf164c3ceeca7153a81b23f90 (diff) | |
| download | scripts.irssi.org-37a10e7d08390547c9771953110d83212f0d62b4.tar.bz2 | |
Add aspell_complete.pl
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/aspell_complete.pl | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/scripts/aspell_complete.pl b/scripts/aspell_complete.pl new file mode 100644 index 0000000..da8d08c --- /dev/null +++ b/scripts/aspell_complete.pl @@ -0,0 +1,86 @@ +#### +# needs: +# - Text::Aspell +# - GNU Aspell - http://aspell.net/ +# +# settings: +# spell_dict - A comma or whitespace seperated list of dictionaries to use. +# First in the list is the default. +# Bind rotate_dict to easily cycle through the list of dictionaries. +# spell_suggestion_mode - The aspell suggestion mode. +# For infos on suggestion modes see the aspell manual. +# + + +use strict; +use vars qw($VERSION %IRSSI); + +use Irssi; +use Text::Aspell; + +$VERSION = '1.00'; +%IRSSI = ( + authors => 'Philipp Haegi', + contact => 'phaegi\@mimir.ch', + name => 'aspell_complete', + description => 'Adds Text::Aspell suggestions to the list of completions', + license => 'Public Domain', + url => 'http://www.mimir.ch/ph/', + changed => '2004-02-05', + commands => 'rotate_dict', + note => '', +); + +my ($setting_spell_dict, $setting_suggestion_mode); +my @langs; + +my $speller = Text::Aspell->new; +die unless $speller; + + +sub cmd_load() { + $setting_spell_dict = Irssi::settings_get_str("spell_dict"); + @langs = split /[,\s]/, $setting_spell_dict; + $speller->set_option('lang', $langs[0]); + Irssi::print($IRSSI{'name'} . ": dictionary language: " . $langs[0]); + + $setting_suggestion_mode = Irssi::settings_get_str("spell_suggestion_mode"); + $speller->set_option('sug-mode', $setting_suggestion_mode); + Irssi::print($IRSSI{'name'} . ": dictionary mode: " . $setting_suggestion_mode); +} + + +sub rotate_dict() { + push(@langs, shift(@langs)); + $speller->set_option('lang', $langs[0]); + Irssi::print($IRSSI{'name'} . ": dictionary language: " . $langs[0]); +} + + +Irssi::signal_add_last 'complete word' => sub { + my ($complist, $window, $word, $linestart, $want_space) = @_; + push(@$complist, $speller->suggest( $word )); +}; + + +Irssi::signal_add_last 'setup changed' => sub { + if ($setting_spell_dict ne Irssi::settings_get_str("spell_dict") || + $setting_suggestion_mode ne Irssi::settings_get_str("spell_suggestion_mode")) + { + cmd_load(); + } +}; + + +#### +# Register commands +Irssi::command_bind('rotate_dict', 'rotate_dict'); + + +### +# Settings +Irssi::settings_add_str($IRSSI{'name'}, 'spell_dict', "en_UK"); +Irssi::settings_add_str($IRSSI{'name'}, 'spell_suggestion_mode', "fast"); + +# Engage! +cmd_load(); |
