emacs-devel
[Top][All Lists]
Advanced

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

Re: Idempotency of add-hook wrt lambda expressions


From: Alan Mackenzie
Subject: Re: Idempotency of add-hook wrt lambda expressions
Date: Thu, 5 Mar 2009 16:38:53 +0000
User-agent: Mutt/1.5.9i

On Thu, Mar 05, 2009 at 10:49:14AM +0100, David Kastrup wrote:
> Geoff Gole <address@hidden> writes:

> >> I'd much rather add a patch that complains when you pass a lambda to
> > add-hook.

> > Sounds good to me.

> Does not jibe with existing practise.

"Me too!".

> For example, (info "(emacs) Init Examples") carefully explains

>    * Turn on Auto Fill mode automatically in Text mode and related
>      modes.

>           (add-hook 'text-mode-hook
>             '(lambda () (auto-fill-mode 1)))

>      This shows how to add a hook function to a normal hook variable
>      (*note Hooks::).  The function we supply is a list starting with
>      `lambda', with a single-quote in front of it to make it a list
>      constant rather than an expression.

>      It's beyond the scope of this manual to explain Lisp functions,
>      but for this example it is enough to know that the effect is to
>      execute `(auto-fill-mode 1)' when Text mode is entered.  You can
>      replace that with any other expression that you like, or with
>      several expressions in a row.

> Sure, you can "fix" the manual here.  But you can't expect that the
> real world has never used an idiom explicitly documented and used as an
> example.

I have stuff like the following in my setup:

    (global-set-key [f1] (lambda () "Switch to frame F1"
                          (interactive)
                          (select-frame-acm-no 0)))

That `global-set-key' might easily have been an `add-hook'.  I think it
would get tedious very quickly if warnings were given with add-hook +
lambda.  To outlaw it would be the Wrong Thing completely.

With all due respect to Geoff, I don't think this is really a problem.

> Also, in some cases you can't avoid lambda, namely when using computed
> functions.

Yes.

> David Kastrup

-- 
Alan Mackenzie (Nuremberg, Germany).




reply via email to

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