如何在 emacs 中为所有文件和所有主要模式启用 Flyspell 模式?
如何在 Emacs 启动时自动对每个文件和每个主要模式使用 Flyspell-mode?
另外,是否有一个 XML 字典不会将 XML 标签标记为拼写错误的单词?
How do you enable flyspell-mode to be automatically used for every file and every major mode as soon as Emacs is started?
Also, is there an XML dictionary that does not mark XML tags as misspelled words?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这个问题的答案对我有用:
如何启用自动拼写默认情况下检查吗?
此外,与其他先前的答案相比,它似乎更笼统。将以下行添加到
.emacs
或init.el
中。The answer from this question worked for me:
How to enable automatic spell check by default?
Furthermore, it appears to be more general compared to the other prior answers. Add the following lines to your
.emacs
orinit.el
.有可能,您并不真正希望为所有模式启用
flyspell-mode
,而是希望为主要处理文本的模式(文本模式、 message-mode 等),以及用于编程模式(C/C++、Java、Ruby、Lisp 等)的flyspell-prog-mode
。两种模式之间的区别在于,第一种模式检查所有单词,而 Flyspell-prog-mode 只检查注释和字符串中的单词(从而避免检查代码,而代码通常不是单词)。不管怎样,没有一个地方可以在所有文件/缓冲区中启用 Flyspell,因为它已被写入始终位于缓冲区本地。一个近似值是,
它不包括没有关联文件的缓冲区,我不建议使用它,因为它不区分编程模式和非编程模式 - 我认为这是有用的。
因为无法知道某些模式是否是编程模式,所以您需要手动为您关心的所有编程模式添加自定义,例如:
注意:这两块代码可能无法很好地协同工作。
而且,关于 XML,flyspell 已经对
sgml-mode
、html-mode
和nxml-mode
进行了自定义,以不对标签进行拼写检查(从 Emacs 23.2 开始)。如果您使用的是旧版本的 Emacs(回到 21.1),您应该能够将其添加到 .emacs 中以获得对nxml-mode
的支持:Chances are, you don't really want
flyspell-mode
enabled for all modes, but instead wantflyspell-mode
enabled for modes that deal primarily with text (text-mode, message-mode, etc.), andflyspell-prog-mode
for the programming modes (C/C++, Java, Ruby, Lisp, etc.). The difference between the two modes is that the first checks all words, whereas theflyspell-prog-mode
only checks words in comments and strings (thereby avoiding checking the code, which generally isn't words).Either way, there is no single place to enable flyspell in all files/buffers because it has been written to always be buffer local. A close approximation would be
That doesn't cover buffers which don't have associated files, and I don't advise using it because it doesn't distinguish between the programming modes and non-programming modes - which I think is useful.
Because there is no way to know whether certain modes are programming modes or not, you need to manually add customizations for all the programming modes you care about, with something like:
Note: the two chunks of code probably don't play well together.
And, regarding the XML, flyspell already has customizations for
sgml-mode
,html-mode
, andnxml-mode
to not spell check the tags (as of Emacs 23.2). If you're using an older version of Emacs (back to 21.1), you should be able to add this to your .emacs to get the support fornxml-mode
:您可以将以下内容添加到 Emacs 初始化文件中:
(flyspell-all-modes)
函数描述如下:
编辑:显然,上述功能仅包含在 Emacs 24 中的 Flyspell 版本中。如果您无法使用该版本,则应该使用 Trey 建议的解决方案来“半全局”启用 Flyspell。要使用 NXML 禁用 XML 标记检查,您可以将以下行添加到 Emacs 初始化文件中:
注意:此行已包含在 Emacs 24 中包含的 Flyspell.el 中。
You can add the following to your Emacs init file:
(flyspell-all-modes)
The function description states:
EDIT: Apparently the above function is only included in the version of flyspell that is in Emacs 24. If you can't use that version, you should instead use the solution suggested by Trey to "semi-globally" enable flyspell. To disable XML tag checking with NXML, you can add the following line to your Emacs init file:
Note: This line is already in the flyspell.el included in Emacs 24.
我无法说出具体时间,但现在 Flyspell-mode 可以很好地了解它所处的模式并做出相应的反应。这是我的使用包实现,带有公司完成的接口。
I couldn't say when, but flyspell-mode now does a pretty good job of knowing what mode it is in and reacting accordingly. Here is my use-package implementation with an interface to company-completion.
我将于 2021 年 10 月在 Debian 11.1 上使用 Emacs 27.1。我编写了一个函数,根据缓冲区主模式的类型执行正确的操作,并将其挂接到
find-file-hook
,该函数针对每个访问的文件运行。我将此作为其他答案的补充,而不是替代。理由:flyspell-mode
(无论是通过按键绑定调用,还是作为模式挂钩),没有自动识别模式类型/buffer/file,与@RichieHH 的回答相反。flyspell-all-modes
不存在,正如 @zev 所暗示的那样。text-mode-hook
的建议和prog-mode-hook
,根据@b4hand,已尽其所能,但离开了Flyspell 关闭了我打开的许多随机文件
基本模式。
一个潜在的缺点是,这不会针对不与任何文件关联的缓冲区运行。显然没有好的方法来挂钩“创建任何缓冲区”。然而,人们应该能够添加多个钩子而不会产生任何不良影响——如果多次调用,该函数应该发现 Flyspell 已经启用,并且不执行任何操作。因此,如果您愿意,也可以向
text-mode-hook
和prog-mode-hook
添加挂钩。I am using Emacs 27.1 on Debian 11.1 in 2021 October. I wrote a function that does the right thing, based on the the type of the buffer's major mode, and hooked that to
find-file-hook
, which runs for every file visited. I offer this as an supplement to other answers, not a replacement. Rationale:flyspell-mode
(whether invoked by key binding, or as a mode hook), did not automatically recognize the type of mode/buffer/file, contrary to answer by @RichieHH.flyspell-all-modes
does not exist, as implied by @zev.text-mode-hook
andprog-mode-hook
, per @b4hand, worked as far as it went, but leftFlyspell off for the many random files I have that open in
Fundamental mode.
One potential drawback is, this will not run for buffers not associated with any file. There is apparently no good way to hook "creation of any buffer". However, one should be able to add to multiple hooks with no ill effects -- if called multiple times, the function should find Flyspell already enabled, and do nothing. So add hooks to
text-mode-hook
andprog-mode-hook
as well, if you like.