diff options
| author | Stefan Monnier | 2012-09-19 15:59:52 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2012-09-19 15:59:52 -0400 |
| commit | ce97595bd4604270075a0a7ff04bceaa97b42d9f (patch) | |
| tree | 820cc64a02f01472a80e3aa848501e325ef52f58 | |
| parent | 46624b4fa190e1bc7265494ff2f4b9990f577830 (diff) | |
| download | emacs-ce97595bd4604270075a0a7ff04bceaa97b42d9f.tar.gz emacs-ce97595bd4604270075a0a7ff04bceaa97b42d9f.zip | |
* lisp/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.
Fixes: debbugs:12371
| -rw-r--r-- | lisp/ChangeLog | 9 | ||||
| -rw-r--r-- | lisp/emacs-lisp/macroexp.el | 50 |
2 files changed, 35 insertions, 24 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 8d90c818d22..d5e01ed08a2 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,10 @@ | |||
| 1 | 2012-09-19 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2012-09-19 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * emacs-lisp/macroexp.el (macroexp--funcall-if-compiled): Rename from | ||
| 4 | macroexp--eval-if-compile. | ||
| 5 | (macroexp--funcall-and-return, macroexp--warn-and-return): New funs. | ||
| 6 | (macroexp--expand-all): Use them (bug#12371). | ||
| 7 | |||
| 3 | * doc-view.el (doc-view-guess-paper-size) | 8 | * doc-view.el (doc-view-guess-paper-size) |
| 4 | (doc-view-scale-bounding-box): Fix unbound `caddr'. | 9 | (doc-view-scale-bounding-box): Fix unbound `caddr'. |
| 5 | 10 | ||
| @@ -174,8 +179,8 @@ | |||
| 174 | (display-buffer-function): Mark as obsolete. | 179 | (display-buffer-function): Mark as obsolete. |
| 175 | 180 | ||
| 176 | * progmodes/compile.el (compilation-parse-errors): Accept list | 181 | * progmodes/compile.el (compilation-parse-errors): Accept list |
| 177 | values similar to font-lock-keywords (Bug#12136). Suggested by | 182 | values similar to font-lock-keywords (Bug#12136). |
| 178 | Oleksandr Manzyuk. | 183 | Suggested by Oleksandr Manzyuk. |
| 179 | (compilation-error-regexp-alist): Doc fix. | 184 | (compilation-error-regexp-alist): Doc fix. |
| 180 | 185 | ||
| 181 | 2012-09-15 Glenn Morris <rgm@gnu.org> | 186 | 2012-09-15 Glenn Morris <rgm@gnu.org> |
diff --git a/lisp/emacs-lisp/macroexp.el b/lisp/emacs-lisp/macroexp.el index 13064800cd5..6a84be06728 100644 --- a/lisp/emacs-lisp/macroexp.el +++ b/lisp/emacs-lisp/macroexp.el | |||
| @@ -100,19 +100,34 @@ each clause." | |||
| 100 | (error (message "Compiler-macro error for %S: %S" (car form) err) | 100 | (error (message "Compiler-macro error for %S: %S" (car form) err) |
| 101 | form))) | 101 | form))) |
| 102 | 102 | ||
| 103 | (defun macroexp--eval-if-compile (&rest _forms) | 103 | (defun macroexp--funcall-if-compiled (_form) |
| 104 | "Pseudo function used internally by macroexp to delay warnings. | 104 | "Pseudo function used internally by macroexp to delay warnings. |
| 105 | The purpose is to delay warnings to bytecomp.el, so they can use things | 105 | The purpose is to delay warnings to bytecomp.el, so they can use things |
| 106 | like `byte-compile-log-warning' to get better file-and-line-number data | 106 | like `byte-compile-log-warning' to get better file-and-line-number data |
| 107 | and also to avoid outputting the warning during normal execution." | 107 | and also to avoid outputting the warning during normal execution." |
| 108 | nil) | 108 | nil) |
| 109 | (put 'macroexp--eval-if-compile 'byte-compile | 109 | (put 'macroexp--funcall-if-compiled 'byte-compile |
| 110 | (lambda (form) | 110 | (lambda (form) |
| 111 | (mapc (lambda (x) (funcall (eval x))) (cdr form)) | 111 | (funcall (eval (cadr form))) |
| 112 | (byte-compile-constant nil))) | 112 | (byte-compile-constant nil))) |
| 113 | 113 | ||
| 114 | (autoload 'byte-compile-warn-obsolete "bytecomp") | 114 | (defun macroexp--funcall-and-return (when-compiled when-interpreted form) |
| 115 | (autoload 'byte-compile-log-warning "bytecomp") | 115 | ;; FIXME: ¡¡Major Ugly Hack!! To determine whether the output of this |
| 116 | ;; macro-expansion will be processed by the byte-compiler, we check | ||
| 117 | ;; circumstantial evidence. | ||
| 118 | (if (member '(declare-function . byte-compile-macroexpand-declare-function) | ||
| 119 | macroexpand-all-environment) | ||
| 120 | `(progn | ||
| 121 | (macroexp--funcall-if-compiled ',when-compiled) | ||
| 122 | ,form) | ||
| 123 | (funcall when-interpreted) | ||
| 124 | form)) | ||
| 125 | |||
| 126 | (defun macroexp--warn-and-return (msg form) | ||
| 127 | (macroexp--funcall-and-return | ||
| 128 | (lambda () (byte-compile-log-warning msg t)) | ||
| 129 | (lambda () (message "%s" msg)) | ||
| 130 | form)) | ||
| 116 | 131 | ||
| 117 | (defun macroexp--expand-all (form) | 132 | (defun macroexp--expand-all (form) |
| 118 | "Expand all macros in FORM. | 133 | "Expand all macros in FORM. |
| @@ -133,9 +148,10 @@ Assumes the caller has bound `macroexpand-all-environment'." | |||
| 133 | (car-safe form) | 148 | (car-safe form) |
| 134 | (symbolp (car form)) | 149 | (symbolp (car form)) |
| 135 | (get (car form) 'byte-obsolete-info)) | 150 | (get (car form) 'byte-obsolete-info)) |
| 136 | `(progn (macroexp--eval-if-compile | 151 | (macroexp--funcall-and-return |
| 137 | (lambda () (byte-compile-warn-obsolete ',(car form)))) | 152 | (lambda () (byte-compile-warn-obsolete ',(car form))) |
| 138 | ,new-form) | 153 | #'ignore ;FIXME: We should `message' something. |
| 154 | new-form) | ||
| 139 | new-form))) | 155 | new-form))) |
| 140 | (pcase form | 156 | (pcase form |
| 141 | (`(cond . ,clauses) | 157 | (`(cond . ,clauses) |
| @@ -178,26 +194,16 @@ Assumes the caller has bound `macroexpand-all-environment'." | |||
| 178 | ;; First arg is a function: | 194 | ;; First arg is a function: |
| 179 | (`(,(and fun (or `funcall `apply `mapcar `mapatoms `mapconcat `mapc)) | 195 | (`(,(and fun (or `funcall `apply `mapcar `mapatoms `mapconcat `mapc)) |
| 180 | ',(and f `(lambda . ,_)) . ,args) | 196 | ',(and f `(lambda . ,_)) . ,args) |
| 181 | (byte-compile-log-warning | 197 | (macroexp--warn-and-return |
| 182 | (format "%s quoted with ' rather than with #'" | 198 | (format "%s quoted with ' rather than with #'" |
| 183 | (list 'lambda (nth 1 f) '...)) | 199 | (list 'lambda (nth 1 f) '...)) |
| 184 | t) | 200 | (macroexp--expand-all `(,fun ,f . ,args)))) |
| 185 | ;; We don't use `macroexp--cons' since there's clearly a change. | ||
| 186 | (cons fun | ||
| 187 | (cons (macroexp--expand-all (list 'function f)) | ||
| 188 | (macroexp--all-forms args)))) | ||
| 189 | ;; Second arg is a function: | 201 | ;; Second arg is a function: |
| 190 | (`(,(and fun (or `sort)) ,arg1 ',(and f `(lambda . ,_)) . ,args) | 202 | (`(,(and fun (or `sort)) ,arg1 ',(and f `(lambda . ,_)) . ,args) |
| 191 | (byte-compile-log-warning | 203 | (macroexp--warn-and-return |
| 192 | (format "%s quoted with ' rather than with #'" | 204 | (format "%s quoted with ' rather than with #'" |
| 193 | (list 'lambda (nth 1 f) '...)) | 205 | (list 'lambda (nth 1 f) '...)) |
| 194 | t) | 206 | (macroexp--expand-all `(,fun ,arg1 ,f . ,args)))) |
| 195 | ;; We don't use `macroexp--cons' since there's clearly a change. | ||
| 196 | (cons fun | ||
| 197 | (cons (macroexp--expand-all arg1) | ||
| 198 | (cons (macroexp--expand-all | ||
| 199 | (list 'function f)) | ||
| 200 | (macroexp--all-forms args))))) | ||
| 201 | (`(,func . ,_) | 207 | (`(,func . ,_) |
| 202 | ;; Macro expand compiler macros. This cannot be delayed to | 208 | ;; Macro expand compiler macros. This cannot be delayed to |
| 203 | ;; byte-optimize-form because the output of the compiler-macro can | 209 | ;; byte-optimize-form because the output of the compiler-macro can |