completion-ui-ispell-source.el 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. ;;; Completion-UI source for ispell correction
  2. (require 'flyspell)
  3. (defgroup completion-ui-ispell nil
  4. "Completion-UI ispell completion source."
  5. :group 'completion-ui)
  6. (defcustom ispell-correct-completion-sort-corrections t
  7. "When non-nil, `complete-ispell' will sort ispell suggestions."
  8. :group 'completion-ui-ispell
  9. :type 'boolean)
  10. (defun ispell-correct-completion-function (word)
  11. (let (poss ; possibilities offered by ispell
  12. ispell-filter)
  13. ;; Now check spelling of word.
  14. (ispell-send-string "%\n") ; put in verbose mode
  15. (ispell-send-string (concat "^" word "\n")) ; lookup the word
  16. ;; Wait until ispell has processed word.
  17. (while (progn
  18. (accept-process-output ispell-process)
  19. (not (string= "" (car ispell-filter)))))
  20. ;; Remove leading empty element
  21. (setq ispell-filter (cdr ispell-filter))
  22. ;; ispell process should return something after word is sent.
  23. ;; Tag word as valid (i.e., skip) otherwise
  24. (or ispell-filter
  25. (setq ispell-filter '(*)))
  26. (when (consp ispell-filter)
  27. (setq poss (ispell-parse-output (car ispell-filter))))
  28. (cond
  29. ((or (eq poss t) (stringp poss))
  30. (message "Ispell: %s is correct" word)
  31. nil)
  32. ((null poss)
  33. (error "Ispell: error in Ispell process")
  34. nil)
  35. (t
  36. ;; The word is incorrect, we have to propose replacements
  37. (if ispell-correct-completion-sort-corrections
  38. (sort (car (cdr (cdr poss))) 'string<)
  39. (car (cdr (cdr poss))))))))
  40. (completion-ui-register-source
  41. 'ispell-correct-completion-function
  42. :non-prefix-completion t
  43. :name 'ispell)
  44. ;; ----------------------------------------------------------------------------