[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: function for spell checking of strings
From: |
Herring, Davis |
Subject: |
RE: function for spell checking of strings |
Date: |
Mon, 3 Sep 2012 22:30:12 +0000 |
> I want to look up a string in one of the dictionaries accessible from
> emacs. The string is not contained in a buffer (in which case I would
> use `ispell-word´) but is only referred to by a variable in my elisp
> code. There used to be a function 'spell-string' but the
> spell-packages is obsoleted and the build in help system refers me to
> 'ispell'. But I cannot find an equivalent function in the 'ispell'
> package. Does any one know of a solution?
I "wrote" this for a similar reason:
;; Ripped off from `ispell-word', of course, since it isn't useful for Lisp.
(defun ispell-check-word (&optional word)
"Check spelling of WORD, or word under or before the cursor if nil.
If it is spelled correctly, return a root string or t if it is exact.
If it is misspelled, return (CORRECTIONS . GUESSES).
If WORD is t, then the following word \(rather than preceding\) is checked.
Word syntax is controlled by the definition of the chosen dictionary,
which is in `ispell-local-dictionary-alist' or `ispell-dictionary-alist'.
This will check or reload the dictionary. Use \\[ispell-change-dictionary]
or \\[ispell-region] to update the Ispell process."
(ispell-init)
(ispell-accept-buffer-local-defs) ; use the correct dictionary
(or (stringp word) (setq word (car (ispell-get-word word))))
(ispell-send-string "%\n") ; put in verbose mode
(ispell-send-string (concat "^" word "\n"))
;; wait until ispell has processed word
(while (progn (ispell-accept-output) (not (string= "" (car ispell-filter)))))
;;(ispell-send-string "!\n") ;back to terse mode.
(setq ispell-filter (cdr ispell-filter)) ; remove extra \n
(let (poss)
(if (and ispell-filter (listp ispell-filter))
(if (> (length ispell-filter) 1)
(error "Ispell and its process have different character maps")
(setq poss (ispell-parse-output (car ispell-filter)))))
(unless poss (error "Error in ispell process"))
(if (or (eq poss t) (stringp poss)) poss
(setq poss (cddr poss)) (cons (car poss) (cadr poss)))))
Davis