changeset 100500:e7cd485b79ff

(ispell-really-hunspell): new variable to signal hunspell (ispell-check-version): Check if hunspell and set ispell-really-hunspell if needed (ispell-send-string), (ispell-start-process), (flyspell-large-region): Pass right options for hunspell if needed
author Agustin Martin <agustin.martin@hispalinux.es>
date Thu, 18 Dec 2008 18:44:31 +0000
parents 9c14df93594d
children 50d559e0f461
files lisp/textmodes/flyspell.el lisp/textmodes/ispell.el
diffstat 2 files changed, 45 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/textmodes/flyspell.el	Thu Dec 18 17:45:28 2008 +0000
+++ b/lisp/textmodes/flyspell.el	Thu Dec 18 18:44:31 2008 +0000
@@ -1526,6 +1526,7 @@
 	  (or ispell-local-pdict ispell-personal-dictionary))
     (let ((args (ispell-get-ispell-args))
 	  (encoding (ispell-get-coding-system))
+	  encoding-command
 	  c)
       (if (and ispell-current-dictionary  ; use specified dictionary
 	       (not (member "-d" args)))  ; only define if not overridden
@@ -1538,14 +1539,21 @@
 			      (expand-file-name
 			       ispell-current-personal-dictionary)))))
       (setq args (append args ispell-extra-args))
-      (if (and ispell-really-aspell
-	       ispell-aspell-supports-utf8)
+
+      ;; If we are using recent aspell or hunspell, make sure we use the right encoding
+      ;; for communication. ispell or older aspell/hunspell does not support this
+      (if (or (and ispell-really-aspell
+		   ispell-aspell-supports-utf8
+		   (setq encoding-command "--encoding="))
+	      (and ispell-really-hunspell
+		   (setq encoding-command "-i ")))
 	  (setq args
 		(append args
 			(list
-			 (concat "--encoding="
+			 (concat encoding-command
 				 (symbol-name
 				  encoding))))))
+
       (let ((process-coding-system-alist (list (cons "\\.*" encoding))))
 	(setq c (apply 'ispell-call-process-region beg
 		       end
--- a/lisp/textmodes/ispell.el	Thu Dec 18 17:45:28 2008 +0000
+++ b/lisp/textmodes/ispell.el	Thu Dec 18 18:44:31 2008 +0000
@@ -668,7 +668,8 @@
 contain the same character set as casechars and otherchars in the
 LANGUAGE.aff file \(e.g., english.aff\).")
 
-(defvar ispell-really-aspell nil) ; Non-nil if aspell extensions should be used
+(defvar ispell-really-aspell nil)   ; Non-nil if aspell extensions should be used
+(defvar ispell-really-hunspell nil) ; Non-nil if hunspell extensions should be used
 
 (defvar ispell-aspell-supports-utf8 nil
   "Non-nil means to try to automatically find aspell dictionaries.
@@ -759,22 +760,29 @@
 		 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.
+
+        ;; Check to see if it's really aspell or hunspell.
         (goto-char (point-min))
         (let (case-fold-search)
-          (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)))))
+	  (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))
+	   )))
       (kill-buffer (current-buffer)))
     result))
 
@@ -1493,7 +1501,10 @@
 			   (point-min) (point-max)
 			   ispell-program-name nil
 			   output-buf nil
-			   "-a" "-m" ispell-args))
+			   "-a"
+			   ;; hunspell -m option means something different
+			   (if ispell-really-hunspell "" "-m")
+			   ispell-args))
 	      (set-buffer output-buf)
 	      (goto-char (point-min))
 	      (save-match-data
@@ -2473,6 +2484,7 @@
   "Start the ispell process, with support for no asynchronous processes.
 Keeps argument list for future ispell invocations for no async support."
   (let ((default-directory default-directory)
+	encoding-command
 	args)
     (unless (and (file-directory-p default-directory)
 		 (file-readable-p default-directory))
@@ -2493,12 +2505,18 @@
 	      (append args
 		      (list "-p"
 			    (expand-file-name ispell-current-personal-dictionary)))))
-    (if (and ispell-really-aspell
-	     ispell-aspell-supports-utf8)
+
+    ;; If we are using recent aspell or hunspell, make sure we use the right encoding
+    ;; for communication. ispell or older aspell/hunspell does not support this
+    (if (or (and ispell-really-aspell
+		 ispell-aspell-supports-utf8
+		 (setq encoding-command "--encoding="))
+	    (and ispell-really-hunspell
+		 (setq encoding-command "-i ")))
 	(setq args
 	      (append args
 		      (list
-		       (concat "--encoding="
+		       (concat encoding-command
 			       (symbol-name (ispell-get-coding-system)))))))
     (setq args (append args ispell-extra-args))
 
@@ -2509,9 +2527,9 @@
 	(let ((process-connection-type ispell-use-ptys-p))
 	  (apply 'start-process
 		 "ispell" nil ispell-program-name
-		 "-a"			; accept single input lines
-		 "-m"			; make root/affix combos not in dict
-		 args))
+		 "-a"			             ; accept single input lines
+		 (if ispell-really-hunspell "" "-m") ; make root/affix combos not in dict
+		 args))                              ; hunspell -m option means different
       (setq ispell-cmd-args args
 	    ispell-output-buffer (generate-new-buffer " *ispell-output*")
 	    ispell-session-buffer (generate-new-buffer " *ispell-session*"))