【问题标题】:hunspell / emacs on OS X 10.9OS X 10.9 上的 hunspell / emacs
【发布时间】:2014-08-20 21:54:41
【问题描述】:

我无法构建 aspell,所以我正在尝试 hunspell。建立了hunspell。设置 .emacs 以便 emacs 可以(并且确实)找到可执行文件,如下所示:

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

这在我的 .bash_profile 中

export DICTIONARY=en_US
export DICPATH=/Users/myname/Applications/en_US

也试过

export DICTIONARY=en_US
export DICPATH=/Users/gpajer/Applications/

(有一个目录 ~/Applications/en_US 存放字典文件)

但是 ispell-buffer 返回类似

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)

hunspell 没有找到字典吗?有什么特别的地方应该放字典吗?或者我如何告诉 emacs/hunspell 在哪里查找字典?

【问题讨论】:

  • 我最初也遇到了 aspell 的问题,但我最终得到了它。这是我关于使用什么源以及如何在 OSX 上安装它的注释的链接——我仍然使用 OSX 10.6.8:stackoverflow.com/a/20013202/2112489
  • ispell-dictionary 有两 (2) 个不同的定义。
  • @lawlist 是的,但这不是问题所在。这是尝试一千万种想法的剩余产物。
  • @lawlist 谢谢,但是您的 aspell 解决方案不起作用。请参阅 my earlier question 我的 aspell 问题。您的解决方案遇到了同样的错误。 Aspell 或 hunspell ...我不在乎哪个!我只想要一个拼写检查器。
  • @Peter Salazar -- 嗯。 . .我不记得为什么我删除了我的帖子——也许有人在没有发表评论的情况下给了我一个缺点,我想。 . . :) 我现在将取消删除它。

标签: emacs hunspell


【解决方案1】:

升级到 Emacs 24.4,方法是安装最近的预测试或构建 Emacs 主干。用于 Emacs 主干的预测试和夜间构建的预构建二进制文件可从 Emacs for Mac OS X 获得,分别位于“预测试”和“夜间”部分。

Emacs 24.4 显着改进了对 Hunspell 的支持,现在只需进一步定制就可以自动使用 Hunspell。值得注意的是,Emacs 现在可以发现可用的 Hunspell 字典,并自动填充 ispell-dictionary-alist。本质上,您只需要以下内容来告诉 Emacs 使用 hunspell:

(setq ispell-program-name (executable-find "hunspell"))

不过,您需要为 Hunspell 显式安装这些词典,具体取决于您安装 Hunspell 的方式。正常情况下,只需要将对应的*.aff*.dic文件放入~/Library/Spelling即可。不过,获取字典要困难一些。最好的方法可能是下载相应的 LibreOffice 扩展并从 OXT 文件中提取 *.dic*.aff 文件,这些文件本质上只是 ZIP 文件。至少,这就是我所做的。可能有更好的字典来源。

除了特定于语言的字典外,您还需要有一个 Emacs 的“默认”字典。这本词典需要按字面意思命名为default。不过,创建它很容易。只需创建指向您首选语言的字典的符号链接:

$ cd ~/Library/Spelling
$ ln -s en_GB.aff default.aff
$ ln -s en_GB.dic default.dic

这就是我启动 Hunspell 并在我的系统上工作所需要的一切。

【讨论】:

  • 我已经尝试了数周来让 any 拼写检查器在新的 Mac 和 emacs 上工作。我有 hunspell,Emacs 24.4.50,并按照你的建议做了。结果:使用默认字典启动新的 Ispell 进程 nil ... ispell-check-version:错误的类型参数:stringp,nil
  • 我的 Emacs 出了点问题。 .emacs 中设置的变量不被接受。无论我在 .emacs 中如何设置,ispell-program-name 在启动后都为零:您的建议,setq ispell-program-name,或通过菜单驱动的自定义...始终为零。如果我在 Emacs 启动后手动设置变量,一切都很好,直到我下次启动 Emacs。
  • Argh ... 没那么简单。即使是手动设置,有时它也能工作,有时不能。我得再挖一些。
  • @garyp 这个错误意味着你没有default 字典。您是否按照答案中的说明添加了default.{aff,dic} 的符号?
  • @garyp 如果变量是nil,即使您在init.el 中设置了它,如this answer中所述,executable-find 返回nil,这表明它没有找到@987654337 @在exec-path。您是否通过 Homebrew 安装了hunspell?如果是这样,/usr/local/bin 在您的exec-path 中吗?你的 Emacs 中有正确的 $PATH 吗?
【解决方案2】:

这是我正在使用的 Emacs 24.4 / OS X 10.9 Hunspell 相关设置,希望对您有所帮助。

首先,让路径正常工作:

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

然后,指向 Hunspell 并进行设置:

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

【讨论】:

    猜你喜欢
    • 2013-11-03
    • 1970-01-01
    • 2013-11-01
    • 2013-11-03
    • 2014-02-12
    • 1970-01-01
    • 2014-03-05
    • 1970-01-01
    相关资源
    最近更新 更多