emacs-devel
[Top][All Lists]
Advanced

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

Re: table.el


From: Stefan Monnier
Subject: Re: table.el
Date: Mon, 03 Dec 2001 01:30:29 -0500

> Mon, 03 Dec 2001 00:26:39 -0500: "Stefan Monnier" 
> <monnier+gnu/address@hidden> wrote:
> 
> > And?  What's the problem with that?  All we want is a function, right?
> 
> As you wrote before it is useful sharing one hook function to handle
> several cases based on the received function.  For this purpose it is
> much easier receiving the symbol rather than lambda expression, which
> is not obvious what function it is.  Sure, there is no problem for
> calling it.

I had in mind the case where the wrapper put on the wrapper-hook
does not care about the function.  It just needs to be able
to call it back after it did its thing.

> I implicitly made an assumption that `with-wrapper-hook' was the
> first, or next to interactive, in the function definition because
> otherwise it defeats its purpose since anything before
> `with-wrapper-hook' cannot be wrapped.

It can be very useful to do some sanitization of the arguments
before calling with-wrapper-hook.  I'm sure there can be other
reasons.  I'd rather not have such a restriction.

> BTW, as I wrote above I found a minor flaw in my approach.  When the
> original function has some operation in interactive body, that
> operation can not be wrapped.  I suppose this limitation is not fatal
> but is something that we must be aware of.

Those restrictions make it difficult to use the construct
and even more difficult to document it.  Better stick to
something simple.

> > But I now think it's better to keep things simple and not pass
> > the function at all.  Or rather, if the function is needed,
> > just pass it explicitly:
> > 
> >     (defun kill-region (beg end)
> >       "bla"
> >       (interactive "r")
> >       (with-wrapper-hook (region-wrapper-hook 'kill-region beg end)
> >         ...))
> 
> I think this is the most elegant solution!

I guess Miles was right all along ;-)

> BTW, RMS said the hook is better be hooks in this case.  Also the

Actually no, he said he preferred `wrappers' to `wrapper'.
I think `with-wrapper-hooks' would be definitely wrong since the
construct only takes a single hook.

> emacs lisp manual says when the hook takes arguments they are called
> hooks instead of hook.

I strongly doubt it.  Hooks should never be called `foo-hooks'.
It's either `foo-hook' for a plain hook and `foo-functions' for
the case where arguments will be passed.

Also the convention for the naming of hooks is independent from the
convention for the naming of functions operating on hooks.
When the function can run several hooks, it's called `run-hooks'
(for example (run-hooks 'text-mode-hook 'message-mode-hook)) and
when it can only run a single hook, it's called `run-hook' as
in (run-hook-with-args 'foo-functions arg1 arg2).


        Stefan




reply via email to

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