2

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.

Community
  • 1
  • 1
Marius Hofert
  • 6,546
  • 10
  • 48
  • 102

2 Answers2

4

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.

Marius Hofert
  • 6,546
  • 10
  • 48
  • 102
2

I used this to conditionally load hunspell if flyspell can be loaded via use-package using en_GB dictionary.

Terminal commands:

brew install hunspell
cd ~/Library/Spelling/
wget http://cgit.freedesktop.org/libreoffice/dictionaries/plain/en/en_GB.aff
wget http://cgit.freedesktop.org/libreoffice/dictionaries/plain/en/en_GB.dic
ln -s en_GB.dic english.dic
ln -s en_GB.aff english.aff

Then in my Emacs init script:

  (use-package flyspell
    :hook ((text-mode . flyspell-mode)
           (prog-mode . flyspell-prog-mode))
    :config
    (when (executable-find "hunspell")
      (setq ispell-program-name (executable-find "hunspell"))
      (setq ispell-really-hunspell t)
      (setenv "DICTIONARY" "english"))
    (setq ispell-dictionary "english"))
cjohansson
  • 1,058
  • 10
  • 13
  • Almost two years later! Do you know how I would use different languages in the setup you showed here? Thanks a lot – Nathan Furnal Dec 31 '19 at 04:23
  • Yeah just replace the language-codes path (en/en_GB) and language names (english) to what you like. You can see the full index here: https://cgit.freedesktop.org/libreoffice/dictionaries/plain/ – cjohansson Jan 03 '20 at 13:01