emacs-diffs
[Top][All Lists]
Advanced

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

master 493ae66be0: Preserve doc string in `byte-compile` (bug#55830)


From: Mattias Engdegård
Subject: master 493ae66be0: Preserve doc string in `byte-compile` (bug#55830)
Date: Wed, 8 Jun 2022 04:28:57 -0400 (EDT)

branch: master
commit 493ae66be08a99ea7918ee8210aec3eb925c8fad
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    Preserve doc string in `byte-compile` (bug#55830)
    
    * lisp/emacs-lisp/bytecomp.el (byte-compile--reify-function):
    Don't transpose doc string and interactive spec, which must come
    in this order.
    * test/lisp/emacs-lisp/bytecomp-tests.el
    (bytecomp-function-attributes): New test.
---
 lisp/emacs-lisp/bytecomp.el            |  1 +
 test/lisp/emacs-lisp/bytecomp-tests.el | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/lisp/emacs-lisp/bytecomp.el b/lisp/emacs-lisp/bytecomp.el
index 2e89504e8f..ab21fba8a2 100644
--- a/lisp/emacs-lisp/bytecomp.el
+++ b/lisp/emacs-lisp/bytecomp.el
@@ -2926,6 +2926,7 @@ FUN should be either a `lambda' value or a `closure' 
value."
       (push (pop body) preamble))
     (when (eq (car-safe (car body)) 'interactive)
       (push (pop body) preamble))
+    (setq preamble (nreverse preamble))
     ;; Turn the function's closed vars (if any) into local let bindings.
     (dolist (binding env)
       (cond
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el 
b/test/lisp/emacs-lisp/bytecomp-tests.el
index 39f053136a..27098d0bb1 100644
--- a/test/lisp/emacs-lisp/bytecomp-tests.el
+++ b/test/lisp/emacs-lisp/bytecomp-tests.el
@@ -1553,6 +1553,27 @@ EXPECTED-POINT BINDINGS (MODES \\='\\='(ruby-mode 
js-mode python-mode)) \
   (should (byte-compile--suspicious-defcustom-choice
            '(choice (const :tag "foo" 'bar)))))
 
+(ert-deftest bytecomp-function-attributes ()
+  ;; Check that `byte-compile' keeps the declarations, interactive spec and
+  ;; doc string of the function (bug#55830).
+  (let ((fname 'bytecomp-test-fun))
+    (fset fname nil)
+    (put fname 'pure nil)
+    (put fname 'lisp-indent-function nil)
+    (eval `(defun ,fname (x)
+             "tata"
+             (declare (pure t) (indent 1))
+             (interactive "P")
+             (list 'toto x))
+          t)
+    (let ((bc (byte-compile fname)))
+      (should (byte-code-function-p bc))
+      (should (equal (funcall bc 'titi) '(toto titi)))
+      (should (equal (aref bc 5) "P"))
+      (should (equal (get fname 'pure) t))
+      (should (equal (get fname 'lisp-indent-function) 1))
+      (should (equal (aref bc 4) "tata\n\n(fn X)")))))
+
 ;; Local Variables:
 ;; no-byte-compile: t
 ;; End:



reply via email to

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