Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Emacs, how to automatically enable a minor mode based on buffer name?

Tags:

emacs

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?

like image 834
Adam Lindberg Avatar asked Aug 19 '09 11:08

Adam Lindberg


2 Answers

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)
like image 181
Dave Webb Avatar answered Nov 06 '22 04:11

Dave Webb


Since your extension is creating the buffer, why not just add:

(compilation-mode)

(or (compilation-minor-mode) if you're really set on the minor mode idea) in the code that's creating the *erl-output* buffer. You can edit the source for the mode, or use advice around the creation routine...

like image 30
Trey Jackson Avatar answered Nov 06 '22 06:11

Trey Jackson