[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
hook syntax (was: Re: how to get around deprecated function)
From: |
Emanuel Berg |
Subject: |
hook syntax (was: Re: how to get around deprecated function) |
Date: |
Fri, 01 May 2015 05:55:10 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) |
Emanuel Berg <embe8573@student.uu.se> writes:
> By the way, and people probably have different views
> on this, but I think all that add-hook stuff is
> confusing. It is better to find out what the hook
> is. Offen it is empty or consists of a single or but
> a few items. Examine what is there and decide if you
> want it. Then set up the hook explicitly, e.g.
>
> (setq perl-mode-hook 'enable-line-mode) ; Perl
>
> But there is nothing wrong with add-hook and I use
> it sometimes dynamically. But in init files, I don't
> see why not setting up the hooks explicitly offers
> a higher degree of clarity and control.
As I expected, in the docs it says you should use
add-hook:
(info "(emacs)Hooks")
You can set a hook variable with ‘setq’ like any
other Lisp variable, but the recommended way to
add a function to a hook ... is to use ‘add-hook’
(info "(elisp)Hooks")
The recommended way to add a hook function to a hook
is by calling ‘add-hook’
However, I have many (10-20) hooks set like this:
(setq perl-mode-hook 'enable-line-mode)
This gets
perl-mode-hook ; => enable-line-mode
If I do
(setq perl-mode-hook nil)
(add-hook 'perl-mode-hook 'enable-line-mode)
I get
perl-mode-hook ; => (enable-line-mode)
The "incorrect" syntax always worked, until I just now
found that for `message-mode-hook' I must do
(setq message-mode-hook '(disable-super-global-keys))
So maybe I should retract my piece of advice. Or at
least, if the setq method is to be used, make it
a list (even for singular functions) at the first
sight of trouble. Because that might be just it...
--
underground experts united
http://user.it.uu.se/~embe8573