Subject: bug#33606: 26.1; An error in ispell-find-hunspell-dictionaries breakes spell checking with hunspell

From: Gregor Grasselli <[email-masked]>
Date: Tue, 4 Dec 2018 01:41:09 +0100

Evaluating in the scratch buffer:

(setq ispell-program-name "hunspell")
"hunspell"

(require 'ispell)
ispell

(ispell-find-hunspell-dictionaries)

Causes this error:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  string-match("," nil 0)
  split-string(nil "," t)
  (let ((dict-list (split-string dict-key "," t)) (first-p t) (dict-arg "")
otherchars-list) (let ((--dolist-tail-- dict-list)) (while --dolist-tail--
(let ((dict-key (car --dolist-tail--))) (let ((affix-file (car (cdr (assoc
dict-key ispell-hunspell-dict-paths-alist))))) (if affix-file nil (error
"ispell-phaf: No matching entry for %s in
`ispell-hunspell-dict-paths-alist'.\n" dict-key)) (if (and first-p (not
(file-exists-p affix-file))) (error "ispell-phaf: File \"%s\" not found.\n"
affix-file)) (and first-p (setq first-p nil)) (let ((dict-name
(file-name-sans-extension (file-name-nondirectory affix-file)))
otherchars-string) (let ((temp-buffer (generate-new-buffer " *temp*")))
(save-current-buffer (set-buffer temp-buffer) (unwind-protect (progn
(insert-file-contents affix-file) (setq otherchars-string (save-excursion
(goto-char (point-min)) (if (search-forward-regexp "^WORDCHARS +" nil t)
(buffer-substring (point) (progn (end-of-line) (point)))))) (if
otherchars-string (let* ((otherchars-string (substring otherchars-string 0
(string-match " +" otherchars-string))) (chars-list (append
otherchars-string nil))) (setq chars-list (delq 32 chars-list)) (let
((--dolist-tail-- chars-list)) (while --dolist-tail-- (let ((ch (car
--dolist-tail--))) (setq otherchars-list (if (member ch otherchars-list)
otherchars-list (cons ch otherchars-list))) (setq --dolist-tail-- (cdr
--dolist-tail--)))))))) (and (buffer-name temp-buffer) (kill-buffer
temp-buffer))))) (setq dict-arg (concat dict-arg (if (> (length dict-arg)
0) ",") dict-name)))) (setq --dolist-tail-- (cdr --dolist-tail--))))) (list
dict-key "[[:alpha:]]" "[^[:alpha:]]" (if otherchars-list (regexp-opt
(mapcar (function char-to-string) otherchars-list)) "") t (list "-d"
dict-arg) nil 'utf-8))
  ispell-parse-hunspell-affix-file(nil)
  (setq hunspell-default-dict-entry (ispell-parse-hunspell-affix-file
hunspell-default-dict))
  (let ((hunspell-found-dicts (split-string (let ((temp-buffer
(generate-new-buffer " *temp*"))) (save-current-buffer (set-buffer
temp-buffer) (unwind-protect (progn (ispell-call-process
ispell-program-name null-device t nil "-D") (buffer-string)) (and
(buffer-name temp-buffer) (kill-buffer temp-buffer))))) "[\n\015]+" t))
hunspell-default-dict hunspell-default-dict-entry hunspell-multi-dict) (let
((--dolist-tail-- hunspell-found-dicts)) (while --dolist-tail-- (let ((dict
(car --dolist-tail--))) (let* ((full-name (file-name-nondirectory dict))
(basename (file-name-sans-extension full-name)) (affix-file (concat dict
".aff"))) (if (string-match "\\.aff$" dict) (progn (if
hunspell-default-dict (setq hunspell-multi-dict (concat (or
hunspell-multi-dict (car hunspell-default-dict)) "," basename)) (setq
affix-file dict) (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)) (let
((affix-file (expand-file-name affix-file))) (ispell-print-if-debug "++
ispell-fhd: dict-entry:%s name:%s basename:%s affix-file:%s\n" dict
full-name basename affix-file) (setq ispell-hunspell-dict-paths-alist (let*
((va (list basename affix-file))) (if (member va
ispell-hunspell-dict-paths-alist) ispell-hunspell-dict-paths-alist (cons va
ispell-hunspell-dict-paths-alist))))) (ispell-print-if-debug "--
ispell-fhd: Skipping entry: %s\n" dict)))) (setq --dolist-tail-- (cdr
--dolist-tail--))))) (let (newlist) (let ((--dolist-tail--
ispell-dicts-name2locale-equivs-alist)) (while --dolist-tail-- (let ((dict
(car --dolist-tail--))) (if (assoc (car dict)
ispell-hunspell-dict-paths-alist) (ispell-print-if-debug "-- ispell-fhd:
Excluding %s alias.  Standalone dict found.\n" (car dict)) (setq newlist
(if (member dict newlist) newlist (cons dict newlist)))) (setq
--dolist-tail-- (cdr --dolist-tail--))))) (setq
ispell-dicts-name2locale-equivs-alist newlist)) (let ((--dolist-tail--
ispell-dicts-name2locale-equivs-alist)) (while --dolist-tail-- (let
((dict-equiv (car --dolist-tail--))) (let ((dict-equiv-key (car
dict-equiv)) (dict-equiv-value (car (cdr dict-equiv))) (exclude-aliases
(list "esperanto-tex" "francais7" "francais-tex" "norsk7-tex"))) (if (and
(assoc dict-equiv-value ispell-hunspell-dict-paths-alist) (not (assoc
dict-equiv-key ispell-hunspell-dict-paths-alist)) (not (member
dict-equiv-key exclude-aliases))) (let ((affix-file (car (cdr (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) (setq ispell-hunspell-dict-paths-alist (let*
((va (list dict-equiv-key affix-file))) (if (member va
ispell-hunspell-dict-paths-alist) ispell-hunspell-dict-paths-alist (cons va
ispell-hunspell-dict-paths-alist))))))) (setq --dolist-tail-- (cdr
--dolist-tail--))))) (setq hunspell-default-dict (or ispell-dictionary
hunspell-multi-dict (car hunspell-default-dict))) (setq
hunspell-default-dict-entry (ispell-parse-hunspell-affix-file
hunspell-default-dict)) (setq ispell-hunspell-dictionary-alist (list (cons
nil (cdr hunspell-default-dict-entry)))) (let ((--dolist-tail-- (mapcar
(function car) ispell-hunspell-dict-paths-alist))) (while --dolist-tail--
(let ((dict (car --dolist-tail--))) (setq ispell-hunspell-dictionary-alist
(let* ((va (if (string= dict hunspell-default-dict)
hunspell-default-dict-entry (list dict)))) (if (member va
ispell-hunspell-dictionary-alist) ispell-hunspell-dictionary-alist (cons va
ispell-hunspell-dictionary-alist)))) (setq --dolist-tail-- (cdr
--dolist-tail--))))))
  ispell-find-hunspell-dictionaries()
  eval((ispell-find-hunspell-dictionaries) nil)
  elisp--eval-last-sexp(t)
  eval-last-sexp(t)
  eval-print-last-sexp(nil)
  funcall-interactively(eval-print-last-sexp nil)
  call-interactively(eval-print-last-sexp nil nil)
  command-execute(eval-print-last-sexp)

The output of hunspell -D is:

SEARCH PATH:
.::/home/gregor/.config/libreoffice/4/user/wordbook::/usr/share/hunspell:/usr/share/myspell:/usr/share/myspell/dicts:/Library/Spelling:/home/gregor/.
openoffice.org/3/user/wordbook:/home/gregor/.openoffice.org2/user/wordbook:/home/gregor/.openoffice.org2.0/user/wordbook:/home/gregor/Library/Spelling:/opt/openoffice.org/basis3.0/share/dict/ooo:/usr/lib/openoffice.org/basis3.0/share/dict/ooo:/opt/openoffice.org2.4/share/dict/ooo:/usr/lib/openoffice.org2.4/share/dict/ooo:/opt/openoffice.org2.3/share/dict/ooo:/usr/lib/openoffice.org2.3/share/dict/ooo:/opt/openoffice.org2.2/share/dict/ooo:/usr/lib/openoffice.org2.2/share/dict/ooo:/opt/openoffice.org2.1/share/dict/ooo:/usr/lib/openoffice.org2.1/share/dict/ooo:/opt/openoffice.org2.0/share/dict/ooo:/usr/lib/openoffice.org2.0/share/dict/ooo
AVAILABLE DICTIONARIES (path is not mandatory for -d option):
/home/gregor/.config/libreoffice/4/user/wordbook/standard
/usr/share/hunspell/en_PH
/usr/share/hunspell/en_US-large
/usr/share/hunspell/en_US
/usr/share/myspell/dicts/en_PH
/usr/share/myspell/dicts/en_US-large
/usr/share/myspell/dicts/en_US
/home/gregor/Library/Spelling/en_GB
/home/gregor/Library/Spelling/sl_SI

Which causes the error since none of the listed dictionary files ends in
.aff, which causes the hunspell-default-dict to be nil on line 1179 in
ispell.el, which causes the error in the next sexp. The consequences of
this error are that spell checking does not work with hunspell and it is
not possible to set a dictionary via ispell-change-dictionary.

The quick and dirty fix of changing the line to

(setq hunspell-default-dict (or "british"
                                 hunspell-multi-dict
                                 (car hunspell-default-dict)))

(added "british" to the or) the problem goes away, and spell checking works
as expected.

hunspell version:
$ hunspell --version
@(#) International Ispell Version 3.2.06 (but really Hunspell 1.7.0)

Copyright (C) 2002-2014 László Németh. License: MPL/GPL/LGPL.

Based on OpenOffice.org's Myspell library.
Myspell's copyright (C) Kevin Hendricks, 2001-2002, License: BSD.

This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.

In GNU Emacs 26.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.30)
 of 2018-07-05 built on juergen
Windowing system distributor 'The X.Org Foundation', version 11.0.12003000
Recent messages:
Checking 105 files in /usr/share/emacs/26.1/lisp/obsolete...
Checking for load-path shadows...done
Mark set [2 times]
Auto-saving...done
Mark set
Sending...
Mark set [2 times]
Sending via mail...
Sending...done
Making completion list...

Configured using:
 'configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib
 --localstatedir=/var --with-x-toolkit=gtk3 --with-xft --with-modules
 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong
 -fno-plt' CPPFLAGS=-D_FORTIFY_SOURCE=2
 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro,-z,now'

Configured features:
XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS NOTIFY
ACL GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS
GTK3 X11 MODULES THREADS LIBSYSTEMD LCMS2

Important settings:
  value of $LANG: en_GB.utf8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Load-path shadows:
None found.

Features:
(mailalias mailclient browse-url qp cus-edit cus-start cus-load wid-edit
pp shadow sort mail-extr emacsbug message rmc puny seq dired
dired-loaddefs format-spec rfc822 mml mml-sec password-cache epa derived
epg epg-config gnus-util rmail rmail-loaddefs mm-decode mm-bodies
mm-encode mail-parse rfc2231 mailabbrev gmm-utils mailheader sendmail
rfc2047 rfc2045 ietf-drums mm-util mail-prsvr mail-utils help-mode
easymenu cl-print byte-opt bytecomp byte-compile cconv debug ispell
easy-mmode cl-macs gv subr-x cl-loaddefs cl-lib jka-compr elec-pair
time-date mule-util tooltip eldoc electric uniquify ediff-hook vc-hooks
lisp-float-type mwheel term/x-win x-win term/common-win x-dnd tool-bar
dnd fontset image regexp-opt fringe tabulated-list replace newcomment
text-mode elisp-mode lisp-mode prog-mode register page menu-bar
rfn-eshadow isearch timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core term/tty-colors frame cl-generic cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese eucjp-ms cp51932 hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese composite charscript charprop
case-table epa-hook jka-cmpr-hook help simple abbrev obarray minibuffer
cl-preloaded nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote dbusbind inotify lcms2
dynamic-setting system-font-setting font-render-setting move-toolbar gtk
x-toolkit x multi-tty make-network-process emacs)

Memory information:
((conses 16 144202 35741)
 (symbols 48 22905 5)
 (miscs 40 134 517)
 (strings 32 35096 3840)
 (string-bytes 1 960874)
 (vectors 16 22356)
 (vector-slots 8 1236476 199416)
 (floats 8 69 414)
 (intervals 56 2733 16)
 (buffers 992 17))