2012-06-08 22:26:47 -04:00
|
|
|
;;; cl-macs.el --- Common Lisp macros -*- lexical-binding: t; coding: utf-8 -*-
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2012-01-05 01:46:05 -08:00
|
|
|
;; Copyright (C) 1993, 2001-2012 Free Software Foundation, Inc.
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
;; Author: Dave Gillespie <daveg@synaptics.com>
|
|
|
|
;; Version: 2.02
|
|
|
|
;; Keywords: extensions
|
2010-08-29 12:17:13 -04:00
|
|
|
;; Package: emacs
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
2008-05-06 03:21:21 +00:00
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
1993-07-30 20:15:09 +00:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 03:21:21 +00:00
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2008-05-06 03:21:21 +00:00
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
1993-07-30 20:15:09 +00:00
|
|
|
|
1994-06-17 20:04:22 +00:00
|
|
|
;;; Commentary:
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
;; These are extensions to Emacs Lisp that provide a degree of
|
|
|
|
;; Common Lisp compatibility, beyond what is already built-in
|
|
|
|
;; in Emacs Lisp.
|
|
|
|
;;
|
|
|
|
;; This package was written by Dave Gillespie; it is a complete
|
|
|
|
;; rewrite of Cesar Quiroz's original cl.el package of December 1986.
|
|
|
|
;;
|
|
|
|
;; Bug reports, comments, and suggestions are welcome!
|
|
|
|
|
|
|
|
;; This file contains the portions of the Common Lisp extensions
|
|
|
|
;; package which should be autoloaded, but need only be present
|
|
|
|
;; if the compiler or interpreter is used---this file is not
|
|
|
|
;; necessary for executing compiled code.
|
|
|
|
|
|
|
|
;; See cl.el for Change Log.
|
|
|
|
|
|
|
|
|
1994-06-17 20:04:22 +00:00
|
|
|
;;; Code:
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2012-06-03 21:05:17 -04:00
|
|
|
(require 'cl-lib)
|
2012-06-07 15:25:48 -04:00
|
|
|
(require 'macroexp)
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
(defmacro cl-pop2 (place)
|
2012-06-03 21:05:17 -04:00
|
|
|
(declare (debug edebug-sexps))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(prog1 (car (cdr ,place))
|
|
|
|
(setq ,place (cdr (cdr ,place)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
(defvar cl-optimize-safety)
|
|
|
|
(defvar cl-optimize-speed)
|
|
|
|
|
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
;; This kludge allows macros which use cl--transform-function-property
|
2007-06-28 15:09:39 +00:00
|
|
|
;; to be called at compile-time.
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2012-06-01 16:36:00 -04:00
|
|
|
(eval-and-compile
|
2012-06-07 15:25:48 -04:00
|
|
|
(or (fboundp 'cl--transform-function-property)
|
|
|
|
(defun cl--transform-function-property (n p f)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(put ',n ',p #'(lambda . ,f)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
;;; Initialization.
|
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
;;; Some predicates for analyzing Lisp forms.
|
|
|
|
;; These are used by various
|
|
|
|
;; macro expanders to optimize the results in certain common cases.
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
(defconst cl--simple-funcs '(car cdr nth aref elt if and or + - 1+ 1- min max
|
2002-11-27 12:25:11 +00:00
|
|
|
car-safe cdr-safe progn prog1 prog2))
|
2012-06-07 15:25:48 -04:00
|
|
|
(defconst cl--safe-funcs '(* / % length memq list vector vectorp
|
2002-11-27 12:25:11 +00:00
|
|
|
< > <= >= = error))
|
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
(defun cl--simple-expr-p (x &optional size)
|
|
|
|
"Check if no side effects, and executes quickly."
|
2002-11-27 12:25:11 +00:00
|
|
|
(or size (setq size 10))
|
2012-06-03 21:05:17 -04:00
|
|
|
(if (and (consp x) (not (memq (car x) '(quote function cl-function))))
|
2002-11-27 12:25:11 +00:00
|
|
|
(and (symbolp (car x))
|
2012-06-07 15:25:48 -04:00
|
|
|
(or (memq (car x) cl--simple-funcs)
|
2002-11-27 12:25:11 +00:00
|
|
|
(get (car x) 'side-effect-free))
|
|
|
|
(progn
|
|
|
|
(setq size (1- size))
|
|
|
|
(while (and (setq x (cdr x))
|
2012-06-07 15:25:48 -04:00
|
|
|
(setq size (cl--simple-expr-p (car x) size))))
|
2002-11-27 12:25:11 +00:00
|
|
|
(and (null x) (>= size 0) size)))
|
|
|
|
(and (> size 0) (1- size))))
|
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
(defun cl--simple-exprs-p (xs)
|
|
|
|
(while (and xs (cl--simple-expr-p (car xs)))
|
2002-11-27 12:25:11 +00:00
|
|
|
(setq xs (cdr xs)))
|
|
|
|
(not xs))
|
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
(defun cl--safe-expr-p (x)
|
|
|
|
"Check if no side effects."
|
2012-06-03 21:05:17 -04:00
|
|
|
(or (not (and (consp x) (not (memq (car x) '(quote function cl-function)))))
|
2002-11-27 12:25:11 +00:00
|
|
|
(and (symbolp (car x))
|
2012-06-07 15:25:48 -04:00
|
|
|
(or (memq (car x) cl--simple-funcs)
|
|
|
|
(memq (car x) cl--safe-funcs)
|
2002-11-27 12:25:11 +00:00
|
|
|
(get (car x) 'side-effect-free))
|
|
|
|
(progn
|
2012-06-07 15:25:48 -04:00
|
|
|
(while (and (setq x (cdr x)) (cl--safe-expr-p (car x))))
|
2002-11-27 12:25:11 +00:00
|
|
|
(null x)))))
|
|
|
|
|
|
|
|
;;; Check if constant (i.e., no side effects or dependencies).
|
2012-06-07 15:25:48 -04:00
|
|
|
(defun cl--const-expr-p (x)
|
2002-11-27 12:25:11 +00:00
|
|
|
(cond ((consp x)
|
|
|
|
(or (eq (car x) 'quote)
|
2012-06-03 21:05:17 -04:00
|
|
|
(and (memq (car x) '(function cl-function))
|
2002-11-27 12:25:11 +00:00
|
|
|
(or (symbolp (nth 1 x))
|
|
|
|
(and (eq (car-safe (nth 1 x)) 'lambda) 'func)))))
|
|
|
|
((symbolp x) (and (memq x '(nil t)) t))
|
|
|
|
(t t)))
|
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
(defun cl--const-expr-val (x)
|
|
|
|
(and (macroexp-const-p x) (if (consp x) (nth 1 x) x)))
|
2002-11-27 12:25:11 +00:00
|
|
|
|
|
|
|
(defun cl-expr-access-order (x v)
|
2010-04-08 15:59:46 -04:00
|
|
|
;; This apparently tries to return nil iff the expression X evaluates
|
|
|
|
;; the variables V in the same order as they appear in V (so as to
|
|
|
|
;; be able to replace those vars with the expressions they're bound
|
|
|
|
;; to).
|
|
|
|
;; FIXME: This is very naive, it doesn't even check to see if those
|
|
|
|
;; variables appear more than once.
|
2012-06-07 15:25:48 -04:00
|
|
|
(if (macroexp-const-p x) v
|
2002-11-27 12:25:11 +00:00
|
|
|
(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)))))
|
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
(defun cl--expr-contains (x y)
|
|
|
|
"Count number of times X refers to Y. Return nil for 0 times."
|
2012-06-03 21:05:17 -04:00
|
|
|
;; FIXME: This is naive, and it will cl-count Y as referred twice in
|
2012-05-06 11:38:30 -04:00
|
|
|
;; (let ((Y 1)) Y) even though it should be 0. Also it is often called on
|
|
|
|
;; non-macroexpanded code, so it may also miss some occurrences that would
|
|
|
|
;; only appear in the expanded code.
|
2002-11-27 12:25:11 +00:00
|
|
|
(cond ((equal y x) 1)
|
2012-06-03 21:05:17 -04:00
|
|
|
((and (consp x) (not (memq (car x) '(quote function cl-function))))
|
2002-11-27 12:25:11 +00:00
|
|
|
(let ((sum 0))
|
2012-05-06 11:38:30 -04:00
|
|
|
(while (consp x)
|
2012-06-07 15:25:48 -04:00
|
|
|
(setq sum (+ sum (or (cl--expr-contains (pop x) y) 0))))
|
|
|
|
(setq sum (+ sum (or (cl--expr-contains x y) 0)))
|
2002-11-27 12:25:11 +00:00
|
|
|
(and (> sum 0) sum)))
|
|
|
|
(t nil)))
|
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
(defun cl--expr-contains-any (x y)
|
|
|
|
(while (and y (not (cl--expr-contains x (car y)))) (pop y))
|
2002-11-27 12:25:11 +00:00
|
|
|
y)
|
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
(defun cl--expr-depends-p (x y)
|
|
|
|
"Check whether X may depend on any of the symbols in Y."
|
|
|
|
(and (not (macroexp-const-p x))
|
|
|
|
(or (not (cl--safe-expr-p x)) (cl--expr-contains-any x y))))
|
2002-11-27 12:25:11 +00:00
|
|
|
|
1993-07-30 20:15:09 +00:00
|
|
|
;;; Symbols.
|
|
|
|
|
2012-05-17 16:04:56 -04:00
|
|
|
(defvar cl--gensym-counter)
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defun cl-gensym (&optional prefix)
|
1993-07-30 20:15:09 +00:00
|
|
|
"Generate a new uninterned symbol.
|
|
|
|
The name is made by appending a number to PREFIX, default \"G\"."
|
2004-05-08 17:23:08 +00:00
|
|
|
(let ((pfix (if (stringp prefix) prefix "G"))
|
|
|
|
(num (if (integerp prefix) prefix
|
2012-05-17 16:04:56 -04:00
|
|
|
(prog1 cl--gensym-counter
|
|
|
|
(setq cl--gensym-counter (1+ cl--gensym-counter))))))
|
2004-05-08 17:23:08 +00:00
|
|
|
(make-symbol (format "%s%d" pfix num))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defun cl-gentemp (&optional prefix)
|
1993-07-30 20:15:09 +00:00
|
|
|
"Generate a new interned symbol with a unique name.
|
|
|
|
The name is made by appending a number to PREFIX, default \"G\"."
|
2004-05-08 17:23:08 +00:00
|
|
|
(let ((pfix (if (stringp prefix) prefix "G"))
|
1993-07-30 20:15:09 +00:00
|
|
|
name)
|
2012-05-17 16:04:56 -04:00
|
|
|
(while (intern-soft (setq name (format "%s%d" pfix cl--gensym-counter)))
|
|
|
|
(setq cl--gensym-counter (1+ cl--gensym-counter)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(intern name)))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Program structure.
|
|
|
|
|
2012-05-17 17:39:36 -04:00
|
|
|
(def-edebug-spec cl-declarations
|
2012-06-03 21:05:17 -04:00
|
|
|
(&rest ("cl-declare" &rest sexp)))
|
2012-05-17 17:39:36 -04:00
|
|
|
|
|
|
|
(def-edebug-spec cl-declarations-or-string
|
|
|
|
(&or stringp cl-declarations))
|
|
|
|
|
|
|
|
(def-edebug-spec cl-lambda-list
|
|
|
|
(([&rest arg]
|
|
|
|
[&optional ["&optional" cl-&optional-arg &rest cl-&optional-arg]]
|
|
|
|
[&optional ["&rest" arg]]
|
|
|
|
[&optional ["&key" [cl-&key-arg &rest cl-&key-arg]
|
|
|
|
&optional "&allow-other-keys"]]
|
|
|
|
[&optional ["&aux" &rest
|
|
|
|
&or (symbolp &optional def-form) symbolp]]
|
|
|
|
)))
|
|
|
|
|
|
|
|
(def-edebug-spec cl-&optional-arg
|
|
|
|
(&or (arg &optional def-form arg) arg))
|
|
|
|
|
|
|
|
(def-edebug-spec cl-&key-arg
|
|
|
|
(&or ([&or (symbolp arg) arg] &optional def-form arg) arg))
|
|
|
|
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(defconst cl--lambda-list-keywords
|
|
|
|
'(&optional &rest &key &allow-other-keys &aux &whole &body &environment))
|
|
|
|
|
|
|
|
(defvar cl--bind-block) (defvar cl--bind-defs) (defvar cl--bind-enquote)
|
|
|
|
(defvar cl--bind-inits) (defvar cl--bind-lets) (defvar cl--bind-forms)
|
|
|
|
|
|
|
|
(defun cl--transform-lambda (form bind-block)
|
|
|
|
(let* ((args (car form)) (body (cdr form)) (orig-args args)
|
|
|
|
(cl--bind-block bind-block) (cl--bind-defs nil) (cl--bind-enquote nil)
|
|
|
|
(cl--bind-inits nil) (cl--bind-lets nil) (cl--bind-forms nil)
|
|
|
|
(header nil) (simple-args nil))
|
|
|
|
(while (or (stringp (car body))
|
|
|
|
(memq (car-safe (car body)) '(interactive cl-declare)))
|
|
|
|
(push (pop body) header))
|
|
|
|
(setq args (if (listp args) (cl-copy-list args) (list '&rest args)))
|
|
|
|
(let ((p (last args))) (if (cdr p) (setcdr p (list '&rest (cdr p)))))
|
|
|
|
(if (setq cl--bind-defs (cadr (memq '&cl-defs args)))
|
|
|
|
(setq args (delq '&cl-defs (delq cl--bind-defs args))
|
|
|
|
cl--bind-defs (cadr cl--bind-defs)))
|
|
|
|
(if (setq cl--bind-enquote (memq '&cl-quote args))
|
|
|
|
(setq args (delq '&cl-quote args)))
|
|
|
|
(if (memq '&whole args) (error "&whole not currently implemented"))
|
|
|
|
(let* ((p (memq '&environment args)) (v (cadr p))
|
|
|
|
(env-exp 'macroexpand-all-environment))
|
|
|
|
(if p (setq args (nconc (delq (car p) (delq v args))
|
|
|
|
(list '&aux (list v env-exp))))))
|
|
|
|
(while (and args (symbolp (car args))
|
|
|
|
(not (memq (car args) '(nil &rest &body &key &aux)))
|
|
|
|
(not (and (eq (car args) '&optional)
|
|
|
|
(or cl--bind-defs (consp (cadr args))))))
|
|
|
|
(push (pop args) simple-args))
|
|
|
|
(or (eq cl--bind-block 'cl-none)
|
|
|
|
(setq body (list `(cl-block ,cl--bind-block ,@body))))
|
|
|
|
(if (null args)
|
|
|
|
(cl-list* nil (nreverse simple-args) (nconc (nreverse header) body))
|
|
|
|
(if (memq '&optional simple-args) (push '&optional args))
|
|
|
|
(cl--do-arglist args nil (- (length simple-args)
|
|
|
|
(if (memq '&optional simple-args) 1 0)))
|
|
|
|
(setq cl--bind-lets (nreverse cl--bind-lets))
|
|
|
|
(cl-list* (and cl--bind-inits `(cl-eval-when (compile load eval)
|
|
|
|
,@(nreverse cl--bind-inits)))
|
|
|
|
(nconc (nreverse simple-args)
|
|
|
|
(list '&rest (car (pop cl--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))
|
|
|
|
(format "%S"
|
|
|
|
(cons 'fn
|
|
|
|
(cl--make-usage-args orig-args))))
|
|
|
|
hdr)))
|
|
|
|
(list `(let* ,cl--bind-lets
|
|
|
|
,@(nreverse cl--bind-forms)
|
|
|
|
,@body)))))))
|
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-defun (name args &rest body)
|
2002-09-27 23:16:27 +00:00
|
|
|
"Define NAME as a function.
|
1993-07-30 20:15:09 +00:00
|
|
|
Like normal `defun', except ARGLIST allows full Common Lisp conventions,
|
2012-06-03 21:05:17 -04:00
|
|
|
and BODY is implicitly surrounded by (cl-block NAME ...).
|
2002-09-27 23:16:27 +00:00
|
|
|
|
|
|
|
\(fn NAME ARGLIST [DOCSTRING] BODY...)"
|
2012-05-17 17:39:36 -04:00
|
|
|
(declare (debug
|
|
|
|
;; Same as defun but use cl-lambda-list.
|
2012-06-03 21:05:17 -04:00
|
|
|
(&define [&or name ("cl-setf" :name cl-setf name)]
|
2012-05-17 17:39:36 -04:00
|
|
|
cl-lambda-list
|
|
|
|
cl-declarations-or-string
|
|
|
|
[&optional ("interactive" interactive)]
|
2012-05-17 17:51:15 -04:00
|
|
|
def-body))
|
2012-05-17 21:46:20 -04:00
|
|
|
(doc-string 3)
|
2012-05-17 17:51:15 -04:00
|
|
|
(indent 2))
|
2012-06-07 15:25:48 -04:00
|
|
|
(let* ((res (cl--transform-lambda (cons args body) name))
|
2012-06-01 16:36:00 -04:00
|
|
|
(form `(defun ,name ,@(cdr res))))
|
|
|
|
(if (car res) `(progn ,(car res) ,form) form)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2012-05-17 17:39:36 -04:00
|
|
|
;; The lambda list for macros is different from that of normal lambdas.
|
|
|
|
;; Note that &environment is only allowed as first or last items in the
|
|
|
|
;; top level list.
|
|
|
|
|
|
|
|
(def-edebug-spec cl-macro-list
|
|
|
|
(([&optional "&environment" arg]
|
|
|
|
[&rest cl-macro-arg]
|
|
|
|
[&optional ["&optional" &rest
|
|
|
|
&or (cl-macro-arg &optional def-form cl-macro-arg) arg]]
|
|
|
|
[&optional [[&or "&rest" "&body"] cl-macro-arg]]
|
|
|
|
[&optional ["&key" [&rest
|
|
|
|
[&or ([&or (symbolp cl-macro-arg) arg]
|
|
|
|
&optional def-form cl-macro-arg)
|
|
|
|
arg]]
|
|
|
|
&optional "&allow-other-keys"]]
|
|
|
|
[&optional ["&aux" &rest
|
|
|
|
&or (symbolp &optional def-form) symbolp]]
|
|
|
|
[&optional "&environment" arg]
|
|
|
|
)))
|
|
|
|
|
|
|
|
(def-edebug-spec cl-macro-arg
|
|
|
|
(&or arg cl-macro-list1))
|
|
|
|
|
|
|
|
(def-edebug-spec cl-macro-list1
|
|
|
|
(([&optional "&whole" arg] ;; only allowed at lower levels
|
|
|
|
[&rest cl-macro-arg]
|
|
|
|
[&optional ["&optional" &rest
|
|
|
|
&or (cl-macro-arg &optional def-form cl-macro-arg) arg]]
|
|
|
|
[&optional [[&or "&rest" "&body"] cl-macro-arg]]
|
|
|
|
[&optional ["&key" [&rest
|
|
|
|
[&or ([&or (symbolp cl-macro-arg) arg]
|
|
|
|
&optional def-form cl-macro-arg)
|
|
|
|
arg]]
|
|
|
|
&optional "&allow-other-keys"]]
|
|
|
|
[&optional ["&aux" &rest
|
|
|
|
&or (symbolp &optional def-form) symbolp]]
|
|
|
|
. [&or arg nil])))
|
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-defmacro (name args &rest body)
|
2002-09-27 23:16:27 +00:00
|
|
|
"Define NAME as a macro.
|
1993-07-30 20:15:09 +00:00
|
|
|
Like normal `defmacro', except ARGLIST allows full Common Lisp conventions,
|
2012-06-03 21:05:17 -04:00
|
|
|
and BODY is implicitly surrounded by (cl-block NAME ...).
|
2002-09-27 23:16:27 +00:00
|
|
|
|
|
|
|
\(fn NAME ARGLIST [DOCSTRING] BODY...)"
|
2012-05-17 17:39:36 -04:00
|
|
|
(declare (debug
|
2012-05-17 17:51:15 -04:00
|
|
|
(&define name cl-macro-list cl-declarations-or-string def-body))
|
2012-05-17 21:46:20 -04:00
|
|
|
(doc-string 3)
|
2012-05-17 17:51:15 -04:00
|
|
|
(indent 2))
|
2012-06-07 15:25:48 -04:00
|
|
|
(let* ((res (cl--transform-lambda (cons args body) name))
|
2012-06-01 16:36:00 -04:00
|
|
|
(form `(defmacro ,name ,@(cdr res))))
|
|
|
|
(if (car res) `(progn ,(car res) ,form) form)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2012-05-17 17:39:36 -04:00
|
|
|
(def-edebug-spec cl-lambda-expr
|
|
|
|
(&define ("lambda" cl-lambda-list
|
|
|
|
;;cl-declarations-or-string
|
|
|
|
;;[&optional ("interactive" interactive)]
|
|
|
|
def-body)))
|
|
|
|
|
2012-06-03 21:05:17 -04:00
|
|
|
;; Redefine function-form to also match cl-function
|
2012-05-17 17:39:36 -04:00
|
|
|
(def-edebug-spec function-form
|
|
|
|
;; form at the end could also handle "function",
|
|
|
|
;; but recognize it specially to avoid wrapping function forms.
|
|
|
|
(&or ([&or "quote" "function"] &or symbolp lambda-expr)
|
2012-06-03 21:05:17 -04:00
|
|
|
("cl-function" cl-function)
|
2012-05-17 17:39:36 -04:00
|
|
|
form))
|
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-function (func)
|
2000-05-05 20:01:01 +00:00
|
|
|
"Introduce a function.
|
(function*, case, ecase, typecase, etypecase, progv, lexical-let, lexical-let*,
multiple-value-bind, multiple-value-setq, shiftf): Improve argument/docstring
consistency.
2005-05-22 17:51:22 +00:00
|
|
|
Like normal `function', except that if argument is a lambda form,
|
|
|
|
its argument list allows full Common Lisp conventions."
|
2012-05-17 17:39:36 -04:00
|
|
|
(declare (debug (&or symbolp cl-lambda-expr)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (eq (car-safe func) 'lambda)
|
2012-06-07 15:25:48 -04:00
|
|
|
(let* ((res (cl--transform-lambda (cdr func) 'cl-none))
|
2012-06-01 16:36:00 -04:00
|
|
|
(form `(function (lambda . ,(cdr res)))))
|
|
|
|
(if (car res) `(progn ,(car res) ,form) form))
|
|
|
|
`(function ,func)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
(defun cl--transform-function-property (func prop form)
|
|
|
|
(let ((res (cl--transform-lambda form func)))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(progn ,@(cdr (cdr (car res)))
|
|
|
|
(put ',func ',prop #'(lambda . ,(cdr res))))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2009-09-11 22:59:36 +00:00
|
|
|
(declare-function help-add-fundoc-usage "help-fns" (docstring arglist))
|
|
|
|
|
2011-08-05 12:31:21 -04:00
|
|
|
(defun cl--make-usage-var (x)
|
|
|
|
"X can be a var or a (destructuring) lambda-list."
|
|
|
|
(cond
|
|
|
|
((symbolp x) (make-symbol (upcase (symbol-name x))))
|
|
|
|
((consp x) (cl--make-usage-args x))
|
|
|
|
(t x)))
|
|
|
|
|
|
|
|
(defun cl--make-usage-args (arglist)
|
|
|
|
;; `orig-args' can contain &cl-defs (an internal
|
|
|
|
;; CL thingy I don't understand), so remove it.
|
|
|
|
(let ((x (memq '&cl-defs arglist)))
|
|
|
|
(when x (setq arglist (delq (car x) (remq (cadr x) arglist)))))
|
|
|
|
(let ((state nil))
|
|
|
|
(mapcar (lambda (x)
|
|
|
|
(cond
|
|
|
|
((symbolp x)
|
|
|
|
(if (eq ?\& (aref (symbol-name x) 0))
|
|
|
|
(setq state x)
|
|
|
|
(make-symbol (upcase (symbol-name x)))))
|
|
|
|
((not (consp x)) x)
|
|
|
|
((memq state '(nil &rest)) (cl--make-usage-args x))
|
|
|
|
(t ;(VAR INITFORM SVAR) or ((KEYWORD VAR) INITFORM SVAR).
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-list*
|
2011-08-05 12:31:21 -04:00
|
|
|
(if (and (consp (car x)) (eq state '&key))
|
|
|
|
(list (caar x) (cl--make-usage-var (nth 1 (car x))))
|
|
|
|
(cl--make-usage-var (car x)))
|
|
|
|
(nth 1 x) ;INITFORM.
|
|
|
|
(cl--make-usage-args (nthcdr 2 x)) ;SVAR.
|
|
|
|
))))
|
|
|
|
arglist)))
|
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
(defun cl--do-arglist (args expr &optional num) ; uses bind-*
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (nlistp args)
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(if (or (memq args cl--lambda-list-keywords) (not (symbolp args)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(error "Invalid argument name: %s" args)
|
2012-06-08 09:18:26 -04:00
|
|
|
(push (list args expr) cl--bind-lets))
|
2012-06-03 21:05:17 -04:00
|
|
|
(setq args (cl-copy-list args))
|
1993-07-30 20:15:09 +00:00
|
|
|
(let ((p (last args))) (if (cdr p) (setcdr p (list '&rest (cdr p)))))
|
|
|
|
(let ((p (memq '&body args))) (if p (setcar p '&rest)))
|
|
|
|
(if (memq '&environment args) (error "&environment used incorrectly"))
|
|
|
|
(let ((save-args args)
|
|
|
|
(restarg (memq '&rest args))
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(safety (if (cl--compiling-file) cl-optimize-safety 3))
|
1993-07-30 20:15:09 +00:00
|
|
|
(keys nil)
|
|
|
|
(laterarg nil) (exactarg nil) minarg)
|
|
|
|
(or num (setq num 0))
|
|
|
|
(if (listp (cadr restarg))
|
2004-11-16 04:05:29 +00:00
|
|
|
(setq restarg (make-symbol "--cl-rest--"))
|
1993-07-30 20:15:09 +00:00
|
|
|
(setq restarg (cadr restarg)))
|
2012-06-08 09:18:26 -04:00
|
|
|
(push (list restarg expr) cl--bind-lets)
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (eq (car args) '&whole)
|
2012-06-08 09:18:26 -04:00
|
|
|
(push (list (cl-pop2 args) restarg) cl--bind-lets))
|
1993-07-30 20:15:09 +00:00
|
|
|
(let ((p args))
|
|
|
|
(setq minarg restarg)
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(while (and p (not (memq (car p) cl--lambda-list-keywords)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(or (eq p args) (setq minarg (list 'cdr minarg)))
|
|
|
|
(setq p (cdr p)))
|
|
|
|
(if (memq (car p) '(nil &aux))
|
2012-06-01 16:36:00 -04:00
|
|
|
(setq minarg `(= (length ,restarg)
|
2012-06-03 21:05:17 -04:00
|
|
|
,(length (cl-ldiff args p)))
|
1993-07-30 20:15:09 +00:00
|
|
|
exactarg (not (eq args p)))))
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(while (and args (not (memq (car args) cl--lambda-list-keywords)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(let ((poparg (list (if (or (cdr args) (not exactarg)) 'pop 'car)
|
|
|
|
restarg)))
|
2012-06-07 15:25:48 -04:00
|
|
|
(cl--do-arglist
|
2002-09-27 23:16:27 +00:00
|
|
|
(pop args)
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (or laterarg (= safety 0)) poparg
|
2012-06-01 16:36:00 -04:00
|
|
|
`(if ,minarg ,poparg
|
|
|
|
(signal 'wrong-number-of-arguments
|
2012-06-08 09:18:26 -04:00
|
|
|
(list ,(and (not (eq cl--bind-block 'cl-none))
|
|
|
|
`',cl--bind-block)
|
2012-06-01 16:36:00 -04:00
|
|
|
(length ,restarg)))))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(setq num (1+ num) laterarg t))
|
2002-09-27 23:16:27 +00:00
|
|
|
(while (and (eq (car args) '&optional) (pop args))
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(while (and args (not (memq (car args) cl--lambda-list-keywords)))
|
2002-09-27 23:16:27 +00:00
|
|
|
(let ((arg (pop args)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(or (consp arg) (setq arg (list arg)))
|
2012-06-07 15:25:48 -04:00
|
|
|
(if (cddr arg) (cl--do-arglist (nth 2 arg) `(and ,restarg t)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(let ((def (if (cdr arg) (nth 1 arg)
|
2012-06-08 09:18:26 -04:00
|
|
|
(or (car cl--bind-defs)
|
|
|
|
(nth 1 (assq (car arg) cl--bind-defs)))))
|
2012-06-01 16:36:00 -04:00
|
|
|
(poparg `(pop ,restarg)))
|
2012-06-08 09:18:26 -04:00
|
|
|
(and def cl--bind-enquote (setq def `',def))
|
2012-06-07 15:25:48 -04:00
|
|
|
(cl--do-arglist (car arg)
|
2012-06-01 16:36:00 -04:00
|
|
|
(if def `(if ,restarg ,poparg ,def) poparg))
|
1993-07-30 20:15:09 +00:00
|
|
|
(setq num (1+ num))))))
|
|
|
|
(if (eq (car args) '&rest)
|
|
|
|
(let ((arg (cl-pop2 args)))
|
2012-06-07 15:25:48 -04:00
|
|
|
(if (consp arg) (cl--do-arglist arg restarg)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(or (eq (car args) '&key) (= safety 0) exactarg
|
2012-06-01 16:36:00 -04:00
|
|
|
(push `(if ,restarg
|
|
|
|
(signal 'wrong-number-of-arguments
|
|
|
|
(list
|
2012-06-08 09:18:26 -04:00
|
|
|
,(and (not (eq cl--bind-block 'cl-none))
|
|
|
|
`',cl--bind-block)
|
2012-06-01 16:36:00 -04:00
|
|
|
(+ ,num (length ,restarg)))))
|
2012-06-08 09:18:26 -04:00
|
|
|
cl--bind-forms)))
|
2002-09-27 23:16:27 +00:00
|
|
|
(while (and (eq (car args) '&key) (pop args))
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(while (and args (not (memq (car args) cl--lambda-list-keywords)))
|
2002-09-27 23:16:27 +00:00
|
|
|
(let ((arg (pop args)))
|
2001-07-02 15:19:07 +00:00
|
|
|
(or (consp arg) (setq arg (list arg)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(let* ((karg (if (consp (car arg)) (caar arg)
|
|
|
|
(intern (format ":%s" (car arg)))))
|
2012-06-03 21:05:17 -04:00
|
|
|
(varg (if (consp (car arg)) (cl-cadar arg) (car arg)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(def (if (cdr arg) (cadr arg)
|
2012-06-08 09:18:26 -04:00
|
|
|
(or (car cl--bind-defs) (cadr (assq varg cl--bind-defs)))))
|
2012-06-01 16:36:00 -04:00
|
|
|
(look `(memq ',karg ,restarg)))
|
2012-06-08 09:18:26 -04:00
|
|
|
(and def cl--bind-enquote (setq def `',def))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (cddr arg)
|
2004-11-16 04:05:29 +00:00
|
|
|
(let* ((temp (or (nth 2 arg) (make-symbol "--cl-var--")))
|
2012-06-01 16:36:00 -04:00
|
|
|
(val `(car (cdr ,temp))))
|
2012-06-07 15:25:48 -04:00
|
|
|
(cl--do-arglist temp look)
|
|
|
|
(cl--do-arglist varg
|
2012-06-01 16:36:00 -04:00
|
|
|
`(if ,temp
|
|
|
|
(prog1 ,val (setq ,temp t))
|
|
|
|
,def)))
|
2012-06-07 15:25:48 -04:00
|
|
|
(cl--do-arglist
|
1993-07-30 20:15:09 +00:00
|
|
|
varg
|
2012-06-01 16:36:00 -04:00
|
|
|
`(car (cdr ,(if (null def)
|
1993-07-30 20:15:09 +00:00
|
|
|
look
|
2012-06-01 16:36:00 -04:00
|
|
|
`(or ,look
|
2012-06-07 15:25:48 -04:00
|
|
|
,(if (eq (cl--const-expr-p def) t)
|
|
|
|
`'(nil ,(cl--const-expr-val def))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(list nil ,def))))))))
|
2002-09-27 23:16:27 +00:00
|
|
|
(push karg keys)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(setq keys (nreverse keys))
|
2002-09-27 23:16:27 +00:00
|
|
|
(or (and (eq (car args) '&allow-other-keys) (pop args))
|
1993-07-30 20:15:09 +00:00
|
|
|
(null keys) (= safety 0)
|
2004-11-16 04:05:29 +00:00
|
|
|
(let* ((var (make-symbol "--cl-keys--"))
|
1993-07-30 20:15:09 +00:00
|
|
|
(allow '(:allow-other-keys))
|
2012-06-01 16:36:00 -04:00
|
|
|
(check `(while ,var
|
|
|
|
(cond
|
|
|
|
((memq (car ,var) ',(append keys allow))
|
|
|
|
(setq ,var (cdr (cdr ,var))))
|
|
|
|
((car (cdr (memq (quote ,@allow) ,restarg)))
|
|
|
|
(setq ,var nil))
|
|
|
|
(t
|
|
|
|
(error
|
|
|
|
,(format "Keyword argument %%s not one of %s"
|
|
|
|
keys)
|
|
|
|
(car ,var)))))))
|
2012-06-08 09:18:26 -04:00
|
|
|
(push `(let ((,var ,restarg)) ,check) cl--bind-forms)))
|
2002-09-27 23:16:27 +00:00
|
|
|
(while (and (eq (car args) '&aux) (pop args))
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(while (and args (not (memq (car args) cl--lambda-list-keywords)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (consp (car args))
|
2012-06-08 09:18:26 -04:00
|
|
|
(if (and cl--bind-enquote (cl-cadar args))
|
2012-06-07 15:25:48 -04:00
|
|
|
(cl--do-arglist (caar args)
|
2012-06-01 16:36:00 -04:00
|
|
|
`',(cadr (pop args)))
|
2012-06-07 15:25:48 -04:00
|
|
|
(cl--do-arglist (caar args) (cadr (pop args))))
|
|
|
|
(cl--do-arglist (pop args) nil))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if args (error "Malformed argument list %s" save-args)))))
|
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
(defun cl--arglist-args (args)
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (nlistp args) (list args)
|
|
|
|
(let ((res nil) (kind nil) arg)
|
|
|
|
(while (consp args)
|
2002-09-27 23:16:27 +00:00
|
|
|
(setq arg (pop args))
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(if (memq arg cl--lambda-list-keywords) (setq kind arg)
|
2002-09-27 23:16:27 +00:00
|
|
|
(if (eq arg '&cl-defs) (pop args)
|
1993-07-30 20:15:09 +00:00
|
|
|
(and (consp arg) kind (setq arg (car arg)))
|
|
|
|
(and (consp arg) (cdr arg) (eq kind '&key) (setq arg (cadr arg)))
|
2012-06-07 15:25:48 -04:00
|
|
|
(setq res (nconc res (cl--arglist-args arg))))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(nconc res (and args (list args))))))
|
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-destructuring-bind (args expr &rest body)
|
2012-05-17 17:51:15 -04:00
|
|
|
(declare (indent 2)
|
|
|
|
(debug (&define cl-macro-list def-form cl-declarations def-body)))
|
2012-06-08 09:18:26 -04:00
|
|
|
(let* ((cl--bind-lets nil) (cl--bind-forms nil) (cl--bind-inits nil)
|
|
|
|
(cl--bind-defs nil) (cl--bind-block 'cl-none) (cl--bind-enquote nil))
|
2012-06-07 15:25:48 -04:00
|
|
|
(cl--do-arglist (or args '(&aux)) expr)
|
2012-06-08 09:18:26 -04:00
|
|
|
(append '(progn) cl--bind-inits
|
|
|
|
(list `(let* ,(nreverse cl--bind-lets)
|
|
|
|
,@(nreverse cl--bind-forms) ,@body)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
|
2012-06-03 21:05:17 -04:00
|
|
|
;;; The `cl-eval-when' form.
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
(defvar cl-not-toplevel nil)
|
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-eval-when (when &rest body)
|
2002-09-27 23:16:27 +00:00
|
|
|
"Control when BODY is evaluated.
|
1993-07-30 20:15:09 +00:00
|
|
|
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.
|
2002-09-27 23:16:27 +00:00
|
|
|
If `eval' is in WHEN, BODY is evaluated when interpreted or at non-top-level.
|
|
|
|
|
|
|
|
\(fn (WHEN...) BODY...)"
|
2012-05-17 17:51:15 -04:00
|
|
|
(declare (indent 1) (debug ((&rest &or "compile" "load" "eval") body)))
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(if (and (fboundp 'cl--compiling-file) (cl--compiling-file)
|
1993-07-30 20:15:09 +00:00
|
|
|
(not cl-not-toplevel) (not (boundp 'for-effect))) ; horrible kludge
|
2000-05-05 20:01:01 +00:00
|
|
|
(let ((comp (or (memq 'compile when) (memq :compile-toplevel when)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(cl-not-toplevel t))
|
2000-05-05 20:01:01 +00:00
|
|
|
(if (or (memq 'load when) (memq :load-toplevel when))
|
2012-06-07 15:25:48 -04:00
|
|
|
(if comp (cons 'progn (mapcar 'cl--compile-time-too body))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(if nil nil ,@body))
|
1993-07-30 20:15:09 +00:00
|
|
|
(progn (if comp (eval (cons 'progn body))) nil)))
|
2000-05-05 20:01:01 +00:00
|
|
|
(and (or (memq 'eval when) (memq :execute when))
|
1993-07-30 20:15:09 +00:00
|
|
|
(cons 'progn body))))
|
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
(defun cl--compile-time-too (form)
|
1993-07-30 20:15:09 +00:00
|
|
|
(or (and (symbolp (car-safe form)) (get (car-safe form) 'byte-hunk-handler))
|
|
|
|
(setq form (macroexpand
|
2012-06-03 21:05:17 -04:00
|
|
|
form (cons '(cl-eval-when) byte-compile-macro-environment))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(cond ((eq (car-safe form) 'progn)
|
2012-06-07 15:25:48 -04:00
|
|
|
(cons 'progn (mapcar 'cl--compile-time-too (cdr form))))
|
2012-06-03 21:05:17 -04:00
|
|
|
((eq (car-safe form) 'cl-eval-when)
|
1993-07-30 20:15:09 +00:00
|
|
|
(let ((when (nth 1 form)))
|
2000-05-05 20:01:01 +00:00
|
|
|
(if (or (memq 'eval when) (memq :execute when))
|
2012-06-03 21:05:17 -04:00
|
|
|
`(cl-eval-when (compile ,@when) ,@(cddr form))
|
1993-07-30 20:15:09 +00:00
|
|
|
form)))
|
|
|
|
(t (eval form) form)))
|
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-08 09:18:26 -04:00
|
|
|
(defmacro cl-load-time-value (form &optional _read-only)
|
1993-07-30 20:15:09 +00:00
|
|
|
"Like `progn', but evaluates the body at load time.
|
|
|
|
The result of the body appears to the compiler as a quoted constant."
|
2012-05-17 17:39:36 -04:00
|
|
|
(declare (debug (form &optional sexp)))
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(if (cl--compiling-file)
|
2012-06-03 21:05:17 -04:00
|
|
|
(let* ((temp (cl-gentemp "--cl-load-time--"))
|
2012-06-01 16:36:00 -04:00
|
|
|
(set `(set ',temp ,form)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (and (fboundp 'byte-compile-file-form-defmumble)
|
|
|
|
(boundp 'this-kind) (boundp 'that-one))
|
|
|
|
(fset 'byte-compile-file-form
|
2012-06-01 16:36:00 -04:00
|
|
|
`(lambda (form)
|
|
|
|
(fset 'byte-compile-file-form
|
|
|
|
',(symbol-function 'byte-compile-file-form))
|
|
|
|
(byte-compile-file-form ',set)
|
|
|
|
(byte-compile-file-form form)))
|
2011-04-01 11:16:50 -04:00
|
|
|
(print set (symbol-value 'byte-compile--outbuffer)))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(symbol-value ',temp))
|
|
|
|
`',(eval form)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
;;; Conditional control structures.
|
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-case (expr &rest clauses)
|
(function*, case, ecase, typecase, etypecase, progv, lexical-let, lexical-let*,
multiple-value-bind, multiple-value-setq, shiftf): Improve argument/docstring
consistency.
2005-05-22 17:51:22 +00:00
|
|
|
"Eval EXPR and choose among clauses on that value.
|
1993-07-30 20:15:09 +00:00
|
|
|
Each clause looks like (KEYLIST BODY...). EXPR is evaluated and compared
|
|
|
|
against each key in each KEYLIST; the corresponding BODY is evaluated.
|
2012-06-03 21:05:17 -04:00
|
|
|
If no clause succeeds, cl-case returns nil. A single atom may be used in
|
2003-05-06 17:37:04 +00:00
|
|
|
place of a KEYLIST of one atom. A KEYLIST of t or `otherwise' is
|
1993-07-30 20:15:09 +00:00
|
|
|
allowed only in the final clause, and matches if no other keys match.
|
(function*, case, ecase, typecase, etypecase, progv, lexical-let, lexical-let*,
multiple-value-bind, multiple-value-setq, shiftf): Improve argument/docstring
consistency.
2005-05-22 17:51:22 +00:00
|
|
|
Key values are compared by `eql'.
|
|
|
|
\n(fn EXPR (KEYLIST BODY...)...)"
|
2012-05-17 17:51:15 -04:00
|
|
|
(declare (indent 1) (debug (form &rest (sexp body))))
|
2012-06-07 15:25:48 -04:00
|
|
|
(let* ((temp (if (cl--simple-expr-p expr 3) expr (make-symbol "--cl-var--")))
|
1993-07-30 20:15:09 +00:00
|
|
|
(head-list nil)
|
|
|
|
(body (cons
|
|
|
|
'cond
|
|
|
|
(mapcar
|
|
|
|
(function
|
|
|
|
(lambda (c)
|
|
|
|
(cons (cond ((memq (car c) '(t otherwise)) t)
|
2012-06-03 21:05:17 -04:00
|
|
|
((eq (car c) 'cl--ecase-error-flag)
|
|
|
|
`(error "cl-ecase failed: %s, %s"
|
2012-06-01 16:36:00 -04:00
|
|
|
,temp ',(reverse head-list)))
|
1993-07-30 20:15:09 +00:00
|
|
|
((listp (car c))
|
|
|
|
(setq head-list (append (car c) head-list))
|
2012-06-03 21:05:17 -04:00
|
|
|
`(cl-member ,temp ',(car c)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(t
|
|
|
|
(if (memq (car c) head-list)
|
|
|
|
(error "Duplicate key in case: %s"
|
|
|
|
(car c)))
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (car c) head-list)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(eql ,temp ',(car c))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(or (cdr c) '(nil)))))
|
|
|
|
clauses))))
|
|
|
|
(if (eq temp expr) body
|
2012-06-01 16:36:00 -04:00
|
|
|
`(let ((,temp ,expr)) ,body))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-ecase (expr &rest clauses)
|
|
|
|
"Like `cl-case', but error if no cl-case fits.
|
(function*, case, ecase, typecase, etypecase, progv, lexical-let, lexical-let*,
multiple-value-bind, multiple-value-setq, shiftf): Improve argument/docstring
consistency.
2005-05-22 17:51:22 +00:00
|
|
|
`otherwise'-clauses are not allowed.
|
|
|
|
\n(fn EXPR (KEYLIST BODY...)...)"
|
2012-06-03 21:05:17 -04:00
|
|
|
(declare (indent 1) (debug cl-case))
|
|
|
|
`(cl-case ,expr ,@clauses (cl--ecase-error-flag)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-typecase (expr &rest clauses)
|
(function*, case, ecase, typecase, etypecase, progv, lexical-let, lexical-let*,
multiple-value-bind, multiple-value-setq, shiftf): Improve argument/docstring
consistency.
2005-05-22 17:51:22 +00:00
|
|
|
"Evals EXPR, chooses among clauses on that value.
|
1993-07-30 20:15:09 +00:00
|
|
|
Each clause looks like (TYPE BODY...). EXPR is evaluated and, if it
|
|
|
|
satisfies TYPE, the corresponding BODY is evaluated. If no clause succeeds,
|
2012-06-03 21:05:17 -04:00
|
|
|
cl-typecase returns nil. A TYPE of t or `otherwise' is allowed only in the
|
(function*, case, ecase, typecase, etypecase, progv, lexical-let, lexical-let*,
multiple-value-bind, multiple-value-setq, shiftf): Improve argument/docstring
consistency.
2005-05-22 17:51:22 +00:00
|
|
|
final clause, and matches if no other keys match.
|
|
|
|
\n(fn EXPR (TYPE BODY...)...)"
|
2012-05-17 17:51:15 -04:00
|
|
|
(declare (indent 1)
|
|
|
|
(debug (form &rest ([&or cl-type-spec "otherwise"] body))))
|
2012-06-07 15:25:48 -04:00
|
|
|
(let* ((temp (if (cl--simple-expr-p expr 3) expr (make-symbol "--cl-var--")))
|
1993-07-30 20:15:09 +00:00
|
|
|
(type-list nil)
|
|
|
|
(body (cons
|
|
|
|
'cond
|
|
|
|
(mapcar
|
|
|
|
(function
|
|
|
|
(lambda (c)
|
|
|
|
(cons (cond ((eq (car c) 'otherwise) t)
|
2012-06-03 21:05:17 -04:00
|
|
|
((eq (car c) 'cl--ecase-error-flag)
|
|
|
|
`(error "cl-etypecase failed: %s, %s"
|
2012-06-01 16:36:00 -04:00
|
|
|
,temp ',(reverse type-list)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(t
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (car c) type-list)
|
2012-06-07 15:25:48 -04:00
|
|
|
(cl--make-type-test temp (car c))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(or (cdr c) '(nil)))))
|
|
|
|
clauses))))
|
|
|
|
(if (eq temp expr) body
|
2012-06-01 16:36:00 -04:00
|
|
|
`(let ((,temp ,expr)) ,body))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-etypecase (expr &rest clauses)
|
|
|
|
"Like `cl-typecase', but error if no case fits.
|
(function*, case, ecase, typecase, etypecase, progv, lexical-let, lexical-let*,
multiple-value-bind, multiple-value-setq, shiftf): Improve argument/docstring
consistency.
2005-05-22 17:51:22 +00:00
|
|
|
`otherwise'-clauses are not allowed.
|
|
|
|
\n(fn EXPR (TYPE BODY...)...)"
|
2012-06-03 21:05:17 -04:00
|
|
|
(declare (indent 1) (debug cl-typecase))
|
|
|
|
`(cl-typecase ,expr ,@clauses (cl--ecase-error-flag)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
;;; Blocks and exits.
|
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-block (name &rest body)
|
2000-05-05 20:01:01 +00:00
|
|
|
"Define a lexically-scoped block named NAME.
|
2012-06-03 21:05:17 -04:00
|
|
|
NAME may be any symbol. Code inside the BODY forms can call `cl-return-from'
|
1993-07-30 20:15:09 +00:00
|
|
|
to jump prematurely out of the block. This differs from `catch' and `throw'
|
|
|
|
in two respects: First, the NAME is an unevaluated symbol rather than a
|
|
|
|
quoted symbol or other form; and second, NAME is lexically rather than
|
|
|
|
dynamically scoped: Only references to it within BODY will work. These
|
|
|
|
references may appear inside macro expansions, but not inside functions
|
|
|
|
called from BODY."
|
2012-05-17 17:51:15 -04:00
|
|
|
(declare (indent 1) (debug (symbolp body)))
|
2012-06-07 15:25:48 -04:00
|
|
|
(if (cl--safe-expr-p `(progn ,@body)) `(progn ,@body)
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
`(cl--block-wrapper
|
2012-06-01 16:36:00 -04:00
|
|
|
(catch ',(intern (format "--cl-block-%s--" name))
|
|
|
|
,@body))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-return (&optional result)
|
2000-05-05 20:01:01 +00:00
|
|
|
"Return from the block named nil.
|
2012-06-03 21:05:17 -04:00
|
|
|
This is equivalent to `(cl-return-from nil RESULT)'."
|
2012-05-17 17:39:36 -04:00
|
|
|
(declare (debug (&optional form)))
|
2012-06-03 21:05:17 -04:00
|
|
|
`(cl-return-from nil ,result))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-return-from (name &optional result)
|
2000-05-05 20:01:01 +00:00
|
|
|
"Return from the block named NAME.
|
2012-06-03 21:05:17 -04:00
|
|
|
This jumps out to the innermost enclosing `(cl-block NAME ...)' form,
|
1993-07-30 20:15:09 +00:00
|
|
|
returning RESULT from that form (or nil if RESULT is omitted).
|
|
|
|
This is compatible with Common Lisp, but note that `defun' and
|
|
|
|
`defmacro' do not create implicit blocks as they do in Common Lisp."
|
2012-05-17 17:51:15 -04:00
|
|
|
(declare (indent 1) (debug (symbolp &optional form)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(let ((name2 (intern (format "--cl-block-%s--" name))))
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
`(cl--block-throw ',name2 ,result)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
|
2012-06-03 21:05:17 -04:00
|
|
|
;;; The "cl-loop" macro.
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
(defvar cl--loop-args) (defvar cl--loop-accum-var) (defvar cl--loop-accum-vars)
|
|
|
|
(defvar cl--loop-bindings) (defvar cl--loop-body) (defvar cl--loop-destr-temps)
|
|
|
|
(defvar cl--loop-finally) (defvar cl--loop-finish-flag)
|
|
|
|
(defvar cl--loop-first-flag)
|
|
|
|
(defvar cl--loop-initially) (defvar cl--loop-map-form) (defvar cl--loop-name)
|
|
|
|
(defvar cl--loop-result) (defvar cl--loop-result-explicit)
|
|
|
|
(defvar cl--loop-result-var) (defvar cl--loop-steps) (defvar cl--loop-symbol-macs)
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-08 09:18:26 -04:00
|
|
|
(defmacro cl-loop (&rest loop-args)
|
2012-06-03 21:05:17 -04:00
|
|
|
"The Common Lisp `cl-loop' macro.
|
1993-07-30 20:15:09 +00:00
|
|
|
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,
|
|
|
|
for VAR across ARRAY, repeat NUM, with VAR = INIT, while COND, until COND,
|
|
|
|
always COND, never COND, thereis COND, collect EXPR into VAR,
|
|
|
|
append EXPR into VAR, nconc EXPR into VAR, sum EXPR into VAR,
|
|
|
|
count EXPR into VAR, maximize EXPR into VAR, minimize EXPR into VAR,
|
|
|
|
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,
|
2002-09-27 23:16:27 +00:00
|
|
|
finally return EXPR, named NAME.
|
|
|
|
|
|
|
|
\(fn CLAUSE...)"
|
2012-05-17 17:39:36 -04:00
|
|
|
(declare (debug (&rest &or symbolp form)))
|
2012-06-08 09:18:26 -04:00
|
|
|
(if (not (memq t (mapcar 'symbolp (delq nil (delq t (cl-copy-list loop-args))))))
|
|
|
|
`(cl-block nil (while t ,@loop-args))
|
|
|
|
(let ((cl--loop-args loop-args) (cl--loop-name nil) (cl--loop-bindings nil)
|
2012-06-07 15:25:48 -04:00
|
|
|
(cl--loop-body nil) (cl--loop-steps nil)
|
|
|
|
(cl--loop-result nil) (cl--loop-result-explicit nil)
|
|
|
|
(cl--loop-result-var nil) (cl--loop-finish-flag nil)
|
|
|
|
(cl--loop-accum-var nil) (cl--loop-accum-vars nil)
|
|
|
|
(cl--loop-initially nil) (cl--loop-finally nil)
|
|
|
|
(cl--loop-map-form nil) (cl--loop-first-flag nil)
|
|
|
|
(cl--loop-destr-temps nil) (cl--loop-symbol-macs nil))
|
|
|
|
(setq cl--loop-args (append cl--loop-args '(cl-end-loop)))
|
|
|
|
(while (not (eq (car cl--loop-args) 'cl-end-loop)) (cl-parse-loop-clause))
|
|
|
|
(if cl--loop-finish-flag
|
|
|
|
(push `((,cl--loop-finish-flag t)) cl--loop-bindings))
|
|
|
|
(if cl--loop-first-flag
|
|
|
|
(progn (push `((,cl--loop-first-flag t)) cl--loop-bindings)
|
|
|
|
(push `(setq ,cl--loop-first-flag nil) cl--loop-steps)))
|
|
|
|
(let* ((epilogue (nconc (nreverse cl--loop-finally)
|
|
|
|
(list (or cl--loop-result-explicit cl--loop-result))))
|
|
|
|
(ands (cl--loop-build-ands (nreverse cl--loop-body)))
|
|
|
|
(while-body (nconc (cadr ands) (nreverse cl--loop-steps)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(body (append
|
2012-06-07 15:25:48 -04:00
|
|
|
(nreverse cl--loop-initially)
|
|
|
|
(list (if cl--loop-map-form
|
2012-06-03 21:05:17 -04:00
|
|
|
`(cl-block --cl-finish--
|
|
|
|
,(cl-subst
|
2012-06-01 16:36:00 -04:00
|
|
|
(if (eq (car ands) t) while-body
|
|
|
|
(cons `(or ,(car ands)
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-return-from --cl-finish--
|
2012-06-01 16:36:00 -04:00
|
|
|
nil))
|
|
|
|
while-body))
|
2012-06-07 15:25:48 -04:00
|
|
|
'--cl-map cl--loop-map-form))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(while ,(car ands) ,@while-body)))
|
2012-06-07 15:25:48 -04:00
|
|
|
(if cl--loop-finish-flag
|
|
|
|
(if (equal epilogue '(nil)) (list cl--loop-result-var)
|
|
|
|
`((if ,cl--loop-finish-flag
|
|
|
|
(progn ,@epilogue) ,cl--loop-result-var)))
|
1993-07-30 20:15:09 +00:00
|
|
|
epilogue))))
|
2012-06-07 15:25:48 -04:00
|
|
|
(if cl--loop-result-var (push (list cl--loop-result-var) cl--loop-bindings))
|
|
|
|
(while cl--loop-bindings
|
|
|
|
(if (cdar cl--loop-bindings)
|
|
|
|
(setq body (list (cl--loop-let (pop cl--loop-bindings) body t)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(let ((lets nil))
|
2012-06-07 15:25:48 -04:00
|
|
|
(while (and cl--loop-bindings
|
|
|
|
(not (cdar cl--loop-bindings)))
|
|
|
|
(push (car (pop cl--loop-bindings)) lets))
|
|
|
|
(setq body (list (cl--loop-let lets body nil))))))
|
|
|
|
(if cl--loop-symbol-macs
|
|
|
|
(setq body (list `(cl-symbol-macrolet ,cl--loop-symbol-macs ,@body))))
|
|
|
|
`(cl-block ,cl--loop-name ,@body)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2012-06-03 21:05:17 -04:00
|
|
|
;; Below is a complete spec for cl-loop, in several parts that correspond
|
2012-05-17 17:39:36 -04:00
|
|
|
;; to the syntax given in CLtL2. The specs do more than specify where
|
|
|
|
;; the forms are; it also specifies, as much as Edebug allows, all the
|
2012-06-03 21:05:17 -04:00
|
|
|
;; syntactically valid cl-loop clauses. The disadvantage of this
|
2012-05-17 17:39:36 -04:00
|
|
|
;; completeness is rigidity, but the "for ... being" clause allows
|
|
|
|
;; arbitrary extensions of the form: [symbolp &rest &or symbolp form].
|
|
|
|
|
2012-06-03 21:05:17 -04:00
|
|
|
;; (def-edebug-spec cl-loop
|
2012-05-17 17:39:36 -04:00
|
|
|
;; ([&optional ["named" symbolp]]
|
|
|
|
;; [&rest
|
|
|
|
;; &or
|
|
|
|
;; ["repeat" form]
|
|
|
|
;; loop-for-as
|
|
|
|
;; loop-with
|
|
|
|
;; loop-initial-final]
|
|
|
|
;; [&rest loop-clause]
|
|
|
|
;; ))
|
|
|
|
|
|
|
|
;; (def-edebug-spec loop-with
|
|
|
|
;; ("with" loop-var
|
|
|
|
;; loop-type-spec
|
|
|
|
;; [&optional ["=" form]]
|
|
|
|
;; &rest ["and" loop-var
|
|
|
|
;; loop-type-spec
|
|
|
|
;; [&optional ["=" form]]]))
|
|
|
|
|
|
|
|
;; (def-edebug-spec loop-for-as
|
|
|
|
;; ([&or "for" "as"] loop-for-as-subclause
|
|
|
|
;; &rest ["and" loop-for-as-subclause]))
|
|
|
|
|
|
|
|
;; (def-edebug-spec loop-for-as-subclause
|
|
|
|
;; (loop-var
|
|
|
|
;; loop-type-spec
|
|
|
|
;; &or
|
|
|
|
;; [[&or "in" "on" "in-ref" "across-ref"]
|
|
|
|
;; form &optional ["by" function-form]]
|
|
|
|
|
|
|
|
;; ["=" form &optional ["then" form]]
|
|
|
|
;; ["across" form]
|
|
|
|
;; ["being"
|
|
|
|
;; [&or "the" "each"]
|
|
|
|
;; &or
|
|
|
|
;; [[&or "element" "elements"]
|
|
|
|
;; [&or "of" "in" "of-ref"] form
|
|
|
|
;; &optional "using" ["index" symbolp]];; is this right?
|
|
|
|
;; [[&or "hash-key" "hash-keys"
|
|
|
|
;; "hash-value" "hash-values"]
|
|
|
|
;; [&or "of" "in"]
|
|
|
|
;; hash-table-p &optional ["using" ([&or "hash-value" "hash-values"
|
|
|
|
;; "hash-key" "hash-keys"] sexp)]]
|
|
|
|
|
|
|
|
;; [[&or "symbol" "present-symbol" "external-symbol"
|
|
|
|
;; "symbols" "present-symbols" "external-symbols"]
|
|
|
|
;; [&or "in" "of"] package-p]
|
|
|
|
|
|
|
|
;; ;; Extensions for Emacs Lisp, including Lucid Emacs.
|
|
|
|
;; [[&or "frame" "frames"
|
|
|
|
;; "screen" "screens"
|
|
|
|
;; "buffer" "buffers"]]
|
|
|
|
|
|
|
|
;; [[&or "window" "windows"]
|
|
|
|
;; [&or "of" "in"] form]
|
|
|
|
|
|
|
|
;; [[&or "overlay" "overlays"
|
|
|
|
;; "extent" "extents"]
|
|
|
|
;; [&or "of" "in"] form
|
|
|
|
;; &optional [[&or "from" "to"] form]]
|
|
|
|
|
|
|
|
;; [[&or "interval" "intervals"]
|
|
|
|
;; [&or "in" "of"] form
|
|
|
|
;; &optional [[&or "from" "to"] form]
|
|
|
|
;; ["property" form]]
|
|
|
|
|
|
|
|
;; [[&or "key-code" "key-codes"
|
|
|
|
;; "key-seq" "key-seqs"
|
|
|
|
;; "key-binding" "key-bindings"]
|
|
|
|
;; [&or "in" "of"] form
|
|
|
|
;; &optional ["using" ([&or "key-code" "key-codes"
|
|
|
|
;; "key-seq" "key-seqs"
|
|
|
|
;; "key-binding" "key-bindings"]
|
|
|
|
;; sexp)]]
|
|
|
|
;; ;; For arbitrary extensions, recognize anything else.
|
|
|
|
;; [symbolp &rest &or symbolp form]
|
|
|
|
;; ]
|
|
|
|
|
|
|
|
;; ;; arithmetic - must be last since all parts are optional.
|
|
|
|
;; [[&optional [[&or "from" "downfrom" "upfrom"] form]]
|
|
|
|
;; [&optional [[&or "to" "downto" "upto" "below" "above"] form]]
|
|
|
|
;; [&optional ["by" form]]
|
|
|
|
;; ]))
|
|
|
|
|
|
|
|
;; (def-edebug-spec loop-initial-final
|
|
|
|
;; (&or ["initially"
|
|
|
|
;; ;; [&optional &or "do" "doing"] ;; CLtL2 doesn't allow this.
|
|
|
|
;; &rest loop-non-atomic-expr]
|
|
|
|
;; ["finally" &or
|
|
|
|
;; [[&optional &or "do" "doing"] &rest loop-non-atomic-expr]
|
|
|
|
;; ["return" form]]))
|
|
|
|
|
|
|
|
;; (def-edebug-spec loop-and-clause
|
|
|
|
;; (loop-clause &rest ["and" loop-clause]))
|
|
|
|
|
|
|
|
;; (def-edebug-spec loop-clause
|
|
|
|
;; (&or
|
|
|
|
;; [[&or "while" "until" "always" "never" "thereis"] form]
|
|
|
|
|
|
|
|
;; [[&or "collect" "collecting"
|
|
|
|
;; "append" "appending"
|
|
|
|
;; "nconc" "nconcing"
|
|
|
|
;; "concat" "vconcat"] form
|
|
|
|
;; [&optional ["into" loop-var]]]
|
|
|
|
|
|
|
|
;; [[&or "count" "counting"
|
|
|
|
;; "sum" "summing"
|
|
|
|
;; "maximize" "maximizing"
|
|
|
|
;; "minimize" "minimizing"] form
|
|
|
|
;; [&optional ["into" loop-var]]
|
|
|
|
;; loop-type-spec]
|
|
|
|
|
|
|
|
;; [[&or "if" "when" "unless"]
|
|
|
|
;; form loop-and-clause
|
|
|
|
;; [&optional ["else" loop-and-clause]]
|
|
|
|
;; [&optional "end"]]
|
|
|
|
|
|
|
|
;; [[&or "do" "doing"] &rest loop-non-atomic-expr]
|
|
|
|
|
|
|
|
;; ["return" form]
|
|
|
|
;; loop-initial-final
|
|
|
|
;; ))
|
|
|
|
|
|
|
|
;; (def-edebug-spec loop-non-atomic-expr
|
|
|
|
;; ([¬ atom] form))
|
|
|
|
|
|
|
|
;; (def-edebug-spec loop-var
|
|
|
|
;; ;; The symbolp must be last alternative to recognize e.g. (a b . c)
|
|
|
|
;; ;; loop-var =>
|
|
|
|
;; ;; (loop-var . [&or nil loop-var])
|
|
|
|
;; ;; (symbolp . [&or nil loop-var])
|
|
|
|
;; ;; (symbolp . loop-var)
|
|
|
|
;; ;; (symbolp . (symbolp . [&or nil loop-var]))
|
|
|
|
;; ;; (symbolp . (symbolp . loop-var))
|
|
|
|
;; ;; (symbolp . (symbolp . symbolp)) == (symbolp symbolp . symbolp)
|
|
|
|
;; (&or (loop-var . [&or nil loop-var]) [gate symbolp]))
|
|
|
|
|
|
|
|
;; (def-edebug-spec loop-type-spec
|
|
|
|
;; (&optional ["of-type" loop-d-type-spec]))
|
|
|
|
|
|
|
|
;; (def-edebug-spec loop-d-type-spec
|
|
|
|
;; (&or (loop-d-type-spec . [&or nil loop-d-type-spec]) cl-type-spec))
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-11-05 00:34:45 -07:00
|
|
|
(defun cl-parse-loop-clause () ; uses loop-*
|
2012-06-07 15:25:48 -04:00
|
|
|
(let ((word (pop cl--loop-args))
|
1993-07-30 20:15:09 +00:00
|
|
|
(hash-types '(hash-key hash-keys hash-value hash-values))
|
|
|
|
(key-types '(key-code key-codes key-seq key-seqs
|
|
|
|
key-binding key-bindings)))
|
|
|
|
(cond
|
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
((null cl--loop-args)
|
2012-06-03 21:05:17 -04:00
|
|
|
(error "Malformed `cl-loop' macro"))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((eq word 'named)
|
2012-06-07 15:25:48 -04:00
|
|
|
(setq cl--loop-name (pop cl--loop-args)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((eq word 'initially)
|
2012-06-07 15:25:48 -04:00
|
|
|
(if (memq (car cl--loop-args) '(do doing)) (pop cl--loop-args))
|
|
|
|
(or (consp (car cl--loop-args)) (error "Syntax error on `initially' clause"))
|
|
|
|
(while (consp (car cl--loop-args))
|
|
|
|
(push (pop cl--loop-args) cl--loop-initially)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((eq word 'finally)
|
2012-06-07 15:25:48 -04:00
|
|
|
(if (eq (car cl--loop-args) 'return)
|
|
|
|
(setq cl--loop-result-explicit (or (cl-pop2 cl--loop-args) '(quote nil)))
|
|
|
|
(if (memq (car cl--loop-args) '(do doing)) (pop cl--loop-args))
|
|
|
|
(or (consp (car cl--loop-args)) (error "Syntax error on `finally' clause"))
|
|
|
|
(if (and (eq (caar cl--loop-args) 'return) (null cl--loop-name))
|
|
|
|
(setq cl--loop-result-explicit (or (nth 1 (pop cl--loop-args)) '(quote nil)))
|
|
|
|
(while (consp (car cl--loop-args))
|
|
|
|
(push (pop cl--loop-args) cl--loop-finally)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((memq word '(for as))
|
|
|
|
(let ((loop-for-bindings nil) (loop-for-sets nil) (loop-for-steps nil)
|
|
|
|
(ands nil))
|
|
|
|
(while
|
2012-06-03 21:05:17 -04:00
|
|
|
;; Use `cl-gensym' rather than `make-symbol'. It's important that
|
2004-11-27 00:20:38 +00:00
|
|
|
;; (not (eq (symbol-name var1) (symbol-name var2))) because
|
2012-06-07 15:25:48 -04:00
|
|
|
;; these vars get added to the macro-environment.
|
|
|
|
(let ((var (or (pop cl--loop-args) (cl-gensym "--cl-var--"))))
|
|
|
|
(setq word (pop cl--loop-args))
|
|
|
|
(if (eq word 'being) (setq word (pop cl--loop-args)))
|
|
|
|
(if (memq word '(the each)) (setq word (pop cl--loop-args)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (memq word '(buffer buffers))
|
2012-06-07 15:25:48 -04:00
|
|
|
(setq word 'in cl--loop-args (cons '(buffer-list) cl--loop-args)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(cond
|
|
|
|
|
|
|
|
((memq word '(from downfrom upfrom to downto upto
|
|
|
|
above below by))
|
2012-06-07 15:25:48 -04:00
|
|
|
(push word cl--loop-args)
|
|
|
|
(if (memq (car cl--loop-args) '(downto above))
|
2012-06-03 21:05:17 -04:00
|
|
|
(error "Must specify `from' value for downward cl-loop"))
|
2012-06-07 15:25:48 -04:00
|
|
|
(let* ((down (or (eq (car cl--loop-args) 'downfrom)
|
|
|
|
(memq (cl-caddr cl--loop-args) '(downto above))))
|
|
|
|
(excl (or (memq (car cl--loop-args) '(above below))
|
|
|
|
(memq (cl-caddr cl--loop-args) '(above below))))
|
|
|
|
(start (and (memq (car cl--loop-args) '(from upfrom downfrom))
|
|
|
|
(cl-pop2 cl--loop-args)))
|
|
|
|
(end (and (memq (car cl--loop-args)
|
1993-07-30 20:15:09 +00:00
|
|
|
'(to upto downto above below))
|
2012-06-07 15:25:48 -04:00
|
|
|
(cl-pop2 cl--loop-args)))
|
|
|
|
(step (and (eq (car cl--loop-args) 'by) (cl-pop2 cl--loop-args)))
|
|
|
|
(end-var (and (not (macroexp-const-p end))
|
2004-11-16 04:05:29 +00:00
|
|
|
(make-symbol "--cl-var--")))
|
2012-06-07 15:25:48 -04:00
|
|
|
(step-var (and (not (macroexp-const-p step))
|
2004-11-16 04:05:29 +00:00
|
|
|
(make-symbol "--cl-var--"))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(and step (numberp step) (<= step 0)
|
|
|
|
(error "Loop `by' value is not positive: %s" step))
|
2002-09-27 23:16:27 +00:00
|
|
|
(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)
|
2004-11-16 04:05:29 +00:00
|
|
|
loop-for-bindings))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if end
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (list
|
2004-11-16 04:05:29 +00:00
|
|
|
(if down (if excl '> '>=) (if excl '< '<=))
|
2012-06-07 15:25:48 -04:00
|
|
|
var (or end-var end)) cl--loop-body))
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (list var (list (if down '- '+) var
|
2004-11-16 04:05:29 +00:00
|
|
|
(or step-var step 1)))
|
|
|
|
loop-for-steps)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((memq word '(in in-ref on))
|
|
|
|
(let* ((on (eq word 'on))
|
2004-11-16 04:05:29 +00:00
|
|
|
(temp (if (and on (symbolp var))
|
|
|
|
var (make-symbol "--cl-var--"))))
|
2012-06-07 15:25:48 -04:00
|
|
|
(push (list temp (pop cl--loop-args)) loop-for-bindings)
|
|
|
|
(push `(consp ,temp) cl--loop-body)
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (eq word 'in-ref)
|
2012-06-07 15:25:48 -04:00
|
|
|
(push (list var `(car ,temp)) cl--loop-symbol-macs)
|
1993-07-30 20:15:09 +00:00
|
|
|
(or (eq temp var)
|
|
|
|
(progn
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (list var nil) loop-for-bindings)
|
2012-06-01 16:36:00 -04:00
|
|
|
(push (list var (if on temp `(car ,temp)))
|
2004-11-16 04:05:29 +00:00
|
|
|
loop-for-sets))))
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (list temp
|
2012-06-07 15:25:48 -04:00
|
|
|
(if (eq (car cl--loop-args) 'by)
|
|
|
|
(let ((step (cl-pop2 cl--loop-args)))
|
2004-11-16 04:05:29 +00:00
|
|
|
(if (and (memq (car-safe step)
|
|
|
|
'(quote function
|
2012-06-03 21:05:17 -04:00
|
|
|
cl-function))
|
2004-11-16 04:05:29 +00:00
|
|
|
(symbolp (nth 1 step)))
|
|
|
|
(list (nth 1 step) temp)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(funcall ,step ,temp)))
|
|
|
|
`(cdr ,temp)))
|
2004-11-16 04:05:29 +00:00
|
|
|
loop-for-steps)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((eq word '=)
|
2012-06-07 15:25:48 -04:00
|
|
|
(let* ((start (pop cl--loop-args))
|
|
|
|
(then (if (eq (car cl--loop-args) 'then) (cl-pop2 cl--loop-args) start)))
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (list var nil) loop-for-bindings)
|
2012-06-07 15:25:48 -04:00
|
|
|
(if (or ands (eq (car cl--loop-args) 'and))
|
1993-07-30 20:15:09 +00:00
|
|
|
(progn
|
2004-11-16 04:05:29 +00:00
|
|
|
(push `(,var
|
2012-06-07 15:25:48 -04:00
|
|
|
(if ,(or cl--loop-first-flag
|
|
|
|
(setq cl--loop-first-flag
|
2004-11-16 04:05:29 +00:00
|
|
|
(make-symbol "--cl-var--")))
|
|
|
|
,start ,var))
|
|
|
|
loop-for-sets)
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (list var then) loop-for-steps))
|
|
|
|
(push (list var
|
2004-11-16 04:05:29 +00:00
|
|
|
(if (eq start then) start
|
2012-06-07 15:25:48 -04:00
|
|
|
`(if ,(or cl--loop-first-flag
|
|
|
|
(setq cl--loop-first-flag
|
2004-11-16 04:05:29 +00:00
|
|
|
(make-symbol "--cl-var--")))
|
|
|
|
,start ,then)))
|
|
|
|
loop-for-sets))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((memq word '(across across-ref))
|
2004-11-16 04:05:29 +00:00
|
|
|
(let ((temp-vec (make-symbol "--cl-vec--"))
|
|
|
|
(temp-idx (make-symbol "--cl-idx--")))
|
2012-06-07 15:25:48 -04:00
|
|
|
(push (list temp-vec (pop cl--loop-args)) loop-for-bindings)
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (list temp-idx -1) loop-for-bindings)
|
2012-06-01 16:36:00 -04:00
|
|
|
(push `(< (setq ,temp-idx (1+ ,temp-idx))
|
2012-06-07 15:25:48 -04:00
|
|
|
(length ,temp-vec)) cl--loop-body)
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (eq word 'across-ref)
|
2012-06-01 16:36:00 -04:00
|
|
|
(push (list var `(aref ,temp-vec ,temp-idx))
|
2012-06-07 15:25:48 -04:00
|
|
|
cl--loop-symbol-macs)
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (list var nil) loop-for-bindings)
|
2012-06-01 16:36:00 -04:00
|
|
|
(push (list var `(aref ,temp-vec ,temp-idx))
|
2004-11-16 04:05:29 +00:00
|
|
|
loop-for-sets))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((memq word '(element elements))
|
2012-06-07 15:25:48 -04:00
|
|
|
(let ((ref (or (memq (car cl--loop-args) '(in-ref of-ref))
|
|
|
|
(and (not (memq (car cl--loop-args) '(in of)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(error "Expected `of'"))))
|
2012-06-07 15:25:48 -04:00
|
|
|
(seq (cl-pop2 cl--loop-args))
|
2004-11-16 04:05:29 +00:00
|
|
|
(temp-seq (make-symbol "--cl-seq--"))
|
2012-06-07 15:25:48 -04:00
|
|
|
(temp-idx (if (eq (car cl--loop-args) 'using)
|
|
|
|
(if (and (= (length (cadr cl--loop-args)) 2)
|
|
|
|
(eq (cl-caadr cl--loop-args) 'index))
|
|
|
|
(cadr (cl-pop2 cl--loop-args))
|
1993-07-30 20:15:09 +00:00
|
|
|
(error "Bad `using' clause"))
|
2004-11-16 04:05:29 +00:00
|
|
|
(make-symbol "--cl-idx--"))))
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (list temp-seq seq) loop-for-bindings)
|
|
|
|
(push (list temp-idx 0) loop-for-bindings)
|
1993-07-30 20:15:09 +00:00
|
|
|
(if ref
|
2004-11-16 04:05:29 +00:00
|
|
|
(let ((temp-len (make-symbol "--cl-len--")))
|
2012-06-01 16:36:00 -04:00
|
|
|
(push (list temp-len `(length ,temp-seq))
|
2004-11-16 04:05:29 +00:00
|
|
|
loop-for-bindings)
|
2012-06-11 16:47:33 -04:00
|
|
|
(push (list var `(elt ,temp-seq ,temp-idx))
|
2012-06-07 15:25:48 -04:00
|
|
|
cl--loop-symbol-macs)
|
|
|
|
(push `(< ,temp-idx ,temp-len) cl--loop-body))
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (list var nil) loop-for-bindings)
|
2012-06-01 16:36:00 -04:00
|
|
|
(push `(and ,temp-seq
|
|
|
|
(or (consp ,temp-seq)
|
|
|
|
(< ,temp-idx (length ,temp-seq))))
|
2012-06-07 15:25:48 -04:00
|
|
|
cl--loop-body)
|
2012-06-01 16:36:00 -04:00
|
|
|
(push (list var `(if (consp ,temp-seq)
|
|
|
|
(pop ,temp-seq)
|
|
|
|
(aref ,temp-seq ,temp-idx)))
|
2004-11-16 04:05:29 +00:00
|
|
|
loop-for-sets))
|
2012-06-01 16:36:00 -04:00
|
|
|
(push (list temp-idx `(1+ ,temp-idx))
|
2004-11-16 04:05:29 +00:00
|
|
|
loop-for-steps)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((memq word hash-types)
|
2012-06-07 15:25:48 -04:00
|
|
|
(or (memq (car cl--loop-args) '(in of)) (error "Expected `of'"))
|
|
|
|
(let* ((table (cl-pop2 cl--loop-args))
|
|
|
|
(other (if (eq (car cl--loop-args) 'using)
|
|
|
|
(if (and (= (length (cadr cl--loop-args)) 2)
|
|
|
|
(memq (cl-caadr cl--loop-args) hash-types)
|
|
|
|
(not (eq (cl-caadr cl--loop-args) word)))
|
|
|
|
(cadr (cl-pop2 cl--loop-args))
|
1993-07-30 20:15:09 +00:00
|
|
|
(error "Bad `using' clause"))
|
2004-11-16 04:05:29 +00:00
|
|
|
(make-symbol "--cl-var--"))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (memq word '(hash-value hash-values))
|
|
|
|
(setq var (prog1 other (setq other var))))
|
2012-06-07 15:25:48 -04:00
|
|
|
(setq cl--loop-map-form
|
2004-11-16 04:05:29 +00:00
|
|
|
`(maphash (lambda (,var ,other) . --cl-map) ,table))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((memq word '(symbol present-symbol external-symbol
|
|
|
|
symbols present-symbols external-symbols))
|
2012-06-07 15:25:48 -04:00
|
|
|
(let ((ob (and (memq (car cl--loop-args) '(in of)) (cl-pop2 cl--loop-args))))
|
|
|
|
(setq cl--loop-map-form
|
2004-11-16 04:05:29 +00:00
|
|
|
`(mapatoms (lambda (,var) . --cl-map) ,ob))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((memq word '(overlay overlays extent extents))
|
|
|
|
(let ((buf nil) (from nil) (to nil))
|
2012-06-07 15:25:48 -04:00
|
|
|
(while (memq (car cl--loop-args) '(in of from to))
|
|
|
|
(cond ((eq (car cl--loop-args) 'from) (setq from (cl-pop2 cl--loop-args)))
|
|
|
|
((eq (car cl--loop-args) 'to) (setq to (cl-pop2 cl--loop-args)))
|
|
|
|
(t (setq buf (cl-pop2 cl--loop-args)))))
|
|
|
|
(setq cl--loop-map-form
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
`(cl--map-overlays
|
2004-11-16 04:05:29 +00:00
|
|
|
(lambda (,var ,(make-symbol "--cl-var--"))
|
|
|
|
(progn . --cl-map) nil)
|
|
|
|
,buf ,from ,to))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((memq word '(interval intervals))
|
|
|
|
(let ((buf nil) (prop nil) (from nil) (to nil)
|
2004-11-16 04:05:29 +00:00
|
|
|
(var1 (make-symbol "--cl-var1--"))
|
|
|
|
(var2 (make-symbol "--cl-var2--")))
|
2012-06-07 15:25:48 -04:00
|
|
|
(while (memq (car cl--loop-args) '(in of property from to))
|
|
|
|
(cond ((eq (car cl--loop-args) 'from) (setq from (cl-pop2 cl--loop-args)))
|
|
|
|
((eq (car cl--loop-args) 'to) (setq to (cl-pop2 cl--loop-args)))
|
|
|
|
((eq (car cl--loop-args) 'property)
|
|
|
|
(setq prop (cl-pop2 cl--loop-args)))
|
|
|
|
(t (setq buf (cl-pop2 cl--loop-args)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (and (consp var) (symbolp (car var)) (symbolp (cdr var)))
|
|
|
|
(setq var1 (car var) var2 (cdr var))
|
2012-06-01 16:36:00 -04:00
|
|
|
(push (list var `(cons ,var1 ,var2)) loop-for-sets))
|
2012-06-07 15:25:48 -04:00
|
|
|
(setq cl--loop-map-form
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
`(cl--map-intervals
|
2004-11-16 04:05:29 +00:00
|
|
|
(lambda (,var1 ,var2) . --cl-map)
|
|
|
|
,buf ,prop ,from ,to))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((memq word key-types)
|
2012-06-07 15:25:48 -04:00
|
|
|
(or (memq (car cl--loop-args) '(in of)) (error "Expected `of'"))
|
|
|
|
(let ((cl-map (cl-pop2 cl--loop-args))
|
|
|
|
(other (if (eq (car cl--loop-args) 'using)
|
|
|
|
(if (and (= (length (cadr cl--loop-args)) 2)
|
|
|
|
(memq (cl-caadr cl--loop-args) key-types)
|
|
|
|
(not (eq (cl-caadr cl--loop-args) word)))
|
|
|
|
(cadr (cl-pop2 cl--loop-args))
|
1993-07-30 20:15:09 +00:00
|
|
|
(error "Bad `using' clause"))
|
2004-11-16 04:05:29 +00:00
|
|
|
(make-symbol "--cl-var--"))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (memq word '(key-binding key-bindings))
|
|
|
|
(setq var (prog1 other (setq other var))))
|
2012-06-07 15:25:48 -04:00
|
|
|
(setq cl--loop-map-form
|
2004-11-16 04:05:29 +00:00
|
|
|
`(,(if (memq word '(key-seq key-seqs))
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
'cl--map-keymap-recursively 'map-keymap)
|
2012-06-03 21:05:17 -04:00
|
|
|
(lambda (,var ,other) . --cl-map) ,cl-map))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((memq word '(frame frames screen screens))
|
2004-11-16 04:05:29 +00:00
|
|
|
(let ((temp (make-symbol "--cl-var--")))
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (list var '(selected-frame))
|
2004-11-16 04:05:29 +00:00
|
|
|
loop-for-bindings)
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (list temp nil) loop-for-bindings)
|
2012-06-01 16:36:00 -04:00
|
|
|
(push `(prog1 (not (eq ,var ,temp))
|
|
|
|
(or ,temp (setq ,temp ,var)))
|
2012-06-07 15:25:48 -04:00
|
|
|
cl--loop-body)
|
2012-06-01 16:36:00 -04:00
|
|
|
(push (list var `(next-frame ,var))
|
2004-11-16 04:05:29 +00:00
|
|
|
loop-for-steps)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((memq word '(window windows))
|
2012-06-07 15:25:48 -04:00
|
|
|
(let ((scr (and (memq (car cl--loop-args) '(in of)) (cl-pop2 cl--loop-args)))
|
2010-12-02 09:36:45 -08:00
|
|
|
(temp (make-symbol "--cl-var--"))
|
|
|
|
(minip (make-symbol "--cl-minip--")))
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (list var (if scr
|
2012-06-01 16:36:00 -04:00
|
|
|
`(frame-selected-window ,scr)
|
2004-11-16 04:05:29 +00:00
|
|
|
'(selected-window)))
|
|
|
|
loop-for-bindings)
|
2010-12-02 09:36:45 -08:00
|
|
|
;; If we started in the minibuffer, we need to
|
|
|
|
;; ensure that next-window will bring us back there
|
|
|
|
;; at some point. (Bug#7492).
|
2012-06-03 21:05:17 -04:00
|
|
|
;; (Consider using walk-windows instead of cl-loop if
|
2010-12-02 09:36:45 -08:00
|
|
|
;; you care about such things.)
|
|
|
|
(push (list minip `(minibufferp (window-buffer ,var)))
|
|
|
|
loop-for-bindings)
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (list temp nil) loop-for-bindings)
|
2012-06-01 16:36:00 -04:00
|
|
|
(push `(prog1 (not (eq ,var ,temp))
|
|
|
|
(or ,temp (setq ,temp ,var)))
|
2012-06-07 15:25:48 -04:00
|
|
|
cl--loop-body)
|
2012-06-01 16:36:00 -04:00
|
|
|
(push (list var `(next-window ,var ,minip))
|
2010-12-02 09:36:45 -08:00
|
|
|
loop-for-steps)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
(t
|
|
|
|
(let ((handler (and (symbolp word)
|
2012-06-07 15:25:48 -04:00
|
|
|
(get word 'cl--loop-for-handler))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if handler
|
|
|
|
(funcall handler var)
|
|
|
|
(error "Expected a `for' preposition, found %s" word)))))
|
2012-06-07 15:25:48 -04:00
|
|
|
(eq (car cl--loop-args) 'and))
|
1993-07-30 20:15:09 +00:00
|
|
|
(setq ands t)
|
2012-06-07 15:25:48 -04:00
|
|
|
(pop cl--loop-args))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (and ands loop-for-bindings)
|
2012-06-07 15:25:48 -04:00
|
|
|
(push (nreverse loop-for-bindings) cl--loop-bindings)
|
|
|
|
(setq cl--loop-bindings (nconc (mapcar 'list loop-for-bindings)
|
|
|
|
cl--loop-bindings)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if loop-for-sets
|
2012-06-01 16:36:00 -04:00
|
|
|
(push `(progn
|
2012-06-07 15:25:48 -04:00
|
|
|
,(cl--loop-let (nreverse loop-for-sets) 'setq ands)
|
|
|
|
t) cl--loop-body))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if loop-for-steps
|
2012-06-03 21:05:17 -04:00
|
|
|
(push (cons (if ands 'cl-psetq 'setq)
|
2004-11-16 04:05:29 +00:00
|
|
|
(apply 'append (nreverse loop-for-steps)))
|
2012-06-07 15:25:48 -04:00
|
|
|
cl--loop-steps))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((eq word 'repeat)
|
2004-11-16 04:05:29 +00:00
|
|
|
(let ((temp (make-symbol "--cl-var--")))
|
2012-06-07 15:25:48 -04:00
|
|
|
(push (list (list temp (pop cl--loop-args))) cl--loop-bindings)
|
|
|
|
(push `(>= (setq ,temp (1- ,temp)) 0) cl--loop-body)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2000-01-28 17:31:00 +00:00
|
|
|
((memq word '(collect collecting))
|
2012-06-07 15:25:48 -04:00
|
|
|
(let ((what (pop cl--loop-args))
|
|
|
|
(var (cl--loop-handle-accum nil 'nreverse)))
|
|
|
|
(if (eq var cl--loop-accum-var)
|
|
|
|
(push `(progn (push ,what ,var) t) cl--loop-body)
|
2012-06-01 16:36:00 -04:00
|
|
|
(push `(progn
|
|
|
|
(setq ,var (nconc ,var (list ,what)))
|
2012-06-07 15:25:48 -04:00
|
|
|
t) cl--loop-body))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((memq word '(nconc nconcing append appending))
|
2012-06-07 15:25:48 -04:00
|
|
|
(let ((what (pop cl--loop-args))
|
|
|
|
(var (cl--loop-handle-accum nil 'nreverse)))
|
2012-06-01 16:36:00 -04:00
|
|
|
(push `(progn
|
|
|
|
(setq ,var
|
2012-06-07 15:25:48 -04:00
|
|
|
,(if (eq var cl--loop-accum-var)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(nconc
|
|
|
|
(,(if (memq word '(nconc nconcing))
|
|
|
|
#'nreverse #'reverse)
|
|
|
|
,what)
|
|
|
|
,var)
|
|
|
|
`(,(if (memq word '(nconc nconcing))
|
|
|
|
#'nconc #'append)
|
2012-06-07 15:25:48 -04:00
|
|
|
,var ,what))) t) cl--loop-body)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((memq word '(concat concating))
|
2012-06-07 15:25:48 -04:00
|
|
|
(let ((what (pop cl--loop-args))
|
|
|
|
(var (cl--loop-handle-accum "")))
|
|
|
|
(push `(progn (cl-callf concat ,var ,what) t) cl--loop-body)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((memq word '(vconcat vconcating))
|
2012-06-07 15:25:48 -04:00
|
|
|
(let ((what (pop cl--loop-args))
|
|
|
|
(var (cl--loop-handle-accum [])))
|
|
|
|
(push `(progn (cl-callf vconcat ,var ,what) t) cl--loop-body)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((memq word '(sum summing))
|
2012-06-07 15:25:48 -04:00
|
|
|
(let ((what (pop cl--loop-args))
|
|
|
|
(var (cl--loop-handle-accum 0)))
|
|
|
|
(push `(progn (cl-incf ,var ,what) t) cl--loop-body)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((memq word '(count counting))
|
2012-06-07 15:25:48 -04:00
|
|
|
(let ((what (pop cl--loop-args))
|
|
|
|
(var (cl--loop-handle-accum 0)))
|
|
|
|
(push `(progn (if ,what (cl-incf ,var)) t) cl--loop-body)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((memq word '(minimize minimizing maximize maximizing))
|
2012-06-07 15:25:48 -04:00
|
|
|
(let* ((what (pop cl--loop-args))
|
|
|
|
(temp (if (cl--simple-expr-p what) what (make-symbol "--cl-var--")))
|
|
|
|
(var (cl--loop-handle-accum nil))
|
1993-07-30 20:15:09 +00:00
|
|
|
(func (intern (substring (symbol-name word) 0 3)))
|
2012-06-01 16:36:00 -04:00
|
|
|
(set `(setq ,var (if ,var (,func ,var ,temp) ,temp))))
|
|
|
|
(push `(progn ,(if (eq temp what) set
|
|
|
|
`(let ((,temp ,what)) ,set))
|
2012-06-07 15:25:48 -04:00
|
|
|
t) cl--loop-body)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((eq word 'with)
|
|
|
|
(let ((bindings nil))
|
2012-06-07 15:25:48 -04:00
|
|
|
(while (progn (push (list (pop cl--loop-args)
|
|
|
|
(and (eq (car cl--loop-args) '=) (cl-pop2 cl--loop-args)))
|
2004-11-16 04:05:29 +00:00
|
|
|
bindings)
|
2012-06-07 15:25:48 -04:00
|
|
|
(eq (car cl--loop-args) 'and))
|
|
|
|
(pop cl--loop-args))
|
|
|
|
(push (nreverse bindings) cl--loop-bindings)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((eq word 'while)
|
2012-06-07 15:25:48 -04:00
|
|
|
(push (pop cl--loop-args) cl--loop-body))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((eq word 'until)
|
2012-06-07 15:25:48 -04:00
|
|
|
(push `(not ,(pop cl--loop-args)) cl--loop-body))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((eq word 'always)
|
2012-06-07 15:25:48 -04:00
|
|
|
(or cl--loop-finish-flag (setq cl--loop-finish-flag (make-symbol "--cl-flag--")))
|
|
|
|
(push `(setq ,cl--loop-finish-flag ,(pop cl--loop-args)) cl--loop-body)
|
|
|
|
(setq cl--loop-result t))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((eq word 'never)
|
2012-06-07 15:25:48 -04:00
|
|
|
(or cl--loop-finish-flag (setq cl--loop-finish-flag (make-symbol "--cl-flag--")))
|
|
|
|
(push `(setq ,cl--loop-finish-flag (not ,(pop cl--loop-args)))
|
|
|
|
cl--loop-body)
|
|
|
|
(setq cl--loop-result t))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((eq word 'thereis)
|
2012-06-07 15:25:48 -04:00
|
|
|
(or cl--loop-finish-flag (setq cl--loop-finish-flag (make-symbol "--cl-flag--")))
|
|
|
|
(or cl--loop-result-var (setq cl--loop-result-var (make-symbol "--cl-var--")))
|
|
|
|
(push `(setq ,cl--loop-finish-flag
|
|
|
|
(not (setq ,cl--loop-result-var ,(pop cl--loop-args))))
|
|
|
|
cl--loop-body))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((memq word '(if when unless))
|
2012-06-07 15:25:48 -04:00
|
|
|
(let* ((cond (pop cl--loop-args))
|
|
|
|
(then (let ((cl--loop-body nil))
|
1993-07-30 20:15:09 +00:00
|
|
|
(cl-parse-loop-clause)
|
2012-06-07 15:25:48 -04:00
|
|
|
(cl--loop-build-ands (nreverse cl--loop-body))))
|
|
|
|
(else (let ((cl--loop-body nil))
|
|
|
|
(if (eq (car cl--loop-args) 'else)
|
|
|
|
(progn (pop cl--loop-args) (cl-parse-loop-clause)))
|
|
|
|
(cl--loop-build-ands (nreverse cl--loop-body))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(simple (and (eq (car then) t) (eq (car else) t))))
|
2012-06-07 15:25:48 -04:00
|
|
|
(if (eq (car cl--loop-args) 'end) (pop cl--loop-args))
|
1993-07-30 20:15:09 +00:00
|
|
|
(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))))))
|
2012-06-07 15:25:48 -04:00
|
|
|
(if (cl--expr-contains form 'it)
|
2004-11-16 04:05:29 +00:00
|
|
|
(let ((temp (make-symbol "--cl-var--")))
|
2012-06-07 15:25:48 -04:00
|
|
|
(push (list temp) cl--loop-bindings)
|
2012-06-01 16:36:00 -04:00
|
|
|
(setq form `(if (setq ,temp ,cond)
|
2012-06-03 21:05:17 -04:00
|
|
|
,@(cl-subst temp 'it form))))
|
2012-06-01 16:36:00 -04:00
|
|
|
(setq form `(if ,cond ,@form)))
|
2012-06-07 15:25:48 -04:00
|
|
|
(push (if simple `(progn ,form t) form) cl--loop-body))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((memq word '(do doing))
|
|
|
|
(let ((body nil))
|
2012-06-07 15:25:48 -04:00
|
|
|
(or (consp (car cl--loop-args)) (error "Syntax error on `do' clause"))
|
|
|
|
(while (consp (car cl--loop-args)) (push (pop cl--loop-args) body))
|
|
|
|
(push (cons 'progn (nreverse (cons t body))) cl--loop-body)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
((eq word 'return)
|
2012-06-07 15:25:48 -04:00
|
|
|
(or cl--loop-finish-flag (setq cl--loop-finish-flag (make-symbol "--cl-var--")))
|
|
|
|
(or cl--loop-result-var (setq cl--loop-result-var (make-symbol "--cl-var--")))
|
|
|
|
(push `(setq ,cl--loop-result-var ,(pop cl--loop-args)
|
|
|
|
,cl--loop-finish-flag nil) cl--loop-body))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
(t
|
2012-06-07 15:25:48 -04:00
|
|
|
(let ((handler (and (symbolp word) (get word 'cl--loop-handler))))
|
2012-06-03 21:05:17 -04:00
|
|
|
(or handler (error "Expected a cl-loop keyword, found %s" word))
|
1993-07-30 20:15:09 +00:00
|
|
|
(funcall handler))))
|
2012-06-07 15:25:48 -04:00
|
|
|
(if (eq (car cl--loop-args) 'and)
|
|
|
|
(progn (pop cl--loop-args) (cl-parse-loop-clause)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
(defun cl--loop-let (specs body par) ; uses loop-*
|
1993-07-30 20:15:09 +00:00
|
|
|
(let ((p specs) (temps nil) (new nil))
|
2012-06-03 21:05:17 -04:00
|
|
|
(while (and p (or (symbolp (car-safe (car p))) (null (cl-cadar p))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(setq p (cdr p)))
|
|
|
|
(and par p
|
|
|
|
(progn
|
|
|
|
(setq par nil p specs)
|
|
|
|
(while p
|
2012-06-07 15:25:48 -04:00
|
|
|
(or (macroexp-const-p (cl-cadar p))
|
2004-11-16 04:05:29 +00:00
|
|
|
(let ((temp (make-symbol "--cl-var--")))
|
2012-06-03 21:05:17 -04:00
|
|
|
(push (list temp (cl-cadar p)) temps)
|
1993-07-30 20:15:09 +00:00
|
|
|
(setcar (cdar p) temp)))
|
|
|
|
(setq p (cdr p)))))
|
|
|
|
(while specs
|
|
|
|
(if (and (consp (car specs)) (listp (caar specs)))
|
|
|
|
(let* ((spec (caar specs)) (nspecs nil)
|
2002-09-27 23:16:27 +00:00
|
|
|
(expr (cadr (pop specs)))
|
2012-06-07 15:25:48 -04:00
|
|
|
(temp (cdr (or (assq spec cl--loop-destr-temps)
|
2002-09-27 23:16:27 +00:00
|
|
|
(car (push (cons spec (or (last spec 0)
|
2004-11-16 04:05:29 +00:00
|
|
|
(make-symbol "--cl-var--")))
|
2012-06-07 15:25:48 -04:00
|
|
|
cl--loop-destr-temps))))))
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (list temp expr) new)
|
1993-07-30 20:15:09 +00:00
|
|
|
(while (consp spec)
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (list (pop spec)
|
1993-07-30 20:15:09 +00:00
|
|
|
(and expr (list (if spec 'pop 'car) temp)))
|
|
|
|
nspecs))
|
|
|
|
(setq specs (nconc (nreverse nspecs) specs)))
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (pop specs) new)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (eq body 'setq)
|
2012-06-03 21:05:17 -04:00
|
|
|
(let ((set (cons (if par 'cl-psetq 'setq) (apply 'nconc (nreverse new)))))
|
2012-06-01 16:36:00 -04:00
|
|
|
(if temps `(let* ,(nreverse temps) ,set) set))
|
|
|
|
`(,(if par 'let 'let*)
|
|
|
|
,(nconc (nreverse temps) (nreverse new)) ,@body))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
(defun cl--loop-handle-accum (def &optional func) ; uses loop-*
|
|
|
|
(if (eq (car cl--loop-args) 'into)
|
|
|
|
(let ((var (cl-pop2 cl--loop-args)))
|
|
|
|
(or (memq var cl--loop-accum-vars)
|
|
|
|
(progn (push (list (list var def)) cl--loop-bindings)
|
|
|
|
(push var cl--loop-accum-vars)))
|
1993-07-30 20:15:09 +00:00
|
|
|
var)
|
2012-06-07 15:25:48 -04:00
|
|
|
(or cl--loop-accum-var
|
1993-07-30 20:15:09 +00:00
|
|
|
(progn
|
2012-06-07 15:25:48 -04:00
|
|
|
(push (list (list (setq cl--loop-accum-var (make-symbol "--cl-var--")) def))
|
|
|
|
cl--loop-bindings)
|
|
|
|
(setq cl--loop-result (if func (list func cl--loop-accum-var)
|
|
|
|
cl--loop-accum-var))
|
|
|
|
cl--loop-accum-var))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
(defun cl--loop-build-ands (clauses)
|
1993-07-30 20:15:09 +00:00
|
|
|
(let ((ands nil)
|
|
|
|
(body nil))
|
|
|
|
(while clauses
|
|
|
|
(if (and (eq (car-safe (car clauses)) 'progn)
|
|
|
|
(eq (car (last (car clauses))) t))
|
|
|
|
(if (cdr clauses)
|
|
|
|
(setq clauses (cons (nconc (butlast (car clauses))
|
|
|
|
(if (eq (car-safe (cadr clauses))
|
|
|
|
'progn)
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-cdadr clauses)
|
1993-07-30 20:15:09 +00:00
|
|
|
(list (cadr clauses))))
|
|
|
|
(cddr clauses)))
|
2002-09-27 23:16:27 +00:00
|
|
|
(setq body (cdr (butlast (pop clauses)))))
|
|
|
|
(push (pop clauses) ands)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(setq ands (or (nreverse ands) (list t)))
|
|
|
|
(list (if (cdr ands) (cons 'and ands) (car ands))
|
|
|
|
body
|
|
|
|
(let ((full (if body
|
|
|
|
(append ands (list (cons 'progn (append body '(t)))))
|
|
|
|
ands)))
|
|
|
|
(if (cdr full) (cons 'and full) (car full))))))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Other iteration control structures.
|
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-do (steps endtest &rest body)
|
|
|
|
"The Common Lisp `cl-do' loop.
|
2004-05-08 17:23:08 +00:00
|
|
|
|
|
|
|
\(fn ((VAR INIT [STEP])...) (END-TEST [RESULT...]) BODY...)"
|
2012-05-17 17:51:15 -04:00
|
|
|
(declare (indent 2)
|
|
|
|
(debug
|
2012-05-17 17:39:36 -04:00
|
|
|
((&rest &or symbolp (symbolp &optional form form))
|
|
|
|
(form body)
|
|
|
|
cl-declarations body)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(cl-expand-do-loop steps endtest body nil))
|
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-do* (steps endtest &rest body)
|
|
|
|
"The Common Lisp `cl-do*' loop.
|
2004-05-08 17:23:08 +00:00
|
|
|
|
|
|
|
\(fn ((VAR INIT [STEP])...) (END-TEST [RESULT...]) BODY...)"
|
2012-06-03 21:05:17 -04:00
|
|
|
(declare (indent 2) (debug cl-do))
|
1993-07-30 20:15:09 +00:00
|
|
|
(cl-expand-do-loop steps endtest body t))
|
|
|
|
|
|
|
|
(defun cl-expand-do-loop (steps endtest body star)
|
2012-06-03 21:05:17 -04:00
|
|
|
`(cl-block nil
|
2012-06-01 16:36:00 -04:00
|
|
|
(,(if star 'let* 'let)
|
|
|
|
,(mapcar (lambda (c) (if (consp c) (list (car c) (nth 1 c)) c))
|
|
|
|
steps)
|
|
|
|
(while (not ,(car endtest))
|
|
|
|
,@body
|
|
|
|
,@(let ((sets (mapcar (lambda (c)
|
|
|
|
(and (consp c) (cdr (cdr c))
|
|
|
|
(list (car c) (nth 2 c))))
|
|
|
|
steps)))
|
|
|
|
(setq sets (delq nil sets))
|
|
|
|
(and sets
|
|
|
|
(list (cons (if (or star (not (cdr sets)))
|
2012-06-03 21:05:17 -04:00
|
|
|
'setq 'cl-psetq)
|
2012-06-01 16:36:00 -04:00
|
|
|
(apply 'append sets))))))
|
|
|
|
,@(or (cdr endtest) '(nil)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-dolist (spec &rest body)
|
2002-09-27 23:16:27 +00:00
|
|
|
"Loop over a list.
|
2000-01-30 13:19:09 +00:00
|
|
|
Evaluate BODY with VAR bound to each `car' from LIST, in turn.
|
2002-09-27 23:16:27 +00:00
|
|
|
Then evaluate RESULT to get return value, default nil.
|
2011-08-02 20:49:12 +02:00
|
|
|
An implicit nil block is established around the loop.
|
2002-09-27 23:16:27 +00:00
|
|
|
|
|
|
|
\(fn (VAR LIST [RESULT]) BODY...)"
|
2012-05-17 17:39:36 -04:00
|
|
|
(declare (debug ((symbolp form &optional form) cl-declarations body)))
|
2004-11-16 04:05:29 +00:00
|
|
|
(let ((temp (make-symbol "--cl-dolist-temp--")))
|
2011-06-01 11:19:45 -03:00
|
|
|
;; FIXME: Copy&pasted from subr.el.
|
2012-06-03 21:05:17 -04:00
|
|
|
`(cl-block nil
|
2011-06-01 11:19:45 -03:00
|
|
|
;; This is not a reliable test, but it does not matter because both
|
|
|
|
;; semantics are acceptable, tho one is slightly faster with dynamic
|
|
|
|
;; scoping and the other is slightly faster (and has cleaner semantics)
|
|
|
|
;; with lexical scoping.
|
|
|
|
,(if lexical-binding
|
|
|
|
`(let ((,temp ,(nth 1 spec)))
|
|
|
|
(while ,temp
|
|
|
|
(let ((,(car spec) (car ,temp)))
|
|
|
|
,@body
|
|
|
|
(setq ,temp (cdr ,temp))))
|
|
|
|
,@(if (cdr (cdr spec))
|
|
|
|
;; FIXME: This let often leads to "unused var" warnings.
|
|
|
|
`((let ((,(car spec) nil)) ,@(cdr (cdr spec))))))
|
|
|
|
`(let ((,temp ,(nth 1 spec))
|
|
|
|
,(car spec))
|
|
|
|
(while ,temp
|
|
|
|
(setq ,(car spec) (car ,temp))
|
|
|
|
,@body
|
|
|
|
(setq ,temp (cdr ,temp)))
|
|
|
|
,@(if (cdr (cdr spec))
|
|
|
|
`((setq ,(car spec) nil) ,@(cddr spec))))))))
|
2000-01-30 13:19:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-dotimes (spec &rest body)
|
2002-09-27 23:16:27 +00:00
|
|
|
"Loop a certain number of times.
|
2000-01-30 13:19:09 +00:00
|
|
|
Evaluate BODY with VAR bound to successive integers from 0, inclusive,
|
|
|
|
to COUNT, exclusive. Then evaluate RESULT to get return value, default
|
2002-09-27 23:16:27 +00:00
|
|
|
nil.
|
|
|
|
|
|
|
|
\(fn (VAR COUNT [RESULT]) BODY...)"
|
2012-06-03 21:05:17 -04:00
|
|
|
(declare (debug cl-dolist))
|
2011-06-01 11:19:45 -03:00
|
|
|
(let ((temp (make-symbol "--cl-dotimes-temp--"))
|
|
|
|
(end (nth 1 spec)))
|
|
|
|
;; FIXME: Copy&pasted from subr.el.
|
2012-06-03 21:05:17 -04:00
|
|
|
`(cl-block nil
|
2011-06-01 11:19:45 -03:00
|
|
|
;; This is not a reliable test, but it does not matter because both
|
|
|
|
;; semantics are acceptable, tho one is slightly faster with dynamic
|
|
|
|
;; scoping and the other has cleaner semantics.
|
|
|
|
,(if lexical-binding
|
|
|
|
(let ((counter '--dotimes-counter--))
|
|
|
|
`(let ((,temp ,end)
|
|
|
|
(,counter 0))
|
|
|
|
(while (< ,counter ,temp)
|
|
|
|
(let ((,(car spec) ,counter))
|
|
|
|
,@body)
|
|
|
|
(setq ,counter (1+ ,counter)))
|
|
|
|
,@(if (cddr spec)
|
|
|
|
;; FIXME: This let often leads to "unused var" warnings.
|
|
|
|
`((let ((,(car spec) ,counter)) ,@(cddr spec))))))
|
|
|
|
`(let ((,temp ,end)
|
|
|
|
(,(car spec) 0))
|
|
|
|
(while (< ,(car spec) ,temp)
|
|
|
|
,@body
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-incf ,(car spec)))
|
2011-06-01 11:19:45 -03:00
|
|
|
,@(cdr (cdr spec)))))))
|
2000-01-30 13:19:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-do-symbols (spec &rest body)
|
2002-09-27 23:16:27 +00:00
|
|
|
"Loop over all symbols.
|
1993-07-30 20:15:09 +00:00
|
|
|
Evaluate BODY with VAR bound to each interned symbol, or to each symbol
|
2002-09-27 23:16:27 +00:00
|
|
|
from OBARRAY.
|
|
|
|
|
|
|
|
\(fn (VAR [OBARRAY [RESULT]]) BODY...)"
|
2012-05-17 17:51:15 -04:00
|
|
|
(declare (indent 1)
|
|
|
|
(debug ((symbolp &optional form form) cl-declarations body)))
|
1993-07-30 20:15:09 +00:00
|
|
|
;; Apparently this doesn't have an implicit block.
|
2012-06-03 21:05:17 -04:00
|
|
|
`(cl-block nil
|
2012-06-01 16:36:00 -04:00
|
|
|
(let (,(car spec))
|
|
|
|
(mapatoms #'(lambda (,(car spec)) ,@body)
|
|
|
|
,@(and (cadr spec) (list (cadr spec))))
|
2012-06-03 21:05:17 -04:00
|
|
|
,(cl-caddr spec))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-do-all-symbols (spec &rest body)
|
2012-05-17 17:51:15 -04:00
|
|
|
(declare (indent 1) (debug ((symbolp &optional form) cl-declarations body)))
|
2012-06-03 21:05:17 -04:00
|
|
|
`(cl-do-symbols (,(car spec) nil ,(cadr spec)) ,@body))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
;;; Assignments.
|
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-psetq (&rest args)
|
2002-09-27 23:16:27 +00:00
|
|
|
"Set SYMs to the values VALs in parallel.
|
1993-07-30 20:15:09 +00:00
|
|
|
This is like `setq', except that all VAL forms are evaluated (in order)
|
2002-09-27 23:16:27 +00:00
|
|
|
before assigning any symbols SYM to the corresponding values.
|
|
|
|
|
|
|
|
\(fn SYM VAL SYM VAL ...)"
|
2012-05-17 17:39:36 -04:00
|
|
|
(declare (debug setq))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cons 'cl-psetf args))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
;;; Binding control structures.
|
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-progv (symbols values &rest body)
|
2000-05-05 20:01:01 +00:00
|
|
|
"Bind SYMBOLS to VALUES dynamically in BODY.
|
1993-07-30 20:15:09 +00:00
|
|
|
The forms SYMBOLS and VALUES are evaluated, and must evaluate to lists.
|
(function*, case, ecase, typecase, etypecase, progv, lexical-let, lexical-let*,
multiple-value-bind, multiple-value-setq, shiftf): Improve argument/docstring
consistency.
2005-05-22 17:51:22 +00:00
|
|
|
Each symbol in the first list is bound to the corresponding value in the
|
1993-07-30 20:15:09 +00:00
|
|
|
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."
|
2012-05-17 17:51:15 -04:00
|
|
|
(declare (indent 2) (debug (form form body)))
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
`(let ((cl--progv-save nil))
|
2012-06-01 16:36:00 -04:00
|
|
|
(unwind-protect
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(progn (cl--progv-before ,symbols ,values) ,@body)
|
|
|
|
(cl--progv-after))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2012-06-07 22:54:35 -04:00
|
|
|
(defvar cl--labels-convert-cache nil)
|
|
|
|
|
|
|
|
(defun cl--labels-convert (f)
|
|
|
|
"Special macro-expander to rename (function F) references in `cl-labels'."
|
|
|
|
(cond
|
|
|
|
;; ¡¡Big Ugly Hack!! We can't use a compiler-macro because those are checked
|
|
|
|
;; *after* handling `function', but we want to stop macroexpansion from
|
|
|
|
;; being applied infinitely, so we use a cache to return the exact `form'
|
|
|
|
;; being expanded even though we don't receive it.
|
|
|
|
((eq f (car cl--labels-convert-cache)) (cdr cl--labels-convert-cache))
|
|
|
|
(t
|
|
|
|
(let ((found (assq f macroexpand-all-environment)))
|
|
|
|
(if (and found (ignore-errors
|
|
|
|
(eq (cadr (cl-caddr found)) 'cl-labels-args)))
|
|
|
|
(cadr (cl-caddr (cl-cadddr found)))
|
|
|
|
(let ((res `(function ,f)))
|
|
|
|
(setq cl--labels-convert-cache (cons f res))
|
|
|
|
res))))))
|
|
|
|
|
1993-07-30 20:15:09 +00:00
|
|
|
;;; This should really have some way to shadow 'byte-compile properties, etc.
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-flet (bindings &rest body)
|
(function*, case, ecase, typecase, etypecase, progv, lexical-let, lexical-let*,
multiple-value-bind, multiple-value-setq, shiftf): Improve argument/docstring
consistency.
2005-05-22 17:51:22 +00:00
|
|
|
"Make temporary function definitions.
|
2012-06-07 22:54:35 -04:00
|
|
|
Like `cl-labels' but the definitions are not recursive.
|
2002-09-27 23:16:27 +00:00
|
|
|
|
|
|
|
\(fn ((FUNC ARGLIST BODY...) ...) FORM...)"
|
2012-06-03 21:05:17 -04:00
|
|
|
(declare (indent 1) (debug ((&rest (cl-defun)) cl-declarations body)))
|
2012-06-07 22:54:35 -04:00
|
|
|
(let ((binds ()) (newenv macroexpand-all-environment))
|
|
|
|
(dolist (binding bindings)
|
|
|
|
(let ((var (make-symbol (format "--cl-%s--" (car binding)))))
|
|
|
|
(push (list var `(cl-function (lambda . ,(cdr binding)))) binds)
|
|
|
|
(push (cons (car binding)
|
|
|
|
`(lambda (&rest cl-labels-args)
|
|
|
|
(cl-list* 'funcall ',var
|
|
|
|
cl-labels-args)))
|
|
|
|
newenv)))
|
|
|
|
`(let ,(nreverse binds)
|
|
|
|
,@(macroexp-unprogn
|
|
|
|
(macroexpand-all
|
|
|
|
`(progn ,@body)
|
|
|
|
;; Don't override lexical-let's macro-expander.
|
|
|
|
(if (assq 'function newenv) newenv
|
|
|
|
(cons (cons 'function #'cl--labels-convert) newenv)))))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-labels (bindings &rest body)
|
(function*, case, ecase, typecase, etypecase, progv, lexical-let, lexical-let*,
multiple-value-bind, multiple-value-setq, shiftf): Improve argument/docstring
consistency.
2005-05-22 17:51:22 +00:00
|
|
|
"Make temporary function bindings.
|
2012-06-07 22:54:35 -04:00
|
|
|
The bindings can be recursive. Assumes the use of `lexical-binding'.
|
2002-09-27 23:16:27 +00:00
|
|
|
|
|
|
|
\(fn ((FUNC ARGLIST BODY...) ...) FORM...)"
|
2012-06-03 21:05:17 -04:00
|
|
|
(declare (indent 1) (debug cl-flet))
|
2012-06-07 22:54:35 -04:00
|
|
|
(let ((binds ()) (newenv macroexpand-all-environment))
|
|
|
|
(dolist (binding bindings)
|
|
|
|
(let ((var (make-symbol (format "--cl-%s--" (car binding)))))
|
|
|
|
(push (list var `(cl-function (lambda . ,(cdr binding)))) binds)
|
|
|
|
(push (cons (car binding)
|
2012-06-07 15:25:48 -04:00
|
|
|
`(lambda (&rest cl-labels-args)
|
|
|
|
(cl-list* 'funcall ',var
|
|
|
|
cl-labels-args)))
|
Move old compatiblity to cl.el. Remove cl-macroexpand-all.
* emacs-lisp/cl-extra.el (cl-map-keymap, cl-copy-tree)
(cl-not-hash-table, cl-builtin-gethash, cl-builtin-remhash)
(cl-builtin-clrhash, cl-builtin-maphash, cl-gethash, cl-puthash)
(cl-remhash, cl-clrhash, cl-maphash, cl-make-hash-table)
(cl-hash-table-p, cl-hash-table-count): Move to cl.el.
(cl-macroexpand-cmacs): Remove var.
(cl-macroexpand-all, cl-macroexpand-body): Remove funs.
Use macroexpand-all instead.
* emacs-lisp/cl-lib.el (cl-macro-environment): Remove decl.
(cl-macroexpand): Move to cl-macs.el and rename to cl--sm-macroexpand.
(cl-member): Remove old alias.
* emacs-lisp/cl-macs.el (cl-macro-environment): Remove var.
Use macroexpand-all-environment instead.
(cl--old-macroexpand): New var.
(cl--sm-macroexpand): New function.
(cl-symbol-macrolet): Use it during macro expansion.
(cl--function-convert-cache): New var.
(cl--function-convert): New function, extracted from
cl-macroexpand-all.
(cl-lexical-let): Use it.
* emacs-lisp/cl.el (cl-macroexpand, cl-macro-environment)
(cl-macroexpand-all, cl-not-hash-table, cl-builtin-gethash)
(cl-builtin-remhash, cl-builtin-clrhash, cl-builtin-maphash)
(cl-map-keymap, cl-copy-tree, cl-gethash, cl-puthash, cl-remhash)
(cl-clrhash, cl-maphash, cl-make-hash-table, cl-hash-table-p)
(cl-hash-table-count): Add old compatibility aliases.
2012-06-07 15:48:22 -04:00
|
|
|
newenv)))
|
2012-06-07 22:54:35 -04:00
|
|
|
(macroexpand-all `(letrec ,(nreverse binds) ,@body)
|
|
|
|
;; Don't override lexical-let's macro-expander.
|
|
|
|
(if (assq 'function newenv) newenv
|
|
|
|
(cons (cons 'function #'cl--labels-convert) newenv)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
;; The following ought to have a better definition for use with newer
|
|
|
|
;; byte compilers.
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-macrolet (bindings &rest body)
|
2005-05-17 00:26:59 +00:00
|
|
|
"Make temporary macro definitions.
|
2012-06-03 21:05:17 -04:00
|
|
|
This is like `cl-flet', but for macros instead of functions.
|
2002-09-27 23:16:27 +00:00
|
|
|
|
|
|
|
\(fn ((NAME ARGLIST BODY...) ...) FORM...)"
|
2012-05-17 17:51:15 -04:00
|
|
|
(declare (indent 1)
|
|
|
|
(debug
|
2012-05-17 17:39:36 -04:00
|
|
|
((&rest (&define name (&rest arg) cl-declarations-or-string
|
|
|
|
def-body))
|
|
|
|
cl-declarations body)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (cdr bindings)
|
2012-06-03 21:05:17 -04:00
|
|
|
`(cl-macrolet (,(car bindings)) (cl-macrolet ,(cdr bindings) ,@body))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (null bindings) (cons 'progn body)
|
|
|
|
(let* ((name (caar bindings))
|
2012-06-07 15:25:48 -04:00
|
|
|
(res (cl--transform-lambda (cdar bindings) name)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(eval (car res))
|
Move old compatiblity to cl.el. Remove cl-macroexpand-all.
* emacs-lisp/cl-extra.el (cl-map-keymap, cl-copy-tree)
(cl-not-hash-table, cl-builtin-gethash, cl-builtin-remhash)
(cl-builtin-clrhash, cl-builtin-maphash, cl-gethash, cl-puthash)
(cl-remhash, cl-clrhash, cl-maphash, cl-make-hash-table)
(cl-hash-table-p, cl-hash-table-count): Move to cl.el.
(cl-macroexpand-cmacs): Remove var.
(cl-macroexpand-all, cl-macroexpand-body): Remove funs.
Use macroexpand-all instead.
* emacs-lisp/cl-lib.el (cl-macro-environment): Remove decl.
(cl-macroexpand): Move to cl-macs.el and rename to cl--sm-macroexpand.
(cl-member): Remove old alias.
* emacs-lisp/cl-macs.el (cl-macro-environment): Remove var.
Use macroexpand-all-environment instead.
(cl--old-macroexpand): New var.
(cl--sm-macroexpand): New function.
(cl-symbol-macrolet): Use it during macro expansion.
(cl--function-convert-cache): New var.
(cl--function-convert): New function, extracted from
cl-macroexpand-all.
(cl-lexical-let): Use it.
* emacs-lisp/cl.el (cl-macroexpand, cl-macro-environment)
(cl-macroexpand-all, cl-not-hash-table, cl-builtin-gethash)
(cl-builtin-remhash, cl-builtin-clrhash, cl-builtin-maphash)
(cl-map-keymap, cl-copy-tree, cl-gethash, cl-puthash, cl-remhash)
(cl-clrhash, cl-maphash, cl-make-hash-table, cl-hash-table-p)
(cl-hash-table-count): Add old compatibility aliases.
2012-06-07 15:48:22 -04:00
|
|
|
(macroexpand-all (cons 'progn body)
|
|
|
|
(cons (cons name `(lambda ,@(cdr res)))
|
|
|
|
macroexpand-all-environment))))))
|
|
|
|
|
|
|
|
(defconst cl--old-macroexpand
|
|
|
|
(if (and (boundp 'cl--old-macroexpand)
|
|
|
|
(eq (symbol-function 'macroexpand)
|
|
|
|
#'cl--sm-macroexpand))
|
|
|
|
cl--old-macroexpand
|
|
|
|
(symbol-function 'macroexpand)))
|
|
|
|
|
|
|
|
(defun cl--sm-macroexpand (cl-macro &optional cl-env)
|
|
|
|
"Special macro expander used inside `cl-symbol-macrolet'.
|
|
|
|
This function replaces `macroexpand' during macro expansion
|
|
|
|
of `cl-symbol-macrolet', and does the same thing as `macroexpand'
|
|
|
|
except that it additionally expands symbol macros."
|
|
|
|
(let ((macroexpand-all-environment cl-env))
|
|
|
|
(while
|
|
|
|
(progn
|
|
|
|
(setq cl-macro (funcall cl--old-macroexpand cl-macro cl-env))
|
|
|
|
(cond
|
|
|
|
((symbolp cl-macro)
|
|
|
|
;; Perform symbol-macro expansion.
|
|
|
|
(when (cdr (assq (symbol-name cl-macro) cl-env))
|
|
|
|
(setq cl-macro (cadr (assq (symbol-name cl-macro) cl-env)))))
|
|
|
|
((eq 'setq (car-safe cl-macro))
|
|
|
|
;; Convert setq to cl-setf if required by symbol-macro expansion.
|
|
|
|
(let* ((args (mapcar (lambda (f) (cl--sm-macroexpand f cl-env))
|
|
|
|
(cdr cl-macro)))
|
|
|
|
(p args))
|
|
|
|
(while (and p (symbolp (car p))) (setq p (cddr p)))
|
|
|
|
(if p (setq cl-macro (cons 'cl-setf args))
|
|
|
|
(setq cl-macro (cons 'setq args))
|
|
|
|
;; Don't loop further.
|
|
|
|
nil))))))
|
|
|
|
cl-macro))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-symbol-macrolet (bindings &rest body)
|
2005-05-17 00:26:59 +00:00
|
|
|
"Make symbol macro definitions.
|
1993-07-30 20:15:09 +00:00
|
|
|
Within the body FORMs, references to the variable NAME will be replaced
|
2012-06-03 21:05:17 -04:00
|
|
|
by EXPANSION, and (setq NAME ...) will act like (cl-setf EXPANSION ...).
|
2002-09-27 23:16:27 +00:00
|
|
|
|
|
|
|
\(fn ((NAME EXPANSION) ...) FORM...)"
|
2012-05-17 17:51:15 -04:00
|
|
|
(declare (indent 1) (debug ((&rest (symbol sexp)) cl-declarations body)))
|
Move old compatiblity to cl.el. Remove cl-macroexpand-all.
* emacs-lisp/cl-extra.el (cl-map-keymap, cl-copy-tree)
(cl-not-hash-table, cl-builtin-gethash, cl-builtin-remhash)
(cl-builtin-clrhash, cl-builtin-maphash, cl-gethash, cl-puthash)
(cl-remhash, cl-clrhash, cl-maphash, cl-make-hash-table)
(cl-hash-table-p, cl-hash-table-count): Move to cl.el.
(cl-macroexpand-cmacs): Remove var.
(cl-macroexpand-all, cl-macroexpand-body): Remove funs.
Use macroexpand-all instead.
* emacs-lisp/cl-lib.el (cl-macro-environment): Remove decl.
(cl-macroexpand): Move to cl-macs.el and rename to cl--sm-macroexpand.
(cl-member): Remove old alias.
* emacs-lisp/cl-macs.el (cl-macro-environment): Remove var.
Use macroexpand-all-environment instead.
(cl--old-macroexpand): New var.
(cl--sm-macroexpand): New function.
(cl-symbol-macrolet): Use it during macro expansion.
(cl--function-convert-cache): New var.
(cl--function-convert): New function, extracted from
cl-macroexpand-all.
(cl-lexical-let): Use it.
* emacs-lisp/cl.el (cl-macroexpand, cl-macro-environment)
(cl-macroexpand-all, cl-not-hash-table, cl-builtin-gethash)
(cl-builtin-remhash, cl-builtin-clrhash, cl-builtin-maphash)
(cl-map-keymap, cl-copy-tree, cl-gethash, cl-puthash, cl-remhash)
(cl-clrhash, cl-maphash, cl-make-hash-table, cl-hash-table-p)
(cl-hash-table-count): Add old compatibility aliases.
2012-06-07 15:48:22 -04:00
|
|
|
(cond
|
|
|
|
((cdr bindings)
|
2012-06-03 21:05:17 -04:00
|
|
|
`(cl-symbol-macrolet (,(car bindings))
|
Move old compatiblity to cl.el. Remove cl-macroexpand-all.
* emacs-lisp/cl-extra.el (cl-map-keymap, cl-copy-tree)
(cl-not-hash-table, cl-builtin-gethash, cl-builtin-remhash)
(cl-builtin-clrhash, cl-builtin-maphash, cl-gethash, cl-puthash)
(cl-remhash, cl-clrhash, cl-maphash, cl-make-hash-table)
(cl-hash-table-p, cl-hash-table-count): Move to cl.el.
(cl-macroexpand-cmacs): Remove var.
(cl-macroexpand-all, cl-macroexpand-body): Remove funs.
Use macroexpand-all instead.
* emacs-lisp/cl-lib.el (cl-macro-environment): Remove decl.
(cl-macroexpand): Move to cl-macs.el and rename to cl--sm-macroexpand.
(cl-member): Remove old alias.
* emacs-lisp/cl-macs.el (cl-macro-environment): Remove var.
Use macroexpand-all-environment instead.
(cl--old-macroexpand): New var.
(cl--sm-macroexpand): New function.
(cl-symbol-macrolet): Use it during macro expansion.
(cl--function-convert-cache): New var.
(cl--function-convert): New function, extracted from
cl-macroexpand-all.
(cl-lexical-let): Use it.
* emacs-lisp/cl.el (cl-macroexpand, cl-macro-environment)
(cl-macroexpand-all, cl-not-hash-table, cl-builtin-gethash)
(cl-builtin-remhash, cl-builtin-clrhash, cl-builtin-maphash)
(cl-map-keymap, cl-copy-tree, cl-gethash, cl-puthash, cl-remhash)
(cl-clrhash, cl-maphash, cl-make-hash-table, cl-hash-table-p)
(cl-hash-table-count): Add old compatibility aliases.
2012-06-07 15:48:22 -04:00
|
|
|
(cl-symbol-macrolet ,(cdr bindings) ,@body)))
|
|
|
|
((null bindings) (macroexp-progn body))
|
|
|
|
(t
|
|
|
|
(let ((previous-macroexpand (symbol-function 'macroexpand)))
|
|
|
|
(unwind-protect
|
|
|
|
(progn
|
|
|
|
(fset 'macroexpand #'cl--sm-macroexpand)
|
|
|
|
;; FIXME: For N bindings, this will traverse `body' N times!
|
|
|
|
(macroexpand-all (cons 'progn body)
|
1993-07-30 20:15:09 +00:00
|
|
|
(cons (list (symbol-name (caar bindings))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-cadar bindings))
|
Move old compatiblity to cl.el. Remove cl-macroexpand-all.
* emacs-lisp/cl-extra.el (cl-map-keymap, cl-copy-tree)
(cl-not-hash-table, cl-builtin-gethash, cl-builtin-remhash)
(cl-builtin-clrhash, cl-builtin-maphash, cl-gethash, cl-puthash)
(cl-remhash, cl-clrhash, cl-maphash, cl-make-hash-table)
(cl-hash-table-p, cl-hash-table-count): Move to cl.el.
(cl-macroexpand-cmacs): Remove var.
(cl-macroexpand-all, cl-macroexpand-body): Remove funs.
Use macroexpand-all instead.
* emacs-lisp/cl-lib.el (cl-macro-environment): Remove decl.
(cl-macroexpand): Move to cl-macs.el and rename to cl--sm-macroexpand.
(cl-member): Remove old alias.
* emacs-lisp/cl-macs.el (cl-macro-environment): Remove var.
Use macroexpand-all-environment instead.
(cl--old-macroexpand): New var.
(cl--sm-macroexpand): New function.
(cl-symbol-macrolet): Use it during macro expansion.
(cl--function-convert-cache): New var.
(cl--function-convert): New function, extracted from
cl-macroexpand-all.
(cl-lexical-let): Use it.
* emacs-lisp/cl.el (cl-macroexpand, cl-macro-environment)
(cl-macroexpand-all, cl-not-hash-table, cl-builtin-gethash)
(cl-builtin-remhash, cl-builtin-clrhash, cl-builtin-maphash)
(cl-map-keymap, cl-copy-tree, cl-gethash, cl-puthash, cl-remhash)
(cl-clrhash, cl-maphash, cl-make-hash-table, cl-hash-table-p)
(cl-hash-table-count): Add old compatibility aliases.
2012-06-07 15:48:22 -04:00
|
|
|
macroexpand-all-environment)))
|
|
|
|
(fset 'macroexpand previous-macroexpand))))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
;;; Multiple values.
|
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-multiple-value-bind (vars form &rest body)
|
2002-09-27 23:16:27 +00:00
|
|
|
"Collect multiple return values.
|
1993-07-30 20:15:09 +00:00
|
|
|
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
|
2012-06-03 21:05:17 -04:00
|
|
|
is analogous to the Common Lisp `cl-multiple-value-bind' macro, using lists to
|
|
|
|
simulate true multiple return values. For compatibility, (cl-values A B C) is
|
2002-09-27 23:16:27 +00:00
|
|
|
a synonym for (list A B C).
|
|
|
|
|
(function*, case, ecase, typecase, etypecase, progv, lexical-let, lexical-let*,
multiple-value-bind, multiple-value-setq, shiftf): Improve argument/docstring
consistency.
2005-05-22 17:51:22 +00:00
|
|
|
\(fn (SYM...) FORM BODY)"
|
2012-05-17 17:51:15 -04:00
|
|
|
(declare (indent 2) (debug ((&rest symbolp) form body)))
|
2004-11-16 04:05:29 +00:00
|
|
|
(let ((temp (make-symbol "--cl-var--")) (n -1))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(let* ((,temp ,form)
|
|
|
|
,@(mapcar (lambda (v)
|
|
|
|
(list v `(nth ,(setq n (1+ n)) ,temp)))
|
|
|
|
vars))
|
|
|
|
,@body)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-multiple-value-setq (vars form)
|
2002-09-27 23:16:27 +00:00
|
|
|
"Collect multiple return values.
|
1993-07-30 20:15:09 +00:00
|
|
|
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
|
2012-06-03 21:05:17 -04:00
|
|
|
`cl-multiple-value-setq' macro, using lists to simulate true multiple return
|
|
|
|
values. For compatibility, (cl-values A B C) is a synonym for (list A B C).
|
2002-09-27 23:16:27 +00:00
|
|
|
|
(function*, case, ecase, typecase, etypecase, progv, lexical-let, lexical-let*,
multiple-value-bind, multiple-value-setq, shiftf): Improve argument/docstring
consistency.
2005-05-22 17:51:22 +00:00
|
|
|
\(fn (SYM...) FORM)"
|
2012-05-17 17:51:15 -04:00
|
|
|
(declare (indent 1) (debug ((&rest symbolp) form)))
|
2012-06-01 16:36:00 -04:00
|
|
|
(cond ((null vars) `(progn ,form nil))
|
|
|
|
((null (cdr vars)) `(setq ,(car vars) (car ,form)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(t
|
2004-11-16 04:05:29 +00:00
|
|
|
(let* ((temp (make-symbol "--cl-var--")) (n 0))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(let ((,temp ,form))
|
|
|
|
(prog1 (setq ,(pop vars) (car ,temp))
|
|
|
|
(setq ,@(apply #'nconc
|
|
|
|
(mapcar (lambda (v)
|
|
|
|
(list v `(nth ,(setq n (1+ n))
|
|
|
|
,temp)))
|
|
|
|
vars)))))))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
;;; Declarations.
|
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-locally (&rest body)
|
2012-05-17 17:39:36 -04:00
|
|
|
(declare (debug t))
|
|
|
|
(cons 'progn body))
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-08 09:18:26 -04:00
|
|
|
(defmacro cl-the (_type form)
|
2012-05-17 17:51:15 -04:00
|
|
|
(declare (indent 1) (debug (cl-type-spec form)))
|
2012-05-17 17:39:36 -04:00
|
|
|
form)
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
(defvar cl-proclaim-history t) ; for future compilers
|
|
|
|
(defvar cl-declare-stack t) ; for future compilers
|
|
|
|
|
|
|
|
(defun cl-do-proclaim (spec hist)
|
2002-09-27 23:16:27 +00:00
|
|
|
(and hist (listp cl-proclaim-history) (push spec cl-proclaim-history))
|
1993-07-30 20:15:09 +00:00
|
|
|
(cond ((eq (car-safe spec) 'special)
|
|
|
|
(if (boundp 'byte-compile-bound-variables)
|
|
|
|
(setq byte-compile-bound-variables
|
|
|
|
(append (cdr spec) byte-compile-bound-variables))))
|
|
|
|
|
|
|
|
((eq (car-safe spec) 'inline)
|
|
|
|
(while (setq spec (cdr spec))
|
|
|
|
(or (memq (get (car spec) 'byte-optimizer)
|
|
|
|
'(nil byte-compile-inline-expand))
|
|
|
|
(error "%s already has a byte-optimizer, can't make it inline"
|
|
|
|
(car spec)))
|
|
|
|
(put (car spec) 'byte-optimizer 'byte-compile-inline-expand)))
|
|
|
|
|
|
|
|
((eq (car-safe spec) 'notinline)
|
|
|
|
(while (setq spec (cdr spec))
|
|
|
|
(if (eq (get (car spec) 'byte-optimizer)
|
|
|
|
'byte-compile-inline-expand)
|
|
|
|
(put (car spec) 'byte-optimizer nil))))
|
|
|
|
|
|
|
|
((eq (car-safe spec) 'optimize)
|
|
|
|
(let ((speed (assq (nth 1 (assq 'speed (cdr spec)))
|
|
|
|
'((0 nil) (1 t) (2 t) (3 t))))
|
|
|
|
(safety (assq (nth 1 (assq 'safety (cdr spec)))
|
|
|
|
'((0 t) (1 t) (2 t) (3 nil)))))
|
|
|
|
(if speed (setq cl-optimize-speed (car speed)
|
|
|
|
byte-optimize (nth 1 speed)))
|
|
|
|
(if safety (setq cl-optimize-safety (car safety)
|
|
|
|
byte-compile-delete-errors (nth 1 safety)))))
|
|
|
|
|
|
|
|
((and (eq (car-safe spec) 'warn) (boundp 'byte-compile-warnings))
|
|
|
|
(while (setq spec (cdr spec))
|
|
|
|
(if (consp (car spec))
|
2012-06-03 21:05:17 -04:00
|
|
|
(if (eq (cl-cadar spec) 0)
|
2007-10-28 23:51:29 +00:00
|
|
|
(byte-compile-disable-warning (caar spec))
|
|
|
|
(byte-compile-enable-warning (caar spec)))))))
|
1993-07-30 20:15:09 +00:00
|
|
|
nil)
|
|
|
|
|
|
|
|
;;; Process any proclamations made before cl-macs was loaded.
|
|
|
|
(defvar cl-proclaims-deferred)
|
|
|
|
(let ((p (reverse cl-proclaims-deferred)))
|
2002-09-27 23:16:27 +00:00
|
|
|
(while p (cl-do-proclaim (pop p) t))
|
1993-07-30 20:15:09 +00:00
|
|
|
(setq cl-proclaims-deferred nil))
|
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-declare (&rest specs)
|
2011-07-15 16:59:42 +02:00
|
|
|
"Declare SPECS about the current function while compiling.
|
2011-07-15 15:46:52 +02:00
|
|
|
For instance
|
|
|
|
|
2012-06-03 21:05:17 -04:00
|
|
|
\(cl-declare (warn 0))
|
2011-07-15 15:46:52 +02:00
|
|
|
|
2011-07-15 18:01:18 +02:00
|
|
|
will turn off byte-compile warnings in the function.
|
|
|
|
See Info node `(cl)Declarations' for details."
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(if (cl--compiling-file)
|
1993-07-30 20:15:09 +00:00
|
|
|
(while specs
|
2002-09-27 23:16:27 +00:00
|
|
|
(if (listp cl-declare-stack) (push (car specs) cl-declare-stack))
|
|
|
|
(cl-do-proclaim (pop specs) nil)))
|
1993-07-30 20:15:09 +00:00
|
|
|
nil)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Generalized variables.
|
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-07 15:25:48 -04:00
|
|
|
(defmacro cl-define-setf-expander (func args &rest body)
|
2012-06-03 21:05:17 -04:00
|
|
|
"Define a `cl-setf' method.
|
|
|
|
This method shows how to handle `cl-setf's to places of the form (NAME ARGS...).
|
1993-07-30 20:15:09 +00:00
|
|
|
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-
|
2012-06-03 21:05:17 -04:00
|
|
|
form. See `cl-defsetf' for a simpler way to define most setf-methods.
|
2002-09-27 23:16:27 +00:00
|
|
|
|
|
|
|
\(fn NAME ARGLIST BODY...)"
|
2012-05-17 17:39:36 -04:00
|
|
|
(declare (debug
|
|
|
|
(&define name cl-lambda-list cl-declarations-or-string def-body)))
|
2012-06-03 21:05:17 -04:00
|
|
|
`(cl-eval-when (compile load eval)
|
2012-06-01 16:36:00 -04:00
|
|
|
,@(if (stringp (car body))
|
|
|
|
(list `(put ',func 'setf-documentation ,(pop body))))
|
2012-06-07 15:25:48 -04:00
|
|
|
,(cl--transform-function-property
|
2012-06-01 16:36:00 -04:00
|
|
|
func 'setf-method (cons args body))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-defsetf (func arg1 &rest args)
|
|
|
|
"Define a `cl-setf' method.
|
2012-06-07 15:25:48 -04:00
|
|
|
This macro is an easy-to-use substitute for `cl-define-setf-expander' that works
|
2012-06-03 21:05:17 -04:00
|
|
|
well for simple place forms. In the simple `cl-defsetf' form, `cl-setf's of
|
|
|
|
the form (cl-setf (NAME ARGS...) VAL) are transformed to function or macro
|
2005-06-01 15:33:50 +00:00
|
|
|
calls of the form (FUNC ARGS... VAL). Example:
|
|
|
|
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-defsetf aref aset)
|
2005-06-01 15:33:50 +00:00
|
|
|
|
2012-06-03 21:05:17 -04:00
|
|
|
Alternate form: (cl-defsetf NAME ARGLIST (STORE) BODY...).
|
|
|
|
Here, the above `cl-setf' call is expanded by binding the argument forms ARGS
|
1993-07-30 20:15:09 +00:00
|
|
|
according to ARGLIST, binding the value form VAL to STORE, then executing
|
2012-06-03 21:05:17 -04:00
|
|
|
BODY, which must return a Lisp form that does the necessary `cl-setf' operation.
|
1993-07-30 20:15:09 +00:00
|
|
|
Actually, ARGLIST and STORE may be bound to temporary variables which are
|
|
|
|
introduced automatically to preserve proper execution order of the arguments.
|
2005-06-01 15:33:50 +00:00
|
|
|
Example:
|
|
|
|
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-defsetf nth (n x) (v) `(setcar (nthcdr ,n ,x) ,v))
|
2005-06-01 15:33:50 +00:00
|
|
|
|
|
|
|
\(fn NAME [FUNC | ARGLIST (STORE) BODY...])"
|
2012-05-17 17:39:36 -04:00
|
|
|
(declare (debug
|
|
|
|
(&define name
|
|
|
|
[&or [symbolp &optional stringp]
|
|
|
|
[cl-lambda-list (symbolp)]]
|
|
|
|
cl-declarations-or-string def-body)))
|
2008-04-03 13:42:25 +00:00
|
|
|
(if (and (listp arg1) (consp args))
|
1993-07-30 20:15:09 +00:00
|
|
|
(let* ((largs nil) (largsr nil)
|
|
|
|
(temps nil) (tempsr nil)
|
|
|
|
(restarg nil) (rest-temps nil)
|
|
|
|
(store-var (car (prog1 (car args) (setq args (cdr args)))))
|
|
|
|
(store-temp (intern (format "--%s--temp--" store-var)))
|
|
|
|
(lets1 nil) (lets2 nil)
|
|
|
|
(docstr nil) (p arg1))
|
|
|
|
(if (stringp (car args))
|
|
|
|
(setq docstr (prog1 (car args) (setq args (cdr args)))))
|
|
|
|
(while (and p (not (eq (car p) '&aux)))
|
|
|
|
(if (eq (car p) '&rest)
|
|
|
|
(setq p (cdr p) restarg (car p))
|
|
|
|
(or (memq (car p) '(&optional &key &allow-other-keys))
|
|
|
|
(setq largs (cons (if (consp (car p)) (car (car p)) (car p))
|
|
|
|
largs)
|
|
|
|
temps (cons (intern (format "--%s--temp--" (car largs)))
|
|
|
|
temps))))
|
|
|
|
(setq p (cdr p)))
|
|
|
|
(setq largs (nreverse largs) temps (nreverse temps))
|
|
|
|
(if restarg
|
|
|
|
(setq largsr (append largs (list restarg))
|
|
|
|
rest-temps (intern (format "--%s--temp--" restarg))
|
|
|
|
tempsr (append temps (list rest-temps)))
|
|
|
|
(setq largsr largs tempsr temps))
|
|
|
|
(let ((p1 largs) (p2 temps))
|
|
|
|
(while p1
|
2004-11-16 04:05:29 +00:00
|
|
|
(setq lets1 (cons `(,(car p2)
|
|
|
|
(make-symbol ,(format "--cl-%s--" (car p1))))
|
1993-07-30 20:15:09 +00:00
|
|
|
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)))
|
2012-06-07 15:25:48 -04:00
|
|
|
`(cl-define-setf-expander ,func ,arg1
|
2004-11-16 04:05:29 +00:00
|
|
|
,@(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
|
2012-06-03 21:05:17 -04:00
|
|
|
(,(if restarg 'cl-list* 'list) ,@tempsr)
|
|
|
|
(,(if restarg 'cl-list* 'list) ,@largsr)
|
2004-11-16 04:05:29 +00:00
|
|
|
(list ,store-temp)
|
|
|
|
(let*
|
|
|
|
,(nreverse
|
|
|
|
(cons (list store-var store-temp)
|
|
|
|
lets2))
|
|
|
|
,@args)
|
2012-06-03 21:05:17 -04:00
|
|
|
(,(if restarg 'cl-list* 'list)
|
2012-06-01 16:36:00 -04:00
|
|
|
,@(cons `',func tempsr))))))
|
2012-06-03 21:05:17 -04:00
|
|
|
`(cl-defsetf ,func (&rest args) (store)
|
2004-11-16 04:05:29 +00:00
|
|
|
,(let ((call `(cons ',arg1
|
|
|
|
(append args (list store)))))
|
|
|
|
(if (car args)
|
|
|
|
`(list 'progn ,call store)
|
|
|
|
call)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
;;; Some standard place types from Common Lisp.
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-defsetf aref aset)
|
|
|
|
(cl-defsetf car setcar)
|
|
|
|
(cl-defsetf cdr setcdr)
|
|
|
|
(cl-defsetf caar (x) (val) `(setcar (car ,x) ,val))
|
|
|
|
(cl-defsetf cadr (x) (val) `(setcar (cdr ,x) ,val))
|
|
|
|
(cl-defsetf cdar (x) (val) `(setcdr (car ,x) ,val))
|
|
|
|
(cl-defsetf cddr (x) (val) `(setcdr (cdr ,x) ,val))
|
|
|
|
(cl-defsetf elt (seq n) (store)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(if (listp ,seq) (setcar (nthcdr ,n ,seq) ,store)
|
|
|
|
(aset ,seq ,n ,store)))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-defsetf get put)
|
|
|
|
(cl-defsetf cl-get (x y &optional d) (store) `(put ,x ,y ,store))
|
|
|
|
(cl-defsetf gethash (x h &optional d) (store) `(puthash ,x ,store ,h))
|
|
|
|
(cl-defsetf nth (n x) (store) `(setcar (nthcdr ,n ,x) ,store))
|
|
|
|
(cl-defsetf cl-subseq (seq start &optional end) (new)
|
|
|
|
`(progn (cl-replace ,seq ,new :start1 ,start :end1 ,end) ,new))
|
|
|
|
(cl-defsetf symbol-function fset)
|
|
|
|
(cl-defsetf symbol-plist setplist)
|
|
|
|
(cl-defsetf symbol-value set)
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
;;; Various car/cdr aliases. Note that `cadr' is handled specially.
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-defsetf cl-first setcar)
|
|
|
|
(cl-defsetf cl-second (x) (store) `(setcar (cdr ,x) ,store))
|
|
|
|
(cl-defsetf cl-third (x) (store) `(setcar (cddr ,x) ,store))
|
|
|
|
(cl-defsetf cl-fourth (x) (store) `(setcar (cl-cdddr ,x) ,store))
|
|
|
|
(cl-defsetf cl-fifth (x) (store) `(setcar (nthcdr 4 ,x) ,store))
|
|
|
|
(cl-defsetf cl-sixth (x) (store) `(setcar (nthcdr 5 ,x) ,store))
|
|
|
|
(cl-defsetf cl-seventh (x) (store) `(setcar (nthcdr 6 ,x) ,store))
|
|
|
|
(cl-defsetf cl-eighth (x) (store) `(setcar (nthcdr 7 ,x) ,store))
|
|
|
|
(cl-defsetf cl-ninth (x) (store) `(setcar (nthcdr 8 ,x) ,store))
|
|
|
|
(cl-defsetf cl-tenth (x) (store) `(setcar (nthcdr 9 ,x) ,store))
|
|
|
|
(cl-defsetf cl-rest setcdr)
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
;;; Some more Emacs-related place types.
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-defsetf buffer-file-name set-visited-file-name t)
|
|
|
|
(cl-defsetf buffer-modified-p (&optional buf) (flag)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(with-current-buffer ,buf
|
|
|
|
(set-buffer-modified-p ,flag)))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-defsetf buffer-name rename-buffer t)
|
|
|
|
(cl-defsetf buffer-string () (store)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(progn (erase-buffer) (insert ,store)))
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(cl-defsetf buffer-substring cl--set-buffer-substring)
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-defsetf current-buffer set-buffer)
|
|
|
|
(cl-defsetf current-case-table set-case-table)
|
|
|
|
(cl-defsetf current-column move-to-column t)
|
|
|
|
(cl-defsetf current-global-map use-global-map t)
|
|
|
|
(cl-defsetf current-input-mode () (store)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(progn (apply #'set-input-mode ,store) ,store))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-defsetf current-local-map use-local-map t)
|
|
|
|
(cl-defsetf current-window-configuration set-window-configuration t)
|
|
|
|
(cl-defsetf default-file-modes set-default-file-modes t)
|
|
|
|
(cl-defsetf default-value set-default)
|
|
|
|
(cl-defsetf documentation-property put)
|
|
|
|
(cl-defsetf face-background (f &optional s) (x) `(set-face-background ,f ,x ,s))
|
|
|
|
(cl-defsetf face-background-pixmap (f &optional s) (x)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(set-face-background-pixmap ,f ,x ,s))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-defsetf face-font (f &optional s) (x) `(set-face-font ,f ,x ,s))
|
|
|
|
(cl-defsetf face-foreground (f &optional s) (x) `(set-face-foreground ,f ,x ,s))
|
|
|
|
(cl-defsetf face-underline-p (f &optional s) (x)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(set-face-underline-p ,f ,x ,s))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-defsetf file-modes set-file-modes t)
|
|
|
|
(cl-defsetf frame-height set-screen-height t)
|
|
|
|
(cl-defsetf frame-parameters modify-frame-parameters t)
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(cl-defsetf frame-visible-p cl--set-frame-visible-p)
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-defsetf frame-width set-screen-width t)
|
|
|
|
(cl-defsetf frame-parameter set-frame-parameter t)
|
|
|
|
(cl-defsetf terminal-parameter set-terminal-parameter)
|
|
|
|
(cl-defsetf getenv setenv t)
|
|
|
|
(cl-defsetf get-register set-register)
|
|
|
|
(cl-defsetf global-key-binding global-set-key)
|
|
|
|
(cl-defsetf keymap-parent set-keymap-parent)
|
|
|
|
(cl-defsetf local-key-binding local-set-key)
|
|
|
|
(cl-defsetf mark set-mark t)
|
|
|
|
(cl-defsetf mark-marker set-mark t)
|
|
|
|
(cl-defsetf marker-position set-marker t)
|
|
|
|
(cl-defsetf match-data set-match-data t)
|
|
|
|
(cl-defsetf mouse-position (scr) (store)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(set-mouse-position ,scr (car ,store) (cadr ,store)
|
|
|
|
(cddr ,store)))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-defsetf overlay-get overlay-put)
|
|
|
|
(cl-defsetf overlay-start (ov) (store)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(progn (move-overlay ,ov ,store (overlay-end ,ov)) ,store))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-defsetf overlay-end (ov) (store)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(progn (move-overlay ,ov (overlay-start ,ov) ,store) ,store))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-defsetf point goto-char)
|
|
|
|
(cl-defsetf point-marker goto-char t)
|
|
|
|
(cl-defsetf point-max () (store)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(progn (narrow-to-region (point-min) ,store) ,store))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-defsetf point-min () (store)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(progn (narrow-to-region ,store (point-max)) ,store))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-defsetf process-buffer set-process-buffer)
|
|
|
|
(cl-defsetf process-filter set-process-filter)
|
|
|
|
(cl-defsetf process-sentinel set-process-sentinel)
|
|
|
|
(cl-defsetf process-get process-put)
|
|
|
|
(cl-defsetf read-mouse-position (scr) (store)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(set-mouse-position ,scr (car ,store) (cdr ,store)))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-defsetf screen-height set-screen-height t)
|
|
|
|
(cl-defsetf screen-width set-screen-width t)
|
|
|
|
(cl-defsetf selected-window select-window)
|
|
|
|
(cl-defsetf selected-screen select-screen)
|
|
|
|
(cl-defsetf selected-frame select-frame)
|
|
|
|
(cl-defsetf standard-case-table set-standard-case-table)
|
|
|
|
(cl-defsetf syntax-table set-syntax-table)
|
|
|
|
(cl-defsetf visited-file-modtime set-visited-file-modtime t)
|
|
|
|
(cl-defsetf window-buffer set-window-buffer t)
|
|
|
|
(cl-defsetf window-display-table set-window-display-table t)
|
|
|
|
(cl-defsetf window-dedicated-p set-window-dedicated-p t)
|
|
|
|
(cl-defsetf window-height () (store)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(progn (enlarge-window (- ,store (window-height))) ,store))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-defsetf window-hscroll set-window-hscroll)
|
|
|
|
(cl-defsetf window-parameter set-window-parameter)
|
|
|
|
(cl-defsetf window-point set-window-point)
|
|
|
|
(cl-defsetf window-start set-window-start)
|
|
|
|
(cl-defsetf window-width () (store)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(progn (enlarge-window (- ,store (window-width)) t) ,store))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-defsetf x-get-secondary-selection x-own-secondary-selection t)
|
|
|
|
(cl-defsetf x-get-selection x-own-selection t)
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2012-06-03 21:05:17 -04:00
|
|
|
;; This is a hack that allows (cl-setf (eq a 7) B) to mean either
|
2010-05-04 22:08:25 -04:00
|
|
|
;; (setq a 7) or (setq a nil) depending on whether B is nil or not.
|
|
|
|
;; This is useful when you have control over the PLACE but not over
|
|
|
|
;; the VALUE, as is the case in define-minor-mode's :variable.
|
2012-06-07 15:25:48 -04:00
|
|
|
(cl-define-setf-expander eq (place val)
|
Move old compatiblity to cl.el. Remove cl-macroexpand-all.
* emacs-lisp/cl-extra.el (cl-map-keymap, cl-copy-tree)
(cl-not-hash-table, cl-builtin-gethash, cl-builtin-remhash)
(cl-builtin-clrhash, cl-builtin-maphash, cl-gethash, cl-puthash)
(cl-remhash, cl-clrhash, cl-maphash, cl-make-hash-table)
(cl-hash-table-p, cl-hash-table-count): Move to cl.el.
(cl-macroexpand-cmacs): Remove var.
(cl-macroexpand-all, cl-macroexpand-body): Remove funs.
Use macroexpand-all instead.
* emacs-lisp/cl-lib.el (cl-macro-environment): Remove decl.
(cl-macroexpand): Move to cl-macs.el and rename to cl--sm-macroexpand.
(cl-member): Remove old alias.
* emacs-lisp/cl-macs.el (cl-macro-environment): Remove var.
Use macroexpand-all-environment instead.
(cl--old-macroexpand): New var.
(cl--sm-macroexpand): New function.
(cl-symbol-macrolet): Use it during macro expansion.
(cl--function-convert-cache): New var.
(cl--function-convert): New function, extracted from
cl-macroexpand-all.
(cl-lexical-let): Use it.
* emacs-lisp/cl.el (cl-macroexpand, cl-macro-environment)
(cl-macroexpand-all, cl-not-hash-table, cl-builtin-gethash)
(cl-builtin-remhash, cl-builtin-clrhash, cl-builtin-maphash)
(cl-map-keymap, cl-copy-tree, cl-gethash, cl-puthash, cl-remhash)
(cl-clrhash, cl-maphash, cl-make-hash-table, cl-hash-table-p)
(cl-hash-table-count): Add old compatibility aliases.
2012-06-07 15:48:22 -04:00
|
|
|
(let ((method (cl-get-setf-method place macroexpand-all-environment))
|
2010-05-04 23:45:21 -04:00
|
|
|
(val-temp (make-symbol "--eq-val--"))
|
|
|
|
(store-temp (make-symbol "--eq-store--")))
|
|
|
|
(list (append (nth 0 method) (list val-temp))
|
|
|
|
(append (nth 1 method) (list val))
|
|
|
|
(list store-temp)
|
|
|
|
`(let ((,(car (nth 2 method))
|
|
|
|
(if ,store-temp ,val-temp (not ,val-temp))))
|
|
|
|
,(nth 3 method) ,store-temp)
|
|
|
|
`(eq ,(nth 4 method) ,val-temp))))
|
2010-05-04 22:08:25 -04:00
|
|
|
|
1993-07-30 20:15:09 +00:00
|
|
|
;;; More complex setf-methods.
|
2010-05-04 22:08:25 -04:00
|
|
|
;; These should take &environment arguments, but since full arglists aren't
|
|
|
|
;; available while compiling cl-macs, we fake it by referring to the global
|
Move old compatiblity to cl.el. Remove cl-macroexpand-all.
* emacs-lisp/cl-extra.el (cl-map-keymap, cl-copy-tree)
(cl-not-hash-table, cl-builtin-gethash, cl-builtin-remhash)
(cl-builtin-clrhash, cl-builtin-maphash, cl-gethash, cl-puthash)
(cl-remhash, cl-clrhash, cl-maphash, cl-make-hash-table)
(cl-hash-table-p, cl-hash-table-count): Move to cl.el.
(cl-macroexpand-cmacs): Remove var.
(cl-macroexpand-all, cl-macroexpand-body): Remove funs.
Use macroexpand-all instead.
* emacs-lisp/cl-lib.el (cl-macro-environment): Remove decl.
(cl-macroexpand): Move to cl-macs.el and rename to cl--sm-macroexpand.
(cl-member): Remove old alias.
* emacs-lisp/cl-macs.el (cl-macro-environment): Remove var.
Use macroexpand-all-environment instead.
(cl--old-macroexpand): New var.
(cl--sm-macroexpand): New function.
(cl-symbol-macrolet): Use it during macro expansion.
(cl--function-convert-cache): New var.
(cl--function-convert): New function, extracted from
cl-macroexpand-all.
(cl-lexical-let): Use it.
* emacs-lisp/cl.el (cl-macroexpand, cl-macro-environment)
(cl-macroexpand-all, cl-not-hash-table, cl-builtin-gethash)
(cl-builtin-remhash, cl-builtin-clrhash, cl-builtin-maphash)
(cl-map-keymap, cl-copy-tree, cl-gethash, cl-puthash, cl-remhash)
(cl-clrhash, cl-maphash, cl-make-hash-table, cl-hash-table-p)
(cl-hash-table-count): Add old compatibility aliases.
2012-06-07 15:48:22 -04:00
|
|
|
;; variable macroexpand-all-environment directly.
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
(cl-define-setf-expander apply (func arg1 &rest rest)
|
2012-06-03 21:05:17 -04:00
|
|
|
(or (and (memq (car-safe func) '(quote function cl-function))
|
1993-07-30 20:15:09 +00:00
|
|
|
(symbolp (car-safe (cdr-safe func))))
|
2012-06-03 21:05:17 -04:00
|
|
|
(error "First arg to apply in cl-setf is not (function SYM): %s" func))
|
1993-07-30 20:15:09 +00:00
|
|
|
(let* ((form (cons (nth 1 func) (cons arg1 rest)))
|
Move old compatiblity to cl.el. Remove cl-macroexpand-all.
* emacs-lisp/cl-extra.el (cl-map-keymap, cl-copy-tree)
(cl-not-hash-table, cl-builtin-gethash, cl-builtin-remhash)
(cl-builtin-clrhash, cl-builtin-maphash, cl-gethash, cl-puthash)
(cl-remhash, cl-clrhash, cl-maphash, cl-make-hash-table)
(cl-hash-table-p, cl-hash-table-count): Move to cl.el.
(cl-macroexpand-cmacs): Remove var.
(cl-macroexpand-all, cl-macroexpand-body): Remove funs.
Use macroexpand-all instead.
* emacs-lisp/cl-lib.el (cl-macro-environment): Remove decl.
(cl-macroexpand): Move to cl-macs.el and rename to cl--sm-macroexpand.
(cl-member): Remove old alias.
* emacs-lisp/cl-macs.el (cl-macro-environment): Remove var.
Use macroexpand-all-environment instead.
(cl--old-macroexpand): New var.
(cl--sm-macroexpand): New function.
(cl-symbol-macrolet): Use it during macro expansion.
(cl--function-convert-cache): New var.
(cl--function-convert): New function, extracted from
cl-macroexpand-all.
(cl-lexical-let): Use it.
* emacs-lisp/cl.el (cl-macroexpand, cl-macro-environment)
(cl-macroexpand-all, cl-not-hash-table, cl-builtin-gethash)
(cl-builtin-remhash, cl-builtin-clrhash, cl-builtin-maphash)
(cl-map-keymap, cl-copy-tree, cl-gethash, cl-puthash, cl-remhash)
(cl-clrhash, cl-maphash, cl-make-hash-table, cl-hash-table-p)
(cl-hash-table-count): Add old compatibility aliases.
2012-06-07 15:48:22 -04:00
|
|
|
(method (cl-get-setf-method form macroexpand-all-environment)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(list (car method) (nth 1 method) (nth 2 method)
|
|
|
|
(cl-setf-make-apply (nth 3 method) (cadr func) (car method))
|
|
|
|
(cl-setf-make-apply (nth 4 method) (cadr func) (car method)))))
|
|
|
|
|
|
|
|
(defun cl-setf-make-apply (form func temps)
|
|
|
|
(if (eq (car form) 'progn)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(progn ,(cl-setf-make-apply (cadr form) func temps) ,@(cddr form))
|
1993-07-30 20:15:09 +00:00
|
|
|
(or (equal (last form) (last temps))
|
|
|
|
(error "%s is not suitable for use with setf-of-apply" func))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(apply ',(car form) ,@(cdr form))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
(cl-define-setf-expander nthcdr (n place)
|
Move old compatiblity to cl.el. Remove cl-macroexpand-all.
* emacs-lisp/cl-extra.el (cl-map-keymap, cl-copy-tree)
(cl-not-hash-table, cl-builtin-gethash, cl-builtin-remhash)
(cl-builtin-clrhash, cl-builtin-maphash, cl-gethash, cl-puthash)
(cl-remhash, cl-clrhash, cl-maphash, cl-make-hash-table)
(cl-hash-table-p, cl-hash-table-count): Move to cl.el.
(cl-macroexpand-cmacs): Remove var.
(cl-macroexpand-all, cl-macroexpand-body): Remove funs.
Use macroexpand-all instead.
* emacs-lisp/cl-lib.el (cl-macro-environment): Remove decl.
(cl-macroexpand): Move to cl-macs.el and rename to cl--sm-macroexpand.
(cl-member): Remove old alias.
* emacs-lisp/cl-macs.el (cl-macro-environment): Remove var.
Use macroexpand-all-environment instead.
(cl--old-macroexpand): New var.
(cl--sm-macroexpand): New function.
(cl-symbol-macrolet): Use it during macro expansion.
(cl--function-convert-cache): New var.
(cl--function-convert): New function, extracted from
cl-macroexpand-all.
(cl-lexical-let): Use it.
* emacs-lisp/cl.el (cl-macroexpand, cl-macro-environment)
(cl-macroexpand-all, cl-not-hash-table, cl-builtin-gethash)
(cl-builtin-remhash, cl-builtin-clrhash, cl-builtin-maphash)
(cl-map-keymap, cl-copy-tree, cl-gethash, cl-puthash, cl-remhash)
(cl-clrhash, cl-maphash, cl-make-hash-table, cl-hash-table-p)
(cl-hash-table-count): Add old compatibility aliases.
2012-06-07 15:48:22 -04:00
|
|
|
(let ((method (cl-get-setf-method place macroexpand-all-environment))
|
2004-11-16 04:05:29 +00:00
|
|
|
(n-temp (make-symbol "--cl-nthcdr-n--"))
|
|
|
|
(store-temp (make-symbol "--cl-nthcdr-store--")))
|
1993-07-30 20:15:09 +00:00
|
|
|
(list (cons n-temp (car method))
|
|
|
|
(cons n (nth 1 method))
|
|
|
|
(list store-temp)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(let ((,(car (nth 2 method))
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(cl--set-nthcdr ,n-temp ,(nth 4 method)
|
|
|
|
,store-temp)))
|
2012-06-01 16:36:00 -04:00
|
|
|
,(nth 3 method) ,store-temp)
|
|
|
|
`(nthcdr ,n-temp ,(nth 4 method)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
(cl-define-setf-expander cl-getf (place tag &optional def)
|
Move old compatiblity to cl.el. Remove cl-macroexpand-all.
* emacs-lisp/cl-extra.el (cl-map-keymap, cl-copy-tree)
(cl-not-hash-table, cl-builtin-gethash, cl-builtin-remhash)
(cl-builtin-clrhash, cl-builtin-maphash, cl-gethash, cl-puthash)
(cl-remhash, cl-clrhash, cl-maphash, cl-make-hash-table)
(cl-hash-table-p, cl-hash-table-count): Move to cl.el.
(cl-macroexpand-cmacs): Remove var.
(cl-macroexpand-all, cl-macroexpand-body): Remove funs.
Use macroexpand-all instead.
* emacs-lisp/cl-lib.el (cl-macro-environment): Remove decl.
(cl-macroexpand): Move to cl-macs.el and rename to cl--sm-macroexpand.
(cl-member): Remove old alias.
* emacs-lisp/cl-macs.el (cl-macro-environment): Remove var.
Use macroexpand-all-environment instead.
(cl--old-macroexpand): New var.
(cl--sm-macroexpand): New function.
(cl-symbol-macrolet): Use it during macro expansion.
(cl--function-convert-cache): New var.
(cl--function-convert): New function, extracted from
cl-macroexpand-all.
(cl-lexical-let): Use it.
* emacs-lisp/cl.el (cl-macroexpand, cl-macro-environment)
(cl-macroexpand-all, cl-not-hash-table, cl-builtin-gethash)
(cl-builtin-remhash, cl-builtin-clrhash, cl-builtin-maphash)
(cl-map-keymap, cl-copy-tree, cl-gethash, cl-puthash, cl-remhash)
(cl-clrhash, cl-maphash, cl-make-hash-table, cl-hash-table-p)
(cl-hash-table-count): Add old compatibility aliases.
2012-06-07 15:48:22 -04:00
|
|
|
(let ((method (cl-get-setf-method place macroexpand-all-environment))
|
2004-11-16 04:05:29 +00:00
|
|
|
(tag-temp (make-symbol "--cl-getf-tag--"))
|
|
|
|
(def-temp (make-symbol "--cl-getf-def--"))
|
|
|
|
(store-temp (make-symbol "--cl-getf-store--")))
|
1993-07-30 20:15:09 +00:00
|
|
|
(list (append (car method) (list tag-temp def-temp))
|
|
|
|
(append (nth 1 method) (list tag def))
|
|
|
|
(list store-temp)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(let ((,(car (nth 2 method))
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(cl--set-getf ,(nth 4 method) ,tag-temp ,store-temp)))
|
2012-06-01 16:36:00 -04:00
|
|
|
,(nth 3 method) ,store-temp)
|
2012-06-03 21:05:17 -04:00
|
|
|
`(cl-getf ,(nth 4 method) ,tag-temp ,def-temp))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
(cl-define-setf-expander substring (place from &optional to)
|
Move old compatiblity to cl.el. Remove cl-macroexpand-all.
* emacs-lisp/cl-extra.el (cl-map-keymap, cl-copy-tree)
(cl-not-hash-table, cl-builtin-gethash, cl-builtin-remhash)
(cl-builtin-clrhash, cl-builtin-maphash, cl-gethash, cl-puthash)
(cl-remhash, cl-clrhash, cl-maphash, cl-make-hash-table)
(cl-hash-table-p, cl-hash-table-count): Move to cl.el.
(cl-macroexpand-cmacs): Remove var.
(cl-macroexpand-all, cl-macroexpand-body): Remove funs.
Use macroexpand-all instead.
* emacs-lisp/cl-lib.el (cl-macro-environment): Remove decl.
(cl-macroexpand): Move to cl-macs.el and rename to cl--sm-macroexpand.
(cl-member): Remove old alias.
* emacs-lisp/cl-macs.el (cl-macro-environment): Remove var.
Use macroexpand-all-environment instead.
(cl--old-macroexpand): New var.
(cl--sm-macroexpand): New function.
(cl-symbol-macrolet): Use it during macro expansion.
(cl--function-convert-cache): New var.
(cl--function-convert): New function, extracted from
cl-macroexpand-all.
(cl-lexical-let): Use it.
* emacs-lisp/cl.el (cl-macroexpand, cl-macro-environment)
(cl-macroexpand-all, cl-not-hash-table, cl-builtin-gethash)
(cl-builtin-remhash, cl-builtin-clrhash, cl-builtin-maphash)
(cl-map-keymap, cl-copy-tree, cl-gethash, cl-puthash, cl-remhash)
(cl-clrhash, cl-maphash, cl-make-hash-table, cl-hash-table-p)
(cl-hash-table-count): Add old compatibility aliases.
2012-06-07 15:48:22 -04:00
|
|
|
(let ((method (cl-get-setf-method place macroexpand-all-environment))
|
2004-11-16 04:05:29 +00:00
|
|
|
(from-temp (make-symbol "--cl-substring-from--"))
|
|
|
|
(to-temp (make-symbol "--cl-substring-to--"))
|
|
|
|
(store-temp (make-symbol "--cl-substring-store--")))
|
1993-07-30 20:15:09 +00:00
|
|
|
(list (append (car method) (list from-temp to-temp))
|
|
|
|
(append (nth 1 method) (list from to))
|
|
|
|
(list store-temp)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(let ((,(car (nth 2 method))
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(cl--set-substring ,(nth 4 method)
|
|
|
|
,from-temp ,to-temp ,store-temp)))
|
2012-06-01 16:36:00 -04:00
|
|
|
,(nth 3 method) ,store-temp)
|
|
|
|
`(substring ,(nth 4 method) ,from-temp ,to-temp))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
;;; Getting and optimizing setf-methods.
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defun cl-get-setf-method (place &optional env)
|
1993-07-30 20:15:09 +00:00
|
|
|
"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
|
2012-06-03 21:05:17 -04:00
|
|
|
a macro like `cl-setf' or `cl-incf'."
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (symbolp place)
|
2004-11-16 04:05:29 +00:00
|
|
|
(let ((temp (make-symbol "--cl-setf--")))
|
2012-06-01 16:36:00 -04:00
|
|
|
(list nil nil (list temp) `(setq ,place ,temp) place))
|
1993-07-30 20:15:09 +00:00
|
|
|
(or (and (symbolp (car place))
|
|
|
|
(let* ((func (car place))
|
|
|
|
(name (symbol-name func))
|
|
|
|
(method (get func 'setf-method))
|
|
|
|
(case-fold-search nil))
|
|
|
|
(or (and method
|
Move old compatiblity to cl.el. Remove cl-macroexpand-all.
* emacs-lisp/cl-extra.el (cl-map-keymap, cl-copy-tree)
(cl-not-hash-table, cl-builtin-gethash, cl-builtin-remhash)
(cl-builtin-clrhash, cl-builtin-maphash, cl-gethash, cl-puthash)
(cl-remhash, cl-clrhash, cl-maphash, cl-make-hash-table)
(cl-hash-table-p, cl-hash-table-count): Move to cl.el.
(cl-macroexpand-cmacs): Remove var.
(cl-macroexpand-all, cl-macroexpand-body): Remove funs.
Use macroexpand-all instead.
* emacs-lisp/cl-lib.el (cl-macro-environment): Remove decl.
(cl-macroexpand): Move to cl-macs.el and rename to cl--sm-macroexpand.
(cl-member): Remove old alias.
* emacs-lisp/cl-macs.el (cl-macro-environment): Remove var.
Use macroexpand-all-environment instead.
(cl--old-macroexpand): New var.
(cl--sm-macroexpand): New function.
(cl-symbol-macrolet): Use it during macro expansion.
(cl--function-convert-cache): New var.
(cl--function-convert): New function, extracted from
cl-macroexpand-all.
(cl-lexical-let): Use it.
* emacs-lisp/cl.el (cl-macroexpand, cl-macro-environment)
(cl-macroexpand-all, cl-not-hash-table, cl-builtin-gethash)
(cl-builtin-remhash, cl-builtin-clrhash, cl-builtin-maphash)
(cl-map-keymap, cl-copy-tree, cl-gethash, cl-puthash, cl-remhash)
(cl-clrhash, cl-maphash, cl-make-hash-table, cl-hash-table-p)
(cl-hash-table-count): Add old compatibility aliases.
2012-06-07 15:48:22 -04:00
|
|
|
(let ((macroexpand-all-environment env))
|
1993-07-30 20:15:09 +00:00
|
|
|
(setq method (apply method (cdr place))))
|
|
|
|
(if (and (consp method) (= (length method) 5))
|
|
|
|
method
|
|
|
|
(error "Setf-method for %s returns malformed method"
|
|
|
|
func)))
|
2008-04-08 11:50:24 +00:00
|
|
|
(and (string-match-p "\\`c[ad][ad][ad]?[ad]?r\\'" name)
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-get-setf-method (cl-compiler-macroexpand place)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(and (eq func 'edebug-after)
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-get-setf-method (nth (1- (length place)) place)
|
1993-07-30 20:15:09 +00:00
|
|
|
env)))))
|
|
|
|
(if (eq place (setq place (macroexpand place env)))
|
|
|
|
(if (and (symbolp (car place)) (fboundp (car place))
|
|
|
|
(symbolp (symbol-function (car place))))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-get-setf-method (cons (symbol-function (car place))
|
1993-07-30 20:15:09 +00:00
|
|
|
(cdr place)) env)
|
|
|
|
(error "No setf-method known for %s" (car place)))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-get-setf-method place env)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
(defun cl-setf-do-modify (place opt-expr)
|
Move old compatiblity to cl.el. Remove cl-macroexpand-all.
* emacs-lisp/cl-extra.el (cl-map-keymap, cl-copy-tree)
(cl-not-hash-table, cl-builtin-gethash, cl-builtin-remhash)
(cl-builtin-clrhash, cl-builtin-maphash, cl-gethash, cl-puthash)
(cl-remhash, cl-clrhash, cl-maphash, cl-make-hash-table)
(cl-hash-table-p, cl-hash-table-count): Move to cl.el.
(cl-macroexpand-cmacs): Remove var.
(cl-macroexpand-all, cl-macroexpand-body): Remove funs.
Use macroexpand-all instead.
* emacs-lisp/cl-lib.el (cl-macro-environment): Remove decl.
(cl-macroexpand): Move to cl-macs.el and rename to cl--sm-macroexpand.
(cl-member): Remove old alias.
* emacs-lisp/cl-macs.el (cl-macro-environment): Remove var.
Use macroexpand-all-environment instead.
(cl--old-macroexpand): New var.
(cl--sm-macroexpand): New function.
(cl-symbol-macrolet): Use it during macro expansion.
(cl--function-convert-cache): New var.
(cl--function-convert): New function, extracted from
cl-macroexpand-all.
(cl-lexical-let): Use it.
* emacs-lisp/cl.el (cl-macroexpand, cl-macro-environment)
(cl-macroexpand-all, cl-not-hash-table, cl-builtin-gethash)
(cl-builtin-remhash, cl-builtin-clrhash, cl-builtin-maphash)
(cl-map-keymap, cl-copy-tree, cl-gethash, cl-puthash, cl-remhash)
(cl-clrhash, cl-maphash, cl-make-hash-table, cl-hash-table-p)
(cl-hash-table-count): Add old compatibility aliases.
2012-06-07 15:48:22 -04:00
|
|
|
(let* ((method (cl-get-setf-method place macroexpand-all-environment))
|
1993-07-30 20:15:09 +00:00
|
|
|
(temps (car method)) (values (nth 1 method))
|
|
|
|
(lets nil) (subs nil)
|
|
|
|
(optimize (and (not (eq opt-expr 'no-opt))
|
|
|
|
(or (and (not (eq opt-expr 'unsafe))
|
2012-06-07 15:25:48 -04:00
|
|
|
(cl--safe-expr-p opt-expr))
|
1993-07-30 20:15:09 +00:00
|
|
|
(cl-setf-simple-store-p (car (nth 2 method))
|
|
|
|
(nth 3 method)))))
|
2012-06-07 15:25:48 -04:00
|
|
|
(simple (and optimize (consp place) (cl--simple-exprs-p (cdr place)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(while values
|
2012-06-07 15:25:48 -04:00
|
|
|
(if (or simple (macroexp-const-p (car values)))
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (cons (pop temps) (pop values)) subs)
|
|
|
|
(push (list (pop temps) (pop values)) lets)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(list (nreverse lets)
|
2012-06-03 21:05:17 -04:00
|
|
|
(cons (car (nth 2 method)) (cl-sublis subs (nth 3 method)))
|
|
|
|
(cl-sublis subs (nth 4 method)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
(defun cl-setf-do-store (spec val)
|
|
|
|
(let ((sym (car spec))
|
|
|
|
(form (cdr spec)))
|
2012-06-07 15:25:48 -04:00
|
|
|
(if (or (macroexp-const-p val)
|
|
|
|
(and (cl--simple-expr-p val) (eq (cl--expr-contains form sym) 1))
|
1993-07-30 20:15:09 +00:00
|
|
|
(cl-setf-simple-store-p sym form))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-subst val sym form)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(let ((,sym ,val)) ,form))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
(defun cl-setf-simple-store-p (sym form)
|
2012-06-07 15:25:48 -04:00
|
|
|
(and (consp form) (eq (cl--expr-contains form sym) 1)
|
1993-07-30 20:15:09 +00:00
|
|
|
(eq (nth (1- (length form)) form) sym)
|
|
|
|
(symbolp (car form)) (fboundp (car form))
|
|
|
|
(not (eq (car-safe (symbol-function (car form))) 'macro))))
|
|
|
|
|
|
|
|
;;; The standard modify macros.
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-setf (&rest args)
|
2002-09-27 23:16:27 +00:00
|
|
|
"Set each PLACE to the value of its VAL.
|
1993-07-30 20:15:09 +00:00
|
|
|
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.
|
2012-06-03 21:05:17 -04:00
|
|
|
For example, (cl-setf (cl-cadar x) y) is equivalent to (setcar (cdar x) y).
|
2002-09-27 23:16:27 +00:00
|
|
|
The return value is the last VAL in the list.
|
|
|
|
|
|
|
|
\(fn PLACE VAL PLACE VAL ...)"
|
2012-05-17 17:39:36 -04:00
|
|
|
(declare (debug (&rest [place form])))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (cdr (cdr args))
|
|
|
|
(let ((sets nil))
|
2012-06-03 21:05:17 -04:00
|
|
|
(while args (push `(cl-setf ,(pop args) ,(pop args)) sets))
|
1993-07-30 20:15:09 +00:00
|
|
|
(cons 'progn (nreverse sets)))
|
|
|
|
(if (symbolp (car args))
|
|
|
|
(and args (cons 'setq args))
|
|
|
|
(let* ((method (cl-setf-do-modify (car args) (nth 1 args)))
|
|
|
|
(store (cl-setf-do-store (nth 1 method) (nth 1 args))))
|
2012-06-01 16:36:00 -04:00
|
|
|
(if (car method) `(let* ,(car method) ,store) store)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-psetf (&rest args)
|
2002-09-27 23:16:27 +00:00
|
|
|
"Set PLACEs to the values VALs in parallel.
|
2012-06-03 21:05:17 -04:00
|
|
|
This is like `cl-setf', except that all VAL forms are evaluated (in order)
|
2002-09-27 23:16:27 +00:00
|
|
|
before assigning any PLACEs to the corresponding values.
|
|
|
|
|
|
|
|
\(fn PLACE VAL PLACE VAL ...)"
|
2012-06-03 21:05:17 -04:00
|
|
|
(declare (debug cl-setf))
|
1993-07-30 20:15:09 +00:00
|
|
|
(let ((p args) (simple t) (vars nil))
|
|
|
|
(while p
|
2012-06-07 15:25:48 -04:00
|
|
|
(if (or (not (symbolp (car p))) (cl--expr-depends-p (nth 1 p) vars))
|
1993-07-30 20:15:09 +00:00
|
|
|
(setq simple nil))
|
|
|
|
(if (memq (car p) vars)
|
|
|
|
(error "Destination duplicated in psetf: %s" (car p)))
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (pop p) vars)
|
2012-06-03 21:05:17 -04:00
|
|
|
(or p (error "Odd number of arguments to cl-psetf"))
|
2002-09-27 23:16:27 +00:00
|
|
|
(pop p))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if simple
|
2012-06-03 21:05:17 -04:00
|
|
|
`(progn (cl-setf ,@args) nil)
|
1993-07-30 20:15:09 +00:00
|
|
|
(setq args (reverse args))
|
2012-06-03 21:05:17 -04:00
|
|
|
(let ((expr `(cl-setf ,(cadr args) ,(car args))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(while (setq args (cddr args))
|
2012-06-03 21:05:17 -04:00
|
|
|
(setq expr `(cl-setf ,(cadr args) (prog1 ,(car args) ,expr))))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(progn ,expr nil)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
1993-07-30 20:15:09 +00:00
|
|
|
(defun cl-do-pop (place)
|
2012-06-07 15:25:48 -04:00
|
|
|
(if (cl--simple-expr-p place)
|
2012-06-03 21:05:17 -04:00
|
|
|
`(prog1 (car ,place) (cl-setf ,place (cdr ,place)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(let* ((method (cl-setf-do-modify place t))
|
2004-11-16 04:05:29 +00:00
|
|
|
(temp (make-symbol "--cl-pop--")))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(let* (,@(car method)
|
|
|
|
(,temp ,(nth 2 method)))
|
|
|
|
(prog1 (car ,temp)
|
|
|
|
,(cl-setf-do-store (nth 1 method) `(cdr ,temp)))))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-remf (place tag)
|
2000-05-05 20:01:01 +00:00
|
|
|
"Remove TAG from property list PLACE.
|
2012-06-03 21:05:17 -04:00
|
|
|
PLACE may be a symbol, or any generalized variable allowed by `cl-setf'.
|
1993-07-30 20:15:09 +00:00
|
|
|
The form returns true if TAG was found and removed, nil otherwise."
|
2012-05-17 17:39:36 -04:00
|
|
|
(declare (debug (place form)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(let* ((method (cl-setf-do-modify place t))
|
2012-06-07 15:25:48 -04:00
|
|
|
(tag-temp (and (not (macroexp-const-p tag)) (make-symbol "--cl-remf-tag--")))
|
|
|
|
(val-temp (and (not (cl--simple-expr-p place))
|
2004-11-16 04:05:29 +00:00
|
|
|
(make-symbol "--cl-remf-place--")))
|
1993-07-30 20:15:09 +00:00
|
|
|
(ttag (or tag-temp tag))
|
|
|
|
(tval (or val-temp (nth 2 method))))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(let* (,@(car method)
|
|
|
|
,@(and val-temp `((,val-temp ,(nth 2 method))))
|
|
|
|
,@(and tag-temp `((,tag-temp ,tag))))
|
|
|
|
(if (eq ,ttag (car ,tval))
|
|
|
|
(progn ,(cl-setf-do-store (nth 1 method) `(cddr ,tval))
|
|
|
|
t)
|
2012-06-12 14:10:34 -04:00
|
|
|
(cl--do-remf ,tval ,ttag)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-shiftf (place &rest args)
|
2002-09-27 23:16:27 +00:00
|
|
|
"Shift left among PLACEs.
|
2012-06-03 21:05:17 -04:00
|
|
|
Example: (cl-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 `cl-setf'.
|
2002-09-27 23:16:27 +00:00
|
|
|
|
(function*, case, ecase, typecase, etypecase, progv, lexical-let, lexical-let*,
multiple-value-bind, multiple-value-setq, shiftf): Improve argument/docstring
consistency.
2005-05-22 17:51:22 +00:00
|
|
|
\(fn PLACE... VAL)"
|
2012-05-17 17:39:36 -04:00
|
|
|
(declare (debug (&rest place)))
|
2001-11-30 08:23:25 +00:00
|
|
|
(cond
|
|
|
|
((null args) place)
|
2012-06-03 21:05:17 -04:00
|
|
|
((symbolp place) `(prog1 ,place (setq ,place (cl-shiftf ,@args))))
|
2001-11-30 08:23:25 +00:00
|
|
|
(t
|
|
|
|
(let ((method (cl-setf-do-modify place 'unsafe)))
|
|
|
|
`(let* ,(car method)
|
|
|
|
(prog1 ,(nth 2 method)
|
2012-06-03 21:05:17 -04:00
|
|
|
,(cl-setf-do-store (nth 1 method) `(cl-shiftf ,@args))))))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-rotatef (&rest args)
|
2002-09-27 23:16:27 +00:00
|
|
|
"Rotate left among PLACEs.
|
2012-06-03 21:05:17 -04:00
|
|
|
Example: (cl-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 `cl-setf'.
|
2002-09-27 23:16:27 +00:00
|
|
|
|
|
|
|
\(fn PLACE...)"
|
2012-05-17 17:39:36 -04:00
|
|
|
(declare (debug (&rest place)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (not (memq nil (mapcar 'symbolp args)))
|
|
|
|
(and (cdr args)
|
|
|
|
(let ((sets nil)
|
|
|
|
(first (car args)))
|
|
|
|
(while (cdr args)
|
2002-09-27 23:16:27 +00:00
|
|
|
(setq sets (nconc sets (list (pop args) (car args)))))
|
2012-06-03 21:05:17 -04:00
|
|
|
`(cl-psetf ,@sets ,(car args) ,first)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(let* ((places (reverse args))
|
2004-11-16 04:05:29 +00:00
|
|
|
(temp (make-symbol "--cl-rotatef--"))
|
1993-07-30 20:15:09 +00:00
|
|
|
(form temp))
|
|
|
|
(while (cdr places)
|
2002-09-27 23:16:27 +00:00
|
|
|
(let ((method (cl-setf-do-modify (pop places) 'unsafe)))
|
2012-06-01 16:36:00 -04:00
|
|
|
(setq form `(let* ,(car method)
|
|
|
|
(prog1 ,(nth 2 method)
|
|
|
|
,(cl-setf-do-store (nth 1 method) form))))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(let ((method (cl-setf-do-modify (car places) 'unsafe)))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(let* (,@(car method) (,temp ,(nth 2 method)))
|
|
|
|
,(cl-setf-do-store (nth 1 method) form) nil)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-letf (bindings &rest body)
|
2002-09-27 23:16:27 +00:00
|
|
|
"Temporarily bind to PLACEs.
|
1993-07-30 20:15:09 +00:00
|
|
|
This is the analogue of `let', but with generalized variables (in the
|
2012-06-03 21:05:17 -04:00
|
|
|
sense of `cl-setf') for the PLACEs. Each PLACE is set to the corresponding
|
1993-07-30 20:15:09 +00:00
|
|
|
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)',
|
2002-09-27 23:16:27 +00:00
|
|
|
the PLACE is not modified before executing BODY.
|
|
|
|
|
|
|
|
\(fn ((PLACE VALUE) ...) BODY...)"
|
2012-05-17 17:51:15 -04:00
|
|
|
(declare (indent 1) (debug ((&rest (gate place &optional form)) body)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (and (not (cdr bindings)) (cdar bindings) (symbolp (caar bindings)))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(let ,bindings ,@body)
|
2012-06-08 09:18:26 -04:00
|
|
|
(let ((lets nil)
|
|
|
|
(rev (reverse bindings)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(while rev
|
|
|
|
(let* ((place (if (symbolp (caar rev))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(symbol-value ',(caar rev))
|
1993-07-30 20:15:09 +00:00
|
|
|
(caar rev)))
|
2012-06-03 21:05:17 -04:00
|
|
|
(value (cl-cadar rev))
|
1993-07-30 20:15:09 +00:00
|
|
|
(method (cl-setf-do-modify place 'no-opt))
|
2004-11-16 04:05:29 +00:00
|
|
|
(save (make-symbol "--cl-letf-save--"))
|
1993-07-30 20:15:09 +00:00
|
|
|
(bound (and (memq (car place) '(symbol-value symbol-function))
|
2004-11-16 04:05:29 +00:00
|
|
|
(make-symbol "--cl-letf-bound--")))
|
2012-06-07 15:25:48 -04:00
|
|
|
(temp (and (not (macroexp-const-p value)) (cdr bindings)
|
2004-11-16 04:05:29 +00:00
|
|
|
(make-symbol "--cl-letf-val--"))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(setq lets (nconc (car method)
|
|
|
|
(if bound
|
|
|
|
(list (list bound
|
|
|
|
(list (if (eq (car place)
|
|
|
|
'symbol-value)
|
|
|
|
'boundp 'fboundp)
|
|
|
|
(nth 1 (nth 2 method))))
|
2012-06-01 16:36:00 -04:00
|
|
|
(list save `(and ,bound
|
|
|
|
,(nth 2 method))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(list (list save (nth 2 method))))
|
|
|
|
(and temp (list (list temp value)))
|
|
|
|
lets)
|
|
|
|
body (list
|
2012-06-01 16:36:00 -04:00
|
|
|
`(unwind-protect
|
|
|
|
(progn
|
|
|
|
,@(if (cdr (car rev))
|
|
|
|
(cons (cl-setf-do-store (nth 1 method)
|
|
|
|
(or temp value))
|
|
|
|
body)
|
|
|
|
body))
|
|
|
|
,(if bound
|
|
|
|
`(if ,bound
|
|
|
|
,(cl-setf-do-store (nth 1 method) save)
|
|
|
|
(,(if (eq (car place) 'symbol-value)
|
|
|
|
#'makunbound #'fmakunbound)
|
|
|
|
,(nth 1 (nth 2 method))))
|
|
|
|
(cl-setf-do-store (nth 1 method) save))))
|
1993-07-30 20:15:09 +00:00
|
|
|
rev (cdr rev))))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(let* ,lets ,@body))))
|
|
|
|
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-letf* (bindings &rest body)
|
2002-09-27 23:16:27 +00:00
|
|
|
"Temporarily bind to PLACEs.
|
1993-07-30 20:15:09 +00:00
|
|
|
This is the analogue of `let*', but with generalized variables (in the
|
2012-06-03 21:05:17 -04:00
|
|
|
sense of `cl-setf') for the PLACEs. Each PLACE is set to the corresponding
|
1993-07-30 20:15:09 +00:00
|
|
|
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)',
|
2002-09-27 23:16:27 +00:00
|
|
|
the PLACE is not modified before executing BODY.
|
|
|
|
|
|
|
|
\(fn ((PLACE VALUE) ...) BODY...)"
|
2012-06-03 21:05:17 -04:00
|
|
|
(declare (indent 1) (debug cl-letf))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (null bindings)
|
|
|
|
(cons 'progn body)
|
|
|
|
(setq bindings (reverse bindings))
|
|
|
|
(while bindings
|
2012-06-03 21:05:17 -04:00
|
|
|
(setq body (list `(cl-letf (,(pop bindings)) ,@body))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(car body)))
|
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-callf (func place &rest args)
|
2002-09-27 23:16:27 +00:00
|
|
|
"Set PLACE to (FUNC PLACE ARGS...).
|
1993-07-30 20:15:09 +00:00
|
|
|
FUNC should be an unquoted function name. PLACE may be a symbol,
|
2012-06-03 21:05:17 -04:00
|
|
|
or any generalized variable allowed by `cl-setf'.
|
2002-09-27 23:16:27 +00:00
|
|
|
|
|
|
|
\(fn FUNC PLACE ARGS...)"
|
2012-06-03 21:05:17 -04:00
|
|
|
(declare (indent 2) (debug (cl-function place &rest form)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(let* ((method (cl-setf-do-modify place (cons 'list args)))
|
|
|
|
(rargs (cons (nth 2 method) args)))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(let* ,(car method)
|
|
|
|
,(cl-setf-do-store (nth 1 method)
|
|
|
|
(if (symbolp func) (cons func rargs)
|
|
|
|
`(funcall #',func ,@rargs))))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-callf2 (func arg1 place &rest args)
|
2002-09-27 23:16:27 +00:00
|
|
|
"Set PLACE to (FUNC ARG1 PLACE ARGS...).
|
2012-06-03 21:05:17 -04:00
|
|
|
Like `cl-callf', but PLACE is the second argument of FUNC, not the first.
|
2002-09-27 23:16:27 +00:00
|
|
|
|
|
|
|
\(fn FUNC ARG1 PLACE ARGS...)"
|
2012-06-03 21:05:17 -04:00
|
|
|
(declare (indent 3) (debug (cl-function form place &rest form)))
|
2012-06-07 15:25:48 -04:00
|
|
|
(if (and (cl--safe-expr-p arg1) (cl--simple-expr-p place) (symbolp func))
|
2012-06-03 21:05:17 -04:00
|
|
|
`(cl-setf ,place (,func ,arg1 ,place ,@args))
|
1993-07-30 20:15:09 +00:00
|
|
|
(let* ((method (cl-setf-do-modify place (cons 'list args)))
|
2012-06-07 15:25:48 -04:00
|
|
|
(temp (and (not (macroexp-const-p arg1)) (make-symbol "--cl-arg1--")))
|
2012-06-03 21:05:17 -04:00
|
|
|
(rargs (cl-list* (or temp arg1) (nth 2 method) args)))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(let* (,@(and temp (list (list temp arg1))) ,@(car method))
|
|
|
|
,(cl-setf-do-store (nth 1 method)
|
|
|
|
(if (symbolp func) (cons func rargs)
|
|
|
|
`(funcall #',func ,@rargs)))))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-define-modify-macro (name arglist func &optional doc)
|
|
|
|
"Define a `cl-setf'-like modify macro.
|
1993-07-30 20:15:09 +00:00
|
|
|
If NAME is called, it combines its PLACE argument with the other arguments
|
2012-06-03 21:05:17 -04:00
|
|
|
from ARGLIST using FUNC: (cl-define-modify-macro cl-incf (&optional (n 1)) +)"
|
2012-05-17 17:39:36 -04:00
|
|
|
(declare (debug
|
|
|
|
(&define name cl-lambda-list ;; should exclude &key
|
|
|
|
symbolp &optional stringp)))
|
2012-06-03 21:05:17 -04:00
|
|
|
(if (memq '&key arglist) (error "&key not allowed in cl-define-modify-macro"))
|
2004-11-16 04:05:29 +00:00
|
|
|
(let ((place (make-symbol "--cl-place--")))
|
2012-06-03 21:05:17 -04:00
|
|
|
`(cl-defmacro ,name (,place ,@arglist)
|
2012-06-01 16:36:00 -04:00
|
|
|
,doc
|
2012-06-03 21:05:17 -04:00
|
|
|
(,(if (memq '&rest arglist) #'cl-list* #'list)
|
|
|
|
#'cl-callf ',func ,place
|
2012-06-07 15:25:48 -04:00
|
|
|
,@(cl--arglist-args arglist)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
;;; Structures.
|
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-defstruct (struct &rest descs)
|
2002-09-27 23:16:27 +00:00
|
|
|
"Define a struct type.
|
2010-01-16 15:04:29 -05:00
|
|
|
This macro defines a new data type called NAME that stores data
|
|
|
|
in SLOTs. It defines a `make-NAME' constructor, a `copy-NAME'
|
|
|
|
copier, a `NAME-p' predicate, and slot accessors named `NAME-SLOT'.
|
2012-06-03 21:05:17 -04:00
|
|
|
You can use the accessors to set the corresponding slots, via `cl-setf'.
|
2002-09-27 23:16:27 +00:00
|
|
|
|
2010-01-16 15:04:29 -05:00
|
|
|
NAME may instead take the form (NAME OPTIONS...), where each
|
|
|
|
OPTION is either a single keyword or (KEYWORD VALUE).
|
|
|
|
See Info node `(cl)Structures' for a list of valid keywords.
|
|
|
|
|
|
|
|
Each SLOT may instead take the form (SLOT SLOT-OPTS...), where
|
|
|
|
SLOT-OPTS are keyword-value pairs for that slot. Currently, only
|
|
|
|
one keyword is supported, `:read-only'. If this has a non-nil
|
2012-06-03 21:05:17 -04:00
|
|
|
value, that slot cannot be set via `cl-setf'.
|
2010-01-16 15:04:29 -05:00
|
|
|
|
|
|
|
\(fn NAME SLOTS...)"
|
2012-05-17 21:46:20 -04:00
|
|
|
(declare (doc-string 2)
|
|
|
|
(debug
|
2012-05-17 17:39:36 -04:00
|
|
|
(&define ;Makes top-level form not be wrapped.
|
|
|
|
[&or symbolp
|
|
|
|
(gate
|
|
|
|
symbolp &rest
|
|
|
|
(&or [":conc-name" symbolp]
|
|
|
|
[":constructor" symbolp &optional cl-lambda-list]
|
|
|
|
[":copier" symbolp]
|
|
|
|
[":predicate" symbolp]
|
|
|
|
[":include" symbolp &rest sexp] ;; Not finished.
|
|
|
|
;; The following are not supported.
|
|
|
|
;; [":print-function" ...]
|
|
|
|
;; [":type" ...]
|
|
|
|
;; [":initial-offset" ...]
|
|
|
|
))]
|
|
|
|
[&optional stringp]
|
|
|
|
;; All the above is for the following def-form.
|
|
|
|
&rest &or symbolp (symbolp def-form
|
|
|
|
&optional ":read-only" sexp))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(let* ((name (if (consp struct) (car struct) struct))
|
|
|
|
(opts (cdr-safe struct))
|
|
|
|
(slots nil)
|
|
|
|
(defaults nil)
|
|
|
|
(conc-name (concat (symbol-name name) "-"))
|
|
|
|
(constructor (intern (format "make-%s" name)))
|
|
|
|
(constrs nil)
|
|
|
|
(copier (intern (format "copy-%s" name)))
|
|
|
|
(predicate (intern (format "%s-p" name)))
|
|
|
|
(print-func nil) (print-auto nil)
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(safety (if (cl--compiling-file) cl-optimize-safety 3))
|
1993-07-30 20:15:09 +00:00
|
|
|
(include nil)
|
|
|
|
(tag (intern (format "cl-struct-%s" name)))
|
|
|
|
(tag-symbol (intern (format "cl-struct-%s-tags" name)))
|
|
|
|
(include-descs nil)
|
|
|
|
(side-eff nil)
|
|
|
|
(type nil)
|
|
|
|
(named nil)
|
|
|
|
(forms nil)
|
|
|
|
pred-form pred-check)
|
|
|
|
(if (stringp (car descs))
|
2012-06-01 16:36:00 -04:00
|
|
|
(push `(put ',name 'structure-documentation
|
|
|
|
,(pop descs)) forms))
|
1993-07-30 20:15:09 +00:00
|
|
|
(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)))
|
2002-09-27 23:16:27 +00:00
|
|
|
(args (cdr-safe (pop opts))))
|
2000-05-05 20:01:01 +00:00
|
|
|
(cond ((eq opt :conc-name)
|
1993-07-30 20:15:09 +00:00
|
|
|
(if args
|
|
|
|
(setq conc-name (if (car args)
|
|
|
|
(symbol-name (car args)) ""))))
|
2000-05-05 20:01:01 +00:00
|
|
|
((eq opt :constructor)
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (cdr args)
|
2005-11-27 20:59:10 +00:00
|
|
|
(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))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if args (setq constructor (car args)))))
|
2000-05-05 20:01:01 +00:00
|
|
|
((eq opt :copier)
|
1993-07-30 20:15:09 +00:00
|
|
|
(if args (setq copier (car args))))
|
2000-05-05 20:01:01 +00:00
|
|
|
((eq opt :predicate)
|
1993-07-30 20:15:09 +00:00
|
|
|
(if args (setq predicate (car args))))
|
2000-05-05 20:01:01 +00:00
|
|
|
((eq opt :include)
|
1993-07-30 20:15:09 +00:00
|
|
|
(setq include (car args)
|
|
|
|
include-descs (mapcar (function
|
|
|
|
(lambda (x)
|
|
|
|
(if (consp x) x (list x))))
|
1996-04-16 04:36:21 +00:00
|
|
|
(cdr args))))
|
2000-05-05 20:01:01 +00:00
|
|
|
((eq opt :print-function)
|
1993-07-30 20:15:09 +00:00
|
|
|
(setq print-func (car args)))
|
2000-05-05 20:01:01 +00:00
|
|
|
((eq opt :type)
|
1993-07-30 20:15:09 +00:00
|
|
|
(setq type (car args)))
|
2000-05-05 20:01:01 +00:00
|
|
|
((eq opt :named)
|
1993-07-30 20:15:09 +00:00
|
|
|
(setq named t))
|
2000-05-05 20:01:01 +00:00
|
|
|
((eq opt :initial-offset)
|
1993-07-30 20:15:09 +00:00
|
|
|
(setq descs (nconc (make-list (car args) '(cl-skip-slot))
|
|
|
|
descs)))
|
|
|
|
(t
|
|
|
|
(error "Slot option %s unrecognized" opt)))))
|
|
|
|
(if print-func
|
2012-06-01 16:36:00 -04:00
|
|
|
(setq print-func
|
|
|
|
`(progn (funcall #',print-func cl-x cl-s cl-n) t))
|
1993-07-30 20:15:09 +00:00
|
|
|
(or type (and include (not (get include 'cl-struct-print)))
|
|
|
|
(setq print-auto t
|
|
|
|
print-func (and (or (not (or include type)) (null print-func))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(progn
|
|
|
|
(princ ,(format "#S(%s" name) cl-s))))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if include
|
|
|
|
(let ((inc-type (get include 'cl-struct-type))
|
|
|
|
(old-descs (get include 'cl-struct-slots)))
|
|
|
|
(or inc-type (error "%s is not a struct name" include))
|
|
|
|
(and type (not (eq (car inc-type) type))
|
|
|
|
(error ":type disagrees with :include for %s" name))
|
|
|
|
(while include-descs
|
|
|
|
(setcar (memq (or (assq (caar include-descs) old-descs)
|
|
|
|
(error "No slot %s in included struct %s"
|
|
|
|
(caar include-descs) include))
|
|
|
|
old-descs)
|
2002-09-27 23:16:27 +00:00
|
|
|
(pop include-descs)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(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))
|
1996-04-16 04:36:21 +00:00
|
|
|
(let ((incl include))
|
|
|
|
(while incl
|
2012-06-03 21:05:17 -04:00
|
|
|
(push `(cl-pushnew ',tag
|
2012-06-01 16:36:00 -04:00
|
|
|
,(intern (format "cl-struct-%s-tags" incl)))
|
|
|
|
forms)
|
1996-04-16 04:36:21 +00:00
|
|
|
(setq incl (get incl 'cl-struct-include)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if type
|
|
|
|
(progn
|
|
|
|
(or (memq type '(vector list))
|
2005-03-25 08:27:58 +00:00
|
|
|
(error "Invalid :type specifier: %s" type))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if named (setq tag name)))
|
|
|
|
(setq type 'vector named 'true)))
|
|
|
|
(or named (setq descs (delq (assq 'cl-tag-slot descs) descs)))
|
2012-06-01 16:36:00 -04:00
|
|
|
(push `(defvar ,tag-symbol) forms)
|
1993-07-30 20:15:09 +00:00
|
|
|
(setq pred-form (and named
|
|
|
|
(let ((pos (- (length descs)
|
|
|
|
(length (memq (assq 'cl-tag-slot descs)
|
|
|
|
descs)))))
|
|
|
|
(if (eq type 'vector)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(and (vectorp cl-x)
|
|
|
|
(>= (length cl-x) ,(length descs))
|
|
|
|
(memq (aref cl-x ,pos) ,tag-symbol))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (= pos 0)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(memq (car-safe cl-x) ,tag-symbol)
|
|
|
|
`(and (consp cl-x)
|
|
|
|
(memq (nth ,pos cl-x) ,tag-symbol))))))
|
1993-07-30 20:15:09 +00:00
|
|
|
pred-check (and pred-form (> safety 0)
|
2012-06-03 21:05:17 -04:00
|
|
|
(if (and (eq (cl-caadr pred-form) 'vectorp)
|
1993-07-30 20:15:09 +00:00
|
|
|
(= safety 1))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cons 'and (cl-cdddr pred-form)) pred-form)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(let ((pos 0) (descp descs))
|
|
|
|
(while descp
|
2002-09-27 23:16:27 +00:00
|
|
|
(let* ((desc (pop descp))
|
1993-07-30 20:15:09 +00:00
|
|
|
(slot (car desc)))
|
|
|
|
(if (memq slot '(cl-tag-slot cl-skip-slot))
|
|
|
|
(progn
|
2002-09-27 23:16:27 +00:00
|
|
|
(push nil slots)
|
2012-06-01 16:36:00 -04:00
|
|
|
(push (and (eq slot 'cl-tag-slot) `',tag)
|
1993-07-30 20:15:09 +00:00
|
|
|
defaults))
|
|
|
|
(if (assq slot descp)
|
|
|
|
(error "Duplicate slots named %s in %s" slot name))
|
|
|
|
(let ((accessor (intern (format "%s%s" conc-name slot))))
|
2002-09-27 23:16:27 +00:00
|
|
|
(push slot slots)
|
|
|
|
(push (nth 1 desc) defaults)
|
2012-06-03 21:05:17 -04:00
|
|
|
(push (cl-list*
|
|
|
|
'cl-defsubst accessor '(cl-x)
|
1993-07-30 20:15:09 +00:00
|
|
|
(append
|
|
|
|
(and pred-check
|
2012-06-01 16:36:00 -04:00
|
|
|
(list `(or ,pred-check
|
|
|
|
(error "%s accessing a non-%s"
|
|
|
|
',accessor ',name))))
|
|
|
|
(list (if (eq type 'vector) `(aref cl-x ,pos)
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (= pos 0) '(car cl-x)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(nth ,pos cl-x)))))) forms)
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (cons accessor t) side-eff)
|
2012-06-07 15:25:48 -04:00
|
|
|
(push `(cl-define-setf-expander ,accessor (cl-x)
|
2012-06-01 16:36:00 -04:00
|
|
|
,(if (cadr (memq :read-only (cddr desc)))
|
|
|
|
`(progn (ignore cl-x)
|
|
|
|
(error "%s is a read-only slot"
|
|
|
|
',accessor))
|
|
|
|
;; 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.
|
|
|
|
`(progn
|
|
|
|
(declare-function
|
|
|
|
cl-struct-setf-expander "cl-macs"
|
|
|
|
(x name accessor pred-form pos))
|
|
|
|
(cl-struct-setf-expander
|
|
|
|
cl-x ',name ',accessor
|
|
|
|
,(and pred-check `',pred-check)
|
|
|
|
,pos))))
|
|
|
|
forms)
|
1993-07-30 20:15:09 +00:00
|
|
|
(if print-auto
|
|
|
|
(nconc print-func
|
2012-06-01 16:36:00 -04:00
|
|
|
(list `(princ ,(format " %s" slot) cl-s)
|
|
|
|
`(prin1 (,accessor cl-x) cl-s)))))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(setq pos (1+ pos))))
|
|
|
|
(setq slots (nreverse slots)
|
|
|
|
defaults (nreverse defaults))
|
|
|
|
(and predicate pred-form
|
2012-06-03 21:05:17 -04:00
|
|
|
(progn (push `(cl-defsubst ,predicate (cl-x)
|
2012-06-01 16:36:00 -04:00
|
|
|
,(if (eq (car pred-form) 'and)
|
|
|
|
(append pred-form '(t))
|
|
|
|
`(and ,pred-form t))) forms)
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (cons predicate 'error-free) side-eff)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(and copier
|
2012-06-01 16:36:00 -04:00
|
|
|
(progn (push `(defun ,copier (x) (copy-sequence x)) forms)
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (cons copier t) side-eff)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if constructor
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (list constructor
|
1993-07-30 20:15:09 +00:00
|
|
|
(cons '&key (delq nil (copy-sequence slots))))
|
|
|
|
constrs))
|
|
|
|
(while constrs
|
|
|
|
(let* ((name (caar constrs))
|
2002-09-27 23:16:27 +00:00
|
|
|
(args (cadr (pop constrs)))
|
2012-06-07 15:25:48 -04:00
|
|
|
(anames (cl--arglist-args args))
|
2012-06-03 21:05:17 -04:00
|
|
|
(make (cl-mapcar (function (lambda (s d) (if (memq s anames) s d)))
|
1993-07-30 20:15:09 +00:00
|
|
|
slots defaults)))
|
2012-06-03 21:05:17 -04:00
|
|
|
(push `(cl-defsubst ,name
|
2012-06-01 16:36:00 -04:00
|
|
|
(&cl-defs '(nil ,@descs) ,@args)
|
|
|
|
(,type ,@make)) forms)
|
2012-06-07 15:25:48 -04:00
|
|
|
(if (cl--safe-expr-p `(progn ,@(mapcar #'cl-second descs)))
|
2002-09-27 23:16:27 +00:00
|
|
|
(push (cons name t) side-eff))))
|
1993-07-30 20:15:09 +00:00
|
|
|
(if print-auto (nconc print-func (list '(princ ")" cl-s) t)))
|
2012-06-13 16:52:25 -04:00
|
|
|
;; Don't bother adding to cl-custom-print-functions since it's not used
|
|
|
|
;; by anything anyway!
|
|
|
|
;;(if print-func
|
|
|
|
;; (push `(if (boundp 'cl-custom-print-functions)
|
|
|
|
;; (push
|
|
|
|
;; ;; The auto-generated function does not pay attention to
|
|
|
|
;; ;; the depth argument cl-n.
|
|
|
|
;; (lambda (cl-x cl-s ,(if print-auto '_cl-n 'cl-n))
|
|
|
|
;; (and ,pred-form ,print-func))
|
|
|
|
;; cl-custom-print-functions))
|
|
|
|
;; forms))
|
2012-06-01 16:36:00 -04:00
|
|
|
(push `(setq ,tag-symbol (list ',tag)) forms)
|
2012-06-03 21:05:17 -04:00
|
|
|
(push `(cl-eval-when (compile load eval)
|
2012-06-01 16:36:00 -04:00
|
|
|
(put ',name 'cl-struct-slots ',descs)
|
|
|
|
(put ',name 'cl-struct-type ',(list type (eq named t)))
|
|
|
|
(put ',name 'cl-struct-include ',include)
|
|
|
|
(put ',name 'cl-struct-print ,print-auto)
|
|
|
|
,@(mapcar (lambda (x)
|
|
|
|
`(put ',(car x) 'side-effect-free ',(cdr x)))
|
|
|
|
side-eff))
|
|
|
|
forms)
|
|
|
|
`(progn ,@(nreverse (cons `',name forms)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
1993-07-30 20:15:09 +00:00
|
|
|
(defun cl-struct-setf-expander (x name accessor pred-form pos)
|
2004-11-16 04:05:29 +00:00
|
|
|
(let* ((temp (make-symbol "--cl-x--")) (store (make-symbol "--cl-store--")))
|
1993-07-30 20:15:09 +00:00
|
|
|
(list (list temp) (list x) (list store)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(progn
|
|
|
|
,@(and pred-form
|
2012-06-03 21:05:17 -04:00
|
|
|
(list `(or ,(cl-subst temp 'cl-x pred-form)
|
2012-06-01 16:36:00 -04:00
|
|
|
(error ,(format
|
|
|
|
"%s storing a non-%s"
|
|
|
|
accessor name)))))
|
|
|
|
,(if (eq (car (get name 'cl-struct-type)) 'vector)
|
|
|
|
`(aset ,temp ,pos ,store)
|
|
|
|
`(setcar
|
|
|
|
,(if (<= pos 5)
|
|
|
|
(let ((xx temp))
|
|
|
|
(while (>= (setq pos (1- pos)) 0)
|
|
|
|
(setq xx `(cdr ,xx)))
|
|
|
|
xx)
|
|
|
|
`(nthcdr ,pos ,temp))
|
|
|
|
,store)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(list accessor temp))))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Types and assertions.
|
|
|
|
|
2009-09-27 23:25:03 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-deftype (name arglist &rest body)
|
2000-05-05 20:01:01 +00:00
|
|
|
"Define NAME as a new data type.
|
2012-06-03 21:05:17 -04:00
|
|
|
The type name can then be used in `cl-typecase', `cl-check-type', etc."
|
|
|
|
(declare (debug cl-defmacro) (doc-string 3))
|
|
|
|
`(cl-eval-when (compile load eval)
|
2012-06-07 15:25:48 -04:00
|
|
|
,(cl--transform-function-property
|
2012-06-01 16:36:00 -04:00
|
|
|
name 'cl-deftype-handler (cons `(&cl-defs '('*) ,@arglist) body))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
(defun cl--make-type-test (val type)
|
1993-07-30 20:15:09 +00:00
|
|
|
(if (symbolp type)
|
|
|
|
(cond ((get type 'cl-deftype-handler)
|
2012-06-07 15:25:48 -04:00
|
|
|
(cl--make-type-test val (funcall (get type 'cl-deftype-handler))))
|
1993-07-30 20:15:09 +00:00
|
|
|
((memq type '(nil t)) type)
|
2001-11-30 00:56:45 +00:00
|
|
|
((eq type 'null) `(null ,val))
|
2005-07-16 11:35:33 +00:00
|
|
|
((eq type 'atom) `(atom ,val))
|
2012-06-03 21:05:17 -04:00
|
|
|
((eq type 'float) `(cl-floatp-safe ,val))
|
2001-11-30 00:56:45 +00:00
|
|
|
((eq type 'real) `(numberp ,val))
|
|
|
|
((eq type 'fixnum) `(integerp ,val))
|
2012-06-03 21:05:17 -04:00
|
|
|
;; FIXME: Should `character' accept things like ?\C-\M-a ? --Stef
|
2003-01-07 18:06:29 +00:00
|
|
|
((memq type '(character string-char)) `(characterp ,val))
|
1993-07-30 20:15:09 +00:00
|
|
|
(t
|
|
|
|
(let* ((name (symbol-name type))
|
|
|
|
(namep (intern (concat name "p"))))
|
|
|
|
(if (fboundp namep) (list namep val)
|
|
|
|
(list (intern (concat name "-p")) val)))))
|
|
|
|
(cond ((get (car type) 'cl-deftype-handler)
|
2012-06-07 15:25:48 -04:00
|
|
|
(cl--make-type-test val (apply (get (car type) 'cl-deftype-handler)
|
1993-07-30 20:15:09 +00:00
|
|
|
(cdr type))))
|
2001-11-30 00:56:45 +00:00
|
|
|
((memq (car type) '(integer float real number))
|
2012-06-07 15:25:48 -04:00
|
|
|
(delq t `(and ,(cl--make-type-test val (car type))
|
2012-06-01 16:36:00 -04:00
|
|
|
,(if (memq (cadr type) '(* nil)) t
|
2012-06-03 21:05:17 -04:00
|
|
|
(if (consp (cadr type)) `(> ,val ,(cl-caadr type))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(>= ,val ,(cadr type))))
|
2012-06-03 21:05:17 -04:00
|
|
|
,(if (memq (cl-caddr type) '(* nil)) t
|
|
|
|
(if (consp (cl-caddr type)) `(< ,val ,(cl-caaddr type))
|
|
|
|
`(<= ,val ,(cl-caddr type)))))))
|
2001-11-30 00:56:45 +00:00
|
|
|
((memq (car type) '(and or not))
|
1993-07-30 20:15:09 +00:00
|
|
|
(cons (car type)
|
2012-06-07 15:25:48 -04:00
|
|
|
(mapcar (function (lambda (x) (cl--make-type-test val x)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(cdr type))))
|
2012-06-03 21:05:17 -04:00
|
|
|
((memq (car type) '(member cl-member))
|
|
|
|
`(and (cl-member ,val ',(cdr type)) t))
|
2001-11-30 00:56:45 +00:00
|
|
|
((eq (car type) 'satisfies) (list (cadr type) val))
|
1993-07-30 20:15:09 +00:00
|
|
|
(t (error "Bad type spec: %s" type)))))
|
|
|
|
|
2012-06-08 09:18:26 -04:00
|
|
|
(defvar cl--object)
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defun cl-typep (object type) ; See compiler macro below.
|
1993-07-30 20:15:09 +00:00
|
|
|
"Check that OBJECT is of type TYPE.
|
|
|
|
TYPE is a Common Lisp-style type specifier."
|
2012-06-08 09:18:26 -04:00
|
|
|
(let ((cl--object object)) ;; Yuck!!
|
|
|
|
(eval (cl--make-type-test 'cl--object type))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-check-type (form type &optional string)
|
1993-07-30 20:15:09 +00:00
|
|
|
"Verify that FORM is of type TYPE; signal an error if not.
|
|
|
|
STRING is an optional description of the desired type."
|
2012-05-17 17:39:36 -04:00
|
|
|
(declare (debug (place cl-type-spec &optional stringp)))
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(and (or (not (cl--compiling-file))
|
1993-07-30 20:15:09 +00:00
|
|
|
(< cl-optimize-speed 3) (= cl-optimize-safety 3))
|
2012-06-07 15:25:48 -04:00
|
|
|
(let* ((temp (if (cl--simple-expr-p form 3)
|
2004-11-16 04:05:29 +00:00
|
|
|
form (make-symbol "--cl-var--")))
|
2012-06-07 15:25:48 -04:00
|
|
|
(body `(or ,(cl--make-type-test temp type)
|
2012-06-01 16:36:00 -04:00
|
|
|
(signal 'wrong-type-argument
|
|
|
|
(list ,(or string `',type)
|
|
|
|
,temp ',form)))))
|
|
|
|
(if (eq temp form) `(progn ,body nil)
|
|
|
|
`(let ((,temp ,form)) ,body nil)))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-assert (form &optional show-args string &rest args)
|
1993-07-30 20:15:09 +00:00
|
|
|
"Verify that FORM returns non-nil; signal an error if not.
|
|
|
|
Second arg SHOW-ARGS means to include arguments of FORM in message.
|
|
|
|
Other args STRING and ARGS... are arguments to be passed to `error'.
|
|
|
|
They are not evaluated unless the assertion fails. If STRING is
|
|
|
|
omitted, a default message listing FORM itself is used."
|
2012-05-17 17:39:36 -04:00
|
|
|
(declare (debug (form &rest form)))
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(and (or (not (cl--compiling-file))
|
1993-07-30 20:15:09 +00:00
|
|
|
(< cl-optimize-speed 3) (= cl-optimize-safety 3))
|
2008-01-25 22:52:50 +00:00
|
|
|
(let ((sargs (and show-args
|
2012-06-07 15:25:48 -04:00
|
|
|
(delq nil (mapcar (lambda (x)
|
|
|
|
(unless (macroexp-const-p x)
|
|
|
|
x))
|
|
|
|
(cdr form))))))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(progn
|
|
|
|
(or ,form
|
|
|
|
,(if string
|
|
|
|
`(error ,string ,@sargs ,@args)
|
|
|
|
`(signal 'cl-assertion-failed
|
|
|
|
(list ',form ,@sargs))))
|
|
|
|
nil))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
;;; Compiler macros.
|
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-define-compiler-macro (func args &rest body)
|
2000-05-05 20:01:01 +00:00
|
|
|
"Define a compiler-only macro.
|
1993-07-30 20:15:09 +00:00
|
|
|
This is like `defmacro', but macro expansion occurs only if the call to
|
|
|
|
FUNC is compiled (i.e., not interpreted). Compiler macros should be used
|
|
|
|
for optimizing the way calls to FUNC are compiled; the form returned by
|
|
|
|
BODY should do the same thing as a call to the normal function called
|
|
|
|
FUNC, though possibly more efficiently. Note that, like regular macros,
|
|
|
|
compiler macros are expanded repeatedly until no further expansions are
|
|
|
|
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."
|
2012-06-03 21:05:17 -04:00
|
|
|
(declare (debug cl-defmacro))
|
1998-01-22 02:26:48 +00:00
|
|
|
(let ((p args) (res nil))
|
2002-09-27 23:16:27 +00:00
|
|
|
(while (consp p) (push (pop p) res))
|
1998-01-22 02:26:48 +00:00
|
|
|
(setq args (nconc (nreverse res) (and p (list '&rest p)))))
|
2012-06-03 21:05:17 -04:00
|
|
|
`(cl-eval-when (compile load eval)
|
2012-06-07 15:25:48 -04:00
|
|
|
,(cl--transform-function-property
|
2012-06-05 11:41:12 -04:00
|
|
|
func 'compiler-macro
|
2012-06-01 16:36:00 -04:00
|
|
|
(cons (if (memq '&whole args) (delq '&whole args)
|
|
|
|
(cons '_cl-whole-arg args)) body))
|
2012-06-05 11:41:12 -04:00
|
|
|
;; This is so that describe-function can locate
|
|
|
|
;; the macro definition.
|
|
|
|
(let ((file ,(or buffer-file-name
|
|
|
|
(and (boundp 'byte-compile-current-file)
|
|
|
|
(stringp byte-compile-current-file)
|
|
|
|
byte-compile-current-file))))
|
|
|
|
(if file (put ',func 'compiler-macro-file
|
|
|
|
(purecopy (file-name-nondirectory file)))))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defun cl-compiler-macroexpand (form)
|
1993-07-30 20:15:09 +00:00
|
|
|
(while
|
|
|
|
(let ((func (car-safe form)) (handler nil))
|
|
|
|
(while (and (symbolp func)
|
2012-06-05 11:41:12 -04:00
|
|
|
(not (setq handler (get func 'compiler-macro)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(fboundp func)
|
|
|
|
(or (not (eq (car-safe (symbol-function func)) 'autoload))
|
|
|
|
(load (nth 1 (symbol-function func)))))
|
|
|
|
(setq func (symbol-function func)))
|
|
|
|
(and handler
|
|
|
|
(not (eq form (setq form (apply handler form (cdr form))))))))
|
|
|
|
form)
|
|
|
|
|
2011-03-18 20:21:27 -04:00
|
|
|
;; Optimize away unused block-wrappers.
|
|
|
|
|
2012-06-07 15:25:48 -04:00
|
|
|
(defvar cl--active-block-names nil)
|
2011-03-18 20:21:27 -04:00
|
|
|
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(cl-define-compiler-macro cl--block-wrapper (cl-form)
|
2011-03-18 20:21:27 -04:00
|
|
|
(let* ((cl-entry (cons (nth 1 (nth 1 cl-form)) nil))
|
2012-06-07 15:25:48 -04:00
|
|
|
(cl--active-block-names (cons cl-entry cl--active-block-names))
|
2011-03-18 20:21:27 -04:00
|
|
|
(cl-body (macroexpand-all ;Performs compiler-macro expansions.
|
|
|
|
(cons 'progn (cddr cl-form))
|
|
|
|
macroexpand-all-environment)))
|
|
|
|
;; FIXME: To avoid re-applying macroexpand-all, we'd like to be able
|
|
|
|
;; to indicate that this return value is already fully expanded.
|
|
|
|
(if (cdr cl-entry)
|
2011-03-20 20:48:12 +11:00
|
|
|
`(catch ,(nth 1 cl-form) ,@(cdr cl-body))
|
2011-03-18 20:21:27 -04:00
|
|
|
cl-body)))
|
|
|
|
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(cl-define-compiler-macro cl--block-throw (cl-tag cl-value)
|
2012-06-07 15:25:48 -04:00
|
|
|
(let ((cl-found (assq (nth 1 cl-tag) cl--active-block-names)))
|
2011-03-18 20:21:27 -04:00
|
|
|
(if cl-found (setcdr cl-found t)))
|
|
|
|
`(throw ,cl-tag ,cl-value))
|
|
|
|
|
2010-03-11 19:19:17 -08:00
|
|
|
;;;###autoload
|
2012-06-03 21:05:17 -04:00
|
|
|
(defmacro cl-defsubst (name args &rest body)
|
2002-09-27 23:16:27 +00:00
|
|
|
"Define NAME as a function.
|
1993-07-30 20:15:09 +00:00
|
|
|
Like `defun', except the function is automatically declared `inline',
|
|
|
|
ARGLIST allows full Common Lisp conventions, and BODY is implicitly
|
2012-06-03 21:05:17 -04:00
|
|
|
surrounded by (cl-block NAME ...).
|
2002-09-27 23:16:27 +00:00
|
|
|
|
|
|
|
\(fn NAME ARGLIST [DOCSTRING] BODY...)"
|
2012-06-03 21:05:17 -04:00
|
|
|
(declare (debug cl-defun))
|
2012-06-07 15:25:48 -04:00
|
|
|
(let* ((argns (cl--arglist-args args)) (p argns)
|
1993-07-30 20:15:09 +00:00
|
|
|
(pbody (cons 'progn body))
|
2012-06-07 15:25:48 -04:00
|
|
|
(unsafe (not (cl--safe-expr-p pbody))))
|
|
|
|
(while (and p (eq (cl--expr-contains args (car p)) 1)) (pop p))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(progn
|
|
|
|
,(if p nil ; give up if defaults refer to earlier args
|
2012-06-03 21:05:17 -04:00
|
|
|
`(cl-define-compiler-macro ,name
|
2012-06-01 16:36:00 -04:00
|
|
|
,(if (memq '&key args)
|
|
|
|
`(&whole cl-whole &cl-quote ,@args)
|
|
|
|
(cons '&cl-quote args))
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(cl--defsubst-expand
|
2012-06-03 21:05:17 -04:00
|
|
|
',argns '(cl-block ,name ,@body)
|
2012-06-01 16:36:00 -04:00
|
|
|
;; We used to pass `simple' as
|
|
|
|
;; (not (or unsafe (cl-expr-access-order pbody argns)))
|
|
|
|
;; But this is much too simplistic since it
|
|
|
|
;; does not pay attention to the argvs (and
|
|
|
|
;; cl-expr-access-order itself is also too naive).
|
|
|
|
nil
|
|
|
|
,(and (memq '&key args) 'cl-whole) ,unsafe ,@argns)))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-defun ,name ,args ,@body))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
(defun cl--defsubst-expand (argns body simple whole unsafe &rest argvs)
|
2012-06-07 15:25:48 -04:00
|
|
|
(if (and whole (not (cl--safe-expr-p (cons 'progn argvs)))) whole
|
|
|
|
(if (cl--simple-exprs-p argvs) (setq simple t))
|
2010-04-08 15:59:46 -04:00
|
|
|
(let* ((substs ())
|
|
|
|
(lets (delq nil
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-mapcar (lambda (argn argv)
|
2012-06-07 15:25:48 -04:00
|
|
|
(if (or simple (macroexp-const-p argv))
|
2012-06-03 21:05:17 -04:00
|
|
|
(progn (push (cons argn argv) substs)
|
|
|
|
(and unsafe (list argn argv)))
|
|
|
|
(list argn argv)))
|
|
|
|
argns argvs))))
|
2010-04-08 15:59:46 -04:00
|
|
|
;; FIXME: `sublis/subst' will happily substitute the symbol
|
|
|
|
;; `argn' in places where it's not used as a reference
|
|
|
|
;; to a variable.
|
|
|
|
;; FIXME: `sublis/subst' will happily copy `argv' to a different
|
|
|
|
;; scope, leading to name capture.
|
|
|
|
(setq body (cond ((null substs) body)
|
|
|
|
((null (cdr substs))
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-subst (cdar substs) (caar substs) body))
|
|
|
|
(t (cl-sublis substs body))))
|
2012-06-01 16:36:00 -04:00
|
|
|
(if lets `(let ,lets ,body) body))))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
|
2007-06-29 04:37:34 +00:00
|
|
|
;; 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.
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2012-06-08 22:26:47 -04:00
|
|
|
(defun cl--compiler-macro-member (form a list &rest keys)
|
2000-05-05 20:01:01 +00:00
|
|
|
(let ((test (and (= (length keys) 2) (eq (car keys) :test)
|
2012-06-07 15:25:48 -04:00
|
|
|
(cl--const-expr-val (nth 1 keys)))))
|
2012-06-01 16:36:00 -04:00
|
|
|
(cond ((eq test 'eq) `(memq ,a ,list))
|
|
|
|
((eq test 'equal) `(member ,a ,list))
|
|
|
|
((or (null keys) (eq test 'eql)) `(memql ,a ,list))
|
1993-07-30 20:15:09 +00:00
|
|
|
(t form))))
|
|
|
|
|
2012-06-08 22:26:47 -04:00
|
|
|
(defun cl--compiler-macro-assoc (form a list &rest keys)
|
2000-05-05 20:01:01 +00:00
|
|
|
(let ((test (and (= (length keys) 2) (eq (car keys) :test)
|
2012-06-07 15:25:48 -04:00
|
|
|
(cl--const-expr-val (nth 1 keys)))))
|
2012-06-01 16:36:00 -04:00
|
|
|
(cond ((eq test 'eq) `(assq ,a ,list))
|
|
|
|
((eq test 'equal) `(assoc ,a ,list))
|
2012-06-07 15:25:48 -04:00
|
|
|
((and (macroexp-const-p a) (or (null keys) (eq test 'eql)))
|
|
|
|
(if (cl-floatp-safe (cl--const-expr-val a))
|
2012-06-01 16:36:00 -04:00
|
|
|
`(assoc ,a ,list) `(assq ,a ,list)))
|
1993-07-30 20:15:09 +00:00
|
|
|
(t form))))
|
|
|
|
|
Fix compiler-expansion of CL's cXXr functions.
* emacs-lisp/cl-lib.el (cl--defalias): New function.
(cl-values, cl-values-list, cl-copy-seq, cl-svref, cl-first)
(cl-second, cl-rest, cl-endp, cl-third, cl-fourth): Use it.
(cl-plusp, cl-minusp, cl-fifth, cl-sixth, cl-seventh, cl-eighth)
(cl-ninth, cl-tenth): Mark them as inlinable.
(cl-caaar, cl-caadr, cl-cadar, cl-caddr, cl-cdaar, cl-cdadr)
(cl-cddar, cl-cdddr, cl-caaaar, cl-caaadr, cl-caadar, cl-caaddr)
(cl-cadaar, cl-cadadr, cl-caddar, cl-cadddr, cl-cdaaar, cl-cdaadr)
(cl-cdadar, cl-cdaddr, cl-cddaar, cl-cddadr, cl-cdddar, cl-cddddr):
Add a compiler-macro declaration to use cl--compiler-macro-cXXr.
(cl-list*, cl-adjoin): Don't put an autoload manually.
* emacs-lisp/cl-macs.el (cl--compiler-macro-adjoin)
(cl--compiler-macro-list*): Add autoload cookie.
(cl--compiler-macro-cXXr): New function.
* help-fns.el (help-fns--compiler-macro): New function extracted from
describe-function-1; follow aliases and use `compiler-macro' property.
(describe-function-1): Use it.
Fixes: debbugs:11673
2012-06-11 16:35:00 -04:00
|
|
|
;;;###autoload
|
2012-06-08 22:26:47 -04:00
|
|
|
(defun cl--compiler-macro-adjoin (form a list &rest keys)
|
2012-06-07 15:25:48 -04:00
|
|
|
(if (and (cl--simple-expr-p a) (cl--simple-expr-p list)
|
2000-05-05 20:01:01 +00:00
|
|
|
(not (memq :key keys)))
|
2012-06-03 21:05:17 -04:00
|
|
|
`(if (cl-member ,a ,list ,@keys) ,list (cons ,a ,list))
|
1993-07-30 20:15:09 +00:00
|
|
|
form))
|
|
|
|
|
Fix compiler-expansion of CL's cXXr functions.
* emacs-lisp/cl-lib.el (cl--defalias): New function.
(cl-values, cl-values-list, cl-copy-seq, cl-svref, cl-first)
(cl-second, cl-rest, cl-endp, cl-third, cl-fourth): Use it.
(cl-plusp, cl-minusp, cl-fifth, cl-sixth, cl-seventh, cl-eighth)
(cl-ninth, cl-tenth): Mark them as inlinable.
(cl-caaar, cl-caadr, cl-cadar, cl-caddr, cl-cdaar, cl-cdadr)
(cl-cddar, cl-cdddr, cl-caaaar, cl-caaadr, cl-caadar, cl-caaddr)
(cl-cadaar, cl-cadadr, cl-caddar, cl-cadddr, cl-cdaaar, cl-cdaadr)
(cl-cdadar, cl-cdaddr, cl-cddaar, cl-cddadr, cl-cdddar, cl-cddddr):
Add a compiler-macro declaration to use cl--compiler-macro-cXXr.
(cl-list*, cl-adjoin): Don't put an autoload manually.
* emacs-lisp/cl-macs.el (cl--compiler-macro-adjoin)
(cl--compiler-macro-list*): Add autoload cookie.
(cl--compiler-macro-cXXr): New function.
* help-fns.el (help-fns--compiler-macro): New function extracted from
describe-function-1; follow aliases and use `compiler-macro' property.
(describe-function-1): Use it.
Fixes: debbugs:11673
2012-06-11 16:35:00 -04:00
|
|
|
;;;###autoload
|
2012-06-08 22:26:47 -04:00
|
|
|
(defun cl--compiler-macro-list* (_form arg &rest others)
|
1993-07-30 20:15:09 +00:00
|
|
|
(let* ((args (reverse (cons arg others)))
|
|
|
|
(form (car args)))
|
|
|
|
(while (setq args (cdr args))
|
2012-06-01 16:36:00 -04:00
|
|
|
(setq form `(cons ,(car args) ,form)))
|
1993-07-30 20:15:09 +00:00
|
|
|
form))
|
|
|
|
|
2012-06-08 22:26:47 -04:00
|
|
|
(defun cl--compiler-macro-get (_form sym prop &optional def)
|
1993-07-30 20:15:09 +00:00
|
|
|
(if def
|
2012-06-03 21:05:17 -04:00
|
|
|
`(cl-getf (symbol-plist ,sym) ,prop ,def)
|
2012-06-01 16:36:00 -04:00
|
|
|
`(get ,sym ,prop)))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-define-compiler-macro cl-typep (&whole form val type)
|
2012-06-07 15:25:48 -04:00
|
|
|
(if (macroexp-const-p type)
|
2012-06-08 22:26:47 -04:00
|
|
|
(macroexp-let² macroexp-copyable-p temp val
|
|
|
|
(cl--make-type-test temp (cl--const-expr-val type)))
|
1993-07-30 20:15:09 +00:00
|
|
|
form))
|
|
|
|
|
Fix compiler-expansion of CL's cXXr functions.
* emacs-lisp/cl-lib.el (cl--defalias): New function.
(cl-values, cl-values-list, cl-copy-seq, cl-svref, cl-first)
(cl-second, cl-rest, cl-endp, cl-third, cl-fourth): Use it.
(cl-plusp, cl-minusp, cl-fifth, cl-sixth, cl-seventh, cl-eighth)
(cl-ninth, cl-tenth): Mark them as inlinable.
(cl-caaar, cl-caadr, cl-cadar, cl-caddr, cl-cdaar, cl-cdadr)
(cl-cddar, cl-cdddr, cl-caaaar, cl-caaadr, cl-caadar, cl-caaddr)
(cl-cadaar, cl-cadadr, cl-caddar, cl-cadddr, cl-cdaaar, cl-cdaadr)
(cl-cdadar, cl-cdaddr, cl-cddaar, cl-cddadr, cl-cdddar, cl-cddddr):
Add a compiler-macro declaration to use cl--compiler-macro-cXXr.
(cl-list*, cl-adjoin): Don't put an autoload manually.
* emacs-lisp/cl-macs.el (cl--compiler-macro-adjoin)
(cl--compiler-macro-list*): Add autoload cookie.
(cl--compiler-macro-cXXr): New function.
* help-fns.el (help-fns--compiler-macro): New function extracted from
describe-function-1; follow aliases and use `compiler-macro' property.
(describe-function-1): Use it.
Fixes: debbugs:11673
2012-06-11 16:35:00 -04:00
|
|
|
;;;###autoload
|
|
|
|
(defun cl--compiler-macro-cXXr (form x)
|
|
|
|
(let* ((head (car form))
|
|
|
|
(n (symbol-name (car form)))
|
|
|
|
(i (- (length n) 2)))
|
|
|
|
(if (not (string-match "c[ad]+r\\'" n))
|
|
|
|
(if (and (fboundp head) (symbolp (symbol-function head)))
|
|
|
|
(cl--compiler-macro-cXXr (cons (symbol-function head) (cdr form))
|
|
|
|
x)
|
|
|
|
(error "Compiler macro for cXXr applied to non-cXXr form"))
|
|
|
|
(while (> i (match-beginning 0))
|
|
|
|
(setq x (list (if (eq (aref n i) ?a) 'car 'cdr) x))
|
|
|
|
(setq i (1- i)))
|
|
|
|
x)))
|
|
|
|
|
|
|
|
(dolist (y '(cl-first cl-second cl-third cl-fourth
|
|
|
|
cl-fifth cl-sixth cl-seventh
|
|
|
|
cl-eighth cl-ninth cl-tenth
|
|
|
|
cl-rest cl-endp cl-plusp cl-minusp
|
|
|
|
cl-caaar cl-caadr cl-cadar
|
|
|
|
cl-caddr cl-cdaar cl-cdadr
|
|
|
|
cl-cddar cl-cdddr cl-caaaar
|
|
|
|
cl-caaadr cl-caadar cl-caaddr
|
|
|
|
cl-cadaar cl-cadadr cl-caddar
|
|
|
|
cl-cadddr cl-cdaaar cl-cdaadr
|
|
|
|
cl-cdadar cl-cdaddr cl-cddaar
|
|
|
|
cl-cddadr cl-cdddar cl-cddddr))
|
|
|
|
(put y 'side-effect-free t))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
;;; Things that are inline.
|
2012-06-03 21:05:17 -04:00
|
|
|
(cl-proclaim '(inline cl-floatp-safe cl-acons cl-map cl-concatenate cl-notany cl-notevery
|
Use lexical-binding for all of CL, and clean up its namespace.
* lisp/emacs-lisp/cl-lib.el: Use lexical-binding.
(cl-map-extents, cl-maclisp-member): Remove.
(cl--set-elt, cl--set-nthcdr, cl--set-buffer-substring)
(cl--set-substring, cl--block-wrapper, cl--block-throw)
(cl--compiling-file, cl--mapcar-many, cl--do-subst): Use "cl--" prefix.
* lisp/emacs-lisp/cl-extra.el: Use lexical-binding.
(cl--mapcar-many, cl--map-keymap-recursively, cl--map-intervals)
(cl--map-overlays, cl--set-frame-visible-p, cl--progv-save)
(cl--progv-before, cl--progv-after, cl--finite-do, cl--set-getf)
(cl--do-remf, cl--do-prettyprint): Use "cl--" prefix.
* lisp/emacs-lisp/cl-seq.el: Use lexical-binding.
(cl--parsing-keywords, cl--check-key, cl--check-test-nokey)
(cl--check-test, cl--check-match): Use "cl--" prefix and backquotes.
(cl--alist, cl--sublis-rec, cl--nsublis-rec, cl--tree-equal-rec):
* lisp/emacs-lisp/cl-macs.el (cl--lambda-list-keywords): Use "cl--" prefix.
* lisp/edmacro.el (edmacro-mismatch): Simplify to remove dependence on
CL's internals.
2012-06-11 11:52:50 -04:00
|
|
|
cl--set-elt cl-revappend cl-nreconc gethash))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
;;; Things that are side-effect-free.
|
2004-11-16 04:05:29 +00:00
|
|
|
(mapc (lambda (x) (put x 'side-effect-free t))
|
2012-06-03 21:05:17 -04:00
|
|
|
'(cl-oddp cl-evenp cl-signum last butlast cl-ldiff cl-pairlis cl-gcd cl-lcm
|
|
|
|
cl-isqrt cl-floor cl-ceiling cl-truncate cl-round cl-mod cl-rem cl-subseq
|
|
|
|
cl-list-length cl-get cl-getf))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
;;; Things that are side-effect-and-error-free.
|
2004-11-16 04:05:29 +00:00
|
|
|
(mapc (lambda (x) (put x 'side-effect-free 'error-free))
|
2012-06-03 21:05:17 -04:00
|
|
|
'(eql cl-floatp-safe cl-list* cl-subst cl-acons cl-equalp cl-random-state-p
|
|
|
|
copy-tree cl-sublis))
|
1993-07-30 20:15:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
(run-hooks 'cl-macs-load-hook)
|
|
|
|
|
2007-06-27 18:53:15 +00:00
|
|
|
;; Local variables:
|
2007-10-28 23:51:29 +00:00
|
|
|
;; byte-compile-dynamic: t
|
|
|
|
;; byte-compile-warnings: (not cl-functions)
|
2007-06-27 18:53:15 +00:00
|
|
|
;; generated-autoload-file: "cl-loaddefs.el"
|
|
|
|
;; End:
|
2002-12-07 21:34:00 +00:00
|
|
|
|
2012-06-07 22:54:35 -04:00
|
|
|
(provide 'cl-macs)
|
|
|
|
|
1993-07-30 20:15:09 +00:00
|
|
|
;;; cl-macs.el ends here
|