Unify local variable section, and set
[bpt/emacs.git] / lisp / emacs-lisp / cl-macs.el
index 3dd8464..f3f28de 100644 (file)
@@ -1,6 +1,7 @@
-;;; cl-macs.el --- Common Lisp macros -*-byte-compile-dynamic: t;-*-
+;;; cl-macs.el --- Common Lisp macros
 
-;; Copyright (C) 1993 Free Software Foundation, Inc.
+;; Copyright (C) 1993, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+;;   Free Software Foundation, Inc.
 
 ;; Author: Dave Gillespie <daveg@synaptics.com>
 ;; Version: 2.02
@@ -10,7 +11,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
@@ -20,8 +21,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
     (error "Tried to load `cl-macs' before `cl'!"))
 
 
-;;; We define these here so that this file can compile without having
-;;; loaded the cl.el file already.
-
-(defmacro cl-push (x place) (list 'setq place (list 'cons x place)))
-(defmacro cl-pop (place)
-  (list 'car (list 'prog1 place (list 'setq place (list 'cdr place)))))
 (defmacro cl-pop2 (place)
   (list 'prog1 (list 'car (list 'cdr place))
        (list 'setq place (list 'cdr (list 'cdr place)))))
-(put 'cl-push 'edebug-form-spec 'edebug-sexps)
-(put 'cl-pop 'edebug-form-spec 'edebug-sexps)
 (put 'cl-pop2 'edebug-form-spec 'edebug-sexps)
 
 (defvar cl-optimize-safety)
 (defvar cl-optimize-speed)
 
 
-;;; This kludge allows macros which use cl-transform-function-property
-;;; to be called at compile-time.
+;; This kludge allows macros which use cl-transform-function-property
+;; to be called at compile-time.
 
 (require
  (progn
 
 (defvar cl-old-bc-file-form nil)
 
+;;;###autoload
 (defun cl-compile-time-init ()
   (run-hooks 'cl-hack-bytecomp-hook))
 
 
+;;; Some predicates for analyzing Lisp forms.  These are used by various
+;;; macro expanders to optimize the results in certain common cases.
+
+(defconst cl-simple-funcs '(car cdr nth aref elt if and or + - 1+ 1- min max
+                           car-safe cdr-safe progn prog1 prog2))
+(defconst cl-safe-funcs '(* / % length memq list vector vectorp
+                         < > <= >= = error))
+
+;;; Check if no side effects, and executes quickly.
+(defun cl-simple-expr-p (x &optional size)
+  (or size (setq size 10))
+  (if (and (consp x) (not (memq (car x) '(quote function function*))))
+      (and (symbolp (car x))
+          (or (memq (car x) cl-simple-funcs)
+              (get (car x) 'side-effect-free))
+          (progn
+            (setq size (1- size))
+            (while (and (setq x (cdr x))
+                        (setq size (cl-simple-expr-p (car x) size))))
+            (and (null x) (>= size 0) size)))
+    (and (> size 0) (1- size))))
+
+(defun cl-simple-exprs-p (xs)
+  (while (and xs (cl-simple-expr-p (car xs)))
+    (setq xs (cdr xs)))
+  (not xs))
+
+;;; Check if no side effects.
+(defun cl-safe-expr-p (x)
+  (or (not (and (consp x) (not (memq (car x) '(quote function function*)))))
+      (and (symbolp (car x))
+          (or (memq (car x) cl-simple-funcs)
+              (memq (car x) cl-safe-funcs)
+              (get (car x) 'side-effect-free))
+          (progn
+            (while (and (setq x (cdr x)) (cl-safe-expr-p (car x))))
+            (null x)))))
+
+;;; Check if constant (i.e., no side effects or dependencies).
+(defun cl-const-expr-p (x)
+  (cond ((consp x)
+        (or (eq (car x) 'quote)
+            (and (memq (car x) '(function function*))
+                 (or (symbolp (nth 1 x))
+                     (and (eq (car-safe (nth 1 x)) 'lambda) 'func)))))
+       ((symbolp x) (and (memq x '(nil t)) t))
+       (t t)))
+
+(defun cl-const-exprs-p (xs)
+  (while (and xs (cl-const-expr-p (car xs)))
+    (setq xs (cdr xs)))
+  (not xs))
+
+(defun cl-const-expr-val (x)
+  (and (eq (cl-const-expr-p x) t) (if (consp x) (nth 1 x) x)))
+
+(defun cl-expr-access-order (x v)
+  (if (cl-const-expr-p x) v
+    (if (consp x)
+       (progn
+         (while (setq x (cdr x)) (setq v (cl-expr-access-order (car x) v)))
+         v)
+      (if (eq x (car v)) (cdr v) '(t)))))
+
+;;; Count number of times X refers to Y.  Return nil for 0 times.
+(defun cl-expr-contains (x y)
+  (cond ((equal y x) 1)
+       ((and (consp x) (not (memq (car-safe x) '(quote function function*))))
+        (let ((sum 0))
+          (while x
+            (setq sum (+ sum (or (cl-expr-contains (pop x) y) 0))))
+          (and (> sum 0) sum)))
+       (t nil)))
+
+(defun cl-expr-contains-any (x y)
+  (while (and y (not (cl-expr-contains x (car y)))) (pop y))
+  y)
+
+;;; Check whether X may depend on any of the symbols in Y.
+(defun cl-expr-depends-p (x y)
+  (and (not (cl-const-expr-p x))
+       (or (not (cl-safe-expr-p x)) (cl-expr-contains-any x y))))
+
 ;;; Symbols.
 
 (defvar *gensym-counter*)
-(defun gensym (&optional arg)
+;;;###autoload
+(defun gensym (&optional prefix)
   "Generate a new uninterned symbol.
 The name is made by appending a number to PREFIX, default \"G\"."
-  (let ((prefix (if (stringp arg) arg "G"))
-       (num (if (integerp arg) arg
+  (let ((pfix (if (stringp prefix) prefix "G"))
+       (num (if (integerp prefix) prefix
               (prog1 *gensym-counter*
                 (setq *gensym-counter* (1+ *gensym-counter*))))))
-    (make-symbol (format "%s%d" prefix num))))
+    (make-symbol (format "%s%d" pfix num))))
 
-(defun gentemp (&optional arg)
+;;;###autoload
+(defun gentemp (&optional prefix)
   "Generate a new interned symbol with a unique name.
 The name is made by appending a number to PREFIX, default \"G\"."
-  (let ((prefix (if (stringp arg) arg "G"))
+  (let ((pfix (if (stringp prefix) prefix "G"))
        name)
-    (while (intern-soft (setq name (format "%s%d" prefix *gensym-counter*)))
+    (while (intern-soft (setq name (format "%s%d" pfix *gensym-counter*)))
       (setq *gensym-counter* (1+ *gensym-counter*)))
     (intern name)))
 
 
 ;;; Program structure.
 
+;;;###autoload
 (defmacro defun* (name args &rest body)
-  "(defun* NAME ARGLIST [DOCSTRING] BODY...): define NAME as a function.
+  "Define NAME as a function.
 Like normal `defun', except ARGLIST allows full Common Lisp conventions,
-and BODY is implicitly surrounded by (block NAME ...)."
+and BODY is implicitly surrounded by (block NAME ...).
+
+\(fn NAME ARGLIST [DOCSTRING] BODY...)"
   (let* ((res (cl-transform-lambda (cons args body) name))
         (form (list* 'defun name (cdr res))))
     (if (car res) (list 'progn (car res) form) form)))
 
+;;;###autoload
 (defmacro defmacro* (name args &rest body)
-  "(defmacro* NAME ARGLIST [DOCSTRING] BODY...): define NAME as a macro.
+  "Define NAME as a macro.
 Like normal `defmacro', except ARGLIST allows full Common Lisp conventions,
-and BODY is implicitly surrounded by (block NAME ...)."
+and BODY is implicitly surrounded by (block NAME ...).
+
+\(fn NAME ARGLIST [DOCSTRING] BODY...)"
   (let* ((res (cl-transform-lambda (cons args body) name))
         (form (list* 'defmacro name (cdr res))))
     (if (car res) (list 'progn (car res) form) form)))
 
+;;;###autoload
 (defmacro function* (func)
   "Introduce a function.
-Like normal `function', except that if argument is a lambda form, its
-ARGLIST allows full Common Lisp conventions."
+Like normal `function', except that if argument is a lambda form,
+its argument list allows full Common Lisp conventions."
   (if (eq (car-safe func) 'lambda)
       (let* ((res (cl-transform-lambda (cdr func) 'cl-none))
             (form (list 'function (cons 'lambda (cdr res)))))
@@ -150,12 +236,13 @@ ARGLIST allows full Common Lisp conventions."
 (defvar bind-inits) (defvar bind-lets) (defvar bind-forms)
 
 (defun cl-transform-lambda (form bind-block)
-  (let* ((args (car form)) (body (cdr form))
+  (let* ((args (car form)) (body (cdr form)) (orig-args args)
         (bind-defs nil) (bind-enquote nil)
         (bind-inits nil) (bind-lets nil) (bind-forms nil)
         (header nil) (simple-args nil))
-    (while (or (stringp (car body)) (eq (car-safe (car body)) 'interactive))
-      (cl-push (cl-pop body) header))
+    (while (or (stringp (car body))
+              (memq (car-safe (car body)) '(interactive declare)))
+      (push (pop body) header))
     (setq args (if (listp args) (copy-list args) (list '&rest args)))
     (let ((p (last args))) (if (cdr p) (setcdr p (list '&rest (cdr p)))))
     (if (setq bind-defs (cadr (memq '&cl-defs args)))
@@ -171,20 +258,33 @@ ARGLIST allows full Common Lisp conventions."
                (not (memq (car args) '(nil &rest &body &key &aux)))
                (not (and (eq (car args) '&optional)
                          (or bind-defs (consp (cadr args))))))
-      (cl-push (cl-pop args) simple-args))
+      (push (pop args) simple-args))
     (or (eq bind-block 'cl-none)
        (setq body (list (list* 'block bind-block body))))
     (if (null args)
        (list* nil (nreverse simple-args) (nconc (nreverse header) body))
-      (if (memq '&optional simple-args) (cl-push '&optional args))
+      (if (memq '&optional simple-args) (push '&optional args))
       (cl-do-arglist args nil (- (length simple-args)
                                 (if (memq '&optional simple-args) 1 0)))
       (setq bind-lets (nreverse bind-lets))
       (list* (and bind-inits (list* 'eval-when '(compile load eval)
                                    (nreverse bind-inits)))
             (nconc (nreverse simple-args)
-                   (list '&rest (car (cl-pop bind-lets))))
-            (nconc (nreverse header)
+                   (list '&rest (car (pop bind-lets))))
+            (nconc (let ((hdr (nreverse header)))
+                      ;; Macro expansion can take place in the middle of
+                      ;; apparently harmless computation, so it should not
+                      ;; touch the match-data.
+                      (save-match-data
+                        (require 'help-fns)
+                        (cons (help-add-fundoc-usage
+                               (if (stringp (car hdr)) (pop hdr))
+                               ;; orig-args can contain &cl-defs (an internal
+                               ;; CL thingy I don't understand), so remove it.
+                               (let ((x (memq '&cl-defs orig-args)))
+                                 (if (null x) orig-args
+                                   (delq (car x) (remq (cadr x) orig-args)))))
+                              hdr)))
                    (list (nconc (list 'let* bind-lets)
                                 (nreverse bind-forms) body)))))))
 
@@ -192,7 +292,7 @@ ARGLIST allows full Common Lisp conventions."
   (if (nlistp args)
       (if (or (memq args lambda-list-keywords) (not (symbolp args)))
          (error "Invalid argument name: %s" args)
-       (cl-push (list args expr) bind-lets))
+       (push (list args expr) bind-lets))
     (setq args (copy-list args))
     (let ((p (last args))) (if (cdr p) (setcdr p (list '&rest (cdr p)))))
     (let ((p (memq '&body args))) (if p (setcar p '&rest)))
@@ -204,11 +304,11 @@ ARGLIST allows full Common Lisp conventions."
          (laterarg nil) (exactarg nil) minarg)
       (or num (setq num 0))
       (if (listp (cadr restarg))
-         (setq restarg (gensym "--rest--"))
+         (setq restarg (make-symbol "--cl-rest--"))
        (setq restarg (cadr restarg)))
-      (cl-push (list restarg expr) bind-lets)
+      (push (list restarg expr) bind-lets)
       (if (eq (car args) '&whole)
-         (cl-push (list (cl-pop2 args) restarg) bind-lets))
+         (push (list (cl-pop2 args) restarg) bind-lets))
       (let ((p args))
        (setq minarg restarg)
        (while (and p (not (memq (car p) lambda-list-keywords)))
@@ -222,7 +322,7 @@ ARGLIST allows full Common Lisp conventions."
        (let ((poparg (list (if (or (cdr args) (not exactarg)) 'pop 'car)
                            restarg)))
          (cl-do-arglist
-          (cl-pop args)
+          (pop args)
           (if (or laterarg (= safety 0)) poparg
             (list 'if minarg poparg
                   (list 'signal '(quote wrong-number-of-arguments)
@@ -230,9 +330,9 @@ ARGLIST allows full Common Lisp conventions."
                                          (list 'quote bind-block))
                               (list 'length restarg)))))))
        (setq num (1+ num) laterarg t))
-      (while (and (eq (car args) '&optional) (cl-pop args))
+      (while (and (eq (car args) '&optional) (pop args))
        (while (and args (not (memq (car args) lambda-list-keywords)))
-         (let ((arg (cl-pop args)))
+         (let ((arg (pop args)))
            (or (consp arg) (setq arg (list arg)))
            (if (cddr arg) (cl-do-arglist (nth 2 arg) (list 'and restarg t)))
            (let ((def (if (cdr arg) (nth 1 arg)
@@ -247,16 +347,16 @@ ARGLIST allows full Common Lisp conventions."
          (let ((arg (cl-pop2 args)))
            (if (consp arg) (cl-do-arglist arg restarg)))
        (or (eq (car args) '&key) (= safety 0) exactarg
-           (cl-push (list 'if restarg
+           (push (list 'if restarg
                           (list 'signal '(quote wrong-number-of-arguments)
                                 (list 'list
                                       (and (not (eq bind-block 'cl-none))
                                            (list 'quote bind-block))
                                       (list '+ num (list 'length restarg)))))
                     bind-forms)))
-      (while (and (eq (car args) '&key) (cl-pop args))
+      (while (and (eq (car args) '&key) (pop args))
        (while (and args (not (memq (car args) lambda-list-keywords)))
-         (let ((arg (cl-pop args)))
+         (let ((arg (pop args)))
            (or (consp arg) (setq arg (list arg)))
            (let* ((karg (if (consp (car arg)) (caar arg)
                           (intern (format ":%s" (car arg)))))
@@ -266,7 +366,7 @@ ARGLIST allows full Common Lisp conventions."
                   (look (list 'memq (list 'quote karg) restarg)))
              (and def bind-enquote (setq def (list 'quote def)))
              (if (cddr arg)
-                 (let* ((temp (or (nth 2 arg) (gensym)))
+                 (let* ((temp (or (nth 2 arg) (make-symbol "--cl-var--")))
                         (val (list 'car (list 'cdr temp))))
                    (cl-do-arglist temp look)
                    (cl-do-arglist varg
@@ -285,11 +385,11 @@ ARGLIST allows full Common Lisp conventions."
                                          'quote
                                          (list nil (cl-const-expr-val def)))
                                       (list 'list nil def))))))))
-             (cl-push karg keys)))))
+             (push karg keys)))))
       (setq keys (nreverse keys))
-      (or (and (eq (car args) '&allow-other-keys) (cl-pop args))
+      (or (and (eq (car args) '&allow-other-keys) (pop args))
          (null keys) (= safety 0)
-         (let* ((var (gensym "--keys--"))
+         (let* ((var (make-symbol "--cl-keys--"))
                 (allow '(:allow-other-keys))
                 (check (list
                         'while var
@@ -309,29 +409,30 @@ ARGLIST allows full Common Lisp conventions."
                                 (format "Keyword argument %%s not one of %s"
                                         keys)
                                 (list 'car var)))))))
-           (cl-push (list 'let (list (list var restarg)) check) bind-forms)))
-      (while (and (eq (car args) '&aux) (cl-pop args))
+           (push (list 'let (list (list var restarg)) check) bind-forms)))
+      (while (and (eq (car args) '&aux) (pop args))
        (while (and args (not (memq (car args) lambda-list-keywords)))
          (if (consp (car args))
              (if (and bind-enquote (cadar args))
                  (cl-do-arglist (caar args)
-                                (list 'quote (cadr (cl-pop args))))
-               (cl-do-arglist (caar args) (cadr (cl-pop args))))
-           (cl-do-arglist (cl-pop args) nil))))
+                                (list 'quote (cadr (pop args))))
+               (cl-do-arglist (caar args) (cadr (pop args))))
+           (cl-do-arglist (pop args) nil))))
       (if args (error "Malformed argument list %s" save-args)))))
 
 (defun cl-arglist-args (args)
   (if (nlistp args) (list args)
     (let ((res nil) (kind nil) arg)
       (while (consp args)
-       (setq arg (cl-pop args))
+       (setq arg (pop args))
        (if (memq arg lambda-list-keywords) (setq kind arg)
-         (if (eq arg '&cl-defs) (cl-pop args)
+         (if (eq arg '&cl-defs) (pop args)
            (and (consp arg) kind (setq arg (car arg)))
            (and (consp arg) (cdr arg) (eq kind '&key) (setq arg (cadr arg)))
            (setq res (nconc res (cl-arglist-args arg))))))
       (nconc res (and args (list args))))))
 
+;;;###autoload
 (defmacro destructuring-bind (args expr &rest body)
   (let* ((bind-lets nil) (bind-forms nil) (bind-inits nil)
         (bind-defs nil) (bind-block 'cl-none))
@@ -345,11 +446,14 @@ ARGLIST allows full Common Lisp conventions."
 
 (defvar cl-not-toplevel nil)
 
+;;;###autoload
 (defmacro eval-when (when &rest body)
-  "(eval-when (WHEN...) BODY...): control when BODY is evaluated.
+  "Control when BODY is evaluated.
 If `compile' is in WHEN, BODY is evaluated when compiled at top-level.
 If `load' is in WHEN, BODY is evaluated when loaded after top-level compile.
-If `eval' is in WHEN, BODY is evaluated when interpreted or at non-top-level."
+If `eval' is in WHEN, BODY is evaluated when interpreted or at non-top-level.
+
+\(fn (WHEN...) BODY...)"
   (if (and (fboundp 'cl-compiling-file) (cl-compiling-file)
           (not cl-not-toplevel) (not (boundp 'for-effect)))  ; horrible kludge
       (let ((comp (or (memq 'compile when) (memq :compile-toplevel when)))
@@ -374,6 +478,7 @@ If `eval' is in WHEN, BODY is evaluated when interpreted or at non-top-level."
             form)))
        (t (eval form) form)))
 
+;;;###autoload
 (defmacro load-time-value (form &optional read-only)
   "Like `progn', but evaluates the body at load time.
 The result of the body appears to the compiler as a quoted constant."
@@ -396,15 +501,17 @@ The result of the body appears to the compiler as a quoted constant."
 
 ;;; Conditional control structures.
 
+;;;###autoload
 (defmacro case (expr &rest clauses)
-  "Eval EXPR and choose from CLAUSES on that value.
+  "Eval EXPR and choose among clauses on that value.
 Each clause looks like (KEYLIST BODY...).  EXPR is evaluated and compared
 against each key in each KEYLIST; the corresponding BODY is evaluated.
 If no clause succeeds, case returns nil.  A single atom may be used in
-place of a KEYLIST of one atom.  A KEYLIST of `t' or `otherwise' is
+place of a KEYLIST of one atom.  A KEYLIST of t or `otherwise' is
 allowed only in the final clause, and matches if no other keys match.
-Key values are compared by `eql'."
-  (let* ((temp (if (cl-simple-expr-p expr 3) expr (gensym)))
+Key values are compared by `eql'.
+\n(fn EXPR (KEYLIST BODY...)...)"
+  (let* ((temp (if (cl-simple-expr-p expr 3) expr (make-symbol "--cl-var--")))
         (head-list nil)
         (body (cons
                'cond
@@ -422,25 +529,29 @@ Key values are compared by `eql'."
                                 (if (memq (car c) head-list)
                                     (error "Duplicate key in case: %s"
                                            (car c)))
-                                (cl-push (car c) head-list)
+                                (push (car c) head-list)
                                 (list 'eql temp (list 'quote (car c)))))
                          (or (cdr c) '(nil)))))
                 clauses))))
     (if (eq temp expr) body
       (list 'let (list (list temp expr)) body))))
 
+;;;###autoload
 (defmacro ecase (expr &rest clauses)
   "Like `case', but error if no case fits.
-`otherwise'-clauses are not allowed."
+`otherwise'-clauses are not allowed.
+\n(fn EXPR (KEYLIST BODY...)...)"
   (list* 'case expr (append clauses '((ecase-error-flag)))))
 
+;;;###autoload
 (defmacro typecase (expr &rest clauses)
-  "Evals EXPR, chooses from CLAUSES on that value.
+  "Evals EXPR, chooses among clauses on that value.
 Each clause looks like (TYPE BODY...).  EXPR is evaluated and, if it
 satisfies TYPE, the corresponding BODY is evaluated.  If no clause succeeds,
-typecase returns nil.  A TYPE of `t' or `otherwise' is allowed only in the
-final clause, and matches if no other keys match."
-  (let* ((temp (if (cl-simple-expr-p expr 3) expr (gensym)))
+typecase returns nil.  A TYPE of t or `otherwise' is allowed only in the
+final clause, and matches if no other keys match.
+\n(fn EXPR (TYPE BODY...)...)"
+  (let* ((temp (if (cl-simple-expr-p expr 3) expr (make-symbol "--cl-var--")))
         (type-list nil)
         (body (cons
                'cond
@@ -452,21 +563,24 @@ final clause, and matches if no other keys match."
                                 (list 'error "etypecase failed: %s, %s"
                                       temp (list 'quote (reverse type-list))))
                                (t
-                                (cl-push (car c) type-list)
+                                (push (car c) type-list)
                                 (cl-make-type-test temp (car c))))
                          (or (cdr c) '(nil)))))
                 clauses))))
     (if (eq temp expr) body
       (list 'let (list (list temp expr)) body))))
 
+;;;###autoload
 (defmacro etypecase (expr &rest clauses)
   "Like `typecase', but error if no case fits.
-`otherwise'-clauses are not allowed."
+`otherwise'-clauses are not allowed.
+\n(fn EXPR (TYPE BODY...)...)"
   (list* 'typecase expr (append clauses '((ecase-error-flag)))))
 
 
 ;;; Blocks and exits.
 
+;;;###autoload
 (defmacro block (name &rest body)
   "Define a lexically-scoped block named NAME.
 NAME may be any symbol.  Code inside the BODY forms can call `return-from'
@@ -502,11 +616,13 @@ called from BODY."
     (if cl-found (setcdr cl-found t)))
   (byte-compile-normal-call (cons 'throw (cdr cl-form))))
 
+;;;###autoload
 (defmacro return (&optional result)
   "Return from the block named nil.
 This is equivalent to `(return-from nil RESULT)'."
   (list 'return-from nil result))
 
+;;;###autoload
 (defmacro return-from (name &optional result)
   "Return from the block named NAME.
 This jump out to the innermost enclosing `(block NAME ...)' form,
@@ -526,8 +642,9 @@ This is compatible with Common Lisp, but note that `defun' and
 (defvar loop-result) (defvar loop-result-explicit)
 (defvar loop-result-var) (defvar loop-steps) (defvar loop-symbol-macs)
 
+;;;###autoload
 (defmacro loop (&rest args)
-  "(loop CLAUSE...): The Common Lisp `loop' macro.
+  "The Common Lisp `loop' macro.
 Valid clauses are:
   for VAR from/upfrom/downfrom NUM to/upto/downto/above/below NUM by NUM,
   for VAR in LIST by FUNC, for VAR on LIST by FUNC, for VAR = INIT then EXPR,
@@ -538,7 +655,9 @@ Valid clauses are:
   if COND CLAUSE [and CLAUSE]... else CLAUSE [and CLAUSE...],
   unless COND CLAUSE [and CLAUSE]... else CLAUSE [and CLAUSE...],
   do EXPRS..., initially EXPRS..., finally EXPRS..., return EXPR,
-  finally return EXPR, named NAME."
+  finally return EXPR, named NAME.
+
+\(fn CLAUSE...)"
   (if (not (memq t (mapcar 'symbolp (delq nil (delq t (copy-list args))))))
       (list 'block nil (list* 'while t args))
     (let ((loop-name nil)      (loop-bindings nil)
@@ -552,10 +671,10 @@ Valid clauses are:
       (setq args (append args '(cl-end-loop)))
       (while (not (eq (car args) 'cl-end-loop)) (cl-parse-loop-clause))
       (if loop-finish-flag
-         (cl-push (list (list loop-finish-flag t)) loop-bindings))
+         (push `((,loop-finish-flag t)) loop-bindings))
       (if loop-first-flag
-         (progn (cl-push (list (list loop-first-flag t)) loop-bindings)
-                (cl-push (list 'setq loop-first-flag nil) loop-steps)))
+         (progn (push `((,loop-first-flag t)) loop-bindings)
+                (push `(setq ,loop-first-flag nil) loop-steps)))
       (let* ((epilogue (nconc (nreverse loop-finally)
                              (list (or loop-result-explicit loop-result))))
             (ands (cl-loop-build-ands (nreverse loop-body)))
@@ -566,32 +685,32 @@ Valid clauses are:
                              (list 'block '--cl-finish--
                                    (subst
                                     (if (eq (car ands) t) while-body
-                                      (cons (list 'or (car ands)
-                                                  '(return-from --cl-finish--
-                                                     nil))
+                                      (cons `(or ,(car ands)
+                                                 (return-from --cl-finish--
+                                                   nil))
                                             while-body))
                                     '--cl-map loop-map-form))
                            (list* 'while (car ands) while-body)))
                    (if loop-finish-flag
                        (if (equal epilogue '(nil)) (list loop-result-var)
-                         (list (list 'if loop-finish-flag
-                                     (cons 'progn epilogue) loop-result-var)))
+                         `((if ,loop-finish-flag
+                               (progn ,@epilogue) ,loop-result-var)))
                      epilogue))))
-       (if loop-result-var (cl-push (list loop-result-var) loop-bindings))
+       (if loop-result-var (push (list loop-result-var) loop-bindings))
        (while loop-bindings
          (if (cdar loop-bindings)
-             (setq body (list (cl-loop-let (cl-pop loop-bindings) body t)))
+             (setq body (list (cl-loop-let (pop loop-bindings) body t)))
            (let ((lets nil))
              (while (and loop-bindings
                          (not (cdar loop-bindings)))
-               (cl-push (car (cl-pop loop-bindings)) lets))
+               (push (car (pop loop-bindings)) lets))
              (setq body (list (cl-loop-let lets body nil))))))
        (if loop-symbol-macs
            (setq body (list (list* 'symbol-macrolet loop-symbol-macs body))))
        (list* 'block loop-name body)))))
 
-(defun cl-parse-loop-clause ()   ; uses args, loop-*
-  (let ((word (cl-pop args))
+(defun cl-parse-loop-clause ()         ; uses args, loop-*
+  (let ((word (pop args))
        (hash-types '(hash-key hash-keys hash-value hash-values))
        (key-types '(key-code key-codes key-seq key-seqs
                     key-binding key-bindings)))
@@ -601,39 +720,42 @@ Valid clauses are:
       (error "Malformed `loop' macro"))
 
      ((eq word 'named)
-      (setq loop-name (cl-pop args)))
+      (setq loop-name (pop args)))
 
      ((eq word 'initially)
-      (if (memq (car args) '(do doing)) (cl-pop args))
+      (if (memq (car args) '(do doing)) (pop args))
       (or (consp (car args)) (error "Syntax error on `initially' clause"))
       (while (consp (car args))
-       (cl-push (cl-pop args) loop-initially)))
+       (push (pop args) loop-initially)))
 
      ((eq word 'finally)
       (if (eq (car args) 'return)
          (setq loop-result-explicit (or (cl-pop2 args) '(quote nil)))
-       (if (memq (car args) '(do doing)) (cl-pop args))
+       (if (memq (car args) '(do doing)) (pop args))
        (or (consp (car args)) (error "Syntax error on `finally' clause"))
        (if (and (eq (caar args) 'return) (null loop-name))
-           (setq loop-result-explicit (or (nth 1 (cl-pop args)) '(quote nil)))
+           (setq loop-result-explicit (or (nth 1 (pop args)) '(quote nil)))
          (while (consp (car args))
-           (cl-push (cl-pop args) loop-finally)))))
+           (push (pop args) loop-finally)))))
 
      ((memq word '(for as))
       (let ((loop-for-bindings nil) (loop-for-sets nil) (loop-for-steps nil)
            (ands nil))
        (while
-           (let ((var (or (cl-pop args) (gensym))))
-             (setq word (cl-pop args))
-             (if (eq word 'being) (setq word (cl-pop args)))
-             (if (memq word '(the each)) (setq word (cl-pop args)))
+           ;; Use `gensym' rather than `make-symbol'.  It's important that
+           ;; (not (eq (symbol-name var1) (symbol-name var2))) because
+           ;; these vars get added to the cl-macro-environment.
+           (let ((var (or (pop args) (gensym "--cl-var--"))))
+             (setq word (pop args))
+             (if (eq word 'being) (setq word (pop args)))
+             (if (memq word '(the each)) (setq word (pop args)))
              (if (memq word '(buffer buffers))
                  (setq word 'in args (cons '(buffer-list) args)))
              (cond
 
               ((memq word '(from downfrom upfrom to downto upto
                             above below by))
-               (cl-push word args)
+               (push word args)
                (if (memq (car args) '(downto above))
                    (error "Must specify `from' value for downward loop"))
                (let* ((down (or (eq (car args) 'downfrom)
@@ -646,115 +768,117 @@ Valid clauses are:
                                       '(to upto downto above below))
                                 (cl-pop2 args)))
                       (step (and (eq (car args) 'by) (cl-pop2 args)))
-                      (end-var (and (not (cl-const-expr-p end)) (gensym)))
+                      (end-var (and (not (cl-const-expr-p end))
+                                    (make-symbol "--cl-var--")))
                       (step-var (and (not (cl-const-expr-p step))
-                                     (gensym))))
+                                     (make-symbol "--cl-var--"))))
                  (and step (numberp step) (<= step 0)
                       (error "Loop `by' value is not positive: %s" step))
-                 (cl-push (list var (or start 0)) loop-for-bindings)
-                 (if end-var (cl-push (list end-var end) loop-for-bindings))
-                 (if step-var (cl-push (list step-var step)
-                                       loop-for-bindings))
+                 (push (list var (or start 0)) loop-for-bindings)
+                 (if end-var (push (list end-var end) loop-for-bindings))
+                 (if step-var (push (list step-var step)
+                                    loop-for-bindings))
                  (if end
-                     (cl-push (list
-                               (if down (if excl '> '>=) (if excl '< '<=))
-                               var (or end-var end)) loop-body))
-                 (cl-push (list var (list (if down '- '+) var
-                                          (or step-var step 1)))
-                          loop-for-steps)))
+                     (push (list
+                            (if down (if excl '> '>=) (if excl '< '<=))
+                            var (or end-var end)) loop-body))
+                 (push (list var (list (if down '- '+) var
+                                       (or step-var step 1)))
+                       loop-for-steps)))
 
               ((memq word '(in in-ref on))
                (let* ((on (eq word 'on))
-                      (temp (if (and on (symbolp var)) var (gensym))))
-                 (cl-push (list temp (cl-pop args)) loop-for-bindings)
-                 (cl-push (list 'consp temp) loop-body)
+                      (temp (if (and on (symbolp var))
+                                var (make-symbol "--cl-var--"))))
+                 (push (list temp (pop args)) loop-for-bindings)
+                 (push (list 'consp temp) loop-body)
                  (if (eq word 'in-ref)
-                     (cl-push (list var (list 'car temp)) loop-symbol-macs)
+                     (push (list var (list 'car temp)) loop-symbol-macs)
                    (or (eq temp var)
                        (progn
-                         (cl-push (list var nil) loop-for-bindings)
-                         (cl-push (list var (if on temp (list 'car temp)))
-                                  loop-for-sets))))
-                 (cl-push (list temp
-                                (if (eq (car args) 'by)
-                                    (let ((step (cl-pop2 args)))
-                                      (if (and (memq (car-safe step)
-                                                     '(quote function
-                                                             function*))
-                                               (symbolp (nth 1 step)))
-                                          (list (nth 1 step) temp)
-                                        (list 'funcall step temp)))
-                                  (list 'cdr temp)))
-                          loop-for-steps)))
+                         (push (list var nil) loop-for-bindings)
+                         (push (list var (if on temp (list 'car temp)))
+                               loop-for-sets))))
+                 (push (list temp
+                             (if (eq (car args) 'by)
+                                 (let ((step (cl-pop2 args)))
+                                   (if (and (memq (car-safe step)
+                                                  '(quote function
+                                                          function*))
+                                            (symbolp (nth 1 step)))
+                                       (list (nth 1 step) temp)
+                                     (list 'funcall step temp)))
+                               (list 'cdr temp)))
+                       loop-for-steps)))
 
               ((eq word '=)
-               (let* ((start (cl-pop args))
+               (let* ((start (pop args))
                       (then (if (eq (car args) 'then) (cl-pop2 args) start)))
-                 (cl-push (list var nil) loop-for-bindings)
+                 (push (list var nil) loop-for-bindings)
                  (if (or ands (eq (car args) 'and))
                      (progn
-                       (cl-push (list var
-                                      (list 'if
-                                            (or loop-first-flag
-                                                (setq loop-first-flag
-                                                      (gensym)))
-                                            start var))
-                                loop-for-sets)
-                       (cl-push (list var then) loop-for-steps))
-                   (cl-push (list var
-                                  (if (eq start then) start
-                                    (list 'if
-                                          (or loop-first-flag
-                                              (setq loop-first-flag (gensym)))
-                                          start then)))
-                            loop-for-sets))))
+                       (push `(,var
+                               (if ,(or loop-first-flag
+                                        (setq loop-first-flag
+                                              (make-symbol "--cl-var--")))
+                                   ,start ,var))
+                             loop-for-sets)
+                       (push (list var then) loop-for-steps))
+                   (push (list var
+                               (if (eq start then) start
+                                 `(if ,(or loop-first-flag
+                                           (setq loop-first-flag
+                                                 (make-symbol "--cl-var--")))
+                                      ,start ,then)))
+                         loop-for-sets))))
 
               ((memq word '(across across-ref))
-               (let ((temp-vec (gensym)) (temp-idx (gensym)))
-                 (cl-push (list temp-vec (cl-pop args)) loop-for-bindings)
-                 (cl-push (list temp-idx -1) loop-for-bindings)
-                 (cl-push (list '< (list 'setq temp-idx (list '1+ temp-idx))
-                                (list 'length temp-vec)) loop-body)
+               (let ((temp-vec (make-symbol "--cl-vec--"))
+                     (temp-idx (make-symbol "--cl-idx--")))
+                 (push (list temp-vec (pop args)) loop-for-bindings)
+                 (push (list temp-idx -1) loop-for-bindings)
+                 (push (list '< (list 'setq temp-idx (list '1+ temp-idx))
+                             (list 'length temp-vec)) loop-body)
                  (if (eq word 'across-ref)
-                     (cl-push (list var (list 'aref temp-vec temp-idx))
-                              loop-symbol-macs)
-                   (cl-push (list var nil) loop-for-bindings)
-                   (cl-push (list var (list 'aref temp-vec temp-idx))
-                            loop-for-sets))))
+                     (push (list var (list 'aref temp-vec temp-idx))
+                           loop-symbol-macs)
+                   (push (list var nil) loop-for-bindings)
+                   (push (list var (list 'aref temp-vec temp-idx))
+                         loop-for-sets))))
 
               ((memq word '(element elements))
                (let ((ref (or (memq (car args) '(in-ref of-ref))
                               (and (not (memq (car args) '(in of)))
                                    (error "Expected `of'"))))
                      (seq (cl-pop2 args))
-                     (temp-seq (gensym))
+                     (temp-seq (make-symbol "--cl-seq--"))
                      (temp-idx (if (eq (car args) 'using)
                                    (if (and (= (length (cadr args)) 2)
                                             (eq (caadr args) 'index))
                                        (cadr (cl-pop2 args))
                                      (error "Bad `using' clause"))
-                                 (gensym))))
-                 (cl-push (list temp-seq seq) loop-for-bindings)
-                 (cl-push (list temp-idx 0) loop-for-bindings)
+                                 (make-symbol "--cl-idx--"))))
+                 (push (list temp-seq seq) loop-for-bindings)
+                 (push (list temp-idx 0) loop-for-bindings)
                  (if ref
-                     (let ((temp-len (gensym)))
-                       (cl-push (list temp-len (list 'length temp-seq))
-                                loop-for-bindings)
-                       (cl-push (list var (list 'elt temp-seq temp-idx))
-                                loop-symbol-macs)
-                       (cl-push (list '< temp-idx temp-len) loop-body))
-                   (cl-push (list var nil) loop-for-bindings)
-                   (cl-push (list 'and temp-seq
-                                  (list 'or (list 'consp temp-seq)
-                                        (list '< temp-idx
-                                              (list 'length temp-seq))))
-                            loop-body)
-                   (cl-push (list var (list 'if (list 'consp temp-seq)
-                                            (list 'pop temp-seq)
-                                            (list 'aref temp-seq temp-idx)))
-                            loop-for-sets))
-                 (cl-push (list temp-idx (list '1+ temp-idx))
-                          loop-for-steps)))
+                     (let ((temp-len (make-symbol "--cl-len--")))
+                       (push (list temp-len (list 'length temp-seq))
+                             loop-for-bindings)
+                       (push (list var (list 'elt temp-seq temp-idx))
+                             loop-symbol-macs)
+                       (push (list '< temp-idx temp-len) loop-body))
+                   (push (list var nil) loop-for-bindings)
+                   (push (list 'and temp-seq
+                               (list 'or (list 'consp temp-seq)
+                                     (list '< temp-idx
+                                           (list 'length temp-seq))))
+                         loop-body)
+                   (push (list var (list 'if (list 'consp temp-seq)
+                                         (list 'pop temp-seq)
+                                         (list 'aref temp-seq temp-idx)))
+                         loop-for-sets))
+                 (push (list temp-idx (list '1+ temp-idx))
+                       loop-for-steps)))
 
               ((memq word hash-types)
                (or (memq (car args) '(in of)) (error "Expected `of'"))
@@ -765,21 +889,17 @@ Valid clauses are:
                                           (not (eq (caadr args) word)))
                                      (cadr (cl-pop2 args))
                                    (error "Bad `using' clause"))
-                               (gensym))))
+                               (make-symbol "--cl-var--"))))
                  (if (memq word '(hash-value hash-values))
                      (setq var (prog1 other (setq other var))))
                  (setq loop-map-form
-                       (list 'maphash (list 'function
-                                            (list* 'lambda (list var other)
-                                                   '--cl-map)) table))))
+                       `(maphash (lambda (,var ,other) . --cl-map) ,table))))
 
               ((memq word '(symbol present-symbol external-symbol
                             symbols present-symbols external-symbols))
                (let ((ob (and (memq (car args) '(in of)) (cl-pop2 args))))
                  (setq loop-map-form
-                       (list 'mapatoms (list 'function
-                                             (list* 'lambda (list var)
-                                                    '--cl-map)) ob))))
+                       `(mapatoms (lambda (,var) . --cl-map) ,ob))))
 
               ((memq word '(overlay overlays extent extents))
                (let ((buf nil) (from nil) (to nil))
@@ -788,14 +908,15 @@ Valid clauses are:
                          ((eq (car args) 'to) (setq to (cl-pop2 args)))
                          (t (setq buf (cl-pop2 args)))))
                  (setq loop-map-form
-                       (list 'cl-map-extents
-                             (list 'function (list 'lambda (list var (gensym))
-                                                   '(progn . --cl-map) nil))
-                             buf from to))))
+                       `(cl-map-extents
+                         (lambda (,var ,(make-symbol "--cl-var--"))
+                           (progn . --cl-map) nil)
+                         ,buf ,from ,to))))
 
               ((memq word '(interval intervals))
                (let ((buf nil) (prop nil) (from nil) (to nil)
-                     (var1 (gensym)) (var2 (gensym)))
+                     (var1 (make-symbol "--cl-var1--"))
+                     (var2 (make-symbol "--cl-var2--")))
                  (while (memq (car args) '(in of property from to))
                    (cond ((eq (car args) 'from) (setq from (cl-pop2 args)))
                          ((eq (car args) 'to) (setq to (cl-pop2 args)))
@@ -804,12 +925,11 @@ Valid clauses are:
                          (t (setq buf (cl-pop2 args)))))
                  (if (and (consp var) (symbolp (car var)) (symbolp (cdr var)))
                      (setq var1 (car var) var2 (cdr var))
-                   (cl-push (list var (list 'cons var1 var2)) loop-for-sets))
+                   (push (list var (list 'cons var1 var2)) loop-for-sets))
                  (setq loop-map-form
-                       (list 'cl-map-intervals
-                             (list 'function (list 'lambda (list var1 var2)
-                                                   '(progn . --cl-map)))
-                             buf prop from to))))
+                       `(cl-map-intervals
+                         (lambda (,var1 ,var2) . --cl-map)
+                         ,buf ,prop ,from ,to))))
 
               ((memq word key-types)
                (or (memq (car args) '(in of)) (error "Expected `of'"))
@@ -820,38 +940,37 @@ Valid clauses are:
                                          (not (eq (caadr args) word)))
                                     (cadr (cl-pop2 args))
                                   (error "Bad `using' clause"))
-                              (gensym))))
+                              (make-symbol "--cl-var--"))))
                  (if (memq word '(key-binding key-bindings))
                      (setq var (prog1 other (setq other var))))
                  (setq loop-map-form
-                       (list (if (memq word '(key-seq key-seqs))
-                                 'cl-map-keymap-recursively 'cl-map-keymap)
-                             (list 'function (list* 'lambda (list var other)
-                                                    '--cl-map)) map))))
+                       `(,(if (memq word '(key-seq key-seqs))
+                              'cl-map-keymap-recursively 'map-keymap)
+                         (lambda (,var ,other) . --cl-map) ,map))))
 
               ((memq word '(frame frames screen screens))
-               (let ((temp (gensym)))
-                 (cl-push (list var  '(selected-frame))
-                          loop-for-bindings)
-                 (cl-push (list temp nil) loop-for-bindings)
-                 (cl-push (list 'prog1 (list 'not (list 'eq var temp))
-                                (list 'or temp (list 'setq temp var)))
-                          loop-body)
-                 (cl-push (list var (list 'next-frame var))
-                          loop-for-steps)))
+               (let ((temp (make-symbol "--cl-var--")))
+                 (push (list var  '(selected-frame))
+                       loop-for-bindings)
+                 (push (list temp nil) loop-for-bindings)
+                 (push (list 'prog1 (list 'not (list 'eq var temp))
+                             (list 'or temp (list 'setq temp var)))
+                       loop-body)
+                 (push (list var (list 'next-frame var))
+                       loop-for-steps)))
 
               ((memq word '(window windows))
                (let ((scr (and (memq (car args) '(in of)) (cl-pop2 args)))
-                     (temp (gensym)))
-                 (cl-push (list var (if scr
-                                        (list 'frame-selected-window scr)
-                                      '(selected-window)))
-                          loop-for-bindings)
-                 (cl-push (list temp nil) loop-for-bindings)
-                 (cl-push (list 'prog1 (list 'not (list 'eq var temp))
-                                (list 'or temp (list 'setq temp var)))
-                          loop-body)
-                 (cl-push (list var (list 'next-window var)) loop-for-steps)))
+                     (temp (make-symbol "--cl-var--")))
+                 (push (list var (if scr
+                                     (list 'frame-selected-window scr)
+                                   '(selected-window)))
+                       loop-for-bindings)
+                 (push (list temp nil) loop-for-bindings)
+                 (push (list 'prog1 (list 'not (list 'eq var temp))
+                             (list 'or temp (list 'setq temp var)))
+                       loop-body)
+                 (push (list var (list 'next-window var)) loop-for-steps)))
 
               (t
                (let ((handler (and (symbolp word)
@@ -861,152 +980,152 @@ Valid clauses are:
                    (error "Expected a `for' preposition, found %s" word)))))
              (eq (car args) 'and))
          (setq ands t)
-         (cl-pop args))
+         (pop args))
        (if (and ands loop-for-bindings)
-           (cl-push (nreverse loop-for-bindings) loop-bindings)
+           (push (nreverse loop-for-bindings) loop-bindings)
          (setq loop-bindings (nconc (mapcar 'list loop-for-bindings)
                                     loop-bindings)))
        (if loop-for-sets
-           (cl-push (list 'progn
-                          (cl-loop-let (nreverse loop-for-sets) 'setq ands)
-                          t) loop-body))
+           (push (list 'progn
+                       (cl-loop-let (nreverse loop-for-sets) 'setq ands)
+                       t) loop-body))
        (if loop-for-steps
-           (cl-push (cons (if ands 'psetq 'setq)
-                          (apply 'append (nreverse loop-for-steps)))
-                    loop-steps))))
+           (push (cons (if ands 'psetq 'setq)
+                       (apply 'append (nreverse loop-for-steps)))
+                 loop-steps))))
 
      ((eq word 'repeat)
-      (let ((temp (gensym)))
-       (cl-push (list (list temp (cl-pop args))) loop-bindings)
-       (cl-push (list '>= (list 'setq temp (list '1- temp)) 0) loop-body)))
+      (let ((temp (make-symbol "--cl-var--")))
+       (push (list (list temp (pop args))) loop-bindings)
+       (push (list '>= (list 'setq temp (list '1- temp)) 0) loop-body)))
 
      ((memq word '(collect collecting))
-      (let ((what (cl-pop args))
+      (let ((what (pop args))
            (var (cl-loop-handle-accum nil 'nreverse)))
        (if (eq var loop-accum-var)
-           (cl-push (list 'progn (list 'push what var) t) loop-body)
-         (cl-push (list 'progn
-                        (list 'setq var (list 'nconc var (list 'list what)))
-                        t) loop-body))))
+           (push (list 'progn (list 'push what var) t) loop-body)
+         (push (list 'progn
+                     (list 'setq var (list 'nconc var (list 'list what)))
+                     t) loop-body))))
 
      ((memq word '(nconc nconcing append appending))
-      (let ((what (cl-pop args))
+      (let ((what (pop args))
            (var (cl-loop-handle-accum nil 'nreverse)))
-       (cl-push (list 'progn
-                      (list 'setq var
-                            (if (eq var loop-accum-var)
-                                (list 'nconc
-                                      (list (if (memq word '(nconc nconcing))
-                                                'nreverse 'reverse)
-                                            what)
-                                      var)
-                              (list (if (memq word '(nconc nconcing))
-                                        'nconc 'append)
-                                    var what))) t) loop-body)))
+       (push (list 'progn
+                   (list 'setq var
+                         (if (eq var loop-accum-var)
+                             (list 'nconc
+                                   (list (if (memq word '(nconc nconcing))
+                                             'nreverse 'reverse)
+                                         what)
+                                   var)
+                           (list (if (memq word '(nconc nconcing))
+                                     'nconc 'append)
+                                 var what))) t) loop-body)))
 
      ((memq word '(concat concating))
-      (let ((what (cl-pop args))
+      (let ((what (pop args))
            (var (cl-loop-handle-accum "")))
-       (cl-push (list 'progn (list 'callf 'concat var what) t) loop-body)))
+       (push (list 'progn (list 'callf 'concat var what) t) loop-body)))
 
      ((memq word '(vconcat vconcating))
-      (let ((what (cl-pop args))
+      (let ((what (pop args))
            (var (cl-loop-handle-accum [])))
-       (cl-push (list 'progn (list 'callf 'vconcat var what) t) loop-body)))
+       (push (list 'progn (list 'callf 'vconcat var what) t) loop-body)))
 
      ((memq word '(sum summing))
-      (let ((what (cl-pop args))
+      (let ((what (pop args))
            (var (cl-loop-handle-accum 0)))
-       (cl-push (list 'progn (list 'incf var what) t) loop-body)))
+       (push (list 'progn (list 'incf var what) t) loop-body)))
 
      ((memq word '(count counting))
-      (let ((what (cl-pop args))
+      (let ((what (pop args))
            (var (cl-loop-handle-accum 0)))
-       (cl-push (list 'progn (list 'if what (list 'incf var)) t) loop-body)))
+       (push (list 'progn (list 'if what (list 'incf var)) t) loop-body)))
 
      ((memq word '(minimize minimizing maximize maximizing))
-      (let* ((what (cl-pop args))
-            (temp (if (cl-simple-expr-p what) what (gensym)))
+      (let* ((what (pop args))
+            (temp (if (cl-simple-expr-p what) what (make-symbol "--cl-var--")))
             (var (cl-loop-handle-accum nil))
             (func (intern (substring (symbol-name word) 0 3)))
             (set (list 'setq var (list 'if var (list func var temp) temp))))
-       (cl-push (list 'progn (if (eq temp what) set
-                               (list 'let (list (list temp what)) set))
-                      t) loop-body)))
+       (push (list 'progn (if (eq temp what) set
+                            (list 'let (list (list temp what)) set))
+                   t) loop-body)))
 
      ((eq word 'with)
       (let ((bindings nil))
-       (while (progn (cl-push (list (cl-pop args)
-                                    (and (eq (car args) '=) (cl-pop2 args)))
-                              bindings)
+       (while (progn (push (list (pop args)
+                                 (and (eq (car args) '=) (cl-pop2 args)))
+                           bindings)
                      (eq (car args) 'and))
-         (cl-pop args))
-       (cl-push (nreverse bindings) loop-bindings)))
+         (pop args))
+       (push (nreverse bindings) loop-bindings)))
 
      ((eq word 'while)
-      (cl-push (cl-pop args) loop-body))
+      (push (pop args) loop-body))
 
      ((eq word 'until)
-      (cl-push (list 'not (cl-pop args)) loop-body))
+      (push (list 'not (pop args)) loop-body))
 
      ((eq word 'always)
-      (or loop-finish-flag (setq loop-finish-flag (gensym)))
-      (cl-push (list 'setq loop-finish-flag (cl-pop args)) loop-body)
+      (or loop-finish-flag (setq loop-finish-flag (make-symbol "--cl-flag--")))
+      (push (list 'setq loop-finish-flag (pop args)) loop-body)
       (setq loop-result t))
 
      ((eq word 'never)
-      (or loop-finish-flag (setq loop-finish-flag (gensym)))
-      (cl-push (list 'setq loop-finish-flag (list 'not (cl-pop args)))
-              loop-body)
+      (or loop-finish-flag (setq loop-finish-flag (make-symbol "--cl-flag--")))
+      (push (list 'setq loop-finish-flag (list 'not (pop args)))
+           loop-body)
       (setq loop-result t))
 
      ((eq word 'thereis)
-      (or loop-finish-flag (setq loop-finish-flag (gensym)))
-      (or loop-result-var (setq loop-result-var (gensym)))
-      (cl-push (list 'setq loop-finish-flag
-                    (list 'not (list 'setq loop-result-var (cl-pop args))))
-              loop-body))
+      (or loop-finish-flag (setq loop-finish-flag (make-symbol "--cl-flag--")))
+      (or loop-result-var (setq loop-result-var (make-symbol "--cl-var--")))
+      (push (list 'setq loop-finish-flag
+                 (list 'not (list 'setq loop-result-var (pop args))))
+           loop-body))
 
      ((memq word '(if when unless))
-      (let* ((cond (cl-pop args))
+      (let* ((cond (pop args))
             (then (let ((loop-body nil))
                     (cl-parse-loop-clause)
                     (cl-loop-build-ands (nreverse loop-body))))
             (else (let ((loop-body nil))
                     (if (eq (car args) 'else)
-                        (progn (cl-pop args) (cl-parse-loop-clause)))
+                        (progn (pop args) (cl-parse-loop-clause)))
                     (cl-loop-build-ands (nreverse loop-body))))
             (simple (and (eq (car then) t) (eq (car else) t))))
-       (if (eq (car args) 'end) (cl-pop args))
+       (if (eq (car args) 'end) (pop args))
        (if (eq word 'unless) (setq then (prog1 else (setq else then))))
        (let ((form (cons (if simple (cons 'progn (nth 1 then)) (nth 2 then))
                          (if simple (nth 1 else) (list (nth 2 else))))))
          (if (cl-expr-contains form 'it)
-             (let ((temp (gensym)))
-               (cl-push (list temp) loop-bindings)
+             (let ((temp (make-symbol "--cl-var--")))
+               (push (list temp) loop-bindings)
                (setq form (list* 'if (list 'setq temp cond)
                                  (subst temp 'it form))))
            (setq form (list* 'if cond form)))
-         (cl-push (if simple (list 'progn form t) form) loop-body))))
+         (push (if simple (list 'progn form t) form) loop-body))))
 
      ((memq word '(do doing))
       (let ((body nil))
        (or (consp (car args)) (error "Syntax error on `do' clause"))
-       (while (consp (car args)) (cl-push (cl-pop args) body))
-       (cl-push (cons 'progn (nreverse (cons t body))) loop-body)))
+       (while (consp (car args)) (push (pop args) body))
+       (push (cons 'progn (nreverse (cons t body))) loop-body)))
 
      ((eq word 'return)
-      (or loop-finish-flag (setq loop-finish-flag (gensym)))
-      (or loop-result-var (setq loop-result-var (gensym)))
-      (cl-push (list 'setq loop-result-var (cl-pop args)
-                    loop-finish-flag nil) loop-body))
+      (or loop-finish-flag (setq loop-finish-flag (make-symbol "--cl-var--")))
+      (or loop-result-var (setq loop-result-var (make-symbol "--cl-var--")))
+      (push (list 'setq loop-result-var (pop args)
+                 loop-finish-flag nil) loop-body))
 
      (t
       (let ((handler (and (symbolp word) (get word 'cl-loop-handler))))
        (or handler (error "Expected a loop keyword, found %s" word))
        (funcall handler))))
     (if (eq (car args) 'and)
-       (progn (cl-pop args) (cl-parse-loop-clause)))))
+       (progn (pop args) (cl-parse-loop-clause)))))
 
 (defun cl-loop-let (specs body par)   ; uses loop-*
   (let ((p specs) (temps nil) (new nil))
@@ -1017,25 +1136,25 @@ Valid clauses are:
           (setq par nil p specs)
           (while p
             (or (cl-const-expr-p (cadar p))
-                (let ((temp (gensym)))
-                  (cl-push (list temp (cadar p)) temps)
+                (let ((temp (make-symbol "--cl-var--")))
+                  (push (list temp (cadar p)) temps)
                   (setcar (cdar p) temp)))
             (setq p (cdr p)))))
     (while specs
       (if (and (consp (car specs)) (listp (caar specs)))
          (let* ((spec (caar specs)) (nspecs nil)
-                (expr (cadr (cl-pop specs)))
+                (expr (cadr (pop specs)))
                 (temp (cdr (or (assq spec loop-destr-temps)
-                               (car (cl-push (cons spec (or (last spec 0)
-                                                            (gensym)))
-                                             loop-destr-temps))))))
-           (cl-push (list temp expr) new)
+                               (car (push (cons spec (or (last spec 0)
+                                                         (make-symbol "--cl-var--")))
+                                          loop-destr-temps))))))
+           (push (list temp expr) new)
            (while (consp spec)
-             (cl-push (list (cl-pop spec)
+             (push (list (pop spec)
                             (and expr (list (if spec 'pop 'car) temp)))
                       nspecs))
            (setq specs (nconc (nreverse nspecs) specs)))
-       (cl-push (cl-pop specs) new)))
+       (push (pop specs) new)))
     (if (eq body 'setq)
        (let ((set (cons (if par 'psetq 'setq) (apply 'nconc (nreverse new)))))
          (if temps (list 'let* (nreverse temps) set) set))
@@ -1046,12 +1165,12 @@ Valid clauses are:
   (if (eq (car args) 'into)
       (let ((var (cl-pop2 args)))
        (or (memq var loop-accum-vars)
-           (progn (cl-push (list (list var def)) loop-bindings)
-                  (cl-push var loop-accum-vars)))
+           (progn (push (list (list var def)) loop-bindings)
+                  (push var loop-accum-vars)))
        var)
     (or loop-accum-var
        (progn
-         (cl-push (list (list (setq loop-accum-var (gensym)) def))
+         (push (list (list (setq loop-accum-var (make-symbol "--cl-var--")) def))
                   loop-bindings)
          (setq loop-result (if func (list func loop-accum-var)
                              loop-accum-var))
@@ -1070,8 +1189,8 @@ Valid clauses are:
                                             (cdadr clauses)
                                           (list (cadr clauses))))
                                  (cddr clauses)))
-           (setq body (cdr (butlast (cl-pop clauses)))))
-       (cl-push (cl-pop clauses) ands)))
+           (setq body (cdr (butlast (pop clauses)))))
+       (push (pop clauses) ands)))
     (setq ands (or (nreverse ands) (list t)))
     (list (if (cdr ands) (cons 'and ands) (car ands))
          body
@@ -1083,14 +1202,18 @@ Valid clauses are:
 
 ;;; Other iteration control structures.
 
+;;;###autoload
 (defmacro do (steps endtest &rest body)
   "The Common Lisp `do' loop.
-Format is: (do ((VAR INIT [STEP])...) (END-TEST [RESULT...]) BODY...)"
+
+\(fn ((VAR INIT [STEP])...) (END-TEST [RESULT...]) BODY...)"
   (cl-expand-do-loop steps endtest body nil))
 
+;;;###autoload
 (defmacro do* (steps endtest &rest body)
   "The Common Lisp `do*' loop.
-Format is: (do* ((VAR INIT [STEP])...) (END-TEST [RESULT...]) BODY...)"
+
+\(fn ((VAR INIT [STEP])...) (END-TEST [RESULT...]) BODY...)"
   (cl-expand-do-loop steps endtest body t))
 
 (defun cl-expand-do-loop (steps endtest body star)
@@ -1114,11 +1237,14 @@ Format is: (do* ((VAR INIT [STEP])...) (END-TEST [RESULT...]) BODY...)"
                                                 (apply 'append sets)))))))
               (or (cdr endtest) '(nil)))))
 
+;;;###autoload
 (defmacro dolist (spec &rest body)
-  "(dolist (VAR LIST [RESULT]) BODY...): loop over a list.
+  "Loop over a list.
 Evaluate BODY with VAR bound to each `car' from LIST, in turn.
-Then evaluate RESULT to get return value, default nil."
-  (let ((temp (gensym "--dolist-temp--")))
+Then evaluate RESULT to get return value, default nil.
+
+\(fn (VAR LIST [RESULT]) BODY...)"
+  (let ((temp (make-symbol "--cl-dolist-temp--")))
     (list 'block nil
          (list* 'let (list (list temp (nth 1 spec)) (car spec))
                 (list* 'while temp (list 'setq (car spec) (list 'car temp))
@@ -1128,22 +1254,28 @@ Then evaluate RESULT to get return value, default nil."
                     (cons (list 'setq (car spec) nil) (cdr (cdr spec)))
                   '(nil))))))
 
+;;;###autoload
 (defmacro dotimes (spec &rest body)
-  "(dotimes (VAR COUNT [RESULT]) BODY...): loop a certain number of times.
+  "Loop a certain number of times.
 Evaluate BODY with VAR bound to successive integers from 0, inclusive,
 to COUNT, exclusive.  Then evaluate RESULT to get return value, default
-nil."
-  (let ((temp (gensym "--dotimes-temp--")))
+nil.
+
+\(fn (VAR COUNT [RESULT]) BODY...)"
+  (let ((temp (make-symbol "--cl-dotimes-temp--")))
     (list 'block nil
          (list* 'let (list (list temp (nth 1 spec)) (list (car spec) 0))
                 (list* 'while (list '< (car spec) temp)
                        (append body (list (list 'incf (car spec)))))
                 (or (cdr (cdr spec)) '(nil))))))
 
+;;;###autoload
 (defmacro do-symbols (spec &rest body)
-  "(dosymbols (VAR [OBARRAY [RESULT]]) BODY...): loop over all symbols.
+  "Loop over all symbols.
 Evaluate BODY with VAR bound to each interned symbol, or to each symbol
-from OBARRAY."
+from OBARRAY.
+
+\(fn (VAR [OBARRAY [RESULT]]) BODY...)"
   ;; Apparently this doesn't have an implicit block.
   (list 'block nil
        (list 'let (list (car spec))
@@ -1152,25 +1284,30 @@ from OBARRAY."
                     (and (cadr spec) (list (cadr spec))))
              (caddr spec))))
 
+;;;###autoload
 (defmacro do-all-symbols (spec &rest body)
   (list* 'do-symbols (list (car spec) nil (cadr spec)) body))
 
 
 ;;; Assignments.
 
+;;;###autoload
 (defmacro psetq (&rest args)
-  "(psetq SYM VAL SYM VAL ...): set SYMs to the values VALs in parallel.
+  "Set SYMs to the values VALs in parallel.
 This is like `setq', except that all VAL forms are evaluated (in order)
-before assigning any symbols SYM to the corresponding values."
+before assigning any symbols SYM to the corresponding values.
+
+\(fn SYM VAL SYM VAL ...)"
   (cons 'psetf args))
 
 
 ;;; Binding control structures.
 
+;;;###autoload
 (defmacro progv (symbols values &rest body)
   "Bind SYMBOLS to VALUES dynamically in BODY.
 The forms SYMBOLS and VALUES are evaluated, and must evaluate to lists.
-Each SYMBOL in the first list is bound to the corresponding VALUE in the
+Each symbol in the first list is bound to the corresponding value in the
 second list (or made unbound if VALUES is shorter than SYMBOLS); then the
 BODY forms are executed and their result is returned.  This is much like
 a `let' form, except that the list of symbols can be computed at run-time."
@@ -1180,12 +1317,15 @@ a `let' form, except that the list of symbols can be computed at run-time."
              '(cl-progv-after))))
 
 ;;; This should really have some way to shadow 'byte-compile properties, etc.
+;;;###autoload
 (defmacro flet (bindings &rest body)
-  "(flet ((FUNC ARGLIST BODY...) ...) FORM...): make temporary function defns.
+  "Make temporary function definitions.
 This is an analogue of `let' that operates on the function cell of FUNC
 rather than its value cell.  The FORMs are evaluated with the specified
 function definitions in place, then the definitions are undone (the FUNCs
-go back to their previous definitions, or lack thereof)."
+go back to their previous definitions, or lack thereof).
+
+\(fn ((FUNC ARGLIST BODY...) ...) FORM...)"
   (list* 'letf*
         (mapcar
          (function
@@ -1199,23 +1339,29 @@ go back to their previous definitions, or lack thereof)."
                                     (list* 'block (car x) (cddr x))))))
               (if (and (cl-compiling-file)
                        (boundp 'byte-compile-function-environment))
-                  (cl-push (cons (car x) (eval func))
+                  (push (cons (car x) (eval func))
                            byte-compile-function-environment))
               (list (list 'symbol-function (list 'quote (car x))) func))))
          bindings)
         body))
 
+;;;###autoload
 (defmacro labels (bindings &rest body)
-  "(labels ((FUNC ARGLIST BODY...) ...) FORM...): make temporary func bindings.
+  "Make temporary function bindings.
 This is like `flet', except the bindings are lexical instead of dynamic.
-Unlike `flet', this macro is fully complaint with the Common Lisp standard."
+Unlike `flet', this macro is fully compliant with the Common Lisp standard.
+
+\(fn ((FUNC ARGLIST BODY...) ...) FORM...)"
   (let ((vars nil) (sets nil) (cl-macro-environment cl-macro-environment))
     (while bindings
-      (let ((var (gensym)))
-       (cl-push var vars)
-       (cl-push (list 'function* (cons 'lambda (cdar bindings))) sets)
-       (cl-push var sets)
-       (cl-push (list (car (cl-pop bindings)) 'lambda '(&rest cl-labels-args)
+      ;; Use `gensym' rather than `make-symbol'.  It's important that
+      ;; (not (eq (symbol-name var1) (symbol-name var2))) because these
+      ;; vars get added to the cl-macro-environment.
+      (let ((var (gensym "--cl-var--")))
+       (push var vars)
+       (push (list 'function* (cons 'lambda (cdar bindings))) sets)
+       (push var sets)
+       (push (list (car (pop bindings)) 'lambda '(&rest cl-labels-args)
                       (list 'list* '(quote funcall) (list 'quote var)
                             'cl-labels-args))
                 cl-macro-environment)))
@@ -1224,9 +1370,12 @@ Unlike `flet', this macro is fully complaint with the Common Lisp standard."
 
 ;; The following ought to have a better definition for use with newer
 ;; byte compilers.
+;;;###autoload
 (defmacro macrolet (bindings &rest body)
-  "(macrolet ((NAME ARGLIST BODY...) ...) FORM...): make temporary macro defns.
-This is like `flet', but for macros instead of functions."
+  "Make temporary macro definitions.
+This is like `flet', but for macros instead of functions.
+
+\(fn ((NAME ARGLIST BODY...) ...) FORM...)"
   (if (cdr bindings)
       (list 'macrolet
            (list (car bindings)) (list* 'macrolet (cdr bindings) body))
@@ -1238,10 +1387,13 @@ This is like `flet', but for macros instead of functions."
                            (cons (list* name 'lambda (cdr res))
                                  cl-macro-environment))))))
 
+;;;###autoload
 (defmacro symbol-macrolet (bindings &rest body)
-  "(symbol-macrolet ((NAME EXPANSION) ...) FORM...): make symbol macro defns.
+  "Make symbol macro definitions.
 Within the body FORMs, references to the variable NAME will be replaced
-by EXPANSION, and (setq NAME ...) will act like (setf EXPANSION ...)."
+by EXPANSION, and (setq NAME ...) will act like (setf EXPANSION ...).
+
+\(fn ((NAME EXPANSION) ...) FORM...)"
   (if (cdr bindings)
       (list 'symbol-macrolet
            (list (car bindings)) (list* 'symbol-macrolet (cdr bindings) body))
@@ -1252,20 +1404,22 @@ by EXPANSION, and (setq NAME ...) will act like (setf EXPANSION ...)."
                                cl-macro-environment)))))
 
 (defvar cl-closure-vars nil)
+;;;###autoload
 (defmacro lexical-let (bindings &rest body)
   "Like `let', but lexically scoped.
 The main visible difference is that lambdas inside BODY will create
-lexical closures as in Common Lisp."
+lexical closures as in Common Lisp.
+\n(fn VARLIST BODY)"
   (let* ((cl-closure-vars cl-closure-vars)
         (vars (mapcar (function
                        (lambda (x)
                          (or (consp x) (setq x (list x)))
-                         (cl-push (gensym (format "--%s--" (car x)))
-                                  cl-closure-vars)
+                         (push (make-symbol (format "--cl-%s--" (car x)))
+                               cl-closure-vars)
                          (set (car cl-closure-vars) [bad-lexical-ref])
                          (list (car x) (cadr x) (car cl-closure-vars))))
                       bindings))
-        (ebody 
+        (ebody
          (cl-macroexpand-all
           (cons 'progn body)
           (nconc (mapcar (function (lambda (x)
@@ -1294,14 +1448,16 @@ lexical closures as in Common Lisp."
                           vars))
            ebody))))
 
+;;;###autoload
 (defmacro lexical-let* (bindings &rest body)
   "Like `let*', but lexically scoped.
 The main visible difference is that lambdas inside BODY will create
-lexical closures as in Common Lisp."
+lexical closures as in Common Lisp.
+\n(fn VARLIST BODY)"
   (if (null bindings) (cons 'progn body)
     (setq bindings (reverse bindings))
     (while bindings
-      (setq body (list (list* 'lexical-let (list (cl-pop bindings)) body))))
+      (setq body (list (list* 'lexical-let (list (pop bindings)) body))))
     (car body)))
 
 (defun cl-defun-expander (func &rest rest)
@@ -1313,14 +1469,17 @@ lexical closures as in Common Lisp."
 
 ;;; Multiple values.
 
+;;;###autoload
 (defmacro multiple-value-bind (vars form &rest body)
-  "(multiple-value-bind (SYM SYM...) FORM BODY): collect multiple return values.
+  "Collect multiple return values.
 FORM must return a list; the BODY is then executed with the first N elements
 of this list bound (`let'-style) to each of the symbols SYM in turn.  This
 is analogous to the Common Lisp `multiple-value-bind' macro, using lists to
 simulate true multiple return values.  For compatibility, (values A B C) is
-a synonym for (list A B C)."
-  (let ((temp (gensym)) (n -1))
+a synonym for (list A B C).
+
+\(fn (SYM...) FORM BODY)"
+  (let ((temp (make-symbol "--cl-var--")) (n -1))
     (list* 'let* (cons (list temp form)
                       (mapcar (function
                                (lambda (v)
@@ -1328,18 +1487,21 @@ a synonym for (list A B C)."
                               vars))
           body)))
 
+;;;###autoload
 (defmacro multiple-value-setq (vars form)
-  "(multiple-value-setq (SYM SYM...) FORM): collect multiple return values.
+  "Collect multiple return values.
 FORM must return a list; the first N elements of this list are stored in
 each of the symbols SYM in turn.  This is analogous to the Common Lisp
 `multiple-value-setq' macro, using lists to simulate true multiple return
-values.  For compatibility, (values A B C) is a synonym for (list A B C)."
+values.  For compatibility, (values A B C) is a synonym for (list A B C).
+
+\(fn (SYM...) FORM)"
   (cond ((null vars) (list 'progn form nil))
        ((null (cdr vars)) (list 'setq (car vars) (list 'car form)))
        (t
-        (let* ((temp (gensym)) (n 0))
+        (let* ((temp (make-symbol "--cl-var--")) (n 0))
           (list 'let (list (list temp form))
-                (list 'prog1 (list 'setq (cl-pop vars) (list 'car temp))
+                (list 'prog1 (list 'setq (pop vars) (list 'car temp))
                       (cons 'setq (apply 'nconc
                                          (mapcar (function
                                                   (lambda (v)
@@ -1352,14 +1514,16 @@ values.  For compatibility, (values A B C) is a synonym for (list A B C)."
 
 ;;; Declarations.
 
+;;;###autoload
 (defmacro locally (&rest body) (cons 'progn body))
+;;;###autoload
 (defmacro the (type form) form)
 
 (defvar cl-proclaim-history t)    ; for future compilers
 (defvar cl-declare-stack t)       ; for future compilers
 
 (defun cl-do-proclaim (spec hist)
-  (and hist (listp cl-proclaim-history) (cl-push spec cl-proclaim-history))
+  (and hist (listp cl-proclaim-history) (push spec cl-proclaim-history))
   (cond ((eq (car-safe spec) 'special)
         (if (boundp 'byte-compile-bound-variables)
             (setq byte-compile-bound-variables
@@ -1390,62 +1554,71 @@ values.  For compatibility, (values A B C) is a synonym for (list A B C)."
                            byte-compile-delete-errors (nth 1 safety)))))
 
        ((and (eq (car-safe spec) 'warn) (boundp 'byte-compile-warnings))
-        (if (eq byte-compile-warnings t)
-            (setq byte-compile-warnings byte-compile-warning-types))
         (while (setq spec (cdr spec))
           (if (consp (car spec))
               (if (eq (cadar spec) 0)
-                  (setq byte-compile-warnings
-                        (delq (caar spec) byte-compile-warnings))
-                (setq byte-compile-warnings
-                      (adjoin (caar spec) byte-compile-warnings)))))))
+                   (byte-compile-disable-warning (caar spec))
+                 (byte-compile-enable-warning (caar spec)))))))
   nil)
 
 ;;; Process any proclamations made before cl-macs was loaded.
 (defvar cl-proclaims-deferred)
 (let ((p (reverse cl-proclaims-deferred)))
-  (while p (cl-do-proclaim (cl-pop p) t))
+  (while p (cl-do-proclaim (pop p) t))
   (setq cl-proclaims-deferred nil))
 
+;;;###autoload
 (defmacro declare (&rest specs)
   (if (cl-compiling-file)
       (while specs
-       (if (listp cl-declare-stack) (cl-push (car specs) cl-declare-stack))
-       (cl-do-proclaim (cl-pop specs) nil)))
+       (if (listp cl-declare-stack) (push (car specs) cl-declare-stack))
+       (cl-do-proclaim (pop specs) nil)))
   nil)
 
 
 
 ;;; Generalized variables.
 
+;;;###autoload
 (defmacro define-setf-method (func args &rest body)
-  "(define-setf-method NAME ARGLIST BODY...): define a `setf' method.
+  "Define a `setf' method.
 This method shows how to handle `setf's to places of the form (NAME ARGS...).
 The argument forms ARGS are bound according to ARGLIST, as if NAME were
 going to be expanded as a macro, then the BODY forms are executed and must
 return a list of five elements: a temporary-variables list, a value-forms
 list, a store-variables list (of length one), a store-form, and an access-
-form.  See `defsetf' for a simpler way to define most setf-methods."
+form.  See `defsetf' for a simpler way to define most setf-methods.
+
+\(fn NAME ARGLIST BODY...)"
   (append '(eval-when (compile load eval))
          (if (stringp (car body))
              (list (list 'put (list 'quote func) '(quote setf-documentation)
-                         (cl-pop body))))
+                         (pop body))))
          (list (cl-transform-function-property
                 func 'setf-method (cons args body)))))
+(defalias 'define-setf-expander 'define-setf-method)
 
+;;;###autoload
 (defmacro defsetf (func arg1 &rest args)
-  "(defsetf NAME FUNC): define a `setf' method.
+  "Define a `setf' method.
 This macro is an easy-to-use substitute for `define-setf-method' that works
 well for simple place forms.  In the simple `defsetf' form, `setf's of
 the form (setf (NAME ARGS...) VAL) are transformed to function or macro
-calls of the form (FUNC ARGS... VAL).  Example: (defsetf aref aset).
+calls of the form (FUNC ARGS... VAL).  Example:
+
+  (defsetf aref aset)
+
 Alternate form: (defsetf NAME ARGLIST (STORE) BODY...).
 Here, the above `setf' call is expanded by binding the argument forms ARGS
 according to ARGLIST, binding the value form VAL to STORE, then executing
 BODY, which must return a Lisp form that does the necessary `setf' operation.
 Actually, ARGLIST and STORE may be bound to temporary variables which are
 introduced automatically to preserve proper execution order of the arguments.
-Example: (defsetf nth (n x) (v) (list 'setcar (list 'nthcdr n x) v))."
+Example:
+
+  (defsetf nth (n x) (v) (list 'setcar (list 'nthcdr n x) v))
+
+\(fn NAME [FUNC | ARGLIST (STORE) BODY...])"
   (if (listp arg1)
       (let* ((largs nil) (largsr nil)
             (temps nil) (tempsr nil)
@@ -1473,44 +1646,41 @@ Example: (defsetf nth (n x) (v) (list 'setcar (list 'nthcdr n x) v))."
          (setq largsr largs tempsr temps))
        (let ((p1 largs) (p2 temps))
          (while p1
-           (setq lets1 (cons (list (car p2)
-                                   (list 'gensym (format "--%s--" (car p1))))
+           (setq lets1 (cons `(,(car p2)
+                               (make-symbol ,(format "--cl-%s--" (car p1))))
                              lets1)
                  lets2 (cons (list (car p1) (car p2)) lets2)
                  p1 (cdr p1) p2 (cdr p2))))
        (if restarg (setq lets2 (cons (list restarg rest-temps) lets2)))
-       (append (list 'define-setf-method func arg1)
-               (and docstr (list docstr))
-               (list
-                (list 'let*
-                      (nreverse
-                       (cons (list store-temp
-                                   (list 'gensym (format "--%s--" store-var)))
-                             (if restarg
-                                 (append
-                                  (list
-                                   (list rest-temps
-                                         (list 'mapcar '(quote gensym)
-                                               restarg)))
-                                  lets1)
-                               lets1)))
-                      (list 'list  ; 'values
-                            (cons (if restarg 'list* 'list) tempsr)
-                            (cons (if restarg 'list* 'list) largsr)
-                            (list 'list store-temp)
-                            (cons 'let*
-                                  (cons (nreverse
-                                         (cons (list store-var store-temp)
-                                               lets2))
-                                        args))
-                            (cons (if restarg 'list* 'list)
-                                  (cons (list 'quote func) tempsr)))))))
-    (list 'defsetf func '(&rest args) '(store)
-         (let ((call (list 'cons (list 'quote arg1)
-                           '(append args (list store)))))
-           (if (car args)
-               (list 'list '(quote progn) call 'store)
-             call)))))
+       `(define-setf-method ,func ,arg1
+          ,@(and docstr (list docstr))
+          (let*
+              ,(nreverse
+                (cons `(,store-temp
+                        (make-symbol ,(format "--cl-%s--" store-var)))
+                      (if restarg
+                          `((,rest-temps
+                             (mapcar (lambda (_) (make-symbol "--cl-var--"))
+                                     ,restarg))
+                            ,@lets1)
+                        lets1)))
+            (list                      ; 'values
+             (,(if restarg 'list* 'list) ,@tempsr)
+             (,(if restarg 'list* 'list) ,@largsr)
+             (list ,store-temp)
+             (let*
+                 ,(nreverse
+                   (cons (list store-var store-temp)
+                         lets2))
+               ,@args)
+             (,(if restarg 'list* 'list)
+              ,@(cons (list 'quote func) tempsr))))))
+    `(defsetf ,func (&rest args) (store)
+       ,(let ((call `(cons ',arg1
+                          (append args (list store)))))
+         (if (car args)
+             `(list 'progn ,call store)
+           call)))))
 
 ;;; Some standard place types from Common Lisp.
 (defsetf aref aset)
@@ -1525,7 +1695,7 @@ Example: (defsetf nth (n x) (v) (list 'setcar (list 'nthcdr n x) v))."
        (list 'aset seq n store)))
 (defsetf get put)
 (defsetf get* (x y &optional d) (store) (list 'put x y store))
-(defsetf gethash (x h &optional d) (store) (list 'cl-puthash x store h))
+(defsetf gethash (x h &optional d) (store) (list 'puthash x store h))
 (defsetf nth (n x) (store) (list 'setcar (list 'nthcdr n x) store))
 (defsetf subseq (seq start &optional end) (new)
   (list 'progn (list 'replace seq new :start1 start :end1 end) new))
@@ -1587,6 +1757,7 @@ Example: (defsetf nth (n x) (v) (list 'setcar (list 'nthcdr n x) v))."
 (defsetf frame-parameters modify-frame-parameters t)
 (defsetf frame-visible-p cl-set-frame-visible-p)
 (defsetf frame-width set-screen-width t)
+(defsetf frame-parameter set-frame-parameter)
 (defsetf getenv setenv t)
 (defsetf get-register set-register)
 (defsetf global-key-binding global-set-key)
@@ -1613,6 +1784,7 @@ Example: (defsetf nth (n x) (v) (list 'setcar (list 'nthcdr n x) v))."
 (defsetf process-buffer set-process-buffer)
 (defsetf process-filter set-process-filter)
 (defsetf process-sentinel set-process-sentinel)
+(defsetf process-get process-put)
 (defsetf read-mouse-position (scr) (store)
   (list 'set-mouse-position scr (list 'car store) (list 'cdr store)))
 (defsetf screen-height set-screen-height t)
@@ -1662,8 +1834,8 @@ Example: (defsetf nth (n x) (v) (list 'setcar (list 'nthcdr n x) v))."
 
 (define-setf-method nthcdr (n place)
   (let ((method (get-setf-method place cl-macro-environment))
-       (n-temp (gensym "--nthcdr-n--"))
-       (store-temp (gensym "--nthcdr-store--")))
+       (n-temp (make-symbol "--cl-nthcdr-n--"))
+       (store-temp (make-symbol "--cl-nthcdr-store--")))
     (list (cons n-temp (car method))
          (cons n (nth 1 method))
          (list store-temp)
@@ -1675,9 +1847,9 @@ Example: (defsetf nth (n x) (v) (list 'setcar (list 'nthcdr n x) v))."
 
 (define-setf-method getf (place tag &optional def)
   (let ((method (get-setf-method place cl-macro-environment))
-       (tag-temp (gensym "--getf-tag--"))
-       (def-temp (gensym "--getf-def--"))
-       (store-temp (gensym "--getf-store--")))
+       (tag-temp (make-symbol "--cl-getf-tag--"))
+       (def-temp (make-symbol "--cl-getf-def--"))
+       (store-temp (make-symbol "--cl-getf-store--")))
     (list (append (car method) (list tag-temp def-temp))
          (append (nth 1 method) (list tag def))
          (list store-temp)
@@ -1689,9 +1861,9 @@ Example: (defsetf nth (n x) (v) (list 'setcar (list 'nthcdr n x) v))."
 
 (define-setf-method substring (place from &optional to)
   (let ((method (get-setf-method place cl-macro-environment))
-       (from-temp (gensym "--substring-from--"))
-       (to-temp (gensym "--substring-to--"))
-       (store-temp (gensym "--substring-store--")))
+       (from-temp (make-symbol "--cl-substring-from--"))
+       (to-temp (make-symbol "--cl-substring-to--"))
+       (store-temp (make-symbol "--cl-substring-store--")))
     (list (append (car method) (list from-temp to-temp))
          (append (nth 1 method) (list from to))
          (list store-temp)
@@ -1702,12 +1874,13 @@ Example: (defsetf nth (n x) (v) (list 'setcar (list 'nthcdr n x) v))."
          (list 'substring (nth 4 method) from-temp to-temp))))
 
 ;;; Getting and optimizing setf-methods.
+;;;###autoload
 (defun get-setf-method (place &optional env)
   "Return a list of five values describing the setf-method for PLACE.
 PLACE may be any Lisp form which can appear as the PLACE argument to
 a macro like `setf' or `incf'."
   (if (symbolp place)
-      (let ((temp (gensym "--setf--")))
+      (let ((temp (make-symbol "--cl-setf--")))
        (list nil nil (list temp) (list 'setq place temp) place))
     (or (and (symbolp (car place))
             (let* ((func (car place))
@@ -1747,8 +1920,8 @@ a macro like `setf' or `incf'."
         (simple (and optimize (consp place) (cl-simple-exprs-p (cdr place)))))
     (while values
       (if (or simple (cl-const-expr-p (car values)))
-         (cl-push (cons (cl-pop temps) (cl-pop values)) subs)
-       (cl-push (list (cl-pop temps) (cl-pop values)) lets)))
+         (push (cons (pop temps) (pop values)) subs)
+       (push (list (pop temps) (pop values)) lets)))
     (list (nreverse lets)
          (cons (car (nth 2 method)) (sublis subs (nth 3 method)))
          (sublis subs (nth 4 method)))))
@@ -1769,15 +1942,18 @@ a macro like `setf' or `incf'."
        (not (eq (car-safe (symbol-function (car form))) 'macro))))
 
 ;;; The standard modify macros.
+;;;###autoload
 (defmacro setf (&rest args)
-  "(setf PLACE VAL PLACE VAL ...): set each PLACE to the value of its VAL.
+  "Set each PLACE to the value of its VAL.
 This is a generalized version of `setq'; the PLACEs may be symbolic
 references such as (car x) or (aref x i), as well as plain symbols.
 For example, (setf (cadar x) y) is equivalent to (setcar (cdar x) y).
-The return value is the last VAL in the list."
+The return value is the last VAL in the list.
+
+\(fn PLACE VAL PLACE VAL ...)"
   (if (cdr (cdr args))
       (let ((sets nil))
-       (while args (cl-push (list 'setf (cl-pop args) (cl-pop args)) sets))
+       (while args (push (list 'setf (pop args) (pop args)) sets))
        (cons 'progn (nreverse sets)))
     (if (symbolp (car args))
        (and args (cons 'setq args))
@@ -1785,19 +1961,22 @@ The return value is the last VAL in the list."
             (store (cl-setf-do-store (nth 1 method) (nth 1 args))))
        (if (car method) (list 'let* (car method) store) store)))))
 
+;;;###autoload
 (defmacro psetf (&rest args)
-  "(psetf PLACE VAL PLACE VAL ...): set PLACEs to the values VALs in parallel.
+  "Set PLACEs to the values VALs in parallel.
 This is like `setf', except that all VAL forms are evaluated (in order)
-before assigning any PLACEs to the corresponding values."
+before assigning any PLACEs to the corresponding values.
+
+\(fn PLACE VAL PLACE VAL ...)"
   (let ((p args) (simple t) (vars nil))
     (while p
       (if (or (not (symbolp (car p))) (cl-expr-depends-p (nth 1 p) vars))
          (setq simple nil))
       (if (memq (car p) vars)
          (error "Destination duplicated in psetf: %s" (car p)))
-      (cl-push (cl-pop p) vars)
+      (push (pop p) vars)
       (or p (error "Odd number of arguments to psetf"))
-      (cl-pop p))
+      (pop p))
     (if simple
        (list 'progn (cons 'setf args) nil)
       (setq args (reverse args))
@@ -1806,11 +1985,12 @@ before assigning any PLACEs to the corresponding values."
          (setq expr (list 'setf (cadr args) (list 'prog1 (car args) expr))))
        (list 'progn expr nil)))))
 
+;;;###autoload
 (defun cl-do-pop (place)
   (if (cl-simple-expr-p place)
       (list 'prog1 (list 'car place) (list 'setf place (list 'cdr place)))
     (let* ((method (cl-setf-do-modify place t))
-          (temp (gensym "--pop--")))
+          (temp (make-symbol "--cl-pop--")))
       (list 'let*
            (append (car method)
                    (list (list temp (nth 2 method))))
@@ -1818,14 +1998,15 @@ before assigning any PLACEs to the corresponding values."
                  (list 'car temp)
                  (cl-setf-do-store (nth 1 method) (list 'cdr temp)))))))
 
+;;;###autoload
 (defmacro remf (place tag)
   "Remove TAG from property list PLACE.
 PLACE may be a symbol, or any generalized variable allowed by `setf'.
 The form returns true if TAG was found and removed, nil otherwise."
   (let* ((method (cl-setf-do-modify place t))
-        (tag-temp (and (not (cl-const-expr-p tag)) (gensym "--remf-tag--")))
+        (tag-temp (and (not (cl-const-expr-p tag)) (make-symbol "--cl-remf-tag--")))
         (val-temp (and (not (cl-simple-expr-p place))
-                       (gensym "--remf-place--")))
+                       (make-symbol "--cl-remf-place--")))
         (ttag (or tag-temp tag))
         (tval (or val-temp (nth 2 method))))
     (list 'let*
@@ -1838,42 +2019,41 @@ The form returns true if TAG was found and removed, nil otherwise."
                      t)
                (list 'cl-do-remf tval ttag)))))
 
+;;;###autoload
 (defmacro shiftf (place &rest args)
-  "(shiftf PLACE PLACE... VAL): shift left among PLACEs.
+  "Shift left among PLACEs.
 Example: (shiftf A B C) sets A to B, B to C, and returns the old A.
-Each PLACE may be a symbol, or any generalized variable allowed by `setf'."
-  (if (not (memq nil (mapcar 'symbolp (butlast (cons place args)))))
-      (list* 'prog1 place
-            (let ((sets nil))
-              (while args
-                (cl-push (list 'setq place (car args)) sets)
-                (setq place (cl-pop args)))
-              (nreverse sets)))
-    (let* ((places (reverse (cons place args)))
-          (form (cl-pop places)))
-      (while places
-       (let ((method (cl-setf-do-modify (cl-pop places) 'unsafe)))
-         (setq form (list 'let* (car method)
-                          (list 'prog1 (nth 2 method)
-                                (cl-setf-do-store (nth 1 method) form))))))
-      form)))
-
+Each PLACE may be a symbol, or any generalized variable allowed by `setf'.
+
+\(fn PLACE... VAL)"
+  (cond
+   ((null args) place)
+   ((symbolp place) `(prog1 ,place (setq ,place (shiftf ,@args))))
+   (t
+    (let ((method (cl-setf-do-modify place 'unsafe)))
+      `(let* ,(car method)
+        (prog1 ,(nth 2 method)
+          ,(cl-setf-do-store (nth 1 method) `(shiftf ,@args))))))))
+
+;;;###autoload
 (defmacro rotatef (&rest args)
-  "(rotatef PLACE...): rotate left among PLACEs.
+  "Rotate left among PLACEs.
 Example: (rotatef A B C) sets A to B, B to C, and C to A.  It returns nil.
-Each PLACE may be a symbol, or any generalized variable allowed by `setf'."
+Each PLACE may be a symbol, or any generalized variable allowed by `setf'.
+
+\(fn PLACE...)"
   (if (not (memq nil (mapcar 'symbolp args)))
       (and (cdr args)
           (let ((sets nil)
                 (first (car args)))
             (while (cdr args)
-              (setq sets (nconc sets (list (cl-pop args) (car args)))))
+              (setq sets (nconc sets (list (pop args) (car args)))))
             (nconc (list 'psetf) sets (list (car args) first))))
     (let* ((places (reverse args))
-          (temp (gensym "--rotatef--"))
+          (temp (make-symbol "--cl-rotatef--"))
           (form temp))
       (while (cdr places)
-       (let ((method (cl-setf-do-modify (cl-pop places) 'unsafe)))
+       (let ((method (cl-setf-do-modify (pop places) 'unsafe)))
          (setq form (list 'let* (car method)
                           (list 'prog1 (nth 2 method)
                                 (cl-setf-do-store (nth 1 method) form))))))
@@ -1881,15 +2061,18 @@ Each PLACE may be a symbol, or any generalized variable allowed by `setf'."
        (list 'let* (append (car method) (list (list temp (nth 2 method))))
              (cl-setf-do-store (nth 1 method) form) nil)))))
 
+;;;###autoload
 (defmacro letf (bindings &rest body)
-  "(letf ((PLACE VALUE) ...) BODY...): temporarily bind to PLACEs.
+  "Temporarily bind to PLACEs.
 This is the analogue of `let', but with generalized variables (in the
 sense of `setf') for the PLACEs.  Each PLACE is set to the corresponding
 VALUE, then the BODY forms are executed.  On exit, either normally or
 because of a `throw' or error, the PLACEs are set back to their original
 values.  Note that this macro is *not* available in Common Lisp.
 As a special case, if `(PLACE)' is used instead of `(PLACE VALUE)',
-the PLACE is not modified before executing BODY."
+the PLACE is not modified before executing BODY.
+
+\(fn ((PLACE VALUE) ...) BODY...)"
   (if (and (not (cdr bindings)) (cdar bindings) (symbolp (caar bindings)))
       (list* 'let bindings body)
     (let ((lets nil) (sets nil)
@@ -1900,11 +2083,11 @@ the PLACE is not modified before executing BODY."
                        (caar rev)))
               (value (cadar rev))
               (method (cl-setf-do-modify place 'no-opt))
-              (save (gensym "--letf-save--"))
+              (save (make-symbol "--cl-letf-save--"))
               (bound (and (memq (car place) '(symbol-value symbol-function))
-                          (gensym "--letf-bound--")))
+                          (make-symbol "--cl-letf-bound--")))
               (temp (and (not (cl-const-expr-p value)) (cdr bindings)
-                         (gensym "--letf-val--"))))
+                         (make-symbol "--cl-letf-val--"))))
          (setq lets (nconc (car method)
                            (if bound
                                (list (list bound
@@ -1935,26 +2118,32 @@ the PLACE is not modified before executing BODY."
                rev (cdr rev))))
       (list* 'let* lets body))))
 
+;;;###autoload
 (defmacro letf* (bindings &rest body)
-  "(letf* ((PLACE VALUE) ...) BODY...): temporarily bind to PLACEs.
+  "Temporarily bind to PLACEs.
 This is the analogue of `let*', but with generalized variables (in the
 sense of `setf') for the PLACEs.  Each PLACE is set to the corresponding
 VALUE, then the BODY forms are executed.  On exit, either normally or
 because of a `throw' or error, the PLACEs are set back to their original
 values.  Note that this macro is *not* available in Common Lisp.
 As a special case, if `(PLACE)' is used instead of `(PLACE VALUE)',
-the PLACE is not modified before executing BODY."
+the PLACE is not modified before executing BODY.
+
+\(fn ((PLACE VALUE) ...) BODY...)"
   (if (null bindings)
       (cons 'progn body)
     (setq bindings (reverse bindings))
     (while bindings
-      (setq body (list (list* 'letf (list (cl-pop bindings)) body))))
+      (setq body (list (list* 'letf (list (pop bindings)) body))))
     (car body)))
 
+;;;###autoload
 (defmacro callf (func place &rest args)
-  "(callf FUNC PLACE ARGS...): set PLACE to (FUNC PLACE ARGS...).
+  "Set PLACE to (FUNC PLACE ARGS...).
 FUNC should be an unquoted function name.  PLACE may be a symbol,
-or any generalized variable allowed by `setf'."
+or any generalized variable allowed by `setf'.
+
+\(fn FUNC PLACE ARGS...)"
   (let* ((method (cl-setf-do-modify place (cons 'list args)))
         (rargs (cons (nth 2 method) args)))
     (list 'let* (car method)
@@ -1963,13 +2152,16 @@ or any generalized variable allowed by `setf'."
                              (list* 'funcall (list 'function func)
                                     rargs))))))
 
+;;;###autoload
 (defmacro callf2 (func arg1 place &rest args)
-  "(callf2 FUNC ARG1 PLACE ARGS...): set PLACE to (FUNC ARG1 PLACE ARGS...).
-Like `callf', but PLACE is the second argument of FUNC, not the first."
+  "Set PLACE to (FUNC ARG1 PLACE ARGS...).
+Like `callf', but PLACE is the second argument of FUNC, not the first.
+
+\(fn FUNC ARG1 PLACE ARGS...)"
   (if (and (cl-safe-expr-p arg1) (cl-simple-expr-p place) (symbolp func))
       (list 'setf place (list* func arg1 place args))
     (let* ((method (cl-setf-do-modify place (cons 'list args)))
-          (temp (and (not (cl-const-expr-p arg1)) (gensym "--arg1--")))
+          (temp (and (not (cl-const-expr-p arg1)) (make-symbol "--cl-arg1--")))
           (rargs (list* (or temp arg1) (nth 2 method) args)))
       (list 'let* (append (and temp (list (list temp arg1))) (car method))
            (cl-setf-do-store (nth 1 method)
@@ -1977,12 +2169,13 @@ Like `callf', but PLACE is the second argument of FUNC, not the first."
                                (list* 'funcall (list 'function func)
                                       rargs)))))))
 
+;;;###autoload
 (defmacro define-modify-macro (name arglist func &optional doc)
   "Define a `setf'-like modify macro.
 If NAME is called, it combines its PLACE argument with the other arguments
 from ARGLIST using FUNC: (define-modify-macro incf (&optional (n 1)) +)"
   (if (memq '&key arglist) (error "&key not allowed in define-modify-macro"))
-  (let ((place (gensym "--place--")))
+  (let ((place (make-symbol "--cl-place--")))
     (list 'defmacro* name (cons place arglist) doc
          (list* (if (memq '&rest arglist) 'list* 'list)
                 '(quote callf) (list 'quote func) place
@@ -1991,11 +2184,14 @@ from ARGLIST using FUNC: (define-modify-macro incf (&optional (n 1)) +)"
 
 ;;; Structures.
 
+;;;###autoload
 (defmacro defstruct (struct &rest descs)
-  "(defstruct (NAME OPTIONS...) (SLOT SLOT-OPTS...)...): define a struct type.
+  "Define a struct type.
 This macro defines a new Lisp data type called NAME, which contains data
 stored in SLOTs.  This defines a `make-NAME' constructor, a `copy-NAME'
-copier, a `NAME-p' predicate, and setf-able `NAME-SLOT' accessors."
+copier, a `NAME-p' predicate, and setf-able `NAME-SLOT' accessors.
+
+\(fn (NAME OPTIONS...) (SLOT SLOT-OPTS...)...)"
   (let* ((name (if (consp struct) (car struct) struct))
         (opts (cdr-safe struct))
         (slots nil)
@@ -2017,21 +2213,26 @@ copier, a `NAME-p' predicate, and setf-able `NAME-SLOT' accessors."
         (forms nil)
         pred-form pred-check)
     (if (stringp (car descs))
-       (cl-push (list 'put (list 'quote name) '(quote structure-documentation)
-                      (cl-pop descs)) forms))
+       (push (list 'put (list 'quote name) '(quote structure-documentation)
+                      (pop descs)) forms))
     (setq descs (cons '(cl-tag-slot)
                      (mapcar (function (lambda (x) (if (consp x) x (list x))))
                              descs)))
     (while opts
       (let ((opt (if (consp (car opts)) (caar opts) (car opts)))
-           (args (cdr-safe (cl-pop opts))))
+           (args (cdr-safe (pop opts))))
        (cond ((eq opt :conc-name)
               (if args
                   (setq conc-name (if (car args)
                                       (symbol-name (car args)) ""))))
              ((eq opt :constructor)
               (if (cdr args)
-                  (cl-push args constrs)
+                   (progn
+                     ;; If this defines a constructor of the same name as
+                     ;; the default one, don't define the default.
+                     (if (eq (car args) constructor)
+                         (setq constructor nil))
+                     (push args constrs))
                 (if args (setq constructor (car args)))))
              ((eq opt :copier)
               (if args (setq copier (car args))))
@@ -2075,25 +2276,25 @@ copier, a `NAME-p' predicate, and setf-able `NAME-SLOT' accessors."
                              (error "No slot %s in included struct %s"
                                     (caar include-descs) include))
                          old-descs)
-                   (cl-pop include-descs)))
+                   (pop include-descs)))
          (setq descs (append old-descs (delq (assq 'cl-tag-slot descs) descs))
                type (car inc-type)
                named (assq 'cl-tag-slot descs))
          (if (cadr inc-type) (setq tag name named t))
          (let ((incl include))
            (while incl
-             (cl-push (list 'pushnew (list 'quote tag)
+             (push (list 'pushnew (list 'quote tag)
                             (intern (format "cl-struct-%s-tags" incl)))
                       forms)
              (setq incl (get incl 'cl-struct-include)))))
       (if type
          (progn
            (or (memq type '(vector list))
-               (error "Illegal :type specifier: %s" type))
+               (error "Invalid :type specifier: %s" type))
            (if named (setq tag name)))
        (setq type 'vector named 'true)))
     (or named (setq descs (delq (assq 'cl-tag-slot descs) descs)))
-    (cl-push (list 'defvar tag-symbol) forms)
+    (push (list 'defvar tag-symbol) forms)
     (setq pred-form (and named
                         (let ((pos (- (length descs)
                                       (length (memq (assq 'cl-tag-slot descs)
@@ -2114,39 +2315,43 @@ copier, a `NAME-p' predicate, and setf-able `NAME-SLOT' accessors."
                              (cons 'and (cdddr pred-form)) pred-form)))
     (let ((pos 0) (descp descs))
       (while descp
-       (let* ((desc (cl-pop descp))
+       (let* ((desc (pop descp))
               (slot (car desc)))
          (if (memq slot '(cl-tag-slot cl-skip-slot))
              (progn
-               (cl-push nil slots)
-               (cl-push (and (eq slot 'cl-tag-slot) (list 'quote tag))
+               (push nil slots)
+               (push (and (eq slot 'cl-tag-slot) (list 'quote tag))
                         defaults))
            (if (assq slot descp)
                (error "Duplicate slots named %s in %s" slot name))
            (let ((accessor (intern (format "%s%s" conc-name slot))))
-             (cl-push slot slots)
-             (cl-push (nth 1 desc) defaults)
-             (cl-push (list*
+             (push slot slots)
+             (push (nth 1 desc) defaults)
+             (push (list*
                        'defsubst* accessor '(cl-x)
                        (append
                         (and pred-check
                              (list (list 'or pred-check
                                          (list 'error
                                                (format "%s accessing a non-%s"
-                                                       accessor name)
-                                               'cl-x))))
+                                                       accessor name)))))
                         (list (if (eq type 'vector) (list 'aref 'cl-x pos)
                                 (if (= pos 0) '(car cl-x)
                                   (list 'nth pos 'cl-x)))))) forms)
-             (cl-push (cons accessor t) side-eff)
-             (cl-push (list 'define-setf-method accessor '(cl-x)
+             (push (cons accessor t) side-eff)
+             (push (list 'define-setf-method accessor '(cl-x)
                             (if (cadr (memq :read-only (cddr desc)))
                                 (list 'error (format "%s is a read-only slot"
                                                      accessor))
-                              (list 'cl-struct-setf-expander 'cl-x
-                                    (list 'quote name) (list 'quote accessor)
-                                    (and pred-check (list 'quote pred-check))
-                                    pos)))
+                              ;; If cl is loaded only for compilation,
+                              ;; the call to cl-struct-setf-expander would
+                              ;; cause a warning because it may not be
+                              ;; defined at run time.  Suppress that warning.
+                              (list 'with-no-warnings
+                                    (list 'cl-struct-setf-expander 'cl-x
+                                          (list 'quote name) (list 'quote accessor)
+                                          (and pred-check (list 'quote pred-check))
+                                          pos))))
                       forms)
              (if print-auto
                  (nconc print-func
@@ -2156,38 +2361,38 @@ copier, a `NAME-p' predicate, and setf-able `NAME-SLOT' accessors."
     (setq slots (nreverse slots)
          defaults (nreverse defaults))
     (and predicate pred-form
-        (progn (cl-push (list 'defsubst* predicate '(cl-x)
+        (progn (push (list 'defsubst* predicate '(cl-x)
                               (if (eq (car pred-form) 'and)
                                   (append pred-form '(t))
                                 (list 'and pred-form t))) forms)
-               (cl-push (cons predicate 'error-free) side-eff)))
+               (push (cons predicate 'error-free) side-eff)))
     (and copier
-        (progn (cl-push (list 'defun copier '(x) '(copy-sequence x)) forms)
-               (cl-push (cons copier t) side-eff)))
+        (progn (push (list 'defun copier '(x) '(copy-sequence x)) forms)
+               (push (cons copier t) side-eff)))
     (if constructor
-       (cl-push (list constructor
+       (push (list constructor
                       (cons '&key (delq nil (copy-sequence slots))))
                 constrs))
     (while constrs
       (let* ((name (caar constrs))
-            (args (cadr (cl-pop constrs)))
+            (args (cadr (pop constrs)))
             (anames (cl-arglist-args args))
             (make (mapcar* (function (lambda (s d) (if (memq s anames) s d)))
                            slots defaults)))
-       (cl-push (list 'defsubst* name
+       (push (list 'defsubst* name
                       (list* '&cl-defs (list 'quote (cons nil descs)) args)
                       (cons type make)) forms)
        (if (cl-safe-expr-p (cons 'progn (mapcar 'second descs)))
-           (cl-push (cons name t) side-eff))))
+           (push (cons name t) side-eff))))
     (if print-auto (nconc print-func (list '(princ ")" cl-s) t)))
     (if print-func
-       (cl-push (list 'push
+       (push (list 'push
                       (list 'function
                             (list 'lambda '(cl-x cl-s cl-n)
                                   (list 'and pred-form print-func)))
                       'custom-print-functions) forms))
-    (cl-push (list 'setq tag-symbol (list 'list (list 'quote tag))) forms)
-    (cl-push (list* 'eval-when '(compile load eval)
+    (push (list 'setq tag-symbol (list 'list (list 'quote tag))) forms)
+    (push (list* 'eval-when '(compile load eval)
                    (list 'put (list 'quote name) '(quote cl-struct-slots)
                          (list 'quote descs))
                    (list 'put (list 'quote name) '(quote cl-struct-type)
@@ -2204,16 +2409,16 @@ copier, a `NAME-p' predicate, and setf-able `NAME-SLOT' accessors."
             forms)
     (cons 'progn (nreverse (cons (list 'quote name) forms)))))
 
+;;;###autoload
 (defun cl-struct-setf-expander (x name accessor pred-form pos)
-  (let* ((temp (gensym "--x--")) (store (gensym "--store--")))
+  (let* ((temp (make-symbol "--cl-x--")) (store (make-symbol "--cl-store--")))
     (list (list temp) (list x) (list store)
          (append '(progn)
                  (and pred-form
                       (list (list 'or (subst temp 'cl-x pred-form)
                                   (list 'error
                                         (format
-                                         "%s storing a non-%s" accessor name)
-                                        temp))))
+                                         "%s storing a non-%s" accessor name)))))
                  (list (if (eq (car (get name 'cl-struct-type)) 'vector)
                            (list 'aset temp pos store)
                          (list 'setcar
@@ -2237,15 +2442,17 @@ The type name can then be used in `typecase', `check-type', etc."
         name 'cl-deftype-handler (cons (list* '&cl-defs ''('*) arglist) body))))
 
 (defun cl-make-type-test (val type)
-  (if (memq type '(character string-char)) (setq type '(integer 0 255)))
   (if (symbolp type)
       (cond ((get type 'cl-deftype-handler)
             (cl-make-type-test val (funcall (get type 'cl-deftype-handler))))
            ((memq type '(nil t)) type)
-           ((eq type 'null) (list 'null val))
-           ((eq type 'float) (list 'floatp-safe val))
-           ((eq type 'real) (list 'numberp val))
-           ((eq type 'fixnum) (list 'integerp val))
+           ((eq type 'null) `(null ,val))
+           ((eq type 'atom) `(atom ,val))
+           ((eq type 'float) `(floatp-safe ,val))
+           ((eq type 'real) `(numberp ,val))
+           ((eq type 'fixnum) `(integerp ,val))
+           ;; FIXME: Should `character' accept things like ?\C-\M-a ?  -stef
+           ((memq type '(character string-char)) `(char-valid-p ,val))
            (t
             (let* ((name (symbol-name type))
                    (namep (intern (concat name "p"))))
@@ -2254,7 +2461,7 @@ The type name can then be used in `typecase', `check-type', etc."
     (cond ((get (car type) 'cl-deftype-handler)
           (cl-make-type-test val (apply (get (car type) 'cl-deftype-handler)
                                         (cdr type))))
-         ((memq (car-safe type) '(integer float real number))
+         ((memq (car type) '(integer float real number))
           (delq t (list 'and (cl-make-type-test val (car type))
                         (if (memq (cadr type) '(* nil)) t
                           (if (consp (cadr type)) (list '> val (caadr type))
@@ -2262,26 +2469,29 @@ The type name can then be used in `typecase', `check-type', etc."
                         (if (memq (caddr type) '(* nil)) t
                           (if (consp (caddr type)) (list '< val (caaddr type))
                             (list '<= val (caddr type)))))))
-         ((memq (car-safe type) '(and or not))
+         ((memq (car type) '(and or not))
           (cons (car type)
                 (mapcar (function (lambda (x) (cl-make-type-test val x)))
                         (cdr type))))
-         ((memq (car-safe type) '(member member*))
+         ((memq (car type) '(member member*))
           (list 'and (list 'member* val (list 'quote (cdr type))) t))
-         ((eq (car-safe type) 'satisfies) (list (cadr type) val))
+         ((eq (car type) 'satisfies) (list (cadr type) val))
          (t (error "Bad type spec: %s" type)))))
 
-(defun typep (val type)   ; See compiler macro below.
+;;;###autoload
+(defun typep (object type)   ; See compiler macro below.
   "Check that OBJECT is of type TYPE.
 TYPE is a Common Lisp-style type specifier."
-  (eval (cl-make-type-test 'val type)))
+  (eval (cl-make-type-test 'object type)))
 
+;;;###autoload
 (defmacro check-type (form type &optional string)
   "Verify that FORM is of type TYPE; signal an error if not.
 STRING is an optional description of the desired type."
   (and (or (not (cl-compiling-file))
           (< cl-optimize-speed 3) (= cl-optimize-safety 3))
-       (let* ((temp (if (cl-simple-expr-p form 3) form (gensym)))
+       (let* ((temp (if (cl-simple-expr-p form 3)
+                       form (make-symbol "--cl-var--")))
              (body (list 'or (cl-make-type-test temp type)
                          (list 'signal '(quote wrong-type-argument)
                                (list 'list (or string (list 'quote type))
@@ -2289,6 +2499,7 @@ STRING is an optional description of the desired type."
         (if (eq temp form) (list 'progn body nil)
           (list 'let (list (list temp form)) body nil)))))
 
+;;;###autoload
 (defmacro assert (form &optional show-args string &rest args)
   "Verify that FORM returns non-nil; signal an error if not.
 Second arg SHOW-ARGS means to include arguments of FORM in message.
@@ -2310,99 +2521,16 @@ omitted, a default message listing FORM itself is used."
                             (list* 'list (list 'quote form) sargs))))
               nil))))
 
+;;;###autoload
 (defmacro ignore-errors (&rest body)
-  "Execute FORMS; if an error occurs, return nil.
-Otherwise, return result of last FORM."
-  (let ((err (gensym)))
-    (list 'condition-case err (cons 'progn body) '(error nil))))
-
-
-;;; Some predicates for analyzing Lisp forms.  These are used by various
-;;; macro expanders to optimize the results in certain common cases.
-
-(defconst cl-simple-funcs '(car cdr nth aref elt if and or + - 1+ 1- min max
-                           car-safe cdr-safe progn prog1 prog2))
-(defconst cl-safe-funcs '(* / % length memq list vector vectorp
-                         < > <= >= = error))
-
-;;; Check if no side effects, and executes quickly.
-(defun cl-simple-expr-p (x &optional size)
-  (or size (setq size 10))
-  (if (and (consp x) (not (memq (car x) '(quote function function*))))
-      (and (symbolp (car x))
-          (or (memq (car x) cl-simple-funcs)
-              (get (car x) 'side-effect-free))
-          (progn
-            (setq size (1- size))
-            (while (and (setq x (cdr x))
-                        (setq size (cl-simple-expr-p (car x) size))))
-            (and (null x) (>= size 0) size)))
-    (and (> size 0) (1- size))))
-
-(defun cl-simple-exprs-p (xs)
-  (while (and xs (cl-simple-expr-p (car xs)))
-    (setq xs (cdr xs)))
-  (not xs))
-
-;;; Check if no side effects.
-(defun cl-safe-expr-p (x)
-  (or (not (and (consp x) (not (memq (car x) '(quote function function*)))))
-      (and (symbolp (car x))
-          (or (memq (car x) cl-simple-funcs)
-              (memq (car x) cl-safe-funcs)
-              (get (car x) 'side-effect-free))
-          (progn
-            (while (and (setq x (cdr x)) (cl-safe-expr-p (car x))))
-            (null x)))))
-
-;;; Check if constant (i.e., no side effects or dependencies).
-(defun cl-const-expr-p (x)
-  (cond ((consp x)
-        (or (eq (car x) 'quote)
-            (and (memq (car x) '(function function*))
-                 (or (symbolp (nth 1 x))
-                     (and (eq (car-safe (nth 1 x)) 'lambda) 'func)))))
-       ((symbolp x) (and (memq x '(nil t)) t))
-       (t t)))
-
-(defun cl-const-exprs-p (xs)
-  (while (and xs (cl-const-expr-p (car xs)))
-    (setq xs (cdr xs)))
-  (not xs))
-
-(defun cl-const-expr-val (x)
-  (and (eq (cl-const-expr-p x) t) (if (consp x) (nth 1 x) x)))
-
-(defun cl-expr-access-order (x v)
-  (if (cl-const-expr-p x) v
-    (if (consp x)
-       (progn
-         (while (setq x (cdr x)) (setq v (cl-expr-access-order (car x) v)))
-         v)
-      (if (eq x (car v)) (cdr v) '(t)))))
-
-;;; Count number of times X refers to Y.  Return NIL for 0 times.
-(defun cl-expr-contains (x y)
-  (cond ((equal y x) 1)
-       ((and (consp x) (not (memq (car-safe x) '(quote function function*))))
-        (let ((sum 0))
-          (while x
-            (setq sum (+ sum (or (cl-expr-contains (cl-pop x) y) 0))))
-          (and (> sum 0) sum)))
-       (t nil)))
-
-(defun cl-expr-contains-any (x y)
-  (while (and y (not (cl-expr-contains x (car y)))) (cl-pop y))
-  y)
-
-;;; Check whether X may depend on any of the symbols in Y.
-(defun cl-expr-depends-p (x y)
-  (and (not (cl-const-expr-p x))
-       (or (not (cl-safe-expr-p x)) (cl-expr-contains-any x y))))
+  "Execute BODY; if an error occurs, return nil.
+Otherwise, return result of last form in BODY."
+  `(condition-case nil (progn ,@body) (error nil)))
 
 
 ;;; Compiler macros.
 
+;;;###autoload
 (defmacro define-compiler-macro (func args &rest body)
   "Define a compiler-only macro.
 This is like `defmacro', but macro expansion occurs only if the call to
@@ -2415,7 +2543,7 @@ possible.  Unlike regular macros, BODY can decide to \"punt\" and leave the
 original function call alone by declaring an initial `&whole foo' parameter
 and then returning foo."
   (let ((p args) (res nil))
-    (while (consp p) (cl-push (cl-pop p) res))
+    (while (consp p) (push (pop p) res))
     (setq args (nconc (nreverse res) (and p (list '&rest p)))))
   (list 'eval-when '(compile load eval)
        (cl-transform-function-property
@@ -2426,6 +2554,7 @@ and then returning foo."
              (list 'put (list 'quote func) '(quote byte-compile)
                    '(quote cl-byte-compile-compiler-macro)))))
 
+;;;###autoload
 (defun compiler-macroexpand (form)
   (while
       (let ((func (car-safe form)) (handler nil))
@@ -2445,18 +2574,22 @@ and then returning foo."
     (byte-compile-form form)))
 
 (defmacro defsubst* (name args &rest body)
-  "(defsubst* NAME ARGLIST [DOCSTRING] BODY...): define NAME as a function.
+  "Define NAME as a function.
 Like `defun', except the function is automatically declared `inline',
 ARGLIST allows full Common Lisp conventions, and BODY is implicitly
-surrounded by (block NAME ...)."
+surrounded by (block NAME ...).
+
+\(fn NAME ARGLIST [DOCSTRING] BODY...)"
   (let* ((argns (cl-arglist-args args)) (p argns)
         (pbody (cons 'progn body))
         (unsafe (not (cl-safe-expr-p pbody))))
-    (while (and p (eq (cl-expr-contains args (car p)) 1)) (cl-pop p))
+    (while (and p (eq (cl-expr-contains args (car p)) 1)) (pop p))
     (list 'progn
          (if p nil   ; give up if defaults refer to earlier args
            (list 'define-compiler-macro name
-                 (list* '&whole 'cl-whole '&cl-quote args)
+                 (if (memq '&key args)
+                     (list* '&whole 'cl-whole '&cl-quote args)
+                   (cons '&cl-quote args))
                  (list* 'cl-defsubst-expand (list 'quote argns)
                         (list 'quote (list* 'block name body))
                         (not (or unsafe (cl-expr-access-order pbody argns)))
@@ -2477,9 +2610,9 @@ surrounded by (block NAME ...)."
       (if lets (list 'let lets body) body))))
 
 
-;;; Compile-time optimizations for some functions defined in this package.
-;;; Note that cl.el arranges to force cl-macs to be loaded at compile-time,
-;;; mainly to make sure these macros will be present.
+;; Compile-time optimizations for some functions defined in this package.
+;; Note that cl.el arranges to force cl-macs to be loaded at compile-time,
+;; mainly to make sure these macros will be present.
 
 (put 'eql 'byte-compile nil)
 (define-compiler-macro eql (&whole form a b)
@@ -2509,21 +2642,7 @@ surrounded by (block NAME ...)."
                   (cl-const-expr-val (nth 1 keys)))))
     (cond ((eq test 'eq) (list 'memq a list))
          ((eq test 'equal) (list 'member a list))
-         ((or (null keys) (eq test 'eql))
-          (if (eq (cl-const-expr-p a) t)
-              (list (if (floatp-safe (cl-const-expr-val a)) 'member 'memq)
-                    a list)
-            (if (eq (cl-const-expr-p list) t)
-                (let ((p (cl-const-expr-val list)) (mb nil) (mq nil))
-                  (if (not (cdr p))
-                      (and p (list 'eql a (list 'quote (car p))))
-                    (while p
-                      (if (floatp-safe (car p)) (setq mb t)
-                        (or (integerp (car p)) (symbolp (car p)) (setq mq t)))
-                      (setq p (cdr p)))
-                    (if (not mb) (list 'memq a list)
-                      (if (not mq) (list 'member a list) form))))
-              form)))
+         ((or (null keys) (eq test 'eql)) (list 'memql a list))
          (t form))))
 
 (define-compiler-macro assoc* (&whole form a list &rest keys)
@@ -2559,50 +2678,56 @@ surrounded by (block NAME ...)."
       (let ((res (cl-make-type-test val (cl-const-expr-val type))))
        (if (or (memq (cl-expr-contains res val) '(nil 1))
                (cl-simple-expr-p val)) res
-         (let ((temp (gensym)))
+         (let ((temp (make-symbol "--cl-var--")))
            (list 'let (list (list temp val)) (subst temp val res)))))
     form))
 
 
-(mapcar (function
-        (lambda (y)
-          (put (car y) 'side-effect-free t)
-          (put (car y) 'byte-compile 'cl-byte-compile-compiler-macro)
-          (put (car y) 'cl-compiler-macro
-               (list 'lambda '(w x)
-                     (if (symbolp (cadr y))
-                         (list 'list (list 'quote (cadr y))
-                               (list 'list (list 'quote (caddr y)) 'x))
-                       (cons 'list (cdr y)))))))
-       '((first 'car x) (second 'cadr x) (third 'caddr x) (fourth 'cadddr x)
-         (fifth 'nth 4 x) (sixth 'nth 5 x) (seventh 'nth 6 x)
-         (eighth 'nth 7 x) (ninth 'nth 8 x) (tenth 'nth 9 x)
-         (rest 'cdr x) (endp 'null x) (plusp '> x 0) (minusp '< x 0)
-         (caaar car caar) (caadr car cadr) (cadar car cdar)
-         (caddr car cddr) (cdaar cdr caar) (cdadr cdr cadr)
-         (cddar cdr cdar) (cdddr cdr cddr) (caaaar car caaar)
-         (caaadr car caadr) (caadar car cadar) (caaddr car caddr)
-         (cadaar car cdaar) (cadadr car cdadr) (caddar car cddar)
-         (cadddr car cdddr) (cdaaar cdr caaar) (cdaadr cdr caadr)
-         (cdadar cdr cadar) (cdaddr cdr caddr) (cddaar cdr cdaar)
-         (cddadr cdr cdadr) (cdddar cdr cddar) (cddddr cdr cdddr) ))
+(mapc (lambda (y)
+       (put (car y) 'side-effect-free t)
+       (put (car y) 'byte-compile 'cl-byte-compile-compiler-macro)
+       (put (car y) 'cl-compiler-macro
+            `(lambda (w x)
+               ,(if (symbolp (cadr y))
+                    `(list ',(cadr y)
+                           (list ',(caddr y) x))
+                  (cons 'list (cdr y))))))
+      '((first 'car x) (second 'cadr x) (third 'caddr x) (fourth 'cadddr x)
+       (fifth 'nth 4 x) (sixth 'nth 5 x) (seventh 'nth 6 x)
+       (eighth 'nth 7 x) (ninth 'nth 8 x) (tenth 'nth 9 x)
+       (rest 'cdr x) (endp 'null x) (plusp '> x 0) (minusp '< x 0)
+       (caaar car caar) (caadr car cadr) (cadar car cdar)
+       (caddr car cddr) (cdaar cdr caar) (cdadr cdr cadr)
+       (cddar cdr cdar) (cdddr cdr cddr) (caaaar car caaar)
+       (caaadr car caadr) (caadar car cadar) (caaddr car caddr)
+       (cadaar car cdaar) (cadadr car cdadr) (caddar car cddar)
+       (cadddr car cdddr) (cdaaar cdr caaar) (cdaadr cdr caadr)
+       (cdadar cdr cadar) (cdaddr cdr caddr) (cddaar cdr cdaar)
+       (cddadr cdr cdadr) (cdddar cdr cddar) (cddddr cdr cdddr) ))
 
 ;;; Things that are inline.
 (proclaim '(inline floatp-safe acons map concatenate notany notevery
                   cl-set-elt revappend nreconc gethash))
 
 ;;; Things that are side-effect-free.
-(mapcar (function (lambda (x) (put x 'side-effect-free t)))
-       '(oddp evenp signum last butlast ldiff pairlis gcd lcm
-         isqrt floor* ceiling* truncate* round* mod* rem* subseq
-         list-length get* getf))
+(mapc (lambda (x) (put x 'side-effect-free t))
+      '(oddp evenp signum last butlast ldiff pairlis gcd lcm
+       isqrt floor* ceiling* truncate* round* mod* rem* subseq
+       list-length get* getf))
 
 ;;; Things that are side-effect-and-error-free.
-(mapcar (function (lambda (x) (put x 'side-effect-free 'error-free)))
-       '(eql floatp-safe list* subst acons equalp random-state-p
-         copy-tree sublis))
+(mapc (lambda (x) (put x 'side-effect-free 'error-free))
+      '(eql floatp-safe list* subst acons equalp random-state-p
+       copy-tree sublis))
 
 
 (run-hooks 'cl-macs-load-hook)
 
+;; Local variables:
+;; byte-compile-dynamic: t
+;; byte-compile-warnings: (not cl-functions)
+;; generated-autoload-file: "cl-loaddefs.el"
+;; End:
+
+;; arch-tag: afd947a6-b553-4df1-bba5-000be6388f46
 ;;; cl-macs.el ends here