Subject: bug#11686: 24.1.50; defun should return name

From: Lawrence Mitchell <[email-masked]>
Date: Wed, 13 Jun 2012 10:13:10 +0100

Johan Bockgård wrote:
> With current trunk,

>    (defun NAME ()) => (lambda nil nil)

>    expected        => NAME

> Ditto for defmacro.

Here's a patch, think this is right:

Return NAME, not definition from defun and defmacro

* lisp/emacs-lisp/byte-run.el (defun, defmacro): Return newly created
definition's name, not its definition.

diff --git a/lisp/emacs-lisp/byte-run.el b/lisp/emacs-lisp/byte-run.el
index 635eef9..fb86b2a 100644
--- a/lisp/emacs-lisp/byte-run.el
+++ b/lisp/emacs-lisp/byte-run.el
@@ -135,9 +135,11 @@ interpreted according to `macro-declarations-alist'."
        (if docstring (setq body (cons docstring body)))
        ;; Can't use backquote because it's not defined yet!
        (let* ((fun (list 'function (cons 'lambda (cons arglist body))))
-              (def (list 'defalias
-                         (list 'quote name)
-                         (list 'cons ''macro fun)))
+              (def (cons 'prog1
+                         (list (list 'quote name)
+                               (list 'defalias
+                                     (list 'quote name)
+                                     (list 'cons ''macro fun)))))
               (declarations
                (mapcar
                 #'(lambda (x)
@@ -190,11 +192,13 @@ interpreted according to `defun-declarations-alist'.
                    (t (message "Warning: Unknown defun property %S in %S"
                                (car x) name)))))
                    decls))
-          (def (list 'defalias
-                     (list 'quote name)
-                     (list 'function
-                           (cons 'lambda
-                                 (cons arglist body))))))
+          (def (cons 'prog1
+                     (list (list 'quote name)
+                           (list 'defalias
+                                 (list 'quote name)
+                                 (list 'function
+                                       (cons 'lambda
+                                             (cons arglist body))))))))
       (if declarations
           (cons 'prog1 (cons def declarations))
         def))))