hunspell / emacs on OS X 10.9

谁说胖子不能爱 提交于 2019-12-06 07:23:28

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.

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)))))
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!