App-tkispell
view release on metacpan or search on metacpan
lib/App/tkispell.pm view on Meta::CPAN
at the top of the window shows unrecognized words, and the listing in
the middle of the window shows the alternative spellings provided by
ispell.
Clicking the, "Dismiss," button exits the program, after asking if the
program should save the spell-checked file and the replacement words
in the user's personal dictionary if necessary.
The entry box at the lower right contains replacement text for
misspelled words. The text in the entry is either a selection
from the word guesses or a word entered by the user.
Buttons on the right side of the window select options for replacing
possibly misspelled words.
=head2 Accept
Accept the word and continue to the next unrecognized word.
=head2 Add
$ispell_prog = `which ispell`;
chomp $ispell_prog;
}
}
if( !defined $ispell_prog or $ispell_prog eq '' ) {
warn "Did not find aspell or ispell. The check will not work. Please install aspell or ispell first and make it available in your PATH.";
}
my ($cw, $b1, @misspelledlist, @replacementlist, @addlist, @guesslist, $midx);
my $ifname = '';
my $lastmatchindex = '1.0';
my $matchlength = 0;
my $nextmiss = 0;
my $scriptname = $PROGRAM_NAME;
sub mainwindow {
$cw = Tk::MainWindow->new(-title => $scriptname);
$b1 = $cw->Balloon();
my @opts = (-padx => 5, -pady => 5);
$mc += length $match;
return "$mr.$mc";
}
sub checkfirst {
get_misspellings();
if ($#misspelledlist < 0) {
complete_notify();
return 0;
}
guesses();
my $term = $misspelledlist[0];
$midx = $cw->Subwidget('text')->search('-forwards', -count => \$matchlength, $term, $lastmatchindex);
$lastmatchindex = adjust_index ($midx, $term);
addtexttags();
show_guesses();
misspelled_replace();
}
sub checknext {
$cw->Subwidget('text')->tagRemove ('sel', '1.0', 'end');
if (++$nextmiss >= $#misspelledlist) {
complete_notify();
return 0;
}
(checknext() && return 1) if grep /$misspelledlist[$nextmiss]/, @addlist;
$midx = ($cw->Subwidget('text')->search ('-forwards',-count=>\$matchlength, $misspelledlist[$nextmiss],$lastmatchindex,'end'));
if ((defined $midx) && (length $midx)) {
addtexttags();
$lastmatchindex = adjust_index($midx,$misspelledlist[$nextmiss]);
show_guesses();
misspelled_replace();
}
return 1;
}
sub complete_notify {
return if ! $ifname;
$cw->Subwidget('list')->delete (0, 'end');
$cw->Subwidget('list')->insert('end', 'Spell check complete.');
return 0;
$midx = ($cw->Subwidget('text')->search('-forwards', -count => \$mlength, $misspelled,$lastindex,'end'));
last unless length $midx;
$cw->Subwidget('text')->delete($midx, "$midx + $mlength chars");
$cw->Subwidget('text')->insert($midx, $replacement);
$lastindex = adjust_index ($midx,$replacement);
}
push @addlist, ($replacement);
$cw->Unbusy;
}
sub guesses {
$cw->Busy;
return if ! $ifname;
@guesslist = qx|"$ispell_prog" -a \<$ifname 2\>&1|;
shift @guesslist; # remove the ispell id
chomp foreach (@guesslist);
$cw->Unbusy;
}
sub show_guesses {
$cw->Subwidget('list')->delete (0, 'end');
my $misspelling = gettextselection();
my @wordguesses = grep /\& $misspelling/, @guesslist;
if ($wordguesses[0]) {
$wordguesses[0] =~ s/.*\: //;
$cw->Subwidget('list')->insert('end', $_)
foreach (split /, /, $wordguesses[0]);
}
}
sub get_misspellings {
return if ! $ifname;
$cw->Busy(-recurse => 1);
@misspelledlist = qx|"$ispell_prog" -l \<$ifname|;
if ($#misspelledlist >= 0) {
chomp foreach (@misspelledlist);
}
( run in 0.591 second using v1.01-cache-2.11-cpan-748bfb374f4 )