Subject: bug#76528: 30; Advising functions can cause docstring to be lost

From: Jonas Bernoulli <[email-masked]>
Date: Mon, 24 Feb 2025 21:42:20 +0100

Stefan Monnier <[email-masked]> writes:

>> Stefan, any comments?
>
> Just that it's directly related to this part of the code in
> `nadvice.el`:
>
>     ;; FIXME: We could use a defmethod on `function-documentation' instead,
>     ;; except when (autoloadp nf)!
>     (put symbol 'function-documentation `(advice--make-docstring ',symbol))

Transient (transient--wrap-command) has to advise every command that is
invoked while the menu is active, so this has the potential to cause a
lot of damage.  How should I deal with that?  Maybe essentially?:

  (let ((docstr (documentation this-command))
        (advice (lambda (fn &rest args) (apply fn args))))
    (advice-add this-command :around advice)
    (advice-remove this-command advice)
    (unless (equal (documentation this-command) docstr)
      (put this-command 'function-documentation docstr)))