GNU bug report logs - #44660
[feature/native-comp] defalias to macro in compiled elisp seems to not work in smartparens

Previous Next

Package: emacs;

Reported by: Jim Myhrberg <contact <at> jimeh.me>

Date: Sun, 15 Nov 2020 18:16:02 UTC

Severity: normal

Done: Andrea Corallo <akrl <at> sdf.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 44660 in the body.
You can then email your comments to 44660 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#44660; Package emacs. (Sun, 15 Nov 2020 18:16:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jim Myhrberg <contact <at> jimeh.me>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sun, 15 Nov 2020 18:16:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Jim Myhrberg <contact <at> jimeh.me>
To: bug-gnu-emacs <at> gnu.org
Subject: [feature/native-comp] defalias to macro in compiled elisp seems to
 not work in smartparens
Date: Sun, 15 Nov 2020 18:14:48 +0000
Hi,

After the following pull request was merged:
https://github.com/Fuco1/smartparens/pull/958

I started getting this error:

    Error running timer ‘sp-show--pair-function’: (invalid-function
sp--while-no-input)

The offending code seems to be:

    (defalias 'sp--while-no-input 'while-no-input)

And then later the call to "sp--while-no-input" within the
"sp-show--pair-function" function. If I manually eval the
"sp-show--pair-function" so it's no longer a natively compiled
function, things start working again.

For now in my personal config (which is not native-compiled), I've
resorted to this work-around which seems to work:

    (defun sp--while-no-input (&rest body)
      (eval (append '(while-no-input) body)))

Thanks again :)




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#44660; Package emacs. (Sun, 15 Nov 2020 20:43:01 GMT) Full text and rfc822 format available.

Message #8 received at 44660 <at> debbugs.gnu.org (full text, mbox):

From: Andrea Corallo <akrl <at> sdf.org>
To: Jim Myhrberg <contact <at> jimeh.me>
Cc: 44660 <at> debbugs.gnu.org
Subject: Re: bug#44660: [feature/native-comp] defalias to macro in compiled
 elisp seems to not work in smartparens
Date: Sun, 15 Nov 2020 20:42:42 +0000
[Message part 1 (text/plain, inline)]
Jim Myhrberg <contact <at> jimeh.me> writes:

> Hi,
>
> After the following pull request was merged:
> https://github.com/Fuco1/smartparens/pull/958
>
> I started getting this error:
>
>     Error running timer ‘sp-show--pair-function’: (invalid-function
> sp--while-no-input)
>
> The offending code seems to be:
>
>     (defalias 'sp--while-no-input 'while-no-input)
>
> And then later the call to "sp--while-no-input" within the
> "sp-show--pair-function" function. If I manually eval the
> "sp-show--pair-function" so it's no longer a natively compiled
> function, things start working again.
>
> For now in my personal config (which is not native-compiled), I've
> resorted to this work-around which seems to work:
>
>     (defun sp--while-no-input (&rest body)
>       (eval (append '(while-no-input) body)))
>
> Thanks again :)

Hi Jim,

does the attached patch to smartparens.el fix the issue?

Ciao!

  Andrea

[smartparens.patch (text/x-diff, inline)]
diff --git a/smartparens.el b/smartparens.el
index ea5221a..2822074 100644
--- a/smartparens.el
+++ b/smartparens.el
@@ -9408,44 +9408,45 @@ support custom pairs."
             (sp-show--pair-enc-function ok)))
       (execute-kbd-macro cmd))))
 
