Subject: Re: bug#25825: 25.1; ispell-find-hunspell-dictionaries not working on Windows

From: Stefan Kangas <[email-masked]>
Date: Wed, 26 Aug 2020 13:01:21 -0700

Stefan Kangas <[email-masked]> writes:

> It seems to be an issue with my environment.  I've been using this for a
> very long time:
>
>     $ locale
>     LANG=

So, I looked into all my locale stuff again, and it turns out that $LANG
was unintentionally left unset here for boring reasons.  (There is no
reason to leave $LANG unset.)

> One idea to improve the situation on our end is to look for "Can't
> open affix or dictionary files for dictionary named 'default'." and
> raise a better error in these cases.

I think it's better to raise the more helpful error.

How does the attached diff look?
diff --git a/lisp/textmodes/ispell.el b/lisp/textmodes/ispell.el
index 6eaa0582aa..6e7eb0fb5e 100644
--- a/lisp/textmodes/ispell.el
+++ b/lisp/textmodes/ispell.el
@@ -1096,28 +1096,38 @@ ispell-find-hunspell-dictionaries
 in `ispell-dicts-name2locale-equivs-alist' if an explicit
 dictionary from that list was found."
   (let ((hunspell-found-dicts
-	 (split-string
-	  (with-temp-buffer
-	    (ispell-call-process ispell-program-name
-				 null-device
-				 t
-				 nil
-                                 "-D"
-                                 ;; Use -a to prevent Hunspell from
-                                 ;; trying to initialize its
-                                 ;; curses/termcap UI, which causes it
-                                 ;; to crash or fail to start in some
-                                 ;; MS-Windows ports.
-                                 "-a"
-                                 ;; Hunspell 1.7.0 (and later?) won't
-                                 ;; show LOADED DICTIONARY unless
-                                 ;; there's at least one file argument
-                                 ;; on the command line.  So we feed
-                                 ;; it with the null device.
-				 null-device)
-	    (buffer-string))
-	  "[\n\r]+"
-	  t))
+         (seq-filter
+          (lambda (str)
+            (when (string-match
+                   ;; Hunspell gives this error when there is some
+                   ;; installation problem, for example if $LANG is unset.
+                   (concat "^Can't open affix or dictionary files "
+                           "for dictionary named \"default\".$")
+                   str)
+              (user-error "Hunspell error: %s" str))
+            (file-name-absolute-p str))
+          (split-string
+           (with-temp-buffer
+             (ispell-call-process ispell-program-name
+                            null-device
+                            t
+                            nil
+                            "-D"
+                            ;; Use -a to prevent Hunspell from
+                            ;; trying to initialize its
+                            ;; curses/termcap UI, which causes it
+                            ;; to crash or fail to start in some
+                            ;; MS-Windows ports.
+                            "-a"
+                            ;; Hunspell 1.7.0 (and later?) won't
+                            ;; show LOADED DICTIONARY unless
+                            ;; there's at least one file argument
+                            ;; on the command line.  So we feed
+                            ;; it with the null device.
+                            null-device)
+             (buffer-string))
+           "[\n\r]+"
+           t)))
 	hunspell-default-dict
 	hunspell-default-dict-entry
 	hunspell-multi-dict)
@@ -1164,7 +1174,7 @@ ispell-find-hunspell-dictionaries
     (dolist (dict-equiv ispell-dicts-name2locale-equivs-alist)
       (let ((dict-equiv-key (car dict-equiv))
 	    (dict-equiv-value (cadr dict-equiv))
-	    (exclude-aliases (list   ;; Exclude TeX aliases
+	    (exclude-aliases (list ;; Exclude TeX aliases
 			      "esperanto-tex"
 			      "francais7"
 			      "francais-tex"
@@ -1175,7 +1185,7 @@ ispell-find-hunspell-dictionaries
 	    (let ((affix-file (cadr (assoc dict-equiv-value
                                            ispell-hunspell-dict-paths-alist))))
 	      (ispell-print-if-debug "++ ispell-fhd: Adding alias %s -> %s.\n"
-                                     dict-equiv-key affix-file)
+                               dict-equiv-key affix-file)
 	      (cl-pushnew (list dict-equiv-key affix-file)
                           ispell-hunspell-dict-paths-alist :test #'equal)))))
     ;; Parse and set values for default dictionary.