Search code examples
macosemacsspell-checkinghunspellispell

Emacs spell checking with hunspell: no spell-checking done


I would like to activate spell checking within GNU Emacs 24.5.1 (on Mac OS X 11.10). I did the following:

1) brew install hunspell
2) cd ~/Library/Spelling
   wget http://cgit.freedesktop.org/libreoffice/dictionaries/plain/en/en_US.aff
   wget http://cgit.freedesktop.org/libreoffice/dictionaries/plain/en/en_US.dic

(hunspell -D runs correctly from the terminal). In ~/.bash_profile I set export DICTIONARY=en_US and my ~/.emacs shows:

;; Activate Hunspell
(when (executable-find "hunspell")
  (setq-default ispell-program-name "/usr/local/bin/hunspell")
  (setq ispell-really-hunspell t))

;; Activate flyspell
(add-hook 'text-mode-hook 'flyspell-mode)
(add-hook 'message-mode-hook 'flyspell-mode)
(setq flyspell-issue-message-flag nil)
(mapcar (lambda (mode-hook) (add-hook mode-hook 'flyspell-prog-mode))
    '(c-mode-common-hook R-mode-hook emacs-lisp-mode-hook))

However, when I open any .txt file, I don't see spell-checking errors underlined or anything... and M-x ispell shows ispell-parse-hunspell-affix-file: ispell-phaf: No matching entry for nil.. How can I get this to work?

I found this and this and this related post, but still couldn't figure out the problem.


Solution

  • Okay, I figured it out: Setting the environment variable DICTIONARY in ~/.bash_profile didn't work, but putting (setenv "DICTIONARY" "en_US") in .emacs solved the problem.