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 00:26:39 -0500

> I tried this but I get lambda expression for the function instead of
> symbol name.

And?  What's the problem with that?  All we want is a function, right?

>   "Invoke wrappers in WRAPPERS-VAR if present, otherwise execute forms in 
> BODY.

As I said WRAPPER-VAR is a misnomer since hooks just aren't variables.
They are represented as symbols (just like coding-systems, faces and
several other kinds of objects) and they happen to use the `symbol-value'
and the `default-value' of a symbol for their internals which makes
them look similar to variables, but they are not variables.

>          ;; Call the first wrapper, with function and args.
>            (funcall (pop ,wrapper-var)
>                   (nth 1 (backtrace-frame
>                           (if (eq (nth 1 (eval-when-compile (backtrace-frame 
> 1))) 'progn) 7 1)))

The problem here is not just that this is brittle, but that
it breaks as soon as you do

        (defun foo ()
          (let ((bli sdf))
            (with-wrapper-hook (foobar arg)
              ...)))

I think it's just fundamentally wrong to use `backtrace-frame'
because we can't and don't want to rely on the fact that the
`with-wrapper-hook' is the first thing in the function's body.
Otherwise, we'd be better off using a macro like `defun-with-wrapper-hook'
so that it's clear that the two are intimately linked and then
we again don't need to use `backtrace-frame'.

That's why my suggestion simply turned the body of `with-wrapper-hook'
into its own function: that allows us to use it anywhere we
please, even deep inside a function, or nested inside another one...

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'd still like to find a way to reuse `run-hooks' rather than
manually handle the non-list-to-list conversion and the local/global
thingy, especially since my hidden agenda is to add support
to run-hooks for negation so that I can buffer-locally remove
a function that was added globally to the hook:

        (add-hook 'foo-hook 'bar)
        (remove-hook 'foo-hook 'bar t)
        (list (default-value 'foo-hook) foo-hook)
        ((bar) ((not bar) t))


-- Stefan




reply via email to

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