使用 hunspell 进行 Emacs 拼写检查:未完成拼写检查

Emacs spell checking with hunspell: no spell-checking done

我想在 GNU Emacs 24.5.1(在 Mac OS X 11.10)中激活拼写检查。我做了以下事情:

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 从终端正确运行)。在 ~/.bash_profile 中,我设置了 export DICTIONARY=en_US 并且我的 ~/.emacs 显示:

;; 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))

但是,当我打开任何 .txt 文件时,我没有看到带下划线的拼写检查错误或任何内容...并且 M-x ispell 显示 ispell-parse-hunspell-affix-file: ispell-phaf: No matching entry for nil.。我怎样才能让它工作?

我找到了this and this and this相关的post,但还是没弄清楚问题所在

好吧,我想通了:在~/.bash_profile中设置环境变量DICTIONARY没有用,但是在.emacs中设置(setenv "DICTIONARY" "en_US")解决了问题。

如果 flyspell 可以使用 en_GB 字典通过 use-package 加载,我用它有条件地加载 hunspell

终端命令:

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

然后在我的 Emacs 初始化脚本中:

  (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"))