Skip to content

Instantly share code, notes, and snippets.

@gamblore
Last active December 19, 2015 18:19
Show Gist options
  • Save gamblore/5998024 to your computer and use it in GitHub Desktop.
Save gamblore/5998024 to your computer and use it in GitHub Desktop.
irssi-hunspell.pl
########################################NEED Text::Hunspell libhunspell-dev INSTALLED##################
#* Copyright (c) 2013, Adam Metcalf
#* All rights reserved.
#*
#* Redistribution and use in source and binary forms, with or without
#* modification, are permitted provided that the following conditions are met:
#* * Redistributions of source code must retain the above copyright
#* notice, this list of conditions and the following disclaimer.
#* * Redistributions in binary form must reproduce the above copyright
#* notice, this list of conditions and the following disclaimer in the
#* documentation and/or other materials provided with the distribution.
#* THIS SOFTWARE IS PROVIDED BY ED HOLLAND ``AS IS'' AND ANY
#* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
#* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
#* DISCLAIMED. IN NO EVENT SHALL ED HOLLAND BE LIABLE FOR ANY
#* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
#* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
#* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
#* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
#* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
use Text::Hunspell;
use Irssi;
use Irssi qw(signal_add_last);
use vars qw($VERSION %IRSSI);
$VERSION = '0.1';
%IRSSI = (
authors => 'Adam Metcalf',
contact => '[email protected]',
name => 'Hunspell Spell Check',
description => 'This script performs ' .
'a hunspell spell check' .
'operation on your text.',
license => 'BSD',
);
my $speller = Text::Hunspell->new(
"/usr/share/hunspell/en_US.aff", # Hunspell affix file
"/usr/share/hunspell/en_US.dic" # Hunspell dictionary file
);
my $line;
my $change = 0;
my @suggestions;
sub sig_complete {
my ($complist, $window, $word, $linestart, $want_space) = @_;
$line = $word;
process();
if ($change == 1) {
push @$complist, @suggestions;
$change = 0;
} else {
push @$complist, ($line);
}
}
sub process {
if ($speller->check($line)) {
$change = 0;
} else {
@suggestions = $speller->suggest($line);
$change = 1;
}
}
signal_add_last 'complete word' => \&sig_complete;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment