如何在默认情况下启用非全局次模式? [英] How to enable a non-global minor mode by default, on emacs startup?

查看:214
本文介绍了如何在默认情况下启用非全局次模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要启动每次我启动emacs 彩虹模式,而不必使用 Mx彩虹模式



我想我有一些命令放在我的.emacs文件中。



以下,但没有一个工作:

 (需要'彩虹模式)

(彩虹模式初始化)

(全球彩虹模式)


$ b $更一般来说,如何在启动时自动加载任何模式/包?

解决方案

彩虹模式不是全局小模式,所以需要在每个缓冲区的基础上启用。



我只使用它对于CSS,所以我有:

 (add-hook'css-mode-hook'我的-css-mode-hook)
(defun my-css-mode-hook()
(彩虹模式1))

如果您真正地希望将其全局化,无处不在,您可以自己轻松定义全局小调模式:

 (define-globalized-minor-模式my-global-rainbow-mode彩虹模式
(lambda()(彩虹模式1))

(my-global-rainbow-mode 1)

您可以向(lambda()(rainbow-mode 1))添加任意逻辑/ code>函数(将在每个缓冲区中进行评估),以确定是否实际调用(彩虹模式1)对于给定的缓冲区,所以如果你喜欢elisp,那么你可以轻松地扩展这种方法来满足你所关注的模式的具体要求。







更一般来说,如何在启动时自动加载任何模式/包?


它可以有所不同,但是我所展示的方法对于大多数次要模式都是足够的:您可以在 MODE 启用时启用它们(是某些特定的其他模式名称),在这种情况下,您可以使用 css> -mode-hook 示例;否则您希望永久启用该模式,在这种情况下,全局小模式是一种很好的方法(因为您可以全局切换)。默认情况下,一些次要模式是全局的(或提供全局变体),但如果需要,可以根据 my-global-rainbow-mode 示例创建自己的模式。 p>

还要注意,模式可以从其他模式导出,在这种情况下所有相关将会运行MODE-hook 钩子(有关详细信息,请参阅 https://stackoverflow.com/a/19295380/ 324105 )。一个常见的用例是使用 prog-mode-hook 来启用所有所需的功能从它派生的编程模式(这是大多数编程模式)。



请记住,许多(希望大多数)库和包将提供使用说明。如果找不到文档,请务必尝试使用 Mx find-library 访问库文件,然后阅读在最佳。通常有一个非常翔实的评论部分,有时这是最终用户文档的主要来源,并解释如何启用其功能。


I want to enable rainbow-mode everytime I start emacs, rather than having to use M-x rainbow-mode.

I guess there is some command I put in my .emacs file.

I tried all of the following, but none of them worked:

(require 'rainbow-mode)   

(rainbow-mode initialize)

(global-rainbow-mode)

More generally, how do I load any mode/package automatically on startup?

解决方案

rainbow-mode isn't a global minor mode, so it needs to be enabled on a per-buffer basis.

I only use it for CSS, so I have:

(add-hook 'css-mode-hook 'my-css-mode-hook)
(defun my-css-mode-hook ()
  (rainbow-mode 1))

If you genuinely want it to be global, everywhere, you can easily define a global minor mode yourself:

(define-globalized-minor-mode my-global-rainbow-mode rainbow-mode
  (lambda () (rainbow-mode 1)))

(my-global-rainbow-mode 1)

You can add any arbitrary logic to that (lambda () (rainbow-mode 1)) function (which will be evaluated in every buffer) in order to decide whether or not to actually call (rainbow-mode 1) for a given buffer, so if you're comfortable with elisp then you can easily extend this approach to cover your specific requirements for the mode in question.


More generally, how do I load any mode/package automatically on startup?

It can vary, but the approaches I've shown would suffice for most minor modes: Either you want them enabled whenever MODE is enabled (being some specific other mode name), in which case you can use the MODE-hook variable (which will always be available) as per the css-mode-hook example; or else you want the mode enabled permanently, in which case a global minor mode is a good approach (because you can toggle it on and off globally). Some minor modes are global by default (or provide global variants), but you can create your own if necessary, as per the my-global-rainbow-mode example.

Also be aware that modes can be derived from other modes, in which case all relevant MODE-hook hooks will be run (for details see https://stackoverflow.com/a/19295380/324105). A common use-case is to use prog-mode-hook to enable functionality wanted for all the programming modes which are derived from it (which is most programming modes).

Remember that many (hopefully most) libraries and packages will provide usage instructions. If you can't find documentation, be sure to try M-x find-library to visit the library file, and then read through the comments at the top. There is often a very informative "Commentary" section, and sometimes this is the primary source of end-user documentation, and explain how to enable its functionality.

这篇关于如何在默认情况下启用非全局次模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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