在 MacOS 上,hunspell 在 Library/Spelling/ 中找不到现有的 .aff 和 .dic 文件

Dan*_*mey 5 macos emacs spelling hunspell

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

使用命令行命令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
Run Code Online (Sandbox Code Playgroud)

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

在 Emacs 中,我尝试过:

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
Run Code Online (Sandbox Code Playgroud)

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

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

...和flyspell模式:

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

谢谢。

ser*_*hei 4

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
Run Code Online (Sandbox Code Playgroud)

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

hunspell -D
Run Code Online (Sandbox Code Playgroud)

hunspell -D /dev/null
Run Code Online (Sandbox Code Playgroud)

看看差异。

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

AVAILABLE DICTIONARIES (path is not mandatory for -d option):
/Users/macbook/Library/Spelling/cs_CZ
Run Code Online (Sandbox Code Playgroud)

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

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

hunspell -D
Run Code Online (Sandbox Code Playgroud)

请注意,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,如下所示:

hunspell -D /dev/null
Run Code Online (Sandbox Code Playgroud)

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