unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Interest in temporary with-advice functionality?
@ 2024-06-18  4:12 Campbell Barton
  2024-06-21  2:08 ` Jim Porter
  0 siblings, 1 reply; 3+ messages in thread
From: Campbell Barton @ 2024-06-18  4:12 UTC (permalink / raw)
  To: emacs-devel

Hi, for the various packages I maintain I've found it's sometimes useful 
to add temporary advice to a function and I was wondering if there is 
any interest to add a macro that supports temporary advice into emacs.

While `cl-letf` can be used, advice is especially useful for it's 
:around functionality, while possible, it gets fairly verbose to use 
cl-letf to override the function in a way that supports calling the 
original.

I've been using a "with-advice" macro (see [0]).

The macros temporarily adds, then removed the advice

(with-advice (('fn :around #'fn-override))
   ;; Run's code with fn override. ...
   )

Multiple functions can be overridden at once.

(with-advice (('fn :around #'fn-override)
               ('fn-another :after #'fn-after))
   ;; Run's code with fn & fn-another override. ...
   )

I've noticed a similar macro exists in emacs but it's only used for testing.

files-tests--with-advice in ./emacs/test/lisp/files-tests.el

I was wondering if there is any interest to have this added to emacs.
If so I could make a patch to support this.

Since it can be useful to give concrete examples, here is some example 
usage [1] .. [4] (it's used 18 times across 9 packages I maintain).

[0]: 
https://codeberg.org/ideasman42/emacs-recomplete/src/commit/7a5c4c86cdbf8ba6b045d5ace466e5dcb2f10db0/recomplete.el#L74
[1]: 
https://codeberg.org/ideasman42/emacs-elisp-autofmt/src/commit/98edd8158b778ff9a0e34b5c6615523c0035f8d6/elisp-autofmt.el#L442
[2]: 
https://codeberg.org/ideasman42/emacs-undo-fu/src/commit/ea902716f39c725db1b90dbb285b44404b3bd6df/undo-fu.el#L164
[3]: 
https://codeberg.org/ideasman42/emacs-recomplete/src/commit/7a5c4c86cdbf8ba6b045d5ace466e5dcb2f10db0/recomplete.el#L240
[4]: 
https://codeberg.org/ideasman42/emacs-doc-show-inline/src/commit/cc363ed39f023642c4d8e7c91b26c802ca356fa3/doc-show-inline.el#L530

Regards,
- Campbell



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

end of thread, other threads:[~2024-06-21 18:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-18  4:12 Interest in temporary with-advice functionality? Campbell Barton
2024-06-21  2:08 ` Jim Porter
2024-06-21 18:51   ` Michael Heerdegen via Emacs development discussions.

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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