emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r118241: * lisp/emacs-lisp/macroexp.el (macroexpand-


From: Stefan Monnier
Subject: [Emacs-diffs] trunk r118241: * lisp/emacs-lisp/macroexp.el (macroexpand-1): New function.
Date: Fri, 31 Oct 2014 21:35:43 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 118241
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=18821
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Fri 2014-10-31 17:35:35 -0400
message:
  * lisp/emacs-lisp/macroexp.el (macroexpand-1): New function.
  (macroexp--expand-all): Unrelated tweaks.
  * lisp/emacs-lisp/gv.el (gv-get): Use macroexpand-1.
modified:
  etc/NEWS                       news-20141002041645-34n5fasbwydbo8t6-1
  lisp/ChangeLog                 changelog-20091113204419-o5vbwnq5f7feedwu-1432
  lisp/emacs-lisp/gv.el          setf.el-20120531120738-6w8114hk2anryyud-1
  lisp/emacs-lisp/macroexp.el    
macroexp.el-20091113204419-o5vbwnq5f7feedwu-2966
=== modified file 'etc/NEWS'
--- a/etc/NEWS  2014-10-30 05:23:50 +0000
+++ b/etc/NEWS  2014-10-31 21:35:35 +0000
@@ -296,6 +296,8 @@
 
 * 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.

=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2014-10-30 22:52:38 +0000
+++ b/lisp/ChangeLog    2014-10-31 21:35:35 +0000
@@ -1,3 +1,10 @@
+2014-10-31  Stefan Monnier  <address@hidden>
+
+       * 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  <address@hidden>
 
        * 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  <address@hidden>
 
-       * 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  <address@hidden>
 
-       * 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  <address@hidden>
 
@@ -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.
 

=== modified file 'lisp/emacs-lisp/gv.el'
--- a/lisp/emacs-lisp/gv.el     2014-10-01 17:23:42 +0000
+++ b/lisp/emacs-lisp/gv.el     2014-10-31 21:35:35 +0000
@@ -89,10 +89,10 @@
     (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.

=== modified file 'lisp/emacs-lisp/macroexp.el'
--- a/lisp/emacs-lisp/macroexp.el       2014-10-24 23:02:25 +0000
+++ b/lisp/emacs-lisp/macroexp.el       2014-10-31 21:35:35 +0000
@@ -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 @@
                   (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 @@
            ;; 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)


reply via email to

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