* Howto override a function only locally in elisp?
@ 2010-05-15 14:58 LanX
2010-05-15 15:45 ` Andreas Politz
0 siblings, 1 reply; 4+ messages in thread
From: LanX @ 2010-05-15 14:58 UTC (permalink / raw)
To: help-gnu-emacs
Hi
what's the best approach to replace a function only for another
function?
My use case is to replace calls to `message' with `tooltip-show'
within some function in certain programming modes.
But I don't want to copy and change the whole function, it would be
sufficient to override locally any call to `message' with a `my-
message' function without globally messing up message.
Any idea? Perhaps with `defadvice'?
Cheers
Rolf
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Howto override a function only locally in elisp?
2010-05-15 14:58 Howto override a function only locally in elisp? LanX
@ 2010-05-15 15:45 ` Andreas Politz
[not found] ` <701f887c-e936-41da-aa7c-c337455d03f4@c11g2000vbe.googlegroups.com>
0 siblings, 1 reply; 4+ messages in thread
From: Andreas Politz @ 2010-05-15 15:45 UTC (permalink / raw)
To: help-gnu-emacs
LanX <lanx.perl@googlemail.com> writes:
> Hi
>
> what's the best approach to replace a function only for another
> function?
>
> My use case is to replace calls to `message' with `tooltip-show'
> within some function in certain programming modes.
>
> But I don't want to copy and change the whole function, it would be
> sufficient to override locally any call to `message' with a `my-
> message' function without globally messing up message.
>
> Any idea? Perhaps with `defadvice'?
>
> Cheers
> Rolf
(require 'cl)
(flet ((message (fmt &rest args)
(tooltip-show (apply 'format fmt args))))
(message "Hello World"))
-ap
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Combining flet and defadvice
[not found] ` <701f887c-e936-41da-aa7c-c337455d03f4@c11g2000vbe.googlegroups.com>
@ 2010-05-21 13:36 ` Andreas Politz
2010-05-21 13:59 ` LanX
0 siblings, 1 reply; 4+ messages in thread
From: Andreas Politz @ 2010-05-21 13:36 UTC (permalink / raw)
To: help-gnu-emacs
LanX <lanx.perl@googlemail.com> writes:
>
> Now I was trying to use this flet approach in combination with
> defadvice around, but it didn't work ...
>
> ------------------------
> (require 'pos-tip)
> (require 'cl)
>
> (add-hook 'cperl-mode-hook
> (lambda ()
> (cperl-toggle-autohelp)
> (setq cperl-lazy-help-time 2)
>
>
> (defadvice cperl-describe-perl-symbol (around cperl-describe-perl-
> symbol-tooltip)
> "redirect message to tooltip"
> (flet ((message (fmt &rest args)
> (pos-tip-show (apply 'format fmt args))))
> ad-do-it))
> ))
> ----------
>
> What am I missing?
You have to somehow activate the advice....
(defadvice cperl-describe-perl-symbol (around ad-name activate)
....)
-ap
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Combining flet and defadvice
2010-05-21 13:36 ` Combining flet and defadvice Andreas Politz
@ 2010-05-21 13:59 ` LanX
0 siblings, 0 replies; 4+ messages in thread
From: LanX @ 2010-05-21 13:59 UTC (permalink / raw)
To: help-gnu-emacs
> You have to somehow activate the advice....
>
> (defadvice cperl-describe-perl-symbol (around ad-name activate)
> ....)
>
> -ap
ahh ...
(when testing in *scratch* the activation wasn't needed)
Great, now it works (beside some problems of pos-tip to figure out th
correct cursor position)
thanks again! :)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-05-21 13:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-05-15 14:58 Howto override a function only locally in elisp? LanX
2010-05-15 15:45 ` Andreas Politz
[not found] ` <701f887c-e936-41da-aa7c-c337455d03f4@c11g2000vbe.googlegroups.com>
2010-05-21 13:36 ` Combining flet and defadvice Andreas Politz
2010-05-21 13:59 ` LanX
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).