+;; Set params according to the selected spellchecker
+
+(defvar ispell-last-program-name nil
+ "Last value of ispell-program name. Internal use.")
+
+(defvar ispell-initialize-spellchecker-hook nil
+ "Actions to be taken on spellchecker initialization.
+This hook is run when an spellchecker is used for the first
+time, before ``ispell-dictionary-alist'' is set. Is intended for
+sysadmins to override entries in the ispell.el base dictionary-alist
+by putting those overrides in a ``ispell-base-dicts-override-alist''
+alist with same format as ``ispell-dictionary-alist''. This alist
+will not override the auto-detected values if a recent aspell is
+used along with emacs.")
+
+(defun ispell-set-spellchecker-params ()
+ "Initialize some spellchecker parameters when changed or first used."
+ (unless (eq ispell-last-program-name ispell-program-name)
+ (setq ispell-last-program-name ispell-program-name)
+ (ispell-kill-ispell t)
+ (if (and (condition-case ()
+ (progn
+ (setq ispell-library-directory (ispell-check-version))
+ t)
+ (error nil))
+ ispell-really-aspell
+ ispell-aspell-supports-utf8
+ ;; xemacs does not like [:alpha:] regexps
+ (string-match "^[[:alpha:]]+$" "abcde"))
+ (unless ispell-aspell-dictionary-alist
+ (ispell-find-aspell-dictionaries)))
+
+ ;; Substitute ispell-dictionary-alist with the list of dictionaries
+ ;; corresponding to the given spellchecker. If a recent aspell, use
+ ;; the list of really installed dictionaries and add to it elements
+ ;; of the original list that are not present there. Allow distro info.
+ (let ((base-dicts-alist
+ (append ispell-dictionary-alist-1 ispell-dictionary-alist-2
+ ispell-dictionary-alist-3 ispell-dictionary-alist-4
+ ispell-dictionary-alist-5 ispell-dictionary-alist-6))
+ (found-dicts-alist
+ (if (and ispell-really-aspell
+ ispell-aspell-supports-utf8)
+ ispell-aspell-dictionary-alist
+ nil))
+ ispell-base-dicts-override-alist ; Override only base-dicts-alist
+ all-dicts-alist)
+
+ (run-hooks 'ispell-initialize-spellchecker-hook)
+
+ ;; Add dicts to ``ispell-dictionary-alist'' unless already present.
+ (dolist (dict (append found-dicts-alist
+ ispell-base-dicts-override-alist
+ base-dicts-alist))
+ (unless (assoc (car dict) all-dicts-alist)
+ (add-to-list 'all-dicts-alist dict)))
+ (setq ispell-dictionary-alist all-dicts-alist))))
+
+