问题
I can't get aspell to build, so I'm trying hunspell. Got hunspell built. Set up .emacs so that emacs can (and does) find the executable, like so:
;;; 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 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's a directory ~/Applications/en_US in which the dictionary files reside)
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 I should put the dictionary? or how do I tell emacs/hunspell where to look for the dictionary?
回答1:
Upgrade to Emacs 24.4, either by installing a recent pretest or by building Emacs trunk. Prebuild binaries for pretests and nightly builds of Emacs trunk are available from Emacs for Mac OS X, in the “Pretests” and “Nightlies” sections respectively.
Emacs 24.4 considerably improves support for Hunspell, and is now able to use Hunspell automatically with only little further customization. Notably, Emacs can now discover available Hunspell dictionaries, and fills ispell-dictionary-alist
automatically. Essentially, you just need the following 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. Normally, you just need to put the corresponding *.aff
and *.dic
files into ~/Library/Spelling
. Obtaining dictionaries is a little more difficult, though. The best way probably is to download the corresponding LibreOffice extensions and extract the *.dic
and *.aff
files from the OXT files, which are essentially just ZIP files. At least, that's what I do. There may be better sources of dictionaries.
Besides language-specific dictioniaries, you also need to have a “default” dictionary for Emacs. This dictionary needs to be named default
, literally. Creating it is easy enough, though. Just create symlinks to the 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 needed to get Hunspell up and working on my system.
回答2:
Here is my working Emacs 24.4 / OS X 10.9 Hunspell related setup, hope it helps.
First, get the path working:
(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 set it up:
(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)))))
来源:https://stackoverflow.com/questions/25415070/hunspell-emacs-on-os-x-10-9