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 08:07:59 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Michael Heerdegen <address@hidden> writes:

> (defun my-fac--print-result-around-advice (orig-fun n)
>   "Print result in the echo area."
>   (let ((result (funcall orig-fun n)))
>     (message "The faculty of %d is %d" n result)
>     (sit-for 3)
>     result))

BTW, what you also see is that advices in nadvice are just normal,
independently defined functions, and not some obscure expressions.  It's
your function definition, you can name and use the arguments as you
like.  In case of an around advice, your advice FUNCTION will be called
that way:

   (apply function oldfun r)

which means, with the arguments that the original function is called
with, prepended with the old function definition.  It must accept these
arguments.

So, for example, the above defun could also be written as

(defun my-fac--print-result-around-advice
 (orig-fun &rest argument-list-to-pass-over)
  "Print result in the echo area."
  (let ((result (apply orig-fun argument-list-to-pass-over)))
    (message "The faculty of %d is %d" n result)
    (sit-for 3)
    result))



Michael.




reply via email to

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