[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: Mon, 03 Dec 2001 18:30:25 -0800 (PST)

I've summarized what we have discussed in the code.  I still owe you
explaining if alternative ways other than the wrapper would work for


(defmacro with-wrapper-hook (wrapper-form &rest body)
  "Invoke wrappers in WRAPPER-HOOK if present, otherwise execute forms in BODY.
WRAPPER-FORM looks like (WRAPPER-HOOK FUNC ARG...), where FUNC is the
original function that is currently being wrapped and ARG... is the
list of arguments passed to each wrapper in WRAPPER-HOOK.  Each
wrapper receives FUNC followed by ARG...  All wrappers must call the
original function from within itself.  While this macro is calling
each wrapper, WRAPPER-HOOK is bound to the cdr of the list, so that
recursive invocations of `with-wrapper-hook' on the same variable
will result in each wrapper in the list being called.  Use `add-hook'
and `remove-hook' for manipuation of WRAPPER-HOOK.

An example usage of this is:

  (defvar kill-region-wrapper-hook nil)

  (defun kill-region (beg end)
    (interactive \"r\")
    (with-wrapper-hook (kill-region-wrapper-hook 'kill-region beg end)
      ...ordinary kill-region stuff...))

  (defun my-wrapper (func beg end)
     ((eq func 'kill-region)
      (let ((offset 5))
        (funcall func (+ beg offset) (+ end offset))))
     (t (funcall func beg end))))

  (add-hook 'kill-region-wrapper-hook 'my-wrapper)"

  (let ((wrapper-hook (car wrapper-form)))
    `(if ,wrapper-hook
         (let ((,wrapper-hook ,wrapper-hook))
           ;; Local/global special handling.
           (when (and (local-variable-p ',wrapper-hook)
                      (eq t (car ,wrapper-hook)))
             (setq ,wrapper-hook
                   (append (default-value ',wrapper-hook)
                           (cdr ,wrapper-hook))))
           ;; Call the first wrapper, with function and args.
           (funcall (pop ,wrapper-hook) ,@(cdr wrapper-form)))

reply via email to

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