[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: table.el
From: |
Tak Ota |
Subject: |
Re: table.el |
Date: |
Sat, 01 Dec 2001 10:12:13 -0800 (PST) |
01 Dec 2001 18:50:48 +0900: Miles Bader <address@hidden> wrote:
> Here's an alternative definition that I think is cleaner:
>
> (defmacro with-wrappers (wrapper-form &rest body)
> "Invoke wrappers in WRAPPERS-VAR if present, otherwise execute forms in
> BODY.
> WRAPPER-FORM looks like (WRAPPERS-VAR ARG...), where ARG... is the
> list of arguments passed to each wrapper in list stored in WRAPPERS-VAR.
> While calling each wrapper, WRAPPERS-VAR is bound to the cdr of the
> list, so that recursive invocations of `with-wrappers' on the same
> variable will result in each wrapper in the list being called."
> (let ((wrapper-var (car wrapper-form))
> (wrapper (make-symbol "wrapper")))
> `(if ,wrapper-var
> (let ((,wrapper (car ,wrapper-var))
> (,wrapper-var (cdr ,wrapper-var)))
> (funcall ,wrapper ,@(cdr wrapper-form)))
> ,@body)))
>
> An example usage of this is:
>
> (defun kill-region (beg end)
> (with-wrappers (kill-region-wrappers beg end)
> ...ordinary kill-region stuff...))
I confirmed it works and I like your implementation much better
including the elaborate doc string. Thank you very much for this work
(without regard to whether this is actually a good idea or not :)
For giving programmers finer control on how wrappers are used I
thought throwing in a global inhibiter might be useful. The doc
string can mention about `add-hook' and `remove-hook'. Also why don't
we have that simple example in the doc string. An example often
speaks more than long explanations.
(defvar inhibit-wrappers nil
"Non-nil inhibits invoking wrappers")
(defmacro with-wrappers (wrapper-form &rest body)
"Invoke wrappers in WRAPPERS-VAR if present, otherwise execute forms in BODY.
WRAPPER-FORM looks like (WRAPPERS-VAR ARG...), where ARG... is the
list of arguments passed to each wrapper in list stored in
WRAPPERS-VAR. Each wrapper must call the original function from
within itself. While calling each wrapper, WRAPPERS-VAR is bound to
the cdr of the list, so that recursive invocations of `with-wrappers'
on the same variable will result in each wrapper in the list being
called. Use `add-hook' and `remove-hook' for manipuation of
WRAPPERS-VAR. When `inhibit-wrappers' is non-nil wrapper invokation
is inhibited.
An example usage of this is:
(defvar kill-region-wrappers nil)
(defun kill-region (beg end)
(with-wrappers (kill-region-wrappers beg end)
...ordinary kill-region stuff...))"
(let ((wrapper-var (car wrapper-form))
(wrapper (make-symbol "wrapper")))
`(if (and (not inhibit-wrappers) ,wrapper-var)
(let ((,wrapper (car ,wrapper-var))
(,wrapper-var (cdr ,wrapper-var)))
(funcall ,wrapper ,@(cdr wrapper-form)))
,@body)))
BTW, what is "lexical binding"? It concerns me. Does it change the
fundamental rule in emacs lisp programming by obsoleting the dynamic
binding?
-Tak
Re: table.el, Richard Stallman, 2001/12/01
Re: table.el, Miles Bader, 2001/12/01
Re: table.el,
Tak Ota <=
- Re: table.el, Tak Ota, 2001/12/01
- Re: table.el, Kai Großjohann, 2001/12/02
- Re: table.el, Miles Bader, 2001/12/02
- Lexical bindings (was Re: table.el), Kim F. Storm, 2001/12/02
- Re: Lexical bindings (was Re: table.el), Kai Großjohann, 2001/12/02
- Re: Lexical bindings (was Re: table.el), Eli Zaretskii, 2001/12/02
- Re: Lexical bindings (was Re: table.el), Kim F. Storm, 2001/12/02
- Re: Lexical bindings (was Re: table.el), Stefan Monnier, 2001/12/02
- Re: Lexical bindings (was Re: table.el), Kim F. Storm, 2001/12/02
- Re: Lexical bindings (was Re: table.el), Miles Bader, 2001/12/02