1

I know this has been asked many times, but the answers don't seem to do it for me.

How do you get Flyspell to work with hunspell?

After installing the hunspell executables via mingw-64-hunspell using MSYS 2 and adding dictionaries, I can successfully check words with the from MSYS shell like so:

$ echo baddword | hunspell -d en_US
Hunspell 1.4.0
& baddword 1 0: broadsword

On emacs i set the following in my config (.spacemacs dotspacemacs/user-config)

  (setq ispell-dictionary nil)
  (setq ispell-program-name "c:/msys64/mingw64/bin/hunspell.exe")
  ;; "en_US" is key to lookup in `ispell-local-dictionary-alist`, please note it will be passed to hunspell CLI as "-d" parameter
  (setq ispell-local-dictionary "en_US") 
  (setq ispell-local-dictionary-alist
        '(("en_US" "[[:alpha:]]" "[^[:alpha:]]" "[']" nil ("-d" "en_US") nil utf-8)))

Saved the config and restarted the program. When I type nonsense words, nothing is highlighted. However, I can do spell-check via the spell check buffer command. The bizarre thing however that this command only worked a couple of times and only on the .spacemacs file. Whenever I open a new empty buffer, it complains that it "can't open affix or dictionary files for dictionary ENU". I never specified an "ENU" dictionary anywhere, so that's not surprising. Also it starts a new "ispell process" every time I open a new file, which slows down performance by about 5 seconds.

TL;DR: how do you get a working spell checker that behaves like the spell-checker in your browser?

more on spell-checking in spacemacs, though I don't see any useful info there

Update

I used a slightly different config before that and it worked with warnings. After adding DICTPATH and the this code to init, everything works well.

  (setenv "LANG" "en_US, ru_RU")
  (setq-default  ispell-program-name "c:/msys64/mingw64/bin/hunspell.exe")
  (with-eval-after-load "ispell"
    (setq ispell-really-hunspell t)
    (setq ispell-program-name "hunspell")
    (setq ispell-dictionary "en_US,ru_RU")
    ;; ispell-set-spellchecker-params has to be called
    ;; before ispell-hunspell-add-multi-dic will work
    (ispell-set-spellchecker-params)
    (ispell-hunspell-add-multi-dic "en_US,ru_RU"))
  • I had the same error setting up hunspell on Win10 for Gnu Emacs. Apart from setting ispell-program-name I just have ((ispell-change-dictionary "en_GB" t) and it works fine now. Does that help? – Reign of Error Jan 15 '17 at 11:45
  • tried with just: (setq ispell-program-name c:/msys64/mingw64/bin/hunspell.exe") (ispell-change-dictionary "en_GB" t) and nothing else. same result. – user27636 Jan 16 '17 at 1:35
  • 1
    Ah - I looked further and I also did (setenv "LANG" "en_GB") in my startup. The "ENU" specifier is the one hunspell was getting by default from Windows 10, so I gave it a *nix-like Lang setting. With your setup I guess you might try "en_US". – Reign of Error Jan 16 '17 at 12:52
  • thanks that worked! now just to add multiple dictionaries and see spelling suggestions (which don't appear on click for some reason). we'll experiment some more tomorrow – user27636 Jan 17 '17 at 0:22
  • Great - if that was the main problem, perhaps you could reformat your question to make it clear, so other users can find it. At the moment your "tldr" summary is too broad and vague to be a useful qurstikn – Reign of Error Jan 18 '17 at 7:02
1

See Hunspell error in emacs my answer.

See Spell check with multiple dictionaries my answer on how to setup multiple dictionaries. I also explained what's the "-d" option in hunspell. You may use ispell-local-dictionary or ispell-dictionary who is nothing but a string key to look up hunspell options in both ispell-local-dictionary-alist and ispell-dictionary-alist. Here is my simplified version of actual code from ispell.el (Emacs 25.1.1):

(setq key (or ispell-local-dictionary ispell-dictionary))
(setq hunspell-options (or (assoc key ispell-local-dictionary-alist)
                           (assoc key ispell-dictionary-alist)))

There is no black magic, everything is documented in manual.

Step 1, You need setup environment variable PATH so (setq ispell-program-name "hunspell") will make Emacs find the hunspell executable

Step 2, You need setup environment variable DICTPATH so hunspell executable knows where to search dictionaries.

Step 3, You can specify dictionaries explicitly by setup of hunspell's -d option, or else hunspell tries to guess the right dictionary by querying your system's locale.

BTW, for step 2, you need check which format of path hunspell supports, it's very possible only Unix format like /usr/share/dict/ is supported. As I know MSYS is based on Cygwin. So it's likely they share the same environment variables setup (quoted from that Cygwin link: In addition to PATH, HOME, LD_LIBRARY_PATH, and GMON_OUT_PREFIX, there are three other environment variables which, if they exist in the Windows environment, are converted to UNIX format: TMPDIR, TMP, and TEMP).

0

I also have had issues with hunspell. Using the famous trial and error pattern, I ended-up with the following configuration:

.emacs

(add-to-list 'exec-path "C:\\Path\\To\\Hunspell\\bin")
(setq ispell-program-name "hunspell")
(use-package ispell
 :init
 (setq ispell-dictionary-alist 
  '(
    (nil
     "[[:alpha:]]"
     "[^[:alpha:]]"
     "[']"
     t
     ("-d" "default" "-p" "C:\\Path\\To\\HunspellDicts\\default")
     nil
     iso-8859-1)

    ("en_GB"
     "[[:alpha:]]"
     "[^[:alpha:]]"
     "[']"
     t
     ("-d" "en_GB" "-p" "C:\\Path\\To\\HunspellDicts\\en_GB")
     nil
     iso-8859-1)
    ))
(setq ispell-dictionary "en_GB")
)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.