* lisp/emacs-lisp/macroexp.el (macroexp--funcall-if-compiled): Rename from
authorStefan Monnier <monnier@iro.umontreal.ca>
Wed, 19 Sep 2012 19:59:52 +0000 (15:59 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Wed, 19 Sep 2012 19:59:52 +0000 (15:59 -0400)
macroexp--eval-if-compile.
(macroexp--funcall-and-return, macroexp--warn-and-return): New funs.
(macroexp--expand-all): Use them.

Fixes: debbugs:12371

lisp/ChangeLog
lisp/emacs-lisp/macroexp.el

index 8d90c81..d5e01ed 100644 (file)
@@ -1,5 +1,10 @@
 2012-09-19  Stefan Monnier  <monnier@iro.umontreal.ca>
 
+       * emacs-lisp/macroexp.el (macroexp--funcall-if-compiled): Rename from
+       macroexp--eval-if-compile.
+       (macroexp--funcall-and-return, macroexp--warn-and-return): New funs.
+       (macroexp--expand-all): Use them (bug#12371).
+
        * doc-view.el (doc-view-guess-paper-size)
        (doc-view-scale-bounding-box): Fix unbound `caddr'.
 
        (display-buffer-function): Mark as obsolete.
 
        * progmodes/compile.el (compilation-parse-errors): Accept list
-       values similar to font-lock-keywords (Bug#12136).  Suggested by
-       Oleksandr Manzyuk.
+       values similar to font-lock-keywords (Bug#12136).
+       Suggested by Oleksandr Manzyuk.
        (compilation-error-regexp-alist): Doc fix.
 
 2012-09-15  Glenn Morris  <rgm@gnu.org>
index 1306480..6a84be0 100644 (file)
@@ -100,19 +100,34 @@ each clause."
     (error (message "Compiler-macro error for %S: %S" (car form) err)
            form)))
 
-(defun macroexp--eval-if-compile (&rest _forms)
+(defun macroexp--funcall-if-compiled (_form)
   "Pseudo function used internally by macroexp to delay warnings.
 The purpose is to delay warnings to bytecomp.el, so they can use things
 like `byte-compile-log-warning' to get better file-and-line-number data
 and also to avoid outputting the warning during normal execution."
   nil)
-(put 'macroexp--eval-if-compile 'byte-compile
+(put 'macroexp--funcall-if-compiled 'byte-compile
      (lambda (form)
-       (mapc (lambda (x) (funcall (eval x))) (cdr form))
+       (funcall (eval (cadr form)))
        (byte-compile-constant nil)))
 
-(autoload 'byte-compile-warn-obsolete "bytecomp")
-(autoload 'byte-compile-log-warning "bytecomp")
+(defun macroexp--funcall-and-return (when-compiled when-interpreted form)
+  ;; FIXME: ¡¡Major Ugly Hack!! To determine whether the output of this
+  ;; macro-expansion will be processed by the byte-compiler, we check
+  ;; circumstantial evidence.
+  (if (member '(declare-function . byte-compile-macroexpand-declare-function)
+              macroexpand-all-environment)
+      `(progn
+         (macroexp--funcall-if-compiled ',when-compiled)
+         ,form)
+    (funcall when-interpreted)
+    form))
+
+(defun macroexp--warn-and-return (msg form)
+  (macroexp--funcall-and-return
+   (lambda () (byte-compile-log-warning msg t))
+   (lambda () (message "%s" msg))
+   form))
 
 (defun macroexp--expand-all (form)
   "Expand all macros in FORM.
@@ -133,9 +148,10 @@ Assumes the caller has bound `macroexpand-all-environment'."
                      (car-safe form)
                      (symbolp (car form))
                      (get (car form) 'byte-obsolete-info))
-                `(progn (macroexp--eval-if-compile
-                         (lambda () (byte-compile-warn-obsolete ',(car form))))
-                        ,new-form)
+                (macroexp--funcall-and-return
+                 (lambda () (byte-compile-warn-obsolete ',(car form)))
+                 #'ignore      ;FIXME: We should `message' something.
+                 new-form)
               new-form)))
     (pcase form
       (`(cond . ,clauses)
@@ -178,26 +194,16 @@ Assumes the caller has bound `macroexpand-all-environment'."
       ;; First arg is a function:
       (`(,(and fun (or `funcall `apply `mapcar `mapatoms `mapconcat `mapc))
          ',(and f `(lambda . ,_)) . ,args)
-       (byte-compile-log-warning
+       (macroexp--warn-and-return
         (format "%s quoted with ' rather than with #'"
                 (list 'lambda (nth 1 f) '...))
-        t)
-       ;; We don't use `macroexp--cons' since there's clearly a change.
-       (cons fun
-             (cons (macroexp--expand-all (list 'function f))
-                   (macroexp--all-forms args))))
+        (macroexp--expand-all `(,fun ,f . ,args))))
       ;; Second arg is a function:
       (`(,(and fun (or `sort)) ,arg1 ',(and f `(lambda . ,_)) . ,args)
-       (byte-compile-log-warning
+       (macroexp--warn-and-return
         (format "%s quoted with ' rather than with #'"
                 (list 'lambda (nth 1 f) '...))
-        t)
-       ;; We don't use `macroexp--cons' since there's clearly a change.
-       (cons fun
-             (cons (macroexp--expand-all arg1)
-                   (cons (macroexp--expand-all
-                          (list 'function f))
-                         (macroexp--all-forms args)))))
+        (macroexp--expand-all `(,fun ,arg1 ,f . ,args))))
       (`(,func . ,_)
        ;; Macro expand compiler macros.  This cannot be delayed to
        ;; byte-optimize-form because the output of the compiler-macro can