help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: replacing a function with another one


From: Michael Heerdegen
Subject: Re: replacing a function with another one
Date: Wed, 12 Mar 2014 00:40:18 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

lee <lee@yun.yagibdah.de> writes:

> > Note that the advice FUNCTION will be called with an additional (the
> > first) argument, which will be bound to the original function when the
> > advice is called.
>
> The documentation doesn´t say that.

It does say it:

  `:around'     (lambda (&rest r) (apply FUNCTION OLDFUN r))
                                             ^^^^^^
> > This way, you have direct access to the original function through that
> > binding in your advice, and you can call it with funcall or apply.
> > This "mechanism" is the replacement for the old ad-do-it.
>
> Why doesn´t the documentation just say that?

Because it's trivial.

> How does that go along with the documentation?  The documentation says
> "(lambda (&rest r) (apply FUNCTION OLDFUN r))", whatever that means.
> You have (f) instead of (&rest r), and "(apply FUNCTION OLDFUN r)" is
> missing.

I think I understand now what you are missing.

  (lambda (&rest r) (apply FUNCTION OLDFUN r))

is _not_ a template of how you would write your advice.  In this line,
FUNCTION means your piece of advice, the function you specify as advice.
The above line describes the semantic of the advised function, i.e., how
the advice will be constructed that will combine the original function
with your advice.

> What if you want to use one of the arguments?

Use an according argument list in FUNCTION, and refer to the arguments in
the function body.

> What when you use find-file-noselect and the file cannot be visited?
> The documentation only says it returns the buffer, not what it returns
> when it fails.

It will raise an error when the file doesn't exist or can't be read, so
you must check that yourself if you need to - see `file-exists-p',
`file-readable-p'.

Michael.




reply via email to

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