changeset 100616:d97232b983fb

* textmodes/ispell.el (ispell-check-minver): New function. (ispell-check-version): Rewrite spellchecker and version checking. Use (ispell-check-minver). Handle hunspell versions.
author Agustin Martin <agustin.martin@hispalinux.es>
date Sat, 20 Dec 2008 18:34:41 +0000
parents 95d9ce85cf2b
children a714dea3017d
files lisp/ChangeLog lisp/textmodes/ispell.el
diffstat 2 files changed, 89 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Sat Dec 20 16:00:39 2008 +0000
+++ b/lisp/ChangeLog	Sat Dec 20 18:34:41 2008 +0000
@@ -1,3 +1,9 @@
+2008-12-20  Agustin Martin <agustin.martin@hispalinux.es>
+
+	* textmodes/ispell.el (ispell-check-minver): New function.
+	(ispell-check-version): Rewrite spellchecker and version checking.
+	Use (ispell-check-minver). Handle hunspell versions.
+
 2008-12-20  Chong Yidong  <cyd@stupidchicken.com>
 
 	* ido.el (ido-read-internal): Handle `confirm' and
@@ -35,7 +41,7 @@
 	(authors-canonical-author-name): Doc fix.  Respect authors-fixed-case.
 	(authors): Ensure error buffer is writable.
 
-2008-12-18  Agustín Martín  <agustin.martin@hispalinux.es>
+2008-12-18  Agustin Martin  <agustin.martin@hispalinux.es>
 
 	(ispell-really-hunspell): New variable to signal hunspell.
 	(ispell-check-version):
--- a/lisp/textmodes/ispell.el	Sat Dec 20 16:00:39 2008 +0000
+++ b/lisp/textmodes/ispell.el	Sat Dec 20 18:34:41 2008 +0000
@@ -196,6 +196,42 @@
 ;; Improved message reference matching in `ispell-message'.
 ;; Fixed bug in returning to nroff mode from tex mode.
 
+;;; Compatibility code for xemacs and (not too) older emacsen:
+
+(if (fboundp 'version<=)
+    (defalias 'ispell-check-minver 'version<=)
+  (defun ispell-check-minver (minver version)
+    "Check if string VERSION is at least string MINVER.
+Both must be in [0-9]+.[0-9]+... format. This is a fallback
+compatibility function in case version<= is not available."
+    (let ((pending t)
+	  (return t)
+	  start-ver start-mver)
+      ;; Loop until an absolute greater or smaller condition is reached
+      ;; or until no elements are left in any of version and minver. In
+      ;; this case version is exactly the minimal, so return OK.
+      (while pending
+	(let (ver mver)
+	  (if (string-match "[0-9]+" version start-ver)
+	      (setq start-ver (match-end 0)
+		    ver (string-to-int (substring version (match-beginning 0) (match-end 0)))))
+	  (if (string-match "[0-9]+" minver start-mver)
+	      (setq start-mver (match-end 0)
+		    mver (string-to-int (substring minver (match-beginning 0) (match-end 0)))))
+
+	  (if (or ver mver)
+	      (progn
+		(or ver  (setq ver 0))
+		(or mver (setq mver 0))
+		;; If none of below conditions match, this element is the
+		;; same. Go checking next element.
+		(if (> ver mver)
+		    (setq pending nil)
+		  (if (< ver mver)
+		      (setq pending nil
+			    return nil))))
+	    (setq pending nil))))
+      return)))
 
 ;;; Code:
 
@@ -714,7 +750,7 @@
 	(default-directory (or (and (boundp 'temporary-file-directory)
 				    temporary-file-directory)
 			       default-directory))
-	result status)
+	result status ispell-program-version)
     (save-excursion
       (let ((buf (get-buffer " *ispell-tmp*")))
 	(if buf (kill-buffer buf)))
@@ -746,43 +782,51 @@
       (if (not (memq status '(0 nil)))
 	  (error "%s exited with %s %s" ispell-program-name
 		 (if (stringp status) "signal" "code") status))
-      (setq case-fold-search t
-	    status (re-search-forward
-		    (concat "\\<\\("
-			    (format "%d" (car ispell-required-version))
-			    "\\)\\.\\([0-9]*\\)\\.\\([0-9]*\\)\\>")
-		    nil t)
-	    case-fold-search case-fold-search-val)
-      (if (or (not status)	; major version mismatch
-	      (< (car (read-from-string (match-string-no-properties 2)))
-		 (car (cdr ispell-required-version)))) ; minor version mismatch
-	  (error "%s version 3 release %d.%d.%d or greater is required"
-		 ispell-program-name (car ispell-required-version)
-		 (car (cdr ispell-required-version))
-		 (car (cdr (cdr ispell-required-version))))
-
-	;; check that it is the correct version.
-	(if (and (= (car (read-from-string (match-string-no-properties 2)))
-		    (car (cdr ispell-required-version)))
-		 (< (car (read-from-string (match-string-no-properties 3)))
-		    (car (cdr (cdr ispell-required-version)))))
-          (setq ispell-offset 0))
-
-        ;; Check to see if it's really aspell or hunspell.
-        (goto-char (point-min))
-        (let (case-fold-search)
-	  (or
-	   (setq ispell-really-aspell
-		 (and (search-forward-regexp
-		       "(but really Aspell \\(.*?\\)\\(-[0-9]+\\)?)" nil t)
-		      (progn
-			(setq ispell-aspell-supports-utf8
-			      (not (version< (match-string 1) "0.60")))
-			t)))
-	   (setq ispell-really-hunspell
-		 (search-forward-regexp
-		  "(but really Hunspell \\(.*?\\)\\(-[0-9]+\\)?)" nil t))
-	   )))
+
+      ;; Get relevant version strings. Only xx.yy.... format works well
+      (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-aspell-supports-utf8 nil
+	      ispell-really-hunspell nil)
+
+	(goto-char (point-min))
+	(or (setq ispell-really-aspell
+		  (and (search-forward-regexp
+			"(but really Aspell \\([0-9]+\\.[0-9\\.]+\\)?)" nil t)
+		       (match-string 1)))
+	    (setq ispell-really-hunspell
+		  (and (search-forward-regexp
+			"(but really Hunspell \\([0-9]+\\.[0-9\\.]+\\)?)" nil t)
+		       (match-string 1)))))
+
+      (let ((aspell-minver    "0.50")
+	    (aspell8-minver   "0.60")
+	    (ispell0-minver   "3.1.0")
+	    (ispell-minver    "3.1.12")
+	    (hunspell8-minver "1.1.6"))
+
+	(if (ispell-check-minver ispell0-minver ispell-program-version)
+	    (or (ispell-check-minver ispell-minver ispell-program-version)
+		(setq ispell-offset 0))
+	  (error "%s release %s or greater is required"
+		 ispell-program-name
+		 ispell-minver))
+
+	(cond
+	 (ispell-really-aspell
+	  (if (ispell-check-minver aspell-minver ispell-really-aspell)
+	      (if (ispell-check-minver aspell8-minver ispell-really-aspell)
+		  (setq ispell-aspell-supports-utf8 t))
+	    (setq ispell-really-aspell nil)))
+	 (ispell-really-hunspell
+	  (or (ispell-check-minver hunspell8-minver ispell-really-hunspell)
+	      (setq ispell-really-hunspell nil)))))
+
       (kill-buffer (current-buffer)))
     result))