如何在emacs中为所有文件和所有主要模式启用flyspell模式? [英] How to enable flyspell-mode in emacs for all files and all major modes?

查看:221
本文介绍了如何在emacs中为所有文件和所有主要模式启用flyspell模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



另外,是否有一个XML字典,那么如何启用flyspell模式,以便在Emacs启动时自动使用每个文件和每个主要模式?那不会将XML标签标记为拼写错误的单词?

解决方案

有可能您不希望对所有模式启用了flyspell-mode ,而是为主要处理文本(文本模式,消息模式)启用了 flyspell-mode ,等等)和 flyspell-prog-mode 用于编程模式(C / C ++,Java,Ruby,Lisp等)。两种模式之间的区别是首先检查所有单词,而 flyspell-prog-mode 仅检查注释和字符串中的单词(从而避免检查代码,一般来说不是单词)。



无论哪种方式,在所有文件/缓冲区中都没有单独的地方启用flyspell,因为它已被写入总是缓冲区本地。近似值将是

 (defun turn-on-flyspell()(flyspell-mode 1))
add-hook'find-file-hooks'turn-on-flyspell)

缓冲区没有关联的文件,我不建议使用它,因为它不区分编程模式和非编程模式 - 我认为是有用的。



由于无法知道某些模式是否为编程模式,因此您需要手动添加您关心的所有编程模式的自定义设置,如下所示:



(pre)(map((模式挂钩)(加钩模式挂钩'flyspell-prog-mode))
'(c-mode-common-hook tcl-mode-hook emacs-lisp-mode-hook
ruby​​-mode-hook java-mode-hook))

注意:这两个代码块可能无法在一起玩得很好。



而且,关于XML,flyspell已经有了 sgml-mode html-mode nxml-mode 不拼写检查标签(从Emacs 23.2开始)。如果您使用的是较早版本的Emacs(返回到21.1),您应该可以将其添加到.emacs以获得 nxml-mode 的支持:

 (put'nxml-mode'flyspell-mode-predicate'sgml-mode-flyspell-verify)


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?

解决方案

Chances are, you don't really want flyspell-mode enabled for all modes, but instead want flyspell-mode enabled for modes that deal primarily with text (text-mode, message-mode, etc.), and flyspell-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 the flyspell-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

(defun turn-on-flyspell () (flyspell-mode 1))
(add-hook 'find-file-hooks 'turn-on-flyspell)

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:

(mapcar (lambda (mode-hook) (add-hook mode-hook 'flyspell-prog-mode))
        '(c-mode-common-hook tcl-mode-hook emacs-lisp-mode-hook 
          ruby-mode-hook java-mode-hook))

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, and nxml-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 for nxml-mode:

(put 'nxml-mode 'flyspell-mode-predicate 'sgml-mode-flyspell-verify)

这篇关于如何在emacs中为所有文件和所有主要模式启用flyspell模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