Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Command using Helm to select spelling corrections
(defun cofi/helm-flyspell-correct ()
"Use helm for flyspell correction.
Adapted from `flyspell-correct-word-before-point'."
;; use the correct dictionary
(let ((cursor-location (point))
(word (flyspell-get-word))
(opoint (point)))
(if (consp word)
(let ((start (car (cdr word)))
(end (car (cdr (cdr word))))
(word (car word))
poss ispell-filter)
;; now check spelling of word.
(ispell-send-string "%\n") ;put in verbose mode
(ispell-send-string (concat "^" word "\n"))
;; wait until ispell has processed word
(while (progn
(accept-process-output ispell-process)
(not (string= "" (car ispell-filter)))))
;; Remove leading empty element
(setq ispell-filter (cdr ispell-filter))
;; ispell process should return something after word is sent.
;; Tag word as valid (i.e., skip) otherwise
(or ispell-filter
(setq ispell-filter '(*)))
(if (consp ispell-filter)
(setq poss (ispell-parse-output (car ispell-filter))))
((or (eq poss t) (stringp poss))
;; don't correct word
((null poss)
;; ispell error
(error "Ispell: error in Ispell process"))
;; The word is incorrect, we have to propose a replacement.
(flyspell-do-correct (helm-comp-read "Correction: "
(third poss)
'(("Save word" . save)
("Accept (session)" . session)
("Accept (buffer)" . buffer)))
:name (format "%s [%s]" word (or ispell-local-dictionary
:must-match t
:alistp t)
poss word cursor-location start end opoint)))
(ispell-pdict-save t)))))
Copy link

jbranso commented Oct 31, 2014

I have no idea how this code works, but I copied it into my init.el, and it works perfectly. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment