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

* Re: Interest in temporary with-advice functionality?
  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.
  0 siblings, 1 reply; 3+ messages in thread
From: Jim Porter @ 2024-06-21  2:08 UTC (permalink / raw)
  To: Campbell Barton, emacs-devel

On 6/17/2024 9:12 PM, Campbell Barton wrote:
> 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
[snip]
> I was wondering if there is any interest to have this added to emacs.

I've done this sort of temporary-advising more than a handful of times 
(mostly in my init.el to work around various bugs on older Emacs 
versions), and would find it useful.



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

* Re: Interest in temporary with-advice functionality?
  2024-06-21  2:08 ` Jim Porter
@ 2024-06-21 18:51   ` Michael Heerdegen via Emacs development discussions.
  0 siblings, 0 replies; 3+ messages in thread
From: Michael Heerdegen via Emacs development discussions. @ 2024-06-21 18:51 UTC (permalink / raw)
  To: emacs-devel

Jim Porter <jporterbugs@gmail.com> writes:

> On 6/17/2024 9:12 PM, Campbell Barton wrote:
> > 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
> [snip]
> > I was wondering if there is any interest to have this added to emacs.
>
> I've done this sort of temporary-advising more than a handful of times
> (mostly in my init.el to work around various bugs on older Emacs
> versions), and would find it useful.

Me too.  But OTOH it's only a tool to write down _hacks_ more
conveniently.  We don't want this in Emacs IMO.

OTOH, such a functionality can definitely be useful for advanced users.
On the third hand, my concern is that having this easily available might
drive unexperienced users into a wrong direction.

So the current state ("people who know what they are doing implement
this feature by and for themselves and will understand the downsides by
themselves) maybe is an optimum.

Michael.




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