unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* About advices.
@ 2013-11-27  8:19 Constantin Kulikov
  2013-11-27 20:52 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Constantin Kulikov @ 2013-11-27  8:19 UTC (permalink / raw)
  To: help-gnu-emacs

What the right way to use advices? (I know that best way it to not use it
at all.;))

At my current level of understanding:

1) You declare advices with `defadvice'. (acces arguments of original
function by `ad-get-arg').
Example:
(defadvice switch-to-buffer (after my-switch-to-buffer-advice)
  (let ((buf (ad-get-arg 0)))
    do something))

2) Then you call `ad-activate'.
Example: (ad-activate 'switch-to-buffer)
The problem here is that it will activate all advices for that function
that were defined before this `ad-activate' call, not only
`my-switch-to-buffer-advice'

3) I'm not sure. You can enable/disable certain advices with
`ad-enable-advice'/`ad-disable-advice'. Example:
(ad-disable-advice 'switch-to-buffer 'after 'my-switch-to-buffer-advice)

4) `ad-deactivate' will disable all advices for function.
Example: (ad-deactivate 'switch-to-buffer)

Am I right?


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: About advices.
  2013-11-27  8:19 About advices Constantin Kulikov
@ 2013-11-27 20:52 ` Stefan Monnier
  2013-11-28 17:23   ` Constantin Kulikov
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2013-11-27 20:52 UTC (permalink / raw)
  To: help-gnu-emacs

> What the right way to use advices? (I know that best way it to not use it
> at all.;))

Here's how in Emacs-24.4:

   (defun my-advice (&rest args)
     (message "After s-t-b: %S" args))
   
   (advice-add 'switch-to-buffer :after #'my-advice)

and when you're tired of those messages, you turn them off with

   (advice-remove 'switch-to-buffer #'my-advice)


-- Stefan




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: About advices.
  2013-11-27 20:52 ` Stefan Monnier
@ 2013-11-28 17:23   ` Constantin Kulikov
  0 siblings, 0 replies; 3+ messages in thread
From: Constantin Kulikov @ 2013-11-28 17:23 UTC (permalink / raw)
  To: help-gnu-emacs

> Here's how in Emacs-24.4
nice. Thanks.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-11-28 17:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-27  8:19 About advices Constantin Kulikov
2013-11-27 20:52 ` Stefan Monnier
2013-11-28 17:23   ` Constantin Kulikov

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).