aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2012-06-07 15:48:22 -0400
committerStefan Monnier2012-06-07 15:48:22 -0400
commit6fa6c4aedbc9f33cf8ed67fdb7794c3b4ff6660a (patch)
tree8d2ba96cad998ec1eb5dbf4c001d464aed2b990a
parent4dd1c416d1c17aee0558dc3c1a37549462e75526 (diff)
downloademacs-6fa6c4aedbc9f33cf8ed67fdb7794c3b4ff6660a.tar.gz
emacs-6fa6c4aedbc9f33cf8ed67fdb7794c3b4ff6660a.zip
Move old compatiblity to cl.el. Remove cl-macroexpand-all.
* emacs-lisp/cl-extra.el (cl-map-keymap, cl-copy-tree) (cl-not-hash-table, cl-builtin-gethash, cl-builtin-remhash) (cl-builtin-clrhash, cl-builtin-maphash, cl-gethash, cl-puthash) (cl-remhash, cl-clrhash, cl-maphash, cl-make-hash-table) (cl-hash-table-p, cl-hash-table-count): Move to cl.el. (cl-macroexpand-cmacs): Remove var. (cl-macroexpand-all, cl-macroexpand-body): Remove funs. Use macroexpand-all instead. * emacs-lisp/cl-lib.el (cl-macro-environment): Remove decl. (cl-macroexpand): Move to cl-macs.el and rename to cl--sm-macroexpand. (cl-member): Remove old alias. * emacs-lisp/cl-macs.el (cl-macro-environment): Remove var. Use macroexpand-all-environment instead. (cl--old-macroexpand): New var. (cl--sm-macroexpand): New function. (cl-symbol-macrolet): Use it during macro expansion. (cl--function-convert-cache): New var. (cl--function-convert): New function, extracted from cl-macroexpand-all. (cl-lexical-let): Use it. * emacs-lisp/cl.el (cl-macroexpand, cl-macro-environment) (cl-macroexpand-all, cl-not-hash-table, cl-builtin-gethash) (cl-builtin-remhash, cl-builtin-clrhash, cl-builtin-maphash) (cl-map-keymap, cl-copy-tree, cl-gethash, cl-puthash, cl-remhash) (cl-clrhash, cl-maphash, cl-make-hash-table, cl-hash-table-p) (cl-hash-table-count): Add old compatibility aliases.
-rw-r--r--lisp/ChangeLog32
-rw-r--r--lisp/emacs-lisp/cl-extra.el123
-rw-r--r--lisp/emacs-lisp/cl-lib.el25
-rw-r--r--lisp/emacs-lisp/cl-loaddefs.el45
-rw-r--r--lisp/emacs-lisp/cl-macs.el144
-rw-r--r--lisp/emacs-lisp/cl.el32
6 files changed, 191 insertions, 210 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 153fb79ef87..07b330a3e6e 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,37 @@
12012-06-07 Stefan Monnier <monnier@iro.umontreal.ca> 12012-06-07 Stefan Monnier <monnier@iro.umontreal.ca>
2 2
3 * emacs-lisp/cl.el (cl-macroexpand, cl-macro-environment)
4 (cl-macroexpand-all, cl-not-hash-table, cl-builtin-gethash)
5 (cl-builtin-remhash, cl-builtin-clrhash, cl-builtin-maphash)
6 (cl-map-keymap, cl-copy-tree, cl-gethash, cl-puthash, cl-remhash)
7 (cl-clrhash, cl-maphash, cl-make-hash-table, cl-hash-table-p)
8 (cl-hash-table-count): Add old compatibility aliases.
9
10 * emacs-lisp/cl-macs.el (cl-macro-environment): Remove var.
11 Use macroexpand-all-environment instead.
12 (cl--old-macroexpand): New var.
13 (cl--sm-macroexpand): New function.
14 (cl-symbol-macrolet): Use it during macro expansion.
15 (cl--function-convert-cache): New var.
16 (cl--function-convert): New function, extracted from
17 cl-macroexpand-all.
18 (cl-lexical-let): Use it.
19
20 * emacs-lisp/cl-lib.el (cl-macro-environment): Remove decl.
21 (cl-macroexpand): Move to cl-macs.el and rename to cl--sm-macroexpand.
22 (cl-member): Remove old alias.
23
24 * emacs-lisp/cl-extra.el (cl-map-keymap, cl-copy-tree)
25 (cl-not-hash-table, cl-builtin-gethash, cl-builtin-remhash)
26 (cl-builtin-clrhash, cl-builtin-maphash, cl-gethash, cl-puthash)
27 (cl-remhash, cl-clrhash, cl-maphash, cl-make-hash-table)
28 (cl-hash-table-p, cl-hash-table-count): Move to cl.el.
29 (cl-macroexpand-cmacs): Remove var.
30 (cl-macroexpand-all, cl-macroexpand-body): Remove funs.
31 Use macroexpand-all instead.
32
332012-06-07 Stefan Monnier <monnier@iro.umontreal.ca>
34
3 * emacs-lisp/macroexp.el (macroexp-progn, macroexp-let*, macroexp-if) 35 * emacs-lisp/macroexp.el (macroexp-progn, macroexp-let*, macroexp-if)
4 (macroexp-let², macroexp--const-symbol-p, macroexp-const-p) 36 (macroexp-let², macroexp--const-symbol-p, macroexp-const-p)
5 (macroexp-copyable-p): New functions and macros. 37 (macroexp-copyable-p): New functions and macros.
diff --git a/lisp/emacs-lisp/cl-extra.el b/lisp/emacs-lisp/cl-extra.el
index db8f663a873..6c774e7e8cd 100644
--- a/lisp/emacs-lisp/cl-extra.el
+++ b/lisp/emacs-lisp/cl-extra.el
@@ -221,10 +221,6 @@ If so, return the true (non-nil) value returned by PREDICATE.
221\n(fn PREDICATE SEQ...)" 221\n(fn PREDICATE SEQ...)"
222 (not (apply 'cl-every cl-pred cl-seq cl-rest))) 222 (not (apply 'cl-every cl-pred cl-seq cl-rest)))
223 223
224;;; Support for `cl-loop'.
225;;;###autoload
226(defalias 'cl-map-keymap 'map-keymap)
227
228;;;###autoload 224;;;###autoload
229(defun cl-map-keymap-recursively (cl-func-rec cl-map &optional cl-base) 225(defun cl-map-keymap-recursively (cl-func-rec cl-map &optional cl-base)
230 (or cl-base 226 (or cl-base
@@ -460,7 +456,7 @@ Optional second arg STATE is a random-state object."
460 "Return a copy of random-state STATE, or of the internal state if omitted. 456 "Return a copy of random-state STATE, or of the internal state if omitted.
461If STATE is t, return a new state object seeded from the time of day." 457If STATE is t, return a new state object seeded from the time of day."
462 (cond ((null state) (cl-make-random-state cl--random-state)) 458 (cond ((null state) (cl-make-random-state cl--random-state))
463 ((vectorp state) (cl-copy-tree state t)) 459 ((vectorp state) (copy-tree state t))
464 ((integerp state) (vector 'cl-random-state-tag -1 30 state)) 460 ((integerp state) (vector 'cl-random-state-tag -1 30 state))
465 (t (cl-make-random-state (cl-random-time))))) 461 (t (cl-make-random-state (cl-random-time)))))
466 462
@@ -585,9 +581,6 @@ If START or END is negative, it counts from the end."
585 (setq list (cdr list))) 581 (setq list (cdr list)))
586 (if (numberp sublist) (equal sublist list) (eq sublist list))) 582 (if (numberp sublist) (equal sublist list) (eq sublist list)))
587 583
588(defalias 'cl-copy-tree 'copy-tree)
589
590
591;;; Property lists. 584;;; Property lists.
592 585
593;;;###autoload 586;;;###autoload
@@ -637,36 +630,6 @@ PROPLIST is a list of the sort returned by `symbol-plist'.
637 (progn (setplist sym (cdr (cdr plist))) t) 630 (progn (setplist sym (cdr (cdr plist))) t)
638 (cl-do-remf plist tag)))) 631 (cl-do-remf plist tag))))
639 632
640;;; Hash tables.
641;; This is just kept for compatibility with code byte-compiled by Emacs-20.
642
643;; No idea if this might still be needed.
644(defun cl-not-hash-table (x &optional y &rest z)
645 (signal 'wrong-type-argument (list 'cl-hash-table-p (or y x))))
646
647(defvar cl-builtin-gethash (symbol-function 'gethash))
648(defvar cl-builtin-remhash (symbol-function 'remhash))
649(defvar cl-builtin-clrhash (symbol-function 'clrhash))
650(defvar cl-builtin-maphash (symbol-function 'maphash))
651
652;;;###autoload
653(defalias 'cl-gethash 'gethash)
654;;;###autoload
655(defalias 'cl-puthash 'puthash)
656;;;###autoload
657(defalias 'cl-remhash 'remhash)
658;;;###autoload
659(defalias 'cl-clrhash 'clrhash)
660;;;###autoload
661(defalias 'cl-maphash 'maphash)
662;; These three actually didn't exist in Emacs-20.
663;;;###autoload
664(defalias 'cl-make-hash-table 'make-hash-table)
665;;;###autoload
666(defalias 'cl-hash-table-p 'hash-table-p)
667;;;###autoload
668(defalias 'cl-hash-table-count 'hash-table-count)
669
670;;; Some debugging aids. 633;;; Some debugging aids.
671 634
672(defun cl-prettyprint (form) 635(defun cl-prettyprint (form)
@@ -710,93 +673,13 @@ PROPLIST is a list of the sort returned by `symbol-plist'.
710 (forward-char 1)))) 673 (forward-char 1))))
711 (forward-sexp))) 674 (forward-sexp)))
712 675
713(defvar cl-macroexpand-cmacs nil)
714(defvar cl-closure-vars nil)
715
716;;;###autoload
717(defun cl-macroexpand-all (form &optional env)
718 "Expand all macro calls through a Lisp FORM.
719This also does some trivial optimizations to make the form prettier."
720 (while (or (not (eq form (setq form (macroexpand form env))))
721 (and cl-macroexpand-cmacs
722 (not (eq form (setq form (cl-compiler-macroexpand form)))))))
723 (cond ((not (consp form)) form)
724 ((memq (car form) '(let let*))
725 (if (null (nth 1 form))
726 (cl-macroexpand-all (cons 'progn (cddr form)) env)
727 (let ((letf nil) (res nil) (lets (cadr form)))
728 (while lets
729 (push (if (consp (car lets))
730 (let ((exp (cl-macroexpand-all (caar lets) env)))
731 (or (symbolp exp) (setq letf t))
732 (cons exp (cl-macroexpand-body (cdar lets) env)))
733 (let ((exp (cl-macroexpand-all (car lets) env)))
734 (if (symbolp exp) exp
735 (setq letf t) (list exp nil)))) res)
736 (setq lets (cdr lets)))
737 (cl-list* (if letf (if (eq (car form) 'let) 'cl-letf 'cl-letf*) (car form))
738 (nreverse res) (cl-macroexpand-body (cddr form) env)))))
739 ((eq (car form) 'cond)
740 (cons (car form)
741 (mapcar (function (lambda (x) (cl-macroexpand-body x env)))
742 (cdr form))))
743 ((eq (car form) 'condition-case)
744 (cl-list* (car form) (nth 1 form) (cl-macroexpand-all (nth 2 form) env)
745 (mapcar (function
746 (lambda (x)
747 (cons (car x) (cl-macroexpand-body (cdr x) env))))
748 (cl-cdddr form))))
749 ((memq (car form) '(quote function))
750 (if (eq (car-safe (nth 1 form)) 'lambda)
751 (let ((body (cl-macroexpand-body (cl-cddadr form) env)))
752 (if (and cl-closure-vars (eq (car form) 'function)
753 (cl-expr-contains-any body cl-closure-vars))
754 (let* ((new (mapcar 'cl-gensym cl-closure-vars))
755 (sub (cl-pairlis cl-closure-vars new)) (decls nil))
756 (while (or (stringp (car body))
757 (eq (car-safe (car body)) 'interactive))
758 (push (list 'quote (pop body)) decls))
759 (put (car (last cl-closure-vars)) 'used t)
760 `(list 'lambda '(&rest --cl-rest--)
761 ,@(cl-sublis sub (nreverse decls))
762 (list 'apply
763 (list 'quote
764 #'(lambda ,(append new (cl-cadadr form))
765 ,@(cl-sublis sub body)))
766 ,@(nconc (mapcar (lambda (x) `(list 'quote ,x))
767 cl-closure-vars)
768 '((quote --cl-rest--))))))
769 (list (car form) (cl-list* 'lambda (cl-cadadr form) body))))
770 (let ((found (assq (cadr form) env)))
771 (if (and found (ignore-errors
772 (eq (cadr (cl-caddr found)) 'cl-labels-args)))
773 (cl-macroexpand-all (cadr (cl-caddr (cl-cadddr found))) env)
774 form))))
775 ((memq (car form) '(defun defmacro))
776 (cl-list* (car form) (nth 1 form) (cl-macroexpand-body (cddr form) env)))
777 ((and (eq (car form) 'progn) (not (cddr form)))
778 (cl-macroexpand-all (nth 1 form) env))
779 ((eq (car form) 'setq)
780 (let* ((args (cl-macroexpand-body (cdr form) env)) (p args))
781 (while (and p (symbolp (car p))) (setq p (cddr p)))
782 (if p (cl-macroexpand-all (cons 'cl-setf args)) (cons 'setq args))))
783 ((consp (car form))
784 (cl-macroexpand-all (cl-list* 'funcall
785 (list 'function (car form))
786 (cdr form))
787 env))
788 (t (cons (car form) (cl-macroexpand-body (cdr form) env)))))
789
790(defun cl-macroexpand-body (body &optional env)
791 (mapcar (function (lambda (x) (cl-macroexpand-all x env))) body))
792
793;;;###autoload 676;;;###autoload
794(defun cl-prettyexpand (form &optional full) 677(defun cl-prettyexpand (form &optional full)
795 (message "Expanding...") 678 (message "Expanding...")
796 (let ((cl-macroexpand-cmacs full) (cl-compiling-file full) 679 (let ((cl-macroexpand-cmacs full) (cl-compiling-file full)
797 (byte-compile-macro-environment nil)) 680 (byte-compile-macro-environment nil))
798 (setq form (cl-macroexpand-all form 681 (setq form (macroexpand-all form
799 (and (not full) '((cl-block) (cl-eval-when))))) 682 (and (not full) '((cl-block) (cl-eval-when)))))
800 (message "Formatting...") 683 (message "Formatting...")
801 (prog1 (cl-prettyprint form) 684 (prog1 (cl-prettyprint form)
802 (message "")))) 685 (message ""))))
diff --git a/lisp/emacs-lisp/cl-lib.el b/lisp/emacs-lisp/cl-lib.el
index d70a98c1bc6..5cfb99bd829 100644
--- a/lisp/emacs-lisp/cl-lib.el
+++ b/lisp/emacs-lisp/cl-lib.el
@@ -267,29 +267,6 @@ right when EXPRESSION calls an ordinary Emacs Lisp function that returns just
267one value." 267one value."
268 (nth n expression)) 268 (nth n expression))
269 269
270;;; Macros.
271
272(defvar cl-macro-environment)
273(defvar cl-old-macroexpand (prog1 (symbol-function 'macroexpand)
274 (defalias 'macroexpand 'cl-macroexpand)))
275
276(defun cl-macroexpand (cl-macro &optional cl-env)
277 "Return result of expanding macros at top level of FORM.
278If FORM is not a macro call, it is returned unchanged.
279Otherwise, the macro is expanded and the expansion is considered
280in place of FORM. When a non-macro-call results, it is returned.
281
282The second optional arg ENVIRONMENT specifies an environment of macro
283definitions to shadow the loaded ones for use in file byte-compilation.
284\n(fn FORM &optional ENVIRONMENT)"
285 (let ((cl-macro-environment cl-env))
286 (while (progn (setq cl-macro (funcall cl-old-macroexpand cl-macro cl-env))
287 (and (symbolp cl-macro)
288 (cdr (assq (symbol-name cl-macro) cl-env))))
289 (setq cl-macro (cadr (assq (symbol-name cl-macro) cl-env))))
290 cl-macro))
291
292
293;;; Declarations. 270;;; Declarations.
294 271
295(defvar cl-compiling-file nil) 272(defvar cl-compiling-file nil)
@@ -600,8 +577,6 @@ The elements of LIST are not copied, just the list structure itself."
600 (while (and list (not (equal item (car list)))) (setq list (cdr list))) 577 (while (and list (not (equal item (car list)))) (setq list (cdr list)))
601 list) 578 list)
602 579
603(defalias 'cl-member 'memq) ; for compatibility with old CL package
604
605;; Autoloaded, but we have not loaded cl-loaddefs yet. 580;; Autoloaded, but we have not loaded cl-loaddefs yet.
606(declare-function cl-floor "cl-extra" (x &optional y)) 581(declare-function cl-floor "cl-extra" (x &optional y))
607(declare-function cl-ceiling "cl-extra" (x &optional y)) 582(declare-function cl-ceiling "cl-extra" (x &optional y))
diff --git a/lisp/emacs-lisp/cl-loaddefs.el b/lisp/emacs-lisp/cl-loaddefs.el
index 0e2c97f9c44..2d7c9153318 100644
--- a/lisp/emacs-lisp/cl-loaddefs.el
+++ b/lisp/emacs-lisp/cl-loaddefs.el
@@ -3,16 +3,15 @@
3;;; Code: 3;;; Code:
4 4
5 5
6;;;### (autoloads (cl-prettyexpand cl-macroexpand-all cl-remprop 6;;;### (autoloads (cl-prettyexpand cl-remprop cl-do-remf cl-set-getf
7;;;;;; cl-do-remf cl-set-getf cl-getf cl-get cl-tailp cl-list-length 7;;;;;; cl-getf cl-get cl-tailp cl-list-length cl-nreconc cl-revappend
8;;;;;; cl-nreconc cl-revappend cl-concatenate cl-subseq cl-float-limits 8;;;;;; cl-concatenate cl-subseq cl-float-limits cl-random-state-p
9;;;;;; cl-random-state-p cl-make-random-state cl-random cl-signum 9;;;;;; cl-make-random-state cl-random cl-signum cl-rem cl-mod cl-round
10;;;;;; cl-rem cl-mod cl-round cl-truncate cl-ceiling cl-floor cl-isqrt 10;;;;;; cl-truncate cl-ceiling cl-floor cl-isqrt cl-lcm cl-gcd cl-progv-before
11;;;;;; cl-lcm cl-gcd cl-progv-before cl-set-frame-visible-p cl-map-overlays 11;;;;;; cl-set-frame-visible-p cl-map-overlays cl-map-intervals cl-map-keymap-recursively
12;;;;;; cl-map-intervals cl-map-keymap-recursively cl-notevery cl-notany 12;;;;;; cl-notevery cl-notany cl-every cl-some cl-mapcon cl-mapcan
13;;;;;; cl-every cl-some cl-mapcon cl-mapcan cl-mapl cl-maplist cl-map 13;;;;;; cl-mapl cl-maplist cl-map cl-mapcar-many cl-equalp cl-coerce)
14;;;;;; cl-mapcar-many cl-equalp cl-coerce) "cl-extra" "cl-extra.el" 14;;;;;; "cl-extra" "cl-extra.el" "fecce2e361fd06364d2ffd8c0d482cd0")
15;;;;;; "acc0000b09b27fb51f5ba23a4b9254e2")
16;;; Generated autoloads from cl-extra.el 15;;; Generated autoloads from cl-extra.el
17 16
18(autoload 'cl-coerce "cl-extra" "\ 17(autoload 'cl-coerce "cl-extra" "\
@@ -83,8 +82,6 @@ Return true if PREDICATE is false of some element of SEQ or SEQs.
83 82
84\(fn PREDICATE SEQ...)" nil nil) 83\(fn PREDICATE SEQ...)" nil nil)
85 84
86(defalias 'cl-map-keymap 'map-keymap)
87
88(autoload 'cl-map-keymap-recursively "cl-extra" "\ 85(autoload 'cl-map-keymap-recursively "cl-extra" "\
89 86
90 87
@@ -248,28 +245,6 @@ Remove from SYMBOL's plist the property PROPNAME and its value.
248 245
249\(fn SYMBOL PROPNAME)" nil nil) 246\(fn SYMBOL PROPNAME)" nil nil)
250 247
251(defalias 'cl-gethash 'gethash)
252
253(defalias 'cl-puthash 'puthash)
254
255(defalias 'cl-remhash 'remhash)
256
257(defalias 'cl-clrhash 'clrhash)
258
259(defalias 'cl-maphash 'maphash)
260
261(defalias 'cl-make-hash-table 'make-hash-table)
262
263(defalias 'cl-hash-table-p 'hash-table-p)
264
265(defalias 'cl-hash-table-count 'hash-table-count)
266
267(autoload 'cl-macroexpand-all "cl-extra" "\
268Expand all macro calls through a Lisp FORM.
269This also does some trivial optimizations to make the form prettier.
270
271\(fn FORM &optional ENV)" nil nil)
272
273(autoload 'cl-prettyexpand "cl-extra" "\ 248(autoload 'cl-prettyexpand "cl-extra" "\
274 249
275 250
@@ -289,7 +264,7 @@ This also does some trivial optimizations to make the form prettier.
289;;;;;; cl-return cl-block cl-etypecase cl-typecase cl-ecase cl-case 264;;;;;; cl-return cl-block cl-etypecase cl-typecase cl-ecase cl-case
290;;;;;; cl-load-time-value cl-eval-when cl-destructuring-bind cl-function 265;;;;;; cl-load-time-value cl-eval-when cl-destructuring-bind cl-function
291;;;;;; cl-defmacro cl-defun cl-gentemp cl-gensym) "cl-macs" "cl-macs.el" 266;;;;;; cl-defmacro cl-defun cl-gentemp cl-gensym) "cl-macs" "cl-macs.el"
292;;;;;; "25086e27342ec0990f35f1748a5b7b4e") 267;;;;;; "c1e8e5391e374630452ab3d78e527086")
293;;; Generated autoloads from cl-macs.el 268;;; Generated autoloads from cl-macs.el
294 269
295(autoload 'cl-gensym "cl-macs" "\ 270(autoload 'cl-gensym "cl-macs" "\
diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el
index acb60373b5a..91d7c211483 100644
--- a/lisp/emacs-lisp/cl-macs.el
+++ b/lisp/emacs-lisp/cl-macs.el
@@ -310,11 +310,6 @@ its argument list allows full Common Lisp conventions."
310(defconst cl-lambda-list-keywords 310(defconst cl-lambda-list-keywords
311 '(&optional &rest &key &allow-other-keys &aux &whole &body &environment)) 311 '(&optional &rest &key &allow-other-keys &aux &whole &body &environment))
312 312
313(defvar cl-macro-environment nil
314 "Keep the list of currently active macros.
315It is a list of elements of the form either:
316- (SYMBOL . FUNCTION) where FUNCTION is the macro expansion function.
317- (SYMBOL-NAME . EXPANSION) where SYMBOL-NAME is the name of a symbol macro.")
318(defvar cl-bind-block) (defvar cl-bind-defs) (defvar cl-bind-enquote) 313(defvar cl-bind-block) (defvar cl-bind-defs) (defvar cl-bind-enquote)
319(defvar cl-bind-inits) (defvar cl-bind-lets) (defvar cl-bind-forms) 314(defvar cl-bind-inits) (defvar cl-bind-lets) (defvar cl-bind-forms)
320 315
@@ -367,9 +362,10 @@ It is a list of elements of the form either:
367 (if (setq cl-bind-enquote (memq '&cl-quote args)) 362 (if (setq cl-bind-enquote (memq '&cl-quote args))
368 (setq args (delq '&cl-quote args))) 363 (setq args (delq '&cl-quote args)))
369 (if (memq '&whole args) (error "&whole not currently implemented")) 364 (if (memq '&whole args) (error "&whole not currently implemented"))
370 (let* ((p (memq '&environment args)) (v (cadr p))) 365 (let* ((p (memq '&environment args)) (v (cadr p))
366 (env-exp 'macroexpand-all-environment))
371 (if p (setq args (nconc (delq (car p) (delq v args)) 367 (if p (setq args (nconc (delq (car p) (delq v args))
372 (list '&aux (list v 'cl-macro-environment)))))) 368 (list '&aux (list v env-exp))))))
373 (while (and args (symbolp (car args)) 369 (while (and args (symbolp (car args))
374 (not (memq (car args) '(nil &rest &body &key &aux))) 370 (not (memq (car args) '(nil &rest &body &key &aux)))
375 (not (and (eq (car args) '&optional) 371 (not (and (eq (car args) '&optional)
@@ -1630,7 +1626,7 @@ go back to their previous definitions, or lack thereof).
1630 (lambda (x) 1626 (lambda (x)
1631 (if (or (and (fboundp (car x)) 1627 (if (or (and (fboundp (car x))
1632 (eq (car-safe (symbol-function (car x))) 'macro)) 1628 (eq (car-safe (symbol-function (car x))) 'macro))
1633 (cdr (assq (car x) cl-macro-environment))) 1629 (cdr (assq (car x) macroexpand-all-environment)))
1634 (error "Use `cl-labels', not `cl-flet', to rebind macro names")) 1630 (error "Use `cl-labels', not `cl-flet', to rebind macro names"))
1635 (let ((func `(cl-function 1631 (let ((func `(cl-function
1636 (lambda ,(cadr x) 1632 (lambda ,(cadr x)
@@ -1657,7 +1653,7 @@ Unlike `cl-flet', this macro is fully compliant with the Common Lisp standard.
1657 1653
1658\(fn ((FUNC ARGLIST BODY...) ...) FORM...)" 1654\(fn ((FUNC ARGLIST BODY...) ...) FORM...)"
1659 (declare (indent 1) (debug cl-flet)) 1655 (declare (indent 1) (debug cl-flet))
1660 (let ((vars nil) (sets nil) (cl-macro-environment cl-macro-environment)) 1656 (let ((vars nil) (sets nil) (newenv macroexpand-all-environment))
1661 (while bindings 1657 (while bindings
1662 ;; Use `cl-gensym' rather than `make-symbol'. It's important that 1658 ;; Use `cl-gensym' rather than `make-symbol'. It's important that
1663 ;; (not (eq (symbol-name var1) (symbol-name var2))) because these 1659 ;; (not (eq (symbol-name var1) (symbol-name var2))) because these
@@ -1670,9 +1666,8 @@ Unlike `cl-flet', this macro is fully compliant with the Common Lisp standard.
1670 `(lambda (&rest cl-labels-args) 1666 `(lambda (&rest cl-labels-args)
1671 (cl-list* 'funcall ',var 1667 (cl-list* 'funcall ',var
1672 cl-labels-args))) 1668 cl-labels-args)))
1673 cl-macro-environment))) 1669 newenv)))
1674 (cl-macroexpand-all `(cl-lexical-let ,vars (setq ,@sets) ,@body) 1670 (macroexpand-all `(cl-lexical-let ,vars (setq ,@sets) ,@body) newenv)))
1675 cl-macro-environment)))
1676 1671
1677;; The following ought to have a better definition for use with newer 1672;; The following ought to have a better definition for use with newer
1678;; byte compilers. 1673;; byte compilers.
@@ -1693,9 +1688,42 @@ This is like `cl-flet', but for macros instead of functions.
1693 (let* ((name (caar bindings)) 1688 (let* ((name (caar bindings))
1694 (res (cl--transform-lambda (cdar bindings) name))) 1689 (res (cl--transform-lambda (cdar bindings) name)))
1695 (eval (car res)) 1690 (eval (car res))
1696 (cl-macroexpand-all (cons 'progn body) 1691 (macroexpand-all (cons 'progn body)
1697 (cons (cons name `(lambda ,@(cdr res))) 1692 (cons (cons name `(lambda ,@(cdr res)))
1698 cl-macro-environment)))))) 1693 macroexpand-all-environment))))))
1694
1695(defconst cl--old-macroexpand
1696 (if (and (boundp 'cl--old-macroexpand)
1697 (eq (symbol-function 'macroexpand)
1698 #'cl--sm-macroexpand))
1699 cl--old-macroexpand
1700 (symbol-function 'macroexpand)))
1701
1702(defun cl--sm-macroexpand (cl-macro &optional cl-env)
1703 "Special macro expander used inside `cl-symbol-macrolet'.
1704This function replaces `macroexpand' during macro expansion
1705of `cl-symbol-macrolet', and does the same thing as `macroexpand'
1706except that it additionally expands symbol macros."
1707 (let ((macroexpand-all-environment cl-env))
1708 (while
1709 (progn
1710 (setq cl-macro (funcall cl--old-macroexpand cl-macro cl-env))
1711 (cond
1712 ((symbolp cl-macro)
1713 ;; Perform symbol-macro expansion.
1714 (when (cdr (assq (symbol-name cl-macro) cl-env))
1715 (setq cl-macro (cadr (assq (symbol-name cl-macro) cl-env)))))
1716 ((eq 'setq (car-safe cl-macro))
1717 ;; Convert setq to cl-setf if required by symbol-macro expansion.
1718 (let* ((args (mapcar (lambda (f) (cl--sm-macroexpand f cl-env))
1719 (cdr cl-macro)))
1720 (p args))
1721 (while (and p (symbolp (car p))) (setq p (cddr p)))
1722 (if p (setq cl-macro (cons 'cl-setf args))
1723 (setq cl-macro (cons 'setq args))
1724 ;; Don't loop further.
1725 nil))))))
1726 cl-macro))
1699 1727
1700;;;###autoload 1728;;;###autoload
1701(defmacro cl-symbol-macrolet (bindings &rest body) 1729(defmacro cl-symbol-macrolet (bindings &rest body)
@@ -1705,16 +1733,71 @@ by EXPANSION, and (setq NAME ...) will act like (cl-setf EXPANSION ...).
1705 1733
1706\(fn ((NAME EXPANSION) ...) FORM...)" 1734\(fn ((NAME EXPANSION) ...) FORM...)"
1707 (declare (indent 1) (debug ((&rest (symbol sexp)) cl-declarations body))) 1735 (declare (indent 1) (debug ((&rest (symbol sexp)) cl-declarations body)))
1708 (if (cdr bindings) 1736 (cond
1737 ((cdr bindings)
1709 `(cl-symbol-macrolet (,(car bindings)) 1738 `(cl-symbol-macrolet (,(car bindings))
1710 (cl-symbol-macrolet ,(cdr bindings) ,@body)) 1739 (cl-symbol-macrolet ,(cdr bindings) ,@body)))
1711 (if (null bindings) (cons 'progn body) 1740 ((null bindings) (macroexp-progn body))
1712 (cl-macroexpand-all (cons 'progn body) 1741 (t
1742 (let ((previous-macroexpand (symbol-function 'macroexpand)))
1743 (unwind-protect
1744 (progn
1745 (fset 'macroexpand #'cl--sm-macroexpand)
1746 ;; FIXME: For N bindings, this will traverse `body' N times!
1747 (macroexpand-all (cons 'progn body)
1713 (cons (list (symbol-name (caar bindings)) 1748 (cons (list (symbol-name (caar bindings))
1714 (cl-cadar bindings)) 1749 (cl-cadar bindings))
1715 cl-macro-environment))))) 1750 macroexpand-all-environment)))
1751 (fset 'macroexpand previous-macroexpand))))))
1716 1752
1717(defvar cl-closure-vars nil) 1753(defvar cl-closure-vars nil)
1754(defvar cl--function-convert-cache nil)
1755
1756(defun cl--function-convert (f)
1757 "Special macro-expander for special cases of (function F).
1758The two cases that are handled are:
1759- closure-conversion of lambda expressions for `cl-lexical-let'.
1760- renaming of F when it's a function defined via `cl-labels'."
1761 (cond
1762 ;; ¡¡Big Ugly Hack!! We can't use a compiler-macro because those are checked
1763 ;; *after* handling `function', but we want to stop macroexpansion from
1764 ;; being applied infinitely, so we use a cache to return the exact `form'
1765 ;; being expanded even though we don't receive it.
1766 ((eq f (car cl--function-convert-cache)) (cdr cl--function-convert-cache))
1767 ((eq (car-safe f) 'lambda)
1768 (let ((body (mapcar (lambda (f)
1769 (macroexpand-all f macroexpand-all-environment))
1770 (cddr f))))
1771 (if (and cl-closure-vars
1772 (cl--expr-contains-any body cl-closure-vars))
1773 (let* ((new (mapcar 'cl-gensym cl-closure-vars))
1774 (sub (cl-pairlis cl-closure-vars new)) (decls nil))
1775 (while (or (stringp (car body))
1776 (eq (car-safe (car body)) 'interactive))
1777 (push (list 'quote (pop body)) decls))
1778 (put (car (last cl-closure-vars)) 'used t)
1779 `(list 'lambda '(&rest --cl-rest--)
1780 ,@(cl-sublis sub (nreverse decls))
1781 (list 'apply
1782 (list 'quote
1783 #'(lambda ,(append new (cadr f))
1784 ,@(cl-sublis sub body)))
1785 ,@(nconc (mapcar (lambda (x) `(list 'quote ,x))
1786 cl-closure-vars)
1787 '((quote --cl-rest--))))))
1788 (let* ((newf `(lambda ,(cadr f) ,@body))
1789 (res `(function ,newf)))
1790 (setq cl--function-convert-cache (cons newf res))
1791 res))))
1792 (t
1793 (let ((found (assq f macroexpand-all-environment)))
1794 (if (and found (ignore-errors
1795 (eq (cadr (cl-caddr found)) 'cl-labels-args)))
1796 (cadr (cl-caddr (cl-cadddr found)))
1797 (let ((res `(function ,f)))
1798 (setq cl--function-convert-cache (cons f res))
1799 res))))))
1800
1718;;;###autoload 1801;;;###autoload
1719(defmacro cl-lexical-let (bindings &rest body) 1802(defmacro cl-lexical-let (bindings &rest body)
1720 "Like `let', but lexically scoped. 1803 "Like `let', but lexically scoped.
@@ -1732,13 +1815,14 @@ lexical closures as in Common Lisp.
1732 (list (car x) (cadr x) (car cl-closure-vars)))) 1815 (list (car x) (cadr x) (car cl-closure-vars))))
1733 bindings)) 1816 bindings))
1734 (ebody 1817 (ebody
1735 (cl-macroexpand-all 1818 (macroexpand-all
1736 `(cl-symbol-macrolet 1819 `(cl-symbol-macrolet
1737 ,(mapcar (lambda (x) 1820 ,(mapcar (lambda (x)
1738 `(,(car x) (symbol-value ,(cl-caddr x)))) 1821 `(,(car x) (symbol-value ,(cl-caddr x))))
1739 vars) 1822 vars)
1740 ,@body) 1823 ,@body)
1741 cl-macro-environment))) 1824 (cons (cons 'function #'cl--function-convert)
1825 macroexpand-all-environment))))
1742 (if (not (get (car (last cl-closure-vars)) 'used)) 1826 (if (not (get (car (last cl-closure-vars)) 'used))
1743 ;; Turn (let ((foo (cl-gensym))) 1827 ;; Turn (let ((foo (cl-gensym)))
1744 ;; (set foo <val>) ...(symbol-value foo)...) 1828 ;; (set foo <val>) ...(symbol-value foo)...)
@@ -2132,7 +2216,7 @@ Example:
2132;; This is useful when you have control over the PLACE but not over 2216;; This is useful when you have control over the PLACE but not over
2133;; the VALUE, as is the case in define-minor-mode's :variable. 2217;; the VALUE, as is the case in define-minor-mode's :variable.
2134(cl-define-setf-expander eq (place val) 2218(cl-define-setf-expander eq (place val)
2135 (let ((method (cl-get-setf-method place cl-macro-environment)) 2219 (let ((method (cl-get-setf-method place macroexpand-all-environment))
2136 (val-temp (make-symbol "--eq-val--")) 2220 (val-temp (make-symbol "--eq-val--"))
2137 (store-temp (make-symbol "--eq-store--"))) 2221 (store-temp (make-symbol "--eq-store--")))
2138 (list (append (nth 0 method) (list val-temp)) 2222 (list (append (nth 0 method) (list val-temp))
@@ -2146,14 +2230,14 @@ Example:
2146;;; More complex setf-methods. 2230;;; More complex setf-methods.
2147;; These should take &environment arguments, but since full arglists aren't 2231;; These should take &environment arguments, but since full arglists aren't
2148;; available while compiling cl-macs, we fake it by referring to the global 2232;; available while compiling cl-macs, we fake it by referring to the global
2149;; variable cl-macro-environment directly. 2233;; variable macroexpand-all-environment directly.
2150 2234
2151(cl-define-setf-expander apply (func arg1 &rest rest) 2235(cl-define-setf-expander apply (func arg1 &rest rest)
2152 (or (and (memq (car-safe func) '(quote function cl-function)) 2236 (or (and (memq (car-safe func) '(quote function cl-function))
2153 (symbolp (car-safe (cdr-safe func)))) 2237 (symbolp (car-safe (cdr-safe func))))
2154 (error "First arg to apply in cl-setf is not (function SYM): %s" func)) 2238 (error "First arg to apply in cl-setf is not (function SYM): %s" func))
2155 (let* ((form (cons (nth 1 func) (cons arg1 rest))) 2239 (let* ((form (cons (nth 1 func) (cons arg1 rest)))
2156 (method (cl-get-setf-method form cl-macro-environment))) 2240 (method (cl-get-setf-method form macroexpand-all-environment)))
2157 (list (car method) (nth 1 method) (nth 2 method) 2241 (list (car method) (nth 1 method) (nth 2 method)
2158 (cl-setf-make-apply (nth 3 method) (cadr func) (car method)) 2242 (cl-setf-make-apply (nth 3 method) (cadr func) (car method))
2159 (cl-setf-make-apply (nth 4 method) (cadr func) (car method))))) 2243 (cl-setf-make-apply (nth 4 method) (cadr func) (car method)))))
@@ -2166,7 +2250,7 @@ Example:
2166 `(apply ',(car form) ,@(cdr form)))) 2250 `(apply ',(car form) ,@(cdr form))))
2167 2251
2168(cl-define-setf-expander nthcdr (n place) 2252(cl-define-setf-expander nthcdr (n place)
2169 (let ((method (cl-get-setf-method place cl-macro-environment)) 2253 (let ((method (cl-get-setf-method place macroexpand-all-environment))
2170 (n-temp (make-symbol "--cl-nthcdr-n--")) 2254 (n-temp (make-symbol "--cl-nthcdr-n--"))
2171 (store-temp (make-symbol "--cl-nthcdr-store--"))) 2255 (store-temp (make-symbol "--cl-nthcdr-store--")))
2172 (list (cons n-temp (car method)) 2256 (list (cons n-temp (car method))
@@ -2179,7 +2263,7 @@ Example:
2179 `(nthcdr ,n-temp ,(nth 4 method))))) 2263 `(nthcdr ,n-temp ,(nth 4 method)))))
2180 2264
2181(cl-define-setf-expander cl-getf (place tag &optional def) 2265(cl-define-setf-expander cl-getf (place tag &optional def)
2182 (let ((method (cl-get-setf-method place cl-macro-environment)) 2266 (let ((method (cl-get-setf-method place macroexpand-all-environment))
2183 (tag-temp (make-symbol "--cl-getf-tag--")) 2267 (tag-temp (make-symbol "--cl-getf-tag--"))
2184 (def-temp (make-symbol "--cl-getf-def--")) 2268 (def-temp (make-symbol "--cl-getf-def--"))
2185 (store-temp (make-symbol "--cl-getf-store--"))) 2269 (store-temp (make-symbol "--cl-getf-store--")))
@@ -2192,7 +2276,7 @@ Example:
2192 `(cl-getf ,(nth 4 method) ,tag-temp ,def-temp)))) 2276 `(cl-getf ,(nth 4 method) ,tag-temp ,def-temp))))
2193 2277
2194(cl-define-setf-expander substring (place from &optional to) 2278(cl-define-setf-expander substring (place from &optional to)
2195 (let ((method (cl-get-setf-method place cl-macro-environment)) 2279 (let ((method (cl-get-setf-method place macroexpand-all-environment))
2196 (from-temp (make-symbol "--cl-substring-from--")) 2280 (from-temp (make-symbol "--cl-substring-from--"))
2197 (to-temp (make-symbol "--cl-substring-to--")) 2281 (to-temp (make-symbol "--cl-substring-to--"))
2198 (store-temp (make-symbol "--cl-substring-store--"))) 2282 (store-temp (make-symbol "--cl-substring-store--")))
@@ -2220,7 +2304,7 @@ a macro like `cl-setf' or `cl-incf'."
2220 (method (get func 'setf-method)) 2304 (method (get func 'setf-method))
2221 (case-fold-search nil)) 2305 (case-fold-search nil))
2222 (or (and method 2306 (or (and method
2223 (let ((cl-macro-environment env)) 2307 (let ((macroexpand-all-environment env))
2224 (setq method (apply method (cdr place)))) 2308 (setq method (apply method (cdr place))))
2225 (if (and (consp method) (= (length method) 5)) 2309 (if (and (consp method) (= (length method) 5))
2226 method 2310 method
@@ -2240,7 +2324,7 @@ a macro like `cl-setf' or `cl-incf'."
2240 (cl-get-setf-method place env))))) 2324 (cl-get-setf-method place env)))))
2241 2325
2242(defun cl-setf-do-modify (place opt-expr) 2326(defun cl-setf-do-modify (place opt-expr)
2243 (let* ((method (cl-get-setf-method place cl-macro-environment)) 2327 (let* ((method (cl-get-setf-method place macroexpand-all-environment))
2244 (temps (car method)) (values (nth 1 method)) 2328 (temps (car method)) (values (nth 1 method))
2245 (lets nil) (subs nil) 2329 (lets nil) (subs nil)
2246 (optimize (and (not (eq opt-expr 'no-opt)) 2330 (optimize (and (not (eq opt-expr 'no-opt))
diff --git a/lisp/emacs-lisp/cl.el b/lisp/emacs-lisp/cl.el
index ad15d038a81..b4be63f2bb1 100644
--- a/lisp/emacs-lisp/cl.el
+++ b/lisp/emacs-lisp/cl.el
@@ -330,5 +330,37 @@
330 (if (get new prop) 330 (if (get new prop)
331 (put fun prop (get new prop)))))) 331 (put fun prop (get new prop))))))
332 332
333;;; Additional compatibility code
334;; For names that were clean but really aren't needed any more.
335
336(defalias 'cl-macroexpand 'macroexpand)
337(defvaralias 'cl-macro-environment 'macroexpand-all-environment)
338(defalias 'cl-macroexpand-all 'macroexpand-all)
339
340;;; Hash tables.
341;; This is just kept for compatibility with code byte-compiled by Emacs-20.
342
343;; No idea if this might still be needed.
344(defun cl-not-hash-table (x &optional y &rest z)
345 (signal 'wrong-type-argument (list 'cl-hash-table-p (or y x))))
346
347(defvar cl-builtin-gethash (symbol-function 'gethash))
348(defvar cl-builtin-remhash (symbol-function 'remhash))
349(defvar cl-builtin-clrhash (symbol-function 'clrhash))
350(defvar cl-builtin-maphash (symbol-function 'maphash))
351
352(defalias 'cl-map-keymap 'map-keymap)
353(defalias 'cl-copy-tree 'copy-tree)
354(defalias 'cl-gethash 'gethash)
355(defalias 'cl-puthash 'puthash)
356(defalias 'cl-remhash 'remhash)
357(defalias 'cl-clrhash 'clrhash)
358(defalias 'cl-maphash 'maphash)
359(defalias 'cl-make-hash-table 'make-hash-table)
360(defalias 'cl-hash-table-p 'hash-table-p)
361(defalias 'cl-hash-table-count 'hash-table-count)
362
363;; FIXME: More candidates: define-modify-macro, define-setf-expander, lexical-let.
364
333(provide 'cl) 365(provide 'cl)
334;;; cl.el ends here 366;;; cl.el ends here