aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Schwab2012-12-31 22:53:33 +0100
committerAndreas Schwab2012-12-31 22:53:33 +0100
commit5cebef2d18da5c7b365875bd2f771a8953284ec5 (patch)
treefea8699522e481d67fec5dbe4a062011f4f7a12a
parent5ee1772e2c5cff56ff1825b79acdd67dc142bf49 (diff)
downloademacs-5cebef2d18da5c7b365875bd2f771a8953284ec5.tar.gz
emacs-5cebef2d18da5c7b365875bd2f771a8953284ec5.zip
* emacs-lisp/byte-run.el (defmacro): Use same argument parsing as
defun. Don't check for DECL if DOCSTRING isn't a string. (defun): Likewise.
-rw-r--r--lisp/ChangeLog6
-rw-r--r--lisp/emacs-lisp/byte-run.el63
2 files changed, 41 insertions, 28 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 49496efec69..65f71eac351 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,9 @@
12012-12-31 Andreas Schwab <schwab@linux-m68k.org>
2
3 * emacs-lisp/byte-run.el (defmacro): Use same argument parsing as
4 defun. Don't check for DECL if DOCSTRING isn't a string.
5 (defun): Likewise.
6
12012-12-31 Glenn Morris <rgm@gnu.org> 72012-12-31 Glenn Morris <rgm@gnu.org>
2 8
3 * eshell/em-cmpl.el (eshell-pcomplete): 9 * eshell/em-cmpl.el (eshell-pcomplete):
diff --git a/lisp/emacs-lisp/byte-run.el b/lisp/emacs-lisp/byte-run.el
index 0cbf2616ba2..0b502aba93c 100644
--- a/lisp/emacs-lisp/byte-run.el
+++ b/lisp/emacs-lisp/byte-run.el
@@ -117,7 +117,7 @@ and the VALUES and should return the code to use to set this property.")
117(defalias 'defmacro 117(defalias 'defmacro
118 (cons 118 (cons
119 'macro 119 'macro
120 #'(lambda (name arglist &optional docstring decl &rest body) 120 #'(lambda (name arglist &optional docstring &rest body)
121 "Define NAME as a macro. 121 "Define NAME as a macro.
122When the macro is called, as in (NAME ARGS...), 122When the macro is called, as in (NAME ARGS...),
123the function (lambda ARGLIST BODY...) is applied to 123the function (lambda ARGLIST BODY...) is applied to
@@ -126,32 +126,38 @@ and the result should be a form to be evaluated instead of the original.
126DECL is a declaration, optional, of the form (declare DECLS...) where 126DECL is a declaration, optional, of the form (declare DECLS...) where
127DECLS is a list of elements of the form (PROP . VALUES). These are 127DECLS is a list of elements of the form (PROP . VALUES). These are
128interpreted according to `macro-declarations-alist'. 128interpreted according to `macro-declarations-alist'.
129The return value is undefined." 129The return value is undefined.
130 (if (stringp docstring) nil 130
131 (setq body (cons decl body)) 131\(fn NAME ARGLIST &optional DOCSTRING DECL &rest BODY)"
132 (setq decl docstring) 132 ;; We can't just have `decl' as an &optional argument, because we need
133 (setq docstring nil)) 133 ;; to distinguish
134 (if (or (null decl) (eq 'declare (car-safe decl))) nil 134 ;; (defmacro foo (arg) (bar) nil)
135 (setq body (cons decl body)) 135 ;; from
136 (setq decl nil)) 136 ;; (defmacro foo (arg) (bar)).
137 (if (null body) (setq body '(nil))) 137 (let ((decls (cond
138 (if docstring (setq body (cons docstring body))) 138 ((eq (car-safe docstring) 'declare)
139 ;; Can't use backquote because it's not defined yet! 139 (prog1 (cdr docstring) (setq docstring nil)))
140 (let* ((fun (list 'function (cons 'lambda (cons arglist body)))) 140 ((and (stringp docstring)
141 (def (list 'defalias 141 (eq (car-safe (car body)) 'declare))
142 (list 'quote name) 142 (prog1 (cdr (car body)) (setq body (cdr body)))))))
143 (list 'cons ''macro fun))) 143 (if docstring (setq body (cons docstring body))
144 (declarations 144 (if (null body) (setq body '(nil))))
145 (mapcar 145 ;; Can't use backquote because it's not defined yet!
146 #'(lambda (x) 146 (let* ((fun (list 'function (cons 'lambda (cons arglist body))))
147 (let ((f (cdr (assq (car x) macro-declarations-alist)))) 147 (def (list 'defalias
148 (if f (apply (car f) name arglist (cdr x)) 148 (list 'quote name)
149 (message "Warning: Unknown macro property %S in %S" 149 (list 'cons ''macro fun)))
150 (car x) name)))) 150 (declarations
151 (cdr decl)))) 151 (mapcar
152 (if declarations 152 #'(lambda (x)
153 (cons 'prog1 (cons def declarations)) 153 (let ((f (cdr (assq (car x) macro-declarations-alist))))
154 def))))) 154 (if f (apply (car f) name arglist (cdr x))
155 (message "Warning: Unknown macro property %S in %S"
156 (car x) name))))
157 decls)))
158 (if declarations
159 (cons 'prog1 (cons def declarations))
160 def))))))
155 161
156;; Now that we defined defmacro we can use it! 162;; Now that we defined defmacro we can use it!
157(defmacro defun (name arglist &optional docstring &rest body) 163(defmacro defun (name arglist &optional docstring &rest body)
@@ -173,7 +179,8 @@ The return value is undefined.
173 (let ((decls (cond 179 (let ((decls (cond
174 ((eq (car-safe docstring) 'declare) 180 ((eq (car-safe docstring) 'declare)
175 (prog1 (cdr docstring) (setq docstring nil))) 181 (prog1 (cdr docstring) (setq docstring nil)))
176 ((eq (car-safe (car body)) 'declare) 182 ((and (stringp docstring)
183 (eq (car-safe (car body)) 'declare))
177 (prog1 (cdr (car body)) (setq body (cdr body))))))) 184 (prog1 (cdr (car body)) (setq body (cdr body)))))))
178 (if docstring (setq body (cons docstring body)) 185 (if docstring (setq body (cons docstring body))
179 (if (null body) (setq body '(nil)))) 186 (if (null body) (setq body '(nil))))