-(defalias 'sp--while-no-input 'while-no-input)
-(when (version< emacs-version "27")
-  ;; Ripped from Emacs 27.0 subr.el.
-  ;; See Github Issue#946 and Emacs bug#31692.
-  (defmacro sp--while-no-input (&rest body)
-    "Execute BODY only as long as there's no pending input.
+(eval-when-compile
+  (defalias 'sp--while-no-input 'while-no-input)
+  (when (version< emacs-version "27")
+    ;; Ripped from Emacs 27.0 subr.el.
+    ;; See Github Issue#946 and Emacs bug#31692.
+    (defmacro sp--while-no-input (&rest body)
+      "Execute BODY only as long as there's no pending input.
 If input arrives, that ends the execution of BODY,
 and `while-no-input' returns t.  Quitting makes it return nil.
 If BODY finishes, `while-no-input' returns whatever value BODY produced."
-    (declare (debug t) (indent 0))
-    (let ((catch-sym (make-symbol "input")))
-      `(with-local-quit
-         (catch ',catch-sym
-           (let ((throw-on-input ',catch-sym)
-                 val)
-             (setq val (or (input-pending-p)
-                           (progn ,@body)))
-             (cond
-              ;; When input arrives while throw-on-input is non-nil,
-              ;; kbd_buffer_store_buffered_event sets quit-flag to the
-              ;; value of throw-on-input.  If, when BODY finishes,
-              ;; quit-flag still has the same value as throw-on-input, it
-              ;; means BODY never tested quit-flag, and therefore ran to
-              ;; completion even though input did arrive before it
-              ;; finished.  In that case, we must manually simulate what
-              ;; 'throw' in process_quit_flag would do, and we must
-              ;; reset quit-flag, because leaving it set will cause us
-              ;; quit to top-level, which has undesirable consequences,
-              ;; such as discarding input etc.  We return t in that case
-              ;; because input did arrive during execution of BODY.
-              ((eq quit-flag throw-on-input)
-               (setq quit-flag nil)
-               t)
-              ;; This is for when the user actually QUITs during
-              ;; execution of BODY.
-              (quit-flag
-               nil)
-              (t val))))))))
+      (declare (debug t) (indent 0))
+      (let ((catch-sym (make-symbol "input")))
+	`(with-local-quit
+           (catch ',catch-sym
+             (let ((throw-on-input ',catch-sym)
+                   val)
+               (setq val (or (input-pending-p)
+                             (progn ,@body)))
+               (cond
+		;; When input arrives while throw-on-input is non-nil,
+		;; kbd_buffer_store_buffered_event sets quit-flag to the
+		;; value of throw-on-input.  If, when BODY finishes,
+		;; quit-flag still has the same value as throw-on-input, it
+		;; means BODY never tested quit-flag, and therefore ran to
+		;; completion even though input did arrive before it
+		;; finished.  In that case, we must manually simulate what
+		;; 'throw' in process_quit_flag would do, and we must
+		;; reset quit-flag, because leaving it set will cause us
+		;; quit to top-level, which has undesirable consequences,
+		;; such as discarding input etc.  We return t in that case
+		;; because input did arrive during execution of BODY.
+		((eq quit-flag throw-on-input)
+		 (setq quit-flag nil)
+		 t)
+		;; This is for when the user actually QUITs during
+		;; execution of BODY.
+		(quit-flag
+		 nil)
+		(t val)))))))))
 
 (defun sp-show--pair-function ()
   "Display the show pair overlays and print the line of the

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#44660; Package emacs. (Sun, 15 Nov 2020 22:34:02 GMT) Full text and rfc822 format available.

Message #11 received at 44660 <at> debbugs.gnu.org (full text, mbox):

From: Jim Myhrberg <contact <at> jimeh.me>
To: Andrea Corallo <akrl <at> sdf.org>
Cc: 44660 <at> debbugs.gnu.org
Subject: Re: bug#44660: [feature/native-comp] defalias to macro in compiled
 elisp seems to not work in smartparens
Date: Sun, 15 Nov 2020 22:32:42 +0000
Hi Andrea,

Yep, it does indeed fix it. I assume it's related to byte compilation
then, and not native-comp? Thanks for your quick response, and I'm
sorry for wasting your time with this :(

On Sun, Nov 15, 2020 at 8:42 PM Andrea Corallo <akrl <at> sdf.org> wrote:
>
> Jim Myhrberg <contact <at> jimeh.me> writes:
>
> > Hi,
> >
> > After the following pull request was merged:
> > https://github.com/Fuco1/smartparens/pull/958
> >
> > I started getting this error:
> >
> >     Error running timer ‘sp-show--pair-function’: (invalid-function
> > sp--while-no-input)
> >
> > The offending code seems to be:
> >
> >     (defalias 'sp--while-no-input 'while-no-input)
> >
> > And then later the call to "sp--while-no-input" within the
> > "sp-show--pair-function" function. If I manually eval the
> > "sp-show--pair-function" so it's no longer a natively compiled
> > function, things start working again.
> >
> > For now in my personal config (which is not native-compiled), I've
> > resorted to this work-around which seems to work:
> >
> >     (defun sp--while-no-input (&rest body)
> >       (eval (append '(while-no-input) body)))
> >
> > Thanks again :)
>
> Hi Jim,
>
> does the attached patch to smartparens.el fix the issue?
>
> Ciao!
>
>   Andrea
>




Reply sent to Andrea Corallo <akrl <at> sdf.org>:
You have taken responsibility. (Mon, 16 Nov 2020 14:39:01 GMT) Full text and rfc822 format available.

Notification sent to Jim Myhrberg <contact <at> jimeh.me>:
bug acknowledged by developer. (Mon, 16 Nov 2020 14:39:02 GMT) Full text and rfc822 format available.

Message #16 received at 44660-done <at> debbugs.gnu.org (full text, mbox):

From: Andrea Corallo <akrl <at> sdf.org>
To: Jim Myhrberg <contact <at> jimeh.me>
Cc: 44660-done <at> debbugs.gnu.org
Subject: Re: bug#44660: [feature/native-comp] defalias to macro in compiled
 elisp seems to not work in smartparens
Date: Mon, 16 Nov 2020 14:38:15 +0000
Jim Myhrberg <contact <at> jimeh.me> writes:

> Hi Andrea,
>
> Yep, it does indeed fix it. I assume it's related to byte compilation
> then, and not native-comp? Thanks for your quick response, and I'm
> sorry for wasting your time with this :(

Hi Jim,

yes this "front-end" related.

To have top level forms taking effect in the compile time those has to
be enclosed into `eval-when-compile' or `cl-eval-when'.

You should be able to see the same issue from command line using like
`batch-byte-compile-file'.

I'm closing this, thanks for reporting!

  Andrea




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 15 Dec 2020 12:24:07 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 182 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.