Plugins ideas

Another free plugin idea for somebody with some time on their hands: word completion for natural language courtesy of a spell-checker.

When given a word on standard input, followed by a newline, the hunspell tool will check it and print a response line. If the response line begins with & (ampersand), the word is misspelled and hunspell provides suggestions:

$ echo 'fud' | hunspell -d en_AU
Hunspell 1.7.0
& fud 15 0: FUD, food, dud, feud, fund, fed, fad, fun, fur, fut, cud, fug, fum, mud, pud

After &, the fields are:

  • the input word
  • the number of suggestions
  • the character offset of the word from the beginning of the line
  • : (colon)
  • the suggestions, separated by , (comma) and space

It should be pretty straight-forward to transform the hunspell output into a completions option (much like racer.kak so we can have sensible completions for plain-text documents.

Right now, I have a hack that reads all of /usr/share/dict/words into the static_words option, which works but it can make Kakoune quite sluggish, and Kakoune’s ranking of completions isn’t really tuned for natural language. I suspect using a tool designed for the task would probably do a better job.