unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How do I inspect advices from Lisp?
@ 2025-01-09 22:39 Eduardo Ochs
  2025-01-09 23:02 ` Michael Heerdegen via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 2+ messages in thread
From: Eduardo Ochs @ 2025-01-09 22:39 UTC (permalink / raw)
  To: help-gnu-emacs

Hello list...


Introduction
============
Consider this code:

--snip--snip--
(defun adt-insert (&rest args) (insert (format "\n;;  --> %S" args)))
(defun adt-1 (o) (adt-insert ':1 o) (list 'adt-1 o))
(defun adt-2 (o) (adt-insert ':2 o) (list 'adt-2 o))
(defun adt-3 (o) (adt-insert ':3 o) (list 'adt-3 o))

;; (adt-2 20)
;; (advice-add    'adt-2 :before 'adt-1)
;; (advice-add    'adt-2 :after  'adt-3)
;; (adt-2 20)
;; (advice-remove 'adt-2         'adt-1)
;; (advice-remove 'adt-2         'adt-3)
;; (adt-2 20)
--snip--snip--

if we execute each line with our favorite variant of C-e C-x C-e -
including the lines in ";;"s, that I will treat as test in comments -
then the middle `(adt-2 20)' inserts this:

;;  --> (:1 20)
;;  --> (:2 20)
;;  --> (:3 20)

then the `advice-remove's remove the advices, and the last `(adt-2 20)'
inserts just this:

;;  --> (:2 20)


Question
========
How do I inspect the advices in `adt-2' _from Lisp_?

If I run this,

  (advice-add 'adt-2 :before 'adt-1)
  (advice-add 'adt-2 :after  'adt-3)
  (describe-function 'adt-2)

the description includes these lines,

  This function has :after advice: `adt-3'.
  This function has :before advice: `adt-1'.

but I tried to single-step through `describe-function' and
`describe-function-1' with edebug, and I found that the lines
above were generated by this call:

  (documentation 'adt-2 t)

but `documentation' is implemented in C, and

  (symbol-function 'adt-2)

returns something whose format I don't understand...
Any hints?

  Thanks in advance,
    Eduardo Ochs
    http://anggtwu.net/#eev



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

* Re: How do I inspect advices from Lisp?
  2025-01-09 22:39 How do I inspect advices from Lisp? Eduardo Ochs
@ 2025-01-09 23:02 ` Michael Heerdegen via Users list for the GNU Emacs text editor
  0 siblings, 0 replies; 2+ messages in thread
From: Michael Heerdegen via Users list for the GNU Emacs text editor @ 2025-01-09 23:02 UTC (permalink / raw)
  To: help-gnu-emacs

Eduardo Ochs <eduardoochs@gmail.com> writes:

> How do I inspect the advices in `adt-2' _from Lisp_?

See `advice-mapc' and `advice-member-p' in nadvice.el.

> If I run this,
>
>   (advice-add 'adt-2 :before 'adt-1)
>   (advice-add 'adt-2 :after  'adt-3)
>   (describe-function 'adt-2)
>
> the description includes these lines,
>
>   This function has :after advice: `adt-3'.
>   This function has :before advice: `adt-1'.
>
> but I tried to single-step through `describe-function' and
> `describe-function-1' with edebug, and I found that the lines
> above were generated by this call:
>
>   (documentation 'adt-2 t)
>
> but `documentation' is implemented in C, and
>
>   (symbol-function 'adt-2)
>
> returns something whose format I don't understand...
> Any hints?

Yes, but nadvice code still has an effect.  C code is able to call Lisp
code again.  Such things can be tricky to reconstruct.

Let's switch the perspective: `advice-add' does

#+begin_src emacs-lisp
  (put symbol 'function-documentation `(advice--make-docstring ',symbol))
#+end_src

`advice--make-docstring' is the function that generates the docstring
dynamically.  This is just called by `documentation' IIRC.

It can't harm to study the whole nadvice library a bit.  It is
relatively small.


Michael.




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

end of thread, other threads:[~2025-01-09 23:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-09 22:39 How do I inspect advices from Lisp? Eduardo Ochs
2025-01-09 23:02 ` Michael Heerdegen via Users list for the GNU Emacs text editor

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