在Emacs中,如何根据缓冲区名称自动启用次模式? [英] In Emacs, how to automatically enable a minor mode based on buffer name?
问题描述
* erl-output *
的缓冲区。默认情况下,此缓冲区仅创建基本模式
。有没有办法在该缓冲区上自动启用 compilation-minor-mode
?要自动更改主要模式,您可以将以下内容添加到.emacs文件中:
(附加到列表'auto-mode-alist'(^ \\ * erl-output\\ * $。my-major-mode))
这不适合你;这是用于主要模式选择,而您在 模式选择之后。
相反,您可以尝试 Hook 。手册说:
一个钩子是一个Lisp变量,它保存一些功能列表,在一些明确定义的场合被调用。 / p>
所以你应该能够编写一个在需要时设置次模式的功能。查看标准挂钩列表 I认为您应该尝试 temp-buffer-setup-hook
或 temp-buffer-show-hook
。
您必须编写一个函数来检查缓冲区名称,并根据需要设置模式,并将其添加到钩子中,使用以下内容: .emacs
:
(add-hook'temp-buffer-setup-hook'my-func-to-设置模式)
I have a Emacs extension that creates a buffer named *erl-output*
. This buffer gets created with only fundamental-mode
by default. Is there any way to automatically enable compilation-minor-mode
on that buffer?
To automatically change major modes you can add the following to your .emacs file:
(add-to-list 'auto-mode-alist '("^\\*erl-output\\*$" . my-major-mode))
This won't work for you; it's for major mode selection and you're after minor mode selection.
Instead you could try a Hook. The manual says:
A hook is a Lisp variable which holds a list of functions, to be called on some well-defined occasion.
So you should be able to write a function which sets the minor mode when required. Looking at the List of Standard Hooks I think you should be trying temp-buffer-setup-hook
or temp-buffer-show-hook
.
You'll have to write a function which checks the buffer name and sets the mode if required, and add it to the hook using something like the following in your .emacs
:
(add-hook 'temp-buffer-setup-hook 'my-func-to-set-mode)
这篇关于在Emacs中,如何根据缓冲区名称自动启用次模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!