在Mac OS X上使用Emacs,如何使拼写检查功能生效?

21

我正从Windows转移到Mac,并花了整个晚上尝试让emacs工作。

我已经安装了GNU Emacs,并简单地复制了我的Windows .emacs文件,看起来一切都正常,除了拼写检查。我安装了CocoAspell,并按照这个设置说明添加了路径并将ispell更改为aspell,但是当我运行拼写检查时,出现了以下情况:

Error: The file "/use/local/lib/aspell-0.60/english" can not be opened for reading.

而且FlySpell也无法工作。

看起来它正在查找错误的目录,但我已经有了

(setq ispell-program-name "aspell"
      ispell-dictionary "english"
      ispell-dictionary-alist
      (let ((default '("[A-Za-z]" "[^A-Za-z]" "[']" nil
                       ("-B" "-d" "english" "--dict-dir"
                        "/Library/Application Support/cocoAspell/aspell6-en-6.0-0")
                       nil iso-8859-1)))
        `((nil ,@default)
          ("english" ,@default))))

它指向正确的字典目录"/Library/Application Support/cocoAspell/aspell6-en-6.0-0"。我不知道为什么会出现错误以及如何修复它。


更新:

现在我已经移除了GNU Emacs和CocoAspell,并像@katspaugh建议的那样使用Homebrew重新安装(并链接)emacs/aspell。我删除了上面显示的代码,只留下

(setq ispell-program-name "aspell")

现在当我运行拼写检查时,我得到了:

Searching for program: No such file or directory, aspell

我已经通过 brew link aspell 将 aspell 进行了链接,为什么它仍然找不到它?


3
错误信息确实说了“use/local”吗?如果是这样,那么你的某处有拼写错误——应该是“usr/local”。 - Lindydancer
1
如果您正在使用CUA模式和其他类似于Mac/Windows的功能,您可能想考虑使用Aquamacs而不是GNU Emacs。除了许多其他有用的功能外,它还配备了正确配置的aspell,并且如果您喜欢,还可以让您使用OS X系统拼写检查器。 - abarnert
请参考以下链接:https://emacs.stackexchange.com/questions/33865/spelling-check-in-emacs-25-2-on-mac-os-sierra - Timur Shtatland
8个回答

29

以下是一种可行的解决方案:

  • 安装Homebrew
  • brew install emacs --with-cocoa --with-gnutls
  • brew install aspell
  • open -a Emacs
  • M-x ispell

享受吧!


2
使用 aspell 而不是 ispell。 - user355252
1
我看到 aspell 有更好的 Unicode 支持。需要检查上面的方法是否与 aspell 相同。 - katspaugh
1
它应该可以。Aspell提供与ispell相同的接口,而ispell和flyspell都应该自动捕获它。 - user355252
2
@katspaugh 这些字典已经包含在公式中了。只需要查看它们的参数,并选择你需要的,例如 brew install aspell --with-lang-de - user355252
1
顺便说一下,使用brew install emacs --cocoa --srgb --with-gnu-tls安装Emacs。这将改善颜色外观,并启用Emacs的加密网络流量。 - user355252
显示剩余7条评论

12

我使用来自Homebrew的aspell。 简单地说:

brew install aspell --with-lang-en

然后,请确保您的brew bin目录在Emacs的exec-path变量中。如果您使用/usr/local作为brew前缀,则它将正常工作,因为该路径默认包含在exec-path中。否则,您需要在您的.emacs文件中添加以下内容:

  (setq exec-path (append "/path/to/brew/bin" exec-path)))

您也可以使用 "M-x customize-variable RET exec-path RET" 命令进入自定义界面,然后使用图形界面添加路径,以实现相同的功能。

这将适用于任何 Emacs,包括来自Emacs for Mac OS X、brew 或系统 Emacs。


1
现在添加语言时会出现“无效选项:--with-lang-en”的错误。请使用“brew install aspell”进行安装。 - miguelmorin

4

我在katspaugh、David Caldwell和Ébe Isaac的回答基础上进行了补充,并使其与最新版本兼容。

安装aspell,例如使用brew

brew install aspell

brew符号链接到/usr/local/bin,您可以验证安装:

$ which aspell
/usr/local/bin/aspell

现在请告知Emacs这个位置,例如在~/.emacs中添加以下行:
(setq ispell-program-name "/opt/local/bin/aspell")

在缓冲区中启动M-x ispell命令即可使用。

要使用ports安装,请查看其他答案。


3
这里提供了一个 MacPorts 解决方案来解决这个问题。 (感谢这篇文章)
然后安装相应语言支持的 aspell 字典之一。 $ sudo port install aspell $ sudo port install aspell-dict-en
最后在你的 init.el 或 .emacs 文件中添加以下行。
(setq ispell-program-name "/opt/local/bin/aspell")

它对我有用。

注意:"sudo ports install ispell"也可以工作,但它不像aspell那样高效和灵活。


1
在OS X 10.12(Sierra)中,在/usr/bin创建符号链接是不允许的,也不必要(或者不是一个好主意)。
$ sudo ln -s /usr/local/bin/ispell /usr/bin/ispell
ln: /usr/bin/ispell: Operation not permitted

我使用这个黑科技多年了,但最后一次升级将其删除后,我终于不得不找出正确的解决方案。我使用 homebrew 安装了 ispell 和 apsell,并通过 ~/.emacs 获取我设置的任何一个。

$ cat ~/.emacs
(setq ispell-program-name "/usr/local/bin/aspell")

这里有一个类似的讨论在这里


0

如果您使用fink而不是home-brew,也可以这样做。 ispell将位于/sw/bin中,要添加到.emacs文件的字符串如下:

(setq ispell-program-name "/sw/bin/ispell")


0

使用brew cask install emacs安装的Emacs将自带一个名为m-x ispell的拼写检查器。

要使其工作,您需要执行两个步骤:

  1. 执行brew install aspell或者brew install aspell --with-lang-en

  2. 进入Emacs并评估此函数,或者更好的方法是将其放入您的init文件中:(setq ispell-program-name "/usr/local/bin/aspell")

注意:在macOS终端中可以使用which aspell找到aspell的位置,应该与上述第2步相等。


0
安装aspell,并在init.el中添加(setq ispell-program-name "/usr/local/bin/aspell")对我来说不起作用。我不得不创建一个符号链接sudo ln -s /usr/local/bin/aspell /usr/bin/ispell,然后emacs flyspell-mode可以正常工作。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接