emacs-devel
[Top][All Lists]
Advanced

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

Re: interactive closure — variables not bound


From: Stefan Monnier
Subject: Re: interactive closure — variables not bound
Date: Wed, 28 Sep 2016 08:41:50 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

> The problem with this definition is that it doesn’t work (the other
> problem is that I’m replacing one ugly hack with another).  At runtime
> Emacs says that “field-type” is undefined.  At compile time Emacs says
> that in the callback “xww”, “field-value”, and “field-type” are
> references to free variables.

Indeed, currently, the `interactive' spec can't be re-created
individually for every closure.  IOW the spec is built once and forall
for a given lambda expression and hence can't refer to surrounding
non-global variables.

I suggest you M-x report-emacs-bug.

This said, in your example, I don't see what benefit you expect to get
from writing

         (call-interactively
          (lambda (str)
            (interactive
             (list (cond ((equal "text" field-type)
                          (read-string "Text: " field-value))
                         ((equal "password" field-type)
                          (read-passwd "Password: " nil field-value))
                         ((equal "textarea" field-type)
                          (xwidget-webkit-begin-edit-textarea xww 
field-value)))))
            (xwidget-webkit-execute-script
             xww
             (format "findactiveelement(document).value='%s'" str)))))))))

instead of

         (let ((str (cond ((equal "text" field-type)
                           (read-string "Text: " field-value))
                          ((equal "password" field-type)
                           (read-passwd "Password: " nil field-value))
                          ((equal "textarea" field-type)
                           (xwidget-webkit-begin-edit-textarea xww 
field-value)))))
          (xwidget-webkit-execute-script
           xww
           (format "findactiveelement(document).value='%s'" str)))))))))

[ Oh, and while I'm here, let me advertize pcase:

     (let ((str (pcase field-type
                  ("text" (read-string "Text: " field-value))
                  ("password" (read-passwd "Password: " nil field-value))
                  ("textarea" ...

]

        Stefan




reply via email to

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