Hunspell / emacs on OS X 10.9
I can't get the aspell to build, so I am trying to hunspell. Built by hunspell. Configure .emacs so emacs can (and does) find the executable, for example:
;;; Spell checking using hunspell
(setq ispell-dictionary-alist
'((nil "[A-Za-z]" "[^A-Za-z]" "[']" t
("-d" "en_US" "-i" "utf-8") nil utf-8)
("american"
"[A-Za-z]" "[^A-Za-z]" "[']" nil
("-d" "en_US") nil utf-8)
("english"
"[A-Za-z]" "[^A-Za-z]" "[']" nil
("-d" "en_GB") nil utf-8)
("british"
"[A-Za-z]" "[^A-Za-z]" "[']" nil
("-d" "en_GB") nil utf-8)
("norsk"
"[A-Za-zÉÆØÅéæøå]" "[^A-Za-zÉÆØÅéæøå]" "[\"]" nil
("-d" "nb_NO") "~list" utf-8)))
(eval-after-load "ispell"
(progn
(setq ispell-dictionary "english"
ispell-extra-args '("-a" "-i" "utf-8")
ispell-silently-savep t)))
(setq ispell-dictionary "en_US")
(setq ispell-program-name "/usr/local/bin/hunspell")
and this is in my .bash_profile
export DICTIONARY=en_US
export DICPATH=/Users/myname/Applications/en_US
also tried
export DICTIONARY=en_US
export DICPATH=/Users/gpajer/Applications/
(there is the ~ / Applications / en_US directory, which contains the dictionary files)
But ispell-buffer returns something like
Can't open affix or dictionary flies for dictionary named "english".
@(#) International Ispell Version 3.2.06 (but really Hunspell 1.3.2)
@(#) International Ispell Version 3.2.06 (but really Hunspell 1.3.2)
Is hunspell not finding the dictionary? Is there a special place where I should put the dictionary? or how can I tell emacs / hunspell where to look for the dictionary?
source to share
Upgrade to Emacs 24.4 by either installing the latest pre-test or by creating an Emacs trunk. Pretest builds and Emacs trunk nightly builds are available from Emacs for Mac OS X under Pretests and Nightlies, respectively.
Emacs 24.4 greatly improves support for Hunspell, and it can now automatically use Hunspell with a little tweak. Notably, Emacs can now find available Hunspell dictionaries and auto-complete ispell-dictionary-alist
. Basically, you just need to tell Emacs to use hunspell:
(setq ispell-program-name (executable-find "hunspell"))
You need to explicitly install these dictionaries for Hunspell, though, depending on how you installed Hunspell. Usually you just need to put the appropriate files *.aff
and *.dic
in ~/Library/Spelling
. However, getting dictionaries is a little more difficult. The best way is probably to download the appropriate LibreOffice extensions and extract the files to *.dic
and *.aff
from OXT files, which are essentially just ZIP files. At least that's what I do. There may be better sources for dictionaries.
In addition to language-speaking dictionaries, you also need a default Emacs dictionary. This dictionary should be called default
literally. However, creating it is quite simple. Just create symbolic links to dictionaries of your preferred language:
$ cd ~/Library/Spelling
$ ln -s en_GB.aff default.aff
$ ln -s en_GB.dic default.dic
That's all I need to get Hunspell and work on my system.
source to share
Here is my Emacs 24.4 / OS X 10.9 work related to Hunspell, hope it helps.
First run the path:
(cond
((eq system-type 'darwin)
;; Sane path (OSX doesn't've much on the path when launching not from shell:
(setq path "/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/texbin:/opt/local/bin")
(setenv "PATH" path)
;; Emacs 24.4 seems to need this...:
(mapc (lambda (p) (push p exec-path)) '("/usr/local/bin" "/usr/texbin" "/opt/local/bin"))))
Then point to Hunspell and configure it:
(setq-default ispell-program-name (executable-find "hunspell"))
(setq ispell-dictionary "american"
ispell-extra-args '() ;; TeX mode "-t"
ispell-silently-savep t
)
(add-hook 'ispell-initialize-spellchecker-hook
(lambda ()
(setq ispell-base-dicts-override-alist
'((nil ; default
"[A-Za-z]" "[^A-Za-z]" "[']" t
("-d" "en_US" "-i" "utf-8") nil utf-8)
("american" ; Yankee English
"[A-Za-z]" "[^A-Za-z]" "[']" t
("-d" "en_US" "-i" "utf-8") nil utf-8)
("british" ; British English
"[A-Za-z]" "[^A-Za-z]" "[']" t
("-d" "en_GB" "-i" "utf-8") nil utf-8)))))
source to share