Subject: Re: bug#59820: [PATCH] * nadvice/nadvice.el: support non-symbol (closure/lambda) advices (old Emacs)

From: daanturo <[email-masked]>
Date: Tue, 13 Dec 2022 21:59:23 +0700

> I usually recommend to use named
> functions for advice anyway

How about we still allow but warn against such problematic usage?

On 13/12/2022 20:50, Stefan Monnier wrote:
>> This patch provides the ELPA version (for Emacs < 24.4) of nadvice.el's
>> advice-add the ability to handle anonymous advices.
> [...]
>> +(defun advice--ensure-symbol (func)
>> +  (if (symbolp func)
>> +      func
>> +    (let* ((sym (intern (format "%S" func))))
>> +      (unless (fboundp sym)
>> +        (defalias sym func))
>> +      sym)))
> I'm not a big fan of this approach, and I usually recommend to use named
> functions for advice anyway (avoids all kinds of problems like the
> `advice-remove` failing to remove, or the equality test taking too much
> time, ...).
>
> IOW I'd rather align the "real nadvice.el" with the one in GNU ELPA than
> the other way around in this respect.
>
>
>         Stefan
>
-- 
Daanturo.
From bf10a19145e3f08acb7d65fa26316fbdbeb6fd17 Mon Sep 17 00:00:00 2001
From: Daanturo <[email-masked]>
Date: Tue, 13 Dec 2022 21:28:03 +0700
Subject: [PATCH] * nadvice/nadvice.el: warn against non-symbol FUNCTIONs

---
 nadvice.el | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/nadvice.el b/nadvice.el
index 443a5d0..e44bfe1 100644
--- a/nadvice.el
+++ b/nadvice.el
@@ -57,6 +57,8 @@
   (if (symbolp func)
       func
     (let* ((sym (intern (format "%S" func))))
+      (message "This version of nadvice.el recommends that \
+FUNCTION: %S is a named symbol instead." func)
       (unless (fboundp sym)
         (defalias sym func))
       sym)))
-- 
2.39.0