Subject: Re: bug#25830: 25.2; ispell doesn't parse hunspell dictionaries properly

From: Eli Zaretskii <[email-masked]>
Date: Sun, 05 Mar 2017 17:42:14 +0200

> Date: Tue, 28 Feb 2017 22:53:52 +0100
> From: Martin Kletzander <[email-masked]>
> Cc: [email-masked]
> 
> >Please try the patch below.  (If it doesn't apply to your version of
> >ispell.el, tell me which version of Emacs you have, and I will try to
> >produce a compatible patch.)
> >
> 
> Sorry I didn't get to this earlier.

Now it's my turn to apologize for the delay...

> One of the hunks didn't apply correctly, so I used the file from
> master and it applied correctly.  So with your patch applied on top
> of ispell.el from current master, the situation is way better.  But
> I feel like it still doesn't work as expected.  Not that anything
> would be broken, but it uses only the first dictionary found.

You are right, that was the wrong direction to try to solve the
problem.

Here's another attempt.  It should be applied _instead_ of the
previous patch, to the original version of ispell.el.  Let me know if
it works OK for you.

Thanks.

--- lisp/textmodes/ispell.el~0	2017-01-08 06:23:52.000000000 +0200
+++ lisp/textmodes/ispell.el	2017-03-05 17:21:10.441710400 +0200
@@ -1094,10 +1094,10 @@
 
 (defun ispell-find-hunspell-dictionaries ()
   "Look for installed Hunspell dictionaries.
-Will initialize `ispell-hunspell-dictionary-alist' and
-`ispell-hunspell-dictionary-alist' after values found
-and remove `ispell-dicts-name2locale-equivs-alist'
-entries if a specific dictionary was found."
+Will initialize `ispell-hunspell-dictionary-alist' according
+to dictionaries found, and will remove aliases from the list
+in `ispell-dicts-name2locale-equivs-alist' if an explicit
+dictionary from that list was found."
   (let ((hunspell-found-dicts
 	 (split-string
 	  (with-temp-buffer
@@ -1110,18 +1110,27 @@
 	  "[\n\r]+"
 	  t))
 	hunspell-default-dict
-	hunspell-default-dict-entry)
+	hunspell-default-dict-entry
+	hunspell-multi-dict)
     (dolist (dict hunspell-found-dicts)
       (let* ((full-name (file-name-nondirectory dict))
 	     (basename  (file-name-sans-extension full-name))
 	     (affix-file (concat dict ".aff")))
 	(if (string-match "\\.aff$" dict)
 	    ;; Found default dictionary
-	    (if hunspell-default-dict
-		(error "ispell-fhd: Default dict already defined as %s.  Not using %s.\n"
-		       hunspell-default-dict dict)
-	      (setq affix-file dict)
-	      (setq hunspell-default-dict (list basename affix-file)))
+	    (progn
+	      (if hunspell-default-dict
+		  (setq hunspell-multi-dict
+			(concat (or hunspell-multi-dict
+				    (car hunspell-default-dict))
+				"," basename))
+		(setq affix-file dict)
+		;; FIXME: The cdr of the list we cons below is never
+		;; used.  Why do we need a list?
+		(setq hunspell-default-dict (list basename affix-file)))
+	      (ispell-print-if-debug
+	       "++ ispell-fhd: default dict-entry:%s name:%s basename:%s\n"
+	       dict full-name basename))
 	  (if (and (not (assoc basename ispell-hunspell-dict-paths-alist))
 		   (file-exists-p affix-file))
 	      ;; Entry has an associated .aff file and no previous value.
@@ -1161,7 +1170,8 @@
 	      (cl-pushnew (list dict-equiv-key affix-file)
                           ispell-hunspell-dict-paths-alist :test #'equal)))))
     ;; Parse and set values for default dictionary.
-    (setq hunspell-default-dict (car hunspell-default-dict))
+    (setq hunspell-default-dict (or hunspell-multi-dict
+				    (car hunspell-default-dict)))
     (setq hunspell-default-dict-entry
 	  (ispell-parse-hunspell-affix-file hunspell-default-dict))
     ;; Create an alist of found dicts with only names, except for default dict.