[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Enabling/disabling minor modes based on major mode

From: PJ Weisberg
Subject: Re: Enabling/disabling minor modes based on major mode
Date: Tue, 22 Feb 2011 13:54:52 -0800

On Tue, Feb 22, 2011 at 5:40 AM, Gary <address@hidden> wrote:
> Is there a nice, consistent, way to do this?
> From reading around I found
> ,----
> | (add-hook 'term-mode-hook '(lambda() (set (make-local-variable
> |                                             'global-hl-line-mode) 0)))
> `----
> but that's clearly specific to global-hl-line-mode.
> Or is it? Could I do the same with, say, yas/minor-mode for the
> yasnippet modes? Is
> ,----
> | (set (make-local-variable '<minor-mode-name>) 0)
> `----
> guaranteed to work for all minor modes?
> Is there a better way of achieving what I want?

There's some function that turns on whatever mode you want, which you
can add to the hook list.  For instance, in my .emacs file I have:

(add-hook 'text-mode-hook 'turn-on-visual-line-mode)

If there were no function called turn-on-visual-line-mode, I could have used:

(add-hook 'text-mode-hook (lambda() (visual-line-mode 1)))

...which is actually all turn-on-visual-line-mode is.  Most (all?)
minor modes have a function of the same name that turns the mode on
with a numeric argument > 0 and off with a numeric argument <= 0, so
you could always do that.  Also, the following:

(add-hook 'text-mode-hook 'visual-line-mode)

...would do what I want, because visual-line-mode with no argument
toggles the mode, and text-mode starts with it OFF.

Hope that helps.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]