[Top][All Lists]

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

Re: Defadvice use

From: Kevin Rodgers
Subject: Re: Defadvice use
Date: Mon, 18 Apr 2005 14:28:37 -0600
User-agent: Mozilla Thunderbird 0.9 (X11/20041105)

Matthias wrote:
> I have the following problem: How do I advice a function so that
> within that function, the function `read-minibuffer' (for example)
> calls the definition of another function, say `my-read-minibuffer'?
> I'm trying to use an advice around the function; the advice providing
> a binding of the symbol `read-minibuffer' to the definition of
> `my-read-minibuffer'. Like the following:
> (defadvice la-fonction
>   (around la-fonction-extended enable compile)
>   "Documentation"
>    (let (f1)
>      (fset 'f1 read-minibuffer)
>      (fset 'read-minibuffer my-read-minibuffer)
>      ad-do-it
>      (fset 'read-minibuffer f1)))
> Any comment? Is it silly? Is there a better way? Any idea?

Here's how I'd do it:

(defvar la-fonction-read-minibuffer nil
  "If non-nil, the function to call instead of `read-minibuffer'.")

(defadvice read-minibuffer (around la-fonction activate)
"If `la-fonction-read-minibuffer' is non-nil, call it and return its result
  (if la-fonction-read-minibuffer
      (apply la-fonction-read-minibuffer (ad-get-args 0))

(defadvice la-fonction (around read-minibuffer activate)
  "Temporarily bind `la-fonction-read-minibuffer' to `my-read-minibuffer'."
  (let ((la-fonction-read-minibuffer 'my-read-minibuffer))

Kevin Rodgers

reply via email to

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