Subject: 24.5; ispell-change-dictionary suggests non-existent dicts (aspell)

From: Ole Jørgen Brønner <[email-masked]>
Date: Thu, 21 Jul 2016 21:49:06 +0200

I'm using aspell as the "ispell provider".

    M-x ispell-change-dictionary

helpfully gives a list of dictionaries to choose from. The list however contains
dictionaries I don't have installed on my system. Only after spellchecking is
attempted I get an error in *Messages*.

Diving into the code I find quite an effort to build a list of
dictionaries for the three different ispell providers.

There's a dedicated function, `ispell-find-aspell-dictionaries`, to find valid
aspell dictionaries. It sanely ask bin/aspell for the list and then does some
post-processing to find the rest of the spec.

But after the *correct* list has been found this code[1] is run:

    ;; Merge into FOUND any elements from the standard
ispell-dictionary-base-alist
    ;; which have no element in FOUND at all.
    (dolist (dict ispell-dictionary-base-alist)
      (unless (assoc (car dict) found)
    (setq found (nconc found (list dict)))))

Adding invalid entries to the list. There might be a rationale behind that, but
to me is seems like `ispell-dictionary-base-alist` mostly exist due to lack of
*ispell* (old aspell?) introspection? (When using *ispell* as the
provider, invalid entries
 are filtered out in `ispell-valid-dictionary-list`)

Removing that code isn't enough though:

In `ispell-set-spellchecker-params` the invalid entries are added again:
(where `found-dicts-alist` is the result of `ispell-find-aspell-dictionaries`
in when aspell is used)

    (run-hooks 'ispell-initialize-spellchecker-hook)

    ;; Add dicts to ``ispell-dictionary-alist'' unless already present.
    (dolist (dict (append found-dicts-alist
                          ispell-base-dicts-override-alist
                          ispell-dictionary-base-alist))
      (unless (assoc (car dict) all-dicts-alist)
        (add-to-list 'all-dicts-alist dict)))
    (setq ispell-dictionary-alist all-dicts-alist))

This code seems to have two purposes:
- When *ispell* is the provider, `found-dicts-alist` is nil at this
point, so the
  default entries must be added
- Apply dictionary overrides (possibly set by the hook above)

I would suggest simply removing [1] and not add the *base-alist above when using
aspell/hunspell, but the following comment makes it seem like the "invalid"
entries are added intentionally:

    ;; Substitute ispell-dictionary-alist with the list of
    ;; dictionaries corresponding to the given spellchecker.
    ;; If a recent aspell or hunspell, use the list of really
    ;; installed dictionaries and add to it elements of the original
    ;; list that are not present there*. Allow distro info.

In GNU Emacs 24.5.1 (x86_64-unknown-linux-gnu, GTK+ Version 3.20.6)
 of 2016-06-04 on juergen
Windowing system distributor `The X.Org Foundation', version 11.0.11803000
Configured using:
 `configure --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib
 --localstatedir=/var --with-x-toolkit=gtk3 --with-xft
 'CFLAGS=-march=x86-64 -mtune=generic -O2 -pipe
 -fstack-protector-strong' CPPFLAGS=-D_FORTIFY_SOURCE=2
 LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro'

Important settings:
  value of $LC_COLLATE: en_US.UTF-8
  value of $LC_CTYPE: en_US.UTF-8
  value of $LC_MESSAGES: en_US.UTF-8
  value of $LC_MONETARY: en_US.UTF-8
  value of $LC_NUMERIC: en_US.UTF-8
  value of $LC_TIME: nb_NO.utf8
  value of $LANG: en_US.utf8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  tooltip-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

Recent messages:
Making completion list... [2 times]
Local Ispell dictionary set to german
Entering debugger...
Back to top level.
<C-tab> is undefined
Making completion list... [2 times]
Starting new Ispell process /usr/bin/aspell with german dictionary...
ispell-init-process: Error: The file "/usr/lib/aspell-0.60/german" can
not be opened for reading.
ESC M-x is undefined [3 times]
Making completion list... [2 times]

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util
help-fns mail-prsvr mail-utils debug ispell help-mode easymenu time-date
tooltip electric uniquify ediff-hook vc-hooks lisp-float-type mwheel
x-win x-dnd tool-bar dnd fontset image regexp-opt fringe tabulated-list
newcomment lisp-mode prog-mode register page menu-bar rfn-eshadow timer
select scroll-bar mouse jit-lock font-lock syntax facemenu font-core
frame cham georgian utf-8-lang misc-lang vietnamese tibetan thai
tai-viet lao korean japanese hebrew greek romanian slovak czech european
ethiopic indian cyrillic chinese case-table epa-hook jka-cmpr-hook help
simple abbrev minibuffer 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 make-network-process
dbusbind gfilenotify dynamic-setting system-font-setting
font-render-setting move-toolbar gtk x-toolkit x multi-tty emacs)

Memory information:
((conses 16 76572 7275)
 (symbols 48 18057 0)
 (miscs 40 46 163)
 (strings 32 10715 4971)
 (string-bytes 1 296127)
 (vectors 16 9261)
 (vector-slots 8 387535 14421)
 (floats 8 65 422)
 (intervals 56 220 26)
 (buffers 960 13)
 (heap 1024 26108 1053))