all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: daanturo <daanturo@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 59820@debbugs.gnu.org
Subject: bug#59820: [PATCH] * nadvice/nadvice.el: support non-symbol (closure/lambda) advices (old Emacs)
Date: Tue, 13 Dec 2022 21:59:23 +0700	[thread overview]
Message-ID: <a157dccd-eb0f-bd28-55f8-55ae6a6e336f@gmail.com> (raw)
In-Reply-To: <jwvwn6vctd0.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 913 bytes --]

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

[-- Attachment #2: 0002-nadvice-nadvice.el-warn-against-non-symbol-FUNCTIONs.patch --]
[-- Type: text/x-patch, Size: 671 bytes --]

From bf10a19145e3f08acb7d65fa26316fbdbeb6fd17 Mon Sep 17 00:00:00 2001
From: Daanturo <daanturo@gmail.com>
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


  reply	other threads:[~2022-12-13 14:59 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-04 17:14 bug#59820: [PATCH] * nadvice/nadvice.el: support non-symbol (closure/lambda) advices (old Emacs) daanturo
2022-12-13  1:04 ` Stefan Kangas
2022-12-13 13:50 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-13 14:59   ` daanturo [this message]
2022-12-13 15:02     ` Daan Ro
2023-10-09  9:45       ` Stefan Kangas
2023-10-09 22:06         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-10 10:44           ` Stefan Kangas
2023-10-11  6:04             ` Daan Ro
2023-10-11  6:50               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a157dccd-eb0f-bd28-55f8-55ae6a6e336f@gmail.com \
    --to=daanturo@gmail.com \
    --cc=59820@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.