Function: ispell-check-version

ispell-check-version is an interactive and byte-compiled function defined in ispell.el.gz.

Signature

(ispell-check-version &optional INTERACTIVEP)

Documentation

Ensure that ispell-program-name is valid and has the correct version.

Returns version number if called interactively. Otherwise returns the library directory name, if that is defined.

Key Bindings

Aliases

check-ispell-version

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/ispell.el.gz
;;; **********************************************************************
;;; The following are used by ispell, and should not be changed.
;;; **********************************************************************

(defun ispell-check-version (&optional interactivep)
  "Ensure that `ispell-program-name' is valid and has the correct version.
Returns version number if called interactively.
Otherwise returns the library directory name, if that is defined."
  ;; This is a little wasteful as we actually launch ispell twice: once
  ;; to make sure it's the right version, and once for real.  But people
  ;; get confused by version mismatches *all* the time (and I've got the
  ;; email to prove it) so I think this is worthwhile.  And the -v[ersion]
  ;; option is the only way I can think of to do this that works with
  ;; all versions, since versions earlier than 3.0.09 didn't identify
  ;; themselves on startup.
  (interactive "p")
  (let ((default-directory (or temporary-file-directory default-directory))
	(get-config-var
	 (lambda (var)
	   (when (re-search-forward
		  (concat var " = \\\"\\(.+?\\)\\\"") nil t)
	     (match-string 1))))
	result libvar status ispell-program-version)

    (with-temp-buffer
      (setq status (ispell-call-process ispell-program-name nil t nil "-vv"))
      (goto-char (point-min))
      (if interactivep
	  ;; Report version information of ispell
	  (progn
	    (end-of-line)
	    (setq result (buffer-substring-no-properties (point-min)
                                                         (point)))
	    (message "%s" result))
	;; return LIBDIR or LIBRARYVAR (overrides LIBDIR) env.
	(progn
	  (setq result (funcall get-config-var "LIBDIR")
		libvar (funcall get-config-var "LIBRARYVAR"))
	  (when libvar
	    (setq libvar (getenv libvar))
	    (unless (member libvar '(nil "")) (setq result libvar)))))
      (goto-char (point-min))
      (if (not (memq status '(0 nil)))
	  (error "%s exited with %s %s" ispell-program-name
		 (if (stringp status) "signal" "code") status))

      ;; Get relevant version strings.
      (let (case-fold-search)
	(setq ispell-program-version
	      (and (search-forward-regexp "\\([0-9]+\\.[0-9.]+\\)" nil t)
		   (match-string 1)))

	;; Make sure these variables are (re-)initialized to the default value
	(setq ispell-really-aspell nil
              ispell-really-hunspell nil
              ispell-really-enchant nil
	      ispell-encoding8-command nil)

	(goto-char (point-min))
	(or (setq ispell-really-aspell
		  (and
                   (search-forward-regexp
                    "(but really Aspell \\([0-9]+\\.[0-9.]+\\([-._+ ]?[a-zA-Z0-9]+\\)?\\)?)"
                    nil t)
		   (match-string 1)))
	    (setq ispell-really-hunspell
		  (and
                   (search-forward-regexp
		    "(but really Hunspell \\([0-9]+\\.[0-9.]+\\([-._+ ]?[a-zA-Z0-9]+\\)?\\)?)"
                    nil t)
		   (match-string 1)))
            (setq ispell-really-enchant
		  (and
                   (search-forward-regexp
		    "(but really Enchant \\([0-9]+\\.[0-9.]+\\([-._+ ]?[a-zA-Z0-9]+\\)?\\)?)"
                    nil t)
		   (match-string 1)))))

      (let* ((aspell8-minver   "0.60")
             (ispell-minver    "3.1.12")
             (hunspell8-minver "1.1.6")
             (enchant-minver   "2.1.0")
             (minver (cond
                      ((not (version<= ispell-minver ispell-program-version))
                       ispell-minver)
                      ((and ispell-really-aspell
                            (not (version<= aspell8-minver ispell-really-aspell)))
                       aspell8-minver)
                      ((and ispell-really-enchant
                            (not (version<= enchant-minver ispell-really-enchant)))
                       enchant-minver))))

        (if minver
	    (error "%s release %s or greater is required"
                   ispell-program-name
                   minver))

	(cond
	 (ispell-really-aspell
	  (setq ispell-encoding8-command "--encoding="))
	 (ispell-really-hunspell
	  (if (version<= hunspell8-minver ispell-really-hunspell)
	      (setq ispell-encoding8-command "-i")
	    (setq ispell-really-hunspell nil))))))
    result))