Reputation: 51
I have downloaded hunspell with a brew command, and want to use it in Emacs, but hunspell doesn't seem to locate my *.aff
and *.dic
files in ~/Library/Spelling
, even though they are there.
With the command line command hunspell -D
, the result is:
SEARCH PATH:
.::/usr/share/hunspell:/usr/share/myspell:/usr/share/myspell/dicts:/Library/Spelling:/Users/macbook/.openoffice.org/3/user/wordbook:/Users/macbook/.openoffice.org2/user/wordbook:/Users/macbook/.openoffice.org2.0/user/wordbook:/Users/macbook/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):
/Users/macbook/Library/Spelling/cs_CZ
Here, cs_CZ is the name of a file where my personal spelling is stored. There are other files in the folder, including cs_CZ.aff
and cs_CZ.dic
, as well as en_GB
, but hunspell simply ignores those.
In Emacs, I tried:
(setenv "DICPATH"
(concat (getenv "HOME") "/Library/Spelling"))
(when (executable-find "hunspell")
(setq-default ispell-program-name "hunspell")
(setq ispell-really-hunspell t))
After running ispell-change-dictinary with a recommended input "czech", ispell-word gives me:
Starting new Ispell process hunspell with czech dictionary... ispell-init-process: Can't open affix or dictionary files for dictionary named "czech".
...and flyspell-mode:
Error enabling Flyspell mode: (Can't open affix or dictionary files for dictionary named "czech".)
Thank you.
Upvotes: 5
Views: 3889
Reputation: 3381
Spell-checkers in Emacs look up spelling in two dictionaries: the standard dictionary and your personal dictionary. The standard dictionary is specified by the variable ispell-local-dictionary
or, if that is nil
, by the variable ispell-dictionary
. And as I can see in your output, Hunspell have only cs_CZ
, but not czech
dictionary:
AVAILABLE DICTIONARIES (path is not mandatory for -d option):
/Users/macbook/Library/Spelling/cs_CZ
By the way, Hunspell 1.7.0 was broken. For more see: https://github.com/hunspell/hunspell/issues/608. You can compare the output between
hunspell -D
and
hunspell -D /dev/null
to see the difference.
First, set the desired dictionary name you have installed:
;; Default dictionary to use
(setq ispell-local-dictionary "czech")
To see a list of found and parsed dictionaries use C-h v ispell-hunspell-dict-paths-alist
.
In addition, I would like to suggest add your preferred dictionaries to ispell-local-dictionary-alist
. This variable used to specify an alist of dictionaries and their associated parameters. Note, you have to use the same dictionary name a in ispell-dictionary
. Something like this should work:
;; Here ("-d" "cs_CZ") is dictionary file name.
;; You could use '("-d" "file1,file2")' form to use multiple dictionaries.
(add-to-list
'ispell-local-dictionary-alist
'(("czech" "[[:alpha:]]" "[^[:alpha]]" "[0-9']" t
("-d" "cs_CZ") nil utf-8)))
Note, Homebrew itself provides no dictionaries for Hunspell, but you can download compatible dictionaries from other sources, such as https://extensions.libreoffice.org/en/extensions/show/czech-dictionaries. For instructions see for example: https://passingcuriosity.com/2017/emacs-hunspell-and-dictionaries.
Finally, I highly recommend to set DICTIONARY
environment variable on macOS. Without this variable you'll see on macOS something like this:
Can't open affix or dictionary files for dictionary named "XXX"
I managed to reproduce this issue on macOS. But on Linux, with the same configuration and Emacs version everything works fine. To set dictionary file name use setenv
defun as follows:
(when (string-equal system-type "darwin") ; Only for macOs
;; Dictionary file name
(setenv "DICTIONARY" "cs_CZ"))
This environment variable is used by Hunspell. For more see man 1 hunspell
.
Upvotes: 4