Petr Hracek a8163b
diff --git a/lisp/textmodes/ispell.el b/lisp/textmodes/ispell.el
Petr Hracek a8163b
index 1daec44..7167dc9 100644
Petr Hracek a8163b
--- a/lisp/textmodes/ispell.el
Petr Hracek a8163b
+++ b/lisp/textmodes/ispell.el
Petr Hracek a8163b
@@ -574,6 +574,40 @@ re-start Emacs."
Jochen Schmitt 668910
 		       (coding-system :tag "Coding System")))
Jochen Schmitt 668910
   :group 'ispell)
Jochen Schmitt 668910
 
Jochen Schmitt 668910
+(defvar ispell-hunspell-dictionary-equivs-alist
Jochen Schmitt 668910
+  '(("american"      "en_US")
Jochen Schmitt 668910
+    ("brasileiro"    "pt_BR")
Jochen Schmitt 668910
+    ("british"       "en_GB")
Jochen Schmitt 668910
+    ("castellano"    "es_ES")
Jochen Schmitt 668910
+    ("castellano8"   "es_ES")
Jochen Schmitt 668910
+    ("czech"         "cs_CZ")
Jochen Schmitt 668910
+    ("dansk"         "da_DK")
Jochen Schmitt 668910
+    ("deutsch"       "de_DE")
Jochen Schmitt 668910
+    ("deutsch8"      "de_DE")
Jochen Schmitt 668910
+    ("english"       "en_US")
Jochen Schmitt 668910
+    ("esperanto"     "eo")
Jochen Schmitt 668910
+    ("esperanto-tex" "eo")
Jochen Schmitt 668910
+    ("finnish"       "fi_FI")
Jochen Schmitt 668910
+    ("francais7"     "fr_FR")
Jochen Schmitt 668910
+    ("francais"      "fr_FR")
Jochen Schmitt 668910
+    ("francais-tex"  "fr_FR")
Jochen Schmitt 668910
+    ("german"        "de_DE")
Jochen Schmitt 668910
+    ("german8"       "de_DE")
Jochen Schmitt 668910
+    ("italiano"      "it_IT")
Jochen Schmitt 668910
+    ("nederlands"    "nl_NL")
Jochen Schmitt 668910
+    ("nederlands8"   "nl_NL")
Jochen Schmitt 668910
+    ("norsk"         "nn_NO")
Jochen Schmitt 668910
+    ("norsk7-tex"    "nn_NO")
Jochen Schmitt 668910
+    ("polish"        "pl_PL")
Jochen Schmitt 668910
+    ("portugues"     "pt_PT")
Jochen Schmitt 668910
+    ("russian"       "ru_RU")
Jochen Schmitt 668910
+    ("russianw"      "ru_RU")
Jochen Schmitt 668910
+    ("slovak"        "sk_SK")
Jochen Schmitt 668910
+    ("slovenian"     "sl_SI")
Jochen Schmitt 668910
+    ("svenska"       "sv_SE")
Jochen Schmitt 668910
+    ("hebrew"        "he_IL"))
Jochen Schmitt 668910
+  "Alist with matching hunspell dict names for standard dict names in
Jochen Schmitt 668910
+  `ispell-dictionary-base-alist'.")
Jochen Schmitt 668910
 
Jochen Schmitt 668910
 (defvar ispell-dictionary-base-alist
Petr Hracek a8163b
   '((nil                                ; default
Petr Hracek a8163b
@@ -1112,9 +1146,57 @@ aspell is used along with Emacs).")
Jochen Schmitt 668910
 		    ispell-encoding8-command)
Jochen Schmitt 668910
 	       ispell-aspell-dictionary-alist
Jochen Schmitt 668910
 	     nil))
Jochen Schmitt 668910
+	  (ispell-dictionary-base-alist ispell-dictionary-base-alist)
Jochen Schmitt 668910
 	  ispell-base-dicts-override-alist ; Override only base-dicts-alist
Jochen Schmitt 668910
 	  all-dicts-alist)
Jochen Schmitt 668910
 
Jochen Schmitt 668910
+      ;; While ispell and aspell (through aliases) use the traditional
Jochen Schmitt 668910
+      ;; dict naming originally expected by ispell.el, hunspell
Jochen Schmitt 668910
+      ;; uses locale based names with no alias.  We need to map
Jochen Schmitt 668910
+      ;; standard names to locale based names to make default dict
Jochen Schmitt 668910
+      ;; definitions available for hunspell.
Jochen Schmitt 668910
+      (if ispell-really-hunspell
Jochen Schmitt 668910
+	  (let (tmp-dicts-alist)
Jochen Schmitt 668910
+	    (dolist (adict ispell-dictionary-base-alist)
Jochen Schmitt 668910
+	      (let* ((dict-name (nth 0 adict))
Jochen Schmitt 668910
+		     (dict-equiv
Jochen Schmitt 668910
+		      (cadr (assoc dict-name
Jochen Schmitt 668910
+				   ispell-hunspell-dictionary-equivs-alist)))
Jochen Schmitt 668910
+		     (ispell-args (nth 5 adict))
Jochen Schmitt 668910
+		     (ispell-args-has-d (member "-d" ispell-args))
Jochen Schmitt 668910
+		     skip-dict)
Jochen Schmitt 668910
+		;; Remove "-d" option from `ispell-args' if present
Jochen Schmitt 668910
+		(if ispell-args-has-d
Jochen Schmitt 668910
+		    (let ((ispell-args-after-d
Jochen Schmitt 668910
+			   (cdr (cdr ispell-args-has-d)))
Jochen Schmitt 668910
+			  (ispell-args-before-d
Jochen Schmitt 668910
+			   (butlast ispell-args (length ispell-args-has-d))))
Jochen Schmitt 668910
+		      (setq ispell-args
Jochen Schmitt 668910
+			    (nconc ispell-args-before-d
Jochen Schmitt 668910
+				   ispell-args-after-d))))
Jochen Schmitt 668910
+		;; Unless default dict, re-add "-d" option with the mapped value
Jochen Schmitt 668910
+		(if dict-name
Jochen Schmitt 668910
+		    (if dict-equiv
Jochen Schmitt 668910
+			(nconc ispell-args (list "-d" dict-equiv))
Jochen Schmitt 668910
+		      (message
Jochen Schmitt 668910
+		       "ispell-set-spellchecker-params: Missing hunspell equiv for \"%s\". Skipping."
Jochen Schmitt 668910
+		       dict-name)
Jochen Schmitt 668910
+		      (setq skip-dict t)))
Jochen Schmitt 668910
+
Jochen Schmitt 668910
+		(unless skip-dict
Jochen Schmitt 668910
+		  (add-to-list 'tmp-dicts-alist
Jochen Schmitt 668910
+			       (list
Jochen Schmitt 668910
+				dict-name      ; dict name
Jochen Schmitt 668910
+				(nth 1 adict)  ; casechars
Jochen Schmitt 668910
+				(nth 2 adict)  ; not-casechars
Jochen Schmitt 668910
+				(nth 3 adict)  ; otherchars
Jochen Schmitt 668910
+				(nth 4 adict)  ; many-otherchars-p
Jochen Schmitt 668910
+				ispell-args    ; ispell-args
Jochen Schmitt 668910
+				(nth 6 adict)  ; extended-character-mode
Jochen Schmitt 668910
+				(nth 7 adict)  ; dict encoding
Jochen Schmitt 668910
+				))))
Jochen Schmitt 668910
+	      (setq ispell-dictionary-base-alist tmp-dicts-alist))))
Jochen Schmitt 668910
+
Jochen Schmitt 668910
       (run-hooks 'ispell-initialize-spellchecker-hook)
Jochen Schmitt 668910
 
Jochen Schmitt 668910
       ;; Add dicts to ``ispell-dictionary-alist'' unless already present.