Mercurial > emacs
annotate lisp/emacs-lisp/macroexp.el @ 112121:a51d791afefe
ChangeLog fix.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Tue, 04 Jan 2011 23:03:21 -0800 |
parents | ba0e3bffdb8b |
children | 417b1e4d63cd |
rev | line source |
---|---|
53905
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
1 ;;; macroexp.el --- Additional macro-expansion support |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
2 ;; |
106815 | 3 ;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. |
53905
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
4 ;; |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
5 ;; Author: Miles Bader <miles@gnu.org> |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
6 ;; Keywords: lisp, compiler, macros |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
7 |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
8 ;; This file is part of GNU Emacs. |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
9 |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
10 ;; GNU Emacs is free software: you can redistribute it and/or modify |
53905
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
11 ;; it under the terms of the GNU General Public License as published by |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
12 ;; the Free Software Foundation, either version 3 of the License, or |
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; (at your option) any later version. |
53905
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
14 |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
15 ;; GNU Emacs is distributed in the hope that it will be useful, |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
18 ;; GNU General Public License for more details. |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
19 |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
20 ;; You should have received a copy of the GNU General Public License |
94655
90a2847062be
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
53905
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
22 |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
23 ;;; Commentary: |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
24 ;; |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
25 ;; This file contains macro-expansions functions that are not defined in |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
26 ;; the Lisp core, namely `macroexpand-all', which expands all macros in |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
27 ;; a form, not just a top-level one. |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
28 ;; |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
29 |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
30 ;;; Code: |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
31 |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
32 ;; Bound by the top-level `macroexpand-all', and modified to include any |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
33 ;; macros defined by `defmacro'. |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
34 (defvar macroexpand-all-environment nil) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
35 |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
36 (defun maybe-cons (car cdr original-cons) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
37 "Return (CAR . CDR), using ORIGINAL-CONS if possible." |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
38 (if (and (eq car (car original-cons)) (eq cdr (cdr original-cons))) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
39 original-cons |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
40 (cons car cdr))) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
41 |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
42 ;; We use this special macro to iteratively process forms and share list |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
43 ;; structure of the result with the input. Doing so recursively using |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
44 ;; `maybe-cons' results in excessively deep recursion for very long |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
45 ;; input forms. |
63940
5412b4421984
(macroexp-accumulate): Rename arg to var+list.
Richard M. Stallman <rms@gnu.org>
parents:
53905
diff
changeset
|
46 (defmacro macroexp-accumulate (var+list &rest body) |
53905
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
47 "Return a list of the results of evaluating BODY for each element of LIST. |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
48 Evaluate BODY with VAR bound to each `car' from LIST, in turn. |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
49 Return a list of the values of the final form in BODY. |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
50 The list structure of the result will share as much with LIST as |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
51 possible (for instance, when BODY just returns VAR unchanged, the |
63940
5412b4421984
(macroexp-accumulate): Rename arg to var+list.
Richard M. Stallman <rms@gnu.org>
parents:
53905
diff
changeset
|
52 result will be eq to LIST). |
5412b4421984
(macroexp-accumulate): Rename arg to var+list.
Richard M. Stallman <rms@gnu.org>
parents:
53905
diff
changeset
|
53 |
5412b4421984
(macroexp-accumulate): Rename arg to var+list.
Richard M. Stallman <rms@gnu.org>
parents:
53905
diff
changeset
|
54 \(fn (VAR LIST) BODY...)" |
110012
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
55 (declare (indent 1)) |
63940
5412b4421984
(macroexp-accumulate): Rename arg to var+list.
Richard M. Stallman <rms@gnu.org>
parents:
53905
diff
changeset
|
56 (let ((var (car var+list)) |
5412b4421984
(macroexp-accumulate): Rename arg to var+list.
Richard M. Stallman <rms@gnu.org>
parents:
53905
diff
changeset
|
57 (list (cadr var+list)) |
53905
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
58 (shared (make-symbol "shared")) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
59 (unshared (make-symbol "unshared")) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
60 (tail (make-symbol "tail")) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
61 (new-el (make-symbol "new-el"))) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
62 `(let* ((,shared ,list) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
63 (,unshared nil) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
64 (,tail ,shared) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
65 ,var ,new-el) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
66 (while ,tail |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
67 (setq ,var (car ,tail) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
68 ,new-el (progn ,@body)) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
69 (unless (eq ,var ,new-el) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
70 (while (not (eq ,shared ,tail)) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
71 (push (pop ,shared) ,unshared)) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
72 (setq ,shared (cdr ,shared)) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
73 (push ,new-el ,unshared)) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
74 (setq ,tail (cdr ,tail))) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
75 (nconc (nreverse ,unshared) ,shared)))) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
76 |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
77 (defun macroexpand-all-forms (forms &optional skip) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
78 "Return FORMS with macros expanded. FORMS is a list of forms. |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
79 If SKIP is non-nil, then don't expand that many elements at the start of |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
80 FORMS." |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
81 (macroexp-accumulate (form forms) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
82 (if (or (null skip) (zerop skip)) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
83 (macroexpand-all-1 form) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
84 (setq skip (1- skip)) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
85 form))) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
86 |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
87 (defun macroexpand-all-clauses (clauses &optional skip) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
88 "Return CLAUSES with macros expanded. |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
89 CLAUSES is a list of lists of forms; any clause that's not a list is ignored. |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
90 If SKIP is non-nil, then don't expand that many elements at the start of |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
91 each clause." |
64751
5b1a238fcbb4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
92 (macroexp-accumulate (clause clauses) |
53905
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
93 (if (listp clause) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
94 (macroexpand-all-forms clause skip) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
95 clause))) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
96 |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
97 (defun macroexpand-all-1 (form) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
98 "Expand all macros in FORM. |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
99 This is an internal version of `macroexpand-all'. |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
100 Assumes the caller has bound `macroexpand-all-environment'." |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
101 (if (and (listp form) (eq (car form) 'backquote-list*)) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
102 ;; Special-case `backquote-list*', as it is normally a macro that |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
103 ;; generates exceedingly deep expansions from relatively shallow input |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
104 ;; forms. We just process it `in reverse' -- first we expand all the |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
105 ;; arguments, _then_ we expand the top-level definition. |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
106 (macroexpand (macroexpand-all-forms form 1) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
107 macroexpand-all-environment) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
108 ;; Normal form; get its expansion, and then expand arguments. |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
109 (setq form (macroexpand form macroexpand-all-environment)) |
110012
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
110 (pcase form |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
111 (`(cond . ,clauses) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
112 (maybe-cons 'cond (macroexpand-all-clauses clauses) form)) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
113 (`(condition-case . ,(or `(,err ,body . ,handlers) dontcare)) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
114 (maybe-cons |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
115 'condition-case |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
116 (maybe-cons err |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
117 (maybe-cons (macroexpand-all-1 body) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
118 (macroexpand-all-clauses handlers 1) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
119 (cddr form)) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
120 (cdr form)) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
121 form)) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
122 (`(defmacro ,name . ,args-and-body) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
123 (push (cons name (cons 'lambda args-and-body)) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
124 macroexpand-all-environment) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
125 (macroexpand-all-forms form 3)) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
126 (`(defun . ,_) (macroexpand-all-forms form 3)) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
127 (`(,(or `defvar `defconst) . ,_) (macroexpand-all-forms form 2)) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
128 (`(function ,(and f `(lambda . ,_))) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
129 (maybe-cons 'function |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
130 (maybe-cons (macroexpand-all-forms f 2) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
131 nil |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
132 (cdr form)) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
133 form)) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
134 (`(,(or `function `quote) . ,_) form) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
135 (`(,(and fun (or `let `let*)) . ,(or `(,bindings . ,body) dontcare)) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
136 (maybe-cons fun |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
137 (maybe-cons (macroexpand-all-clauses bindings 1) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
138 (macroexpand-all-forms body) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
139 (cdr form)) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
140 form)) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
141 (`(,(and fun `(lambda . ,_)) . ,args) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
142 ;; Embedded lambda in function position. |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
143 (maybe-cons (macroexpand-all-forms fun 2) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
144 (macroexpand-all-forms args) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
145 form)) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
146 ;; The following few cases are for normal function calls that |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
147 ;; are known to funcall one of their arguments. The byte |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
148 ;; compiler has traditionally handled these functions specially |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
149 ;; by treating a lambda expression quoted by `quote' as if it |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
150 ;; were quoted by `function'. We make the same transformation |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
151 ;; here, so that any code that cares about the difference will |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
152 ;; see the same transformation. |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
153 ;; First arg is a function: |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
154 (`(,(and fun (or `apply `mapcar `mapatoms `mapconcat `mapc)) ',f . ,args) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
155 ;; We don't use `maybe-cons' since there's clearly a change. |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
156 (cons fun |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
157 (cons (macroexpand-all-1 (list 'function f)) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
158 (macroexpand-all-forms args)))) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
159 ;; Second arg is a function: |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
160 (`(,(and fun (or `sort)) ,arg1 ',f . ,args) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
161 ;; We don't use `maybe-cons' since there's clearly a change. |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
162 (cons fun |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
163 (cons (macroexpand-all-1 arg1) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
164 (cons (macroexpand-all-1 |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
165 (list 'function f)) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
166 (macroexpand-all-forms args))))) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
167 (`(,_ . ,_) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
168 ;; For every other list, we just expand each argument (for |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
169 ;; setq/setq-default this works alright because the variable names |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
170 ;; are symbols). |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
171 (macroexpand-all-forms form 1)) |
ba0e3bffdb8b
* lisp/emacs-lisp/macroexp.el (macroexpand-all-1): Use pcase.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
109015
diff
changeset
|
172 (t form)))) |
53905
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
173 |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
174 ;;;###autoload |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
175 (defun macroexpand-all (form &optional environment) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
176 "Return result of expanding macros at all levels in FORM. |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
177 If no macros are expanded, FORM is returned unchanged. |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
178 The second optional arg ENVIRONMENT specifies an environment of macro |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
179 definitions to shadow the loaded ones for use in file byte-compilation." |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
180 (let ((macroexpand-all-environment environment)) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
181 (macroexpand-all-1 form))) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
182 |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
183 (provide 'macroexp) |
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
184 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79704
diff
changeset
|
185 ;; arch-tag: af9b8c24-c196-43bc-91e1-a3570790fa5a |
53905
328854727be4
Revision: miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-84
Miles Bader <miles@gnu.org>
parents:
diff
changeset
|
186 ;;; macroexp.el ends here |