【问题标题】:On MacOS, hunspell can't find existing .aff and .dic files in Library/Spelling/在 MacOS 上,hunspell 在 Library/Spelling/ 中找不到现有的 .aff 和 .dic 文件
【发布时间】:2019-10-19 03:36:29
【问题描述】:

我已经下载了带有 brew 命令的 hunspell,并想在 Emacs 中使用它,但 hunspell 似乎没有在 ~/Library/Spelling 中找到我的 *.aff*.dic 文件,即使它们在那里。

用命令行命令hunspell -D,结果是:

SEARCH PATH:
.::/usr/share/hunspell:/usr/share/myspell:/usr/share/myspell/dicts:/Library/Spelling:/Users/macbook/.openoffice.org/3/user/wordbook:/Users/macbook/.openoffice.org2/user/wordbook:/Users/macbook/.openoffice.org2.0/user/wordbook:/Users/macbook/Library/Spelling:/opt/openoffice.org/basis3.0/share/dict/ooo:/usr/lib/openoffice.org/basis3.0/share/dict/ooo:/opt/openoffice.org2.4/share/dict/ooo:/usr/lib/openoffice.org2.4/share/dict/ooo:/opt/openoffice.org2.3/share/dict/ooo:/usr/lib/openoffice.org2.3/share/dict/ooo:/opt/openoffice.org2.2/share/dict/ooo:/usr/lib/openoffice.org2.2/share/dict/ooo:/opt/openoffice.org2.1/share/dict/ooo:/usr/lib/openoffice.org2.1/share/dict/ooo:/opt/openoffice.org2.0/share/dict/ooo:/usr/lib/openoffice.org2.0/share/dict/ooo
AVAILABLE DICTIONARIES (path is not mandatory for -d option):
/Users/macbook/Library/Spelling/cs_CZ

这里,cs_CZ 是存储我个人拼写的文件的名称。该文件夹中还有其他文件,包括cs_CZ.affcs_CZ.dic,以及en_GB,但hunspell 只是忽略了这些。

在 Emacs 中,我尝试过:

(setenv "DICPATH"
    (concat (getenv "HOME") "/Library/Spelling"))
(when (executable-find "hunspell")
      (setq-default ispell-program-name "hunspell")
      (setq ispell-really-hunspell t))

使用推荐的输入“czech”运行 ispell-change-dictinary 后,ispell-word 给出:

使用捷克语词典启动新的 Ispell 进程 hunspell... ispell-init-process:无法打开词缀或字典文件 字典名为“捷克语”。

...和flyspell模式:

启用 Flyspell 模式时出错:(无法打开词缀或字典文件 对于名为“czech”的字典。)

谢谢。

【问题讨论】:

    标签: macos emacs hunspell spelling


    【解决方案1】:

    Emacs 中的拼写检查器在两个字典中查找拼写:标准字典和您的个人字典。标准字典由变量ispell-local-dictionary 指定,或者,如果是nil,则由变量ispell-dictionary 指定。正如我在您的输出中看到的,Hunspell 只有cs_CZ,但没有czech 字典:

    AVAILABLE DICTIONARIES (path is not mandatory for -d option):
    /Users/macbook/Library/Spelling/cs_CZ
    

    顺便说一句,Hunspell 1.7.0 被破坏了。有关更多信息,请参阅:https://github.com/hunspell/hunspell/issues/608。您可以比较输出之间的

    hunspell -D
    

    hunspell -D /dev/null
    

    看看有什么不同。

    首先,设置您已安装的所需字典名称:

    ;; Default dictionary to use
    (setq ispell-local-dictionary "czech")
    

    要查看找到并解析的词典列表,请使用 C-h v ispell-hunspell-dict-paths-alist

    此外,我想建议将您喜欢的词典添加到ispell-local-dictionary-alist。此变量用于指定字典及其相关参数的alist。请注意,您必须在 ispell-dictionary 中使用相同的字典名称 a。像这样的东西应该可以工作:

    ;; Here ("-d" "cs_CZ") is dictionary file name.
    ;; You could use '("-d" "file1,file2")' form to use multiple dictionaries.
    (add-to-list
     'ispell-local-dictionary-alist
     '(("czech" "[[:alpha:]]" "[^[:alpha]]" "[0-9']" t
        ("-d" "cs_CZ") nil utf-8)))
    

    注意,Homebrew 本身没有为 Hunspell 提供字典,但你可以下载 来自其他来源的兼容字典,例如 https://extensions.libreoffice.org/en/extensions/show/czech-dictionaries。有关说明,请参见例如:https://passingcuriosity.com/2017/emacs-hunspell-and-dictionaries

    最后,我强烈建议在 macOS 上设置 DICTIONARY 环境变量。如果没有这个变量,你会在 macOS 上看到类似这样的东西:

    无法打开名为“XXX”的词典的词缀或词典文件

    我设法在 macOS 上重现了这个问题。但在 Linux 上,使用相同的配置和 Emacs 版本,一切正常。设置字典文件名使用setenvdefun,如下:

    (when (string-equal system-type "darwin") ; Only for macOs
      ;; Dictionary file name
      (setenv "DICTIONARY" "cs_CZ"))
    

    Hunspell 使用此环境变量。更多信息请见man 1 hunspell

    【讨论】:

      猜你喜欢
      • 2016-02-26
      • 1970-01-01
      • 2021-08-17
      • 1970-01-01
      • 2018-10-05
      • 2021-03-30
      • 1970-01-01
      • 2020-07-01
      • 1970-01-01
      相关资源
      最近更新 更多