Emacs用hunspell进行拼写检查:没有进行拼写检查

时间:2015-10-22 21:00:34

标签: macos emacs spell-checking hunspell ispell

我想在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.。我怎样才能让它发挥作用?

我找到了thisthis以及this相关帖子,但仍然无法找出问题。

2 个答案:

答案 0 :(得分:2)

好的,我明白了:在DICTIONARY中设置环境变量~/.bash_profile不起作用,但在(setenv "DICTIONARY" "en_US")中放置.emacs可以解决问题。

答案 1 :(得分:0)

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

终端命令:

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 init脚本中:

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