From d5262b384e9a831340b906e3a0db5f11984736b0 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Fri, 31 Oct 2014 17:35:35 -0400 Subject: [PATCH] * lisp/emacs-lisp/macroexp.el (macroexpand-1): New function. (macroexp--expand-all): Unrelated tweaks. * lisp/emacs-lisp/gv.el (gv-get): Use macroexpand-1. Fixes: debbugs:18821 --- etc/NEWS | 2 ++ lisp/ChangeLog | 29 ++++++++++++++++++----------- lisp/emacs-lisp/gv.el | 8 ++++---- lisp/emacs-lisp/macroexp.el | 29 ++++++++++++++++++++++++++--- 4 files changed, 50 insertions(+), 18 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 6cf981cd255..a07cb5f2949 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -296,6 +296,8 @@ Emacs-21. * Lisp Changes in Emacs 25.1 +** New function macroexpand-1 to perform a single step of macroexpansion. + ** Some "x-*" were obsoleted: *** x-select-text is renamed gui-select-text. *** x-selection-value is renamed gui-selection-value. diff --git a/lisp/ChangeLog b/lisp/ChangeLog index e56829783f4..2b170dba51b 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2014-10-31 Stefan Monnier + + * emacs-lisp/macroexp.el (macroexpand-1): New function (bug#18821). + (macroexp--expand-all): Unrelated tweaks. + + * emacs-lisp/gv.el (gv-get): Use macroexpand-1. + 2014-10-30 Glenn Morris * startup.el (command-line): Remove pointless attempt to avoid @@ -8,8 +15,8 @@ Add "enum classs" support to C++ mode. * progmodes/cc-langs.el (c-after-brace-list-decl-kwds) (c-after-brace-list-key): New language consts/variables. - * progmodes/cc-engine.el (c-looking-at-decl-block): Exclude - spurious match of "enum struct" from decl-block recognition. + * progmodes/cc-engine.el (c-looking-at-decl-block): + Exclude spurious match of "enum struct" from decl-block recognition. (c-backward-colon-prefixed-type): New function. (c-backward-over-enum-header): Call above function to extend recognition of enum structure. @@ -125,7 +132,7 @@ 2014-10-25 Vincent Belaïche - * ses.el (macroexp): add require for this package, so that + * ses.el (macroexp): Add require for this package, so that function `ses--cell' gets macroexp-quote --- this change was supposed to be in my previous commit, but left out by mistake. (ses--cell): Do not make formula a macroexp-quote of value when @@ -133,22 +140,22 @@ 2014-10-24 Vincent Belaïche - * ses.el (macroexp): add require for this package, so that function + * ses.el (macroexp): Add require for this package, so that function `ses--cell gets macroexp-quote. - (ses--cell): makes formula a macroexp-quote of value when formula + (ses--cell): Makes formula a macroexp-quote of value when formula is nil. The rationale of this changr is to allow in the future shorter SES files, e.g. we could have only `(ses-cell A1 1.0)' instead of `(ses-cell A1 1.0 1.0 nil REFLIST)'. In such a case reference list REFLIST would be re-computed after load --- thus trading off load time against file size. - * emacs-lisp/package.el (package--alist-to-plist-args): use - macroexp-quote instead of a lambda expression which has the same + * emacs-lisp/package.el (package--alist-to-plist-args): + Use macroexp-quote instead of a lambda expression which has the same content as macroexp-quote. - (macroexp): add require for this package, so that function + (macroexp): Add require for this package, so that function `package--alist-to-plist-args' gets macroexp-quote. - * emacs-lisp/macroexp.el (macroexp-quote): new defun. + * emacs-lisp/macroexp.el (macroexp-quote): New defun. 2014-10-24 Stefan Monnier @@ -452,8 +459,8 @@ * net/newst-reader.el (newsticker-html-renderer): Whitespace. (newsticker--print-extra-elements) - (newsticker--do-print-extra-element): Documentation - (newsticker--image-read): Optionally limit image height. + (newsticker--do-print-extra-element): + Documentation (newsticker--image-read): Optionally limit image height. Use imagemagick if possible. (newsticker--icon-read): New. diff --git a/lisp/emacs-lisp/gv.el b/lisp/emacs-lisp/gv.el index 229ad275bf5..a0f92a5f94a 100644 --- a/lisp/emacs-lisp/gv.el +++ b/lisp/emacs-lisp/gv.el @@ -89,10 +89,10 @@ DO must return an Elisp expression." (let* ((head (car place)) (gf (function-get head 'gv-expander 'autoload))) (if gf (apply gf do (cdr place)) - (let ((me (macroexpand place ;FIXME: expand one step at a time! - ;; (append macroexpand-all-environment - ;; gv--macro-environment) - macroexpand-all-environment))) + (let ((me (macroexpand-1 place + ;; (append macroexpand-all-environment + ;; gv--macro-environment) + macroexpand-all-environment))) (if (and (eq me place) (get head 'compiler-macro)) ;; Expand compiler macros: this takes care of all the accessors ;; defined via cl-defsubst, such as cXXXr and defstruct slots. diff --git a/lisp/emacs-lisp/macroexp.el b/lisp/emacs-lisp/macroexp.el index b3bcc2d4078..3ce369fd5fd 100644 --- a/lisp/emacs-lisp/macroexp.el +++ b/lisp/emacs-lisp/macroexp.el @@ -25,7 +25,6 @@ ;; This file contains macro-expansions functions that are not defined in ;; the Lisp core, namely `macroexpand-all', which expands all macros in ;; a form, not just a top-level one. -;; ;;; Code: @@ -147,11 +146,35 @@ and also to avoid outputting the warning during normal execution." (instead (format "; use `%s' instead." instead)) (t "."))))) +(defun macroexpand-1 (form &optional environment) + "Perform (at most) one step of macroexpansion." + (cond + ((consp form) + (let* ((head (car form)) + (env-expander (assq head environment))) + (if env-expander + (if (cdr env-expander) + (apply (cdr env-expander) (cdr form)) + form) + (if (not (and (symbolp head) (fboundp head))) + form + (let ((def (autoload-do-load (symbol-function head) head 'macro))) + (cond + ;; Follow alias, but only for macros, otherwise we may end up + ;; skipping an important compiler-macro (e.g. cl--block-wrapper). + ((and (symbolp def) (macrop def)) (cons def (cdr form))) + ((not (consp def)) form) + (t + (if (eq 'macro (car def)) + (apply (cdr def) (cdr form)) + form)))))))) + (t form))) + (defun macroexp--expand-all (form) "Expand all macros in FORM. This is an internal version of `macroexpand-all'. Assumes the caller has bound `macroexpand-all-environment'." - (if (and (listp form) (eq (car form) 'backquote-list*)) + (if (eq (car-safe form) 'backquote-list*) ;; Special-case `backquote-list*', as it is normally a macro that ;; generates exceedingly deep expansions from relatively shallow input ;; forms. We just process it `in reverse' -- first we expand all the @@ -241,7 +264,7 @@ Assumes the caller has bound `macroexpand-all-environment'." ;; If the handler is not loaded yet, try (auto)loading the ;; function itself, which may in turn load the handler. (unless (functionp handler) - (ignore-errors + (with-demoted-errors "macroexp--expand-all: %S" (autoload-do-load (indirect-function func) func))) (let ((newform (macroexp--compiler-macro handler form))) (if (eq form newform) -- 2.39.5