From: Tom Wesley Date: Tue, 10 Jun 2014 18:24:09 +0000 (+0100) Subject: Add aspell_complete.pl X-Git-Url: http://git.99rst.org/?a=commitdiff_plain;h=37a10e7d08390547c9771953110d83212f0d62b4;p=irssi-scripts.irssi.org.git Add aspell_complete.pl --- 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();