How I could create an auto-correcting text-editor application?

You tried to integrate Term::Complete into your curses UI, but that's not about auto-correction.

First thing you have to do is get the snippet of text which has to be examined as e.g. $candidate:

$cui->add_callback( 'editor', \&current_word); my $candidate; # word to build a complete list from, or to spell-check sub current_word { my ($x, $y); Curses::UI::TextEditor::getsyx($y, $x); # not $editor->getsyx($foo +), this would overwrite $editor. BUG! $y--; # there's 1 padding line chomp (my $line = $editor->getline_at_ypos($y-1)); # first line is + 0 my $part = substr $line, 0, $x; ($candidate) = $part =~ /\b(\w+)$/; # caveat locale, utf8 warn $fh "x: $x y: $y '$line' - '$part' candidate: '$candidate'\n" +; }

This will give you information to STDERR about the current word under the cursor at every keystroke.

You can build a list of completion candidates based on that word, or check the spelling with e.g. the aspell library.

Based on that word, you could decide wether adding a <Tab> to the text, or attempt completion.

You could mark misspelled words in terms of Term::ANSIColor or such, do completion with either Term::Complete or Term::ReadLine::Gnu (with both you have to shoehorn the results into your $editor widget) - or just do your own completion routine with Curses::UI using Curses::UI::Listbox to display possible completions.

Way to go yet...

PS: why? are you trying to re-implement vi or emacs in perl? ;)

PS2: "Find and Replace" comes first in functionality, then more sophisticated things like (auto-)completion and spellcheck.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

In reply to Re^6: word auto-corrector in Curses::UI by shmem
in thread word auto-corrector in Curses::UI by Bpl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.