emacs-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#61179: closed (lambda inside interactive form of around advice isn't


From: GNU bug Tracking System
Subject: bug#61179: closed (lambda inside interactive form of around advice isn't a closure)
Date: Wed, 08 Feb 2023 14:39:02 +0000

Your message dated Wed, 08 Feb 2023 09:38:16 -0500
with message-id <jwv8rh8fcjj.fsf-monnier+emacs@gnu.org>
and subject line Re: lambda inside interactive form of around advice isn't a 
closure
has caused the debbugs.gnu.org bug report #61179,
regarding lambda inside interactive form of around advice isn't a closure
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs@gnu.org.)


-- 
61179: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=61179
GNU Bug Tracking System
Contact help-debbugs@gnu.org with problems
--- Begin Message --- Subject: lambda inside interactive form of around advice isn't a closure Date: Mon, 30 Jan 2023 16:48:13 +0100
A function used as an around advice may advise the advised function's
interactive form, using (interactive (lambda (spec) ...)).

Unfortunately this inner lambda expression is not turned into a closure
as demonstrated by this simple example:

  ;; -*- lexical-binding: t -*-
  (let ((var :value))
    (lambda (fn &rest args)
      (interactive
       (lambda (spec)
         (message "interactive: %s" var)
         (advice-eval-interactive-spec spec)))
      (message "body: %s" var)
      (apply fn args)))

Or if you want to observe the failure when trying to use such an advice:

  (defun -make-advice ()
    (let ((var :value))
      (lambda (fn &rest args)
        (interactive
         (lambda (spec)
           (message "interactive: %s" var)
           (advice-eval-interactive-spec spec)))
        (message "body: %s" var)
        (apply fn args))))

  (defun -command (arg)
    (interactive (list (read-string ": "))))
  (advice-add '-command :around (-make-advice) '((name . "-advice")))

Could this be changed in the next Emacs release?  Even if this should
make it into 29.1 (which I doubt), it would still be very useful for me
if this could somehow be rewritten to also work in older Emacs releases.
I have tried throwing an eval or two in there, but with limited success.

This gives me an inner closure, but the outside closure does not capture
the same environment it seems:

  (let ((var :value))
    (eval `(lambda (fn &rest args)
             (interactive
              ,(lambda (spec)
                 (message "interactive: %s" var)
                 (advice-eval-interactive-spec spec)))
             (message "body: %s" var)
             (apply fn args))
          t))

I got desperate and also tried things like:

  (call-interactively
   (let ((lex '((var . :value))))
     (eval `(lambda ()
              (interactive
               ,(eval '(lambda (spec)
                        (message "interactive: %s" var)
                        nil)
                      lex))
              (message "body: %s" var))
           lex)))

Thanks for your help!
Jonas



--- End Message ---
--- Begin Message --- Subject: Re: lambda inside interactive form of around advice isn't a closure Date: Wed, 08 Feb 2023 09:38:16 -0500 User-agent: Gnus/5.13 (Gnus v5.13)
> Could you confirm that it works for you?
[ Confirmed.  ]

Thanks, closing,


        Stefan



--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]