1 ;;; cl-extra.el --- Common Lisp features, part 2 -*- lexical-binding: t -*-
3 ;; Copyright (C) 1993, 2000-2015 Free Software Foundation, Inc.
5 ;; Author: Dave Gillespie <daveg@synaptics.com>
6 ;; Keywords: extensions
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; These are extensions to Emacs Lisp that provide a degree of
27 ;; Common Lisp compatibility, beyond what is already built-in
30 ;; This package was written by Dave Gillespie; it is a complete
31 ;; rewrite of Cesar Quiroz's original cl.el package of December 1986.
33 ;; Bug reports, comments, and suggestions are welcome!
35 ;; This file contains portions of the Common Lisp extensions
36 ;; package which are autoloaded since they are relatively obscure.
46 (defun cl-coerce (x type
)
47 "Coerce OBJECT to type TYPE.
48 TYPE is a Common Lisp type specifier.
50 (cond ((eq type
'list
) (if (listp x
) x
(append x nil
)))
51 ((eq type
'vector
) (if (vectorp x
) x
(vconcat x
)))
52 ((eq type
'string
) (if (stringp x
) x
(concat x
)))
53 ((eq type
'array
) (if (arrayp x
) x
(vconcat x
)))
54 ((and (eq type
'character
) (stringp x
) (= (length x
) 1)) (aref x
0))
55 ((and (eq type
'character
) (symbolp x
))
56 (cl-coerce (symbol-name x
) type
))
57 ((eq type
'float
) (float x
))
59 (t (error "Can't coerce %s to type %s" x type
))))
65 (defun cl-equalp (x y
)
66 "Return t if two Lisp objects have similar structures and contents.
67 This is like `equal', except that it accepts numerically equal
68 numbers of different types (float vs. integer), and also compares
69 strings case-insensitively."
72 (and (stringp y
) (= (length x
) (length y
))
73 (or (string-equal x y
)
74 (string-equal (downcase x
) (downcase y
))))) ;Lazy but simple!
76 (and (numberp y
) (= x y
)))
78 (while (and (consp x
) (consp y
) (cl-equalp (car x
) (car y
)))
79 (setq x
(cdr x
) y
(cdr y
)))
80 (and (not (consp x
)) (cl-equalp x y
)))
82 (and (vectorp y
) (= (length x
) (length y
))
84 (while (and (>= (setq i
(1- i
)) 0)
85 (cl-equalp (aref x i
) (aref y i
))))
90 ;;; Control structures.
93 (defun cl--mapcar-many (cl-func cl-seqs
)
94 (if (cdr (cdr cl-seqs
))
96 (cl-n (apply 'min
(mapcar 'length cl-seqs
)))
98 (cl-args (copy-sequence cl-seqs
))
100 (setq cl-seqs
(copy-sequence cl-seqs
))
102 (setq cl-p1 cl-seqs cl-p2 cl-args
)
105 (if (consp (car cl-p1
))
106 (prog1 (car (car cl-p1
))
107 (setcar cl-p1
(cdr (car cl-p1
))))
108 (aref (car cl-p1
) cl-i
)))
109 (setq cl-p1
(cdr cl-p1
) cl-p2
(cdr cl-p2
)))
110 (push (apply cl-func cl-args
) cl-res
)
111 (setq cl-i
(1+ cl-i
)))
115 (cl-y (nth 1 cl-seqs
)))
116 (let ((cl-n (min (length cl-x
) (length cl-y
)))
118 (while (< (setq cl-i
(1+ cl-i
)) cl-n
)
119 (push (funcall cl-func
120 (if (consp cl-x
) (pop cl-x
) (aref cl-x cl-i
))
121 (if (consp cl-y
) (pop cl-y
) (aref cl-y cl-i
)))
126 (defun cl-map (cl-type cl-func cl-seq
&rest cl-rest
)
127 "Map a FUNCTION across one or more SEQUENCEs, returning a sequence.
128 TYPE is the sequence type to return.
129 \n(fn TYPE FUNCTION SEQUENCE...)"
130 (let ((cl-res (apply 'cl-mapcar cl-func cl-seq cl-rest
)))
131 (and cl-type
(cl-coerce cl-res cl-type
))))
134 (defun cl-maplist (cl-func cl-list
&rest cl-rest
)
135 "Map FUNCTION to each sublist of LIST or LISTs.
136 Like `cl-mapcar', except applies to lists and their cdr's rather than to
137 the elements themselves.
138 \n(fn FUNCTION LIST...)"
141 (cl-args (cons cl-list
(copy-sequence cl-rest
)))
143 (while (not (memq nil cl-args
))
144 (push (apply cl-func cl-args
) cl-res
)
146 (while cl-p
(setcar cl-p
(cdr (pop cl-p
)) )))
150 (push (funcall cl-func cl-list
) cl-res
)
151 (setq cl-list
(cdr cl-list
)))
155 (defun cl-mapc (cl-func cl-seq
&rest cl-rest
)
156 "Like `cl-mapcar', but does not accumulate values returned by the function.
157 \n(fn FUNCTION SEQUENCE...)"
159 (progn (apply 'cl-map nil cl-func cl-seq cl-rest
)
161 (mapc cl-func cl-seq
)))
164 (defun cl-mapl (cl-func cl-list
&rest cl-rest
)
165 "Like `cl-maplist', but does not accumulate values returned by the function.
166 \n(fn FUNCTION LIST...)"
168 (apply 'cl-maplist cl-func cl-list cl-rest
)
169 (let ((cl-p cl-list
))
170 (while cl-p
(funcall cl-func cl-p
) (setq cl-p
(cdr cl-p
)))))
174 (defun cl-mapcan (cl-func cl-seq
&rest cl-rest
)
175 "Like `cl-mapcar', but nconc's together the values returned by the function.
176 \n(fn FUNCTION SEQUENCE...)"
177 (apply 'nconc
(apply 'cl-mapcar cl-func cl-seq cl-rest
)))
180 (defun cl-mapcon (cl-func cl-list
&rest cl-rest
)
181 "Like `cl-maplist', but nconc's together the values returned by the function.
182 \n(fn FUNCTION LIST...)"
183 (apply 'nconc
(apply 'cl-maplist cl-func cl-list cl-rest
)))
186 (defun cl-some (cl-pred cl-seq
&rest cl-rest
)
187 "Return true if PREDICATE is true of any element of SEQ or SEQs.
188 If so, return the true (non-nil) value returned by PREDICATE.
189 \n(fn PREDICATE SEQ...)"
190 (if (or cl-rest
(nlistp cl-seq
))
193 (function (lambda (&rest cl-x
)
194 (let ((cl-res (apply cl-pred cl-x
)))
195 (if cl-res
(throw 'cl-some cl-res
)))))
198 (while (and cl-seq
(not (setq cl-x
(funcall cl-pred
(pop cl-seq
))))))
202 (defun cl-every (cl-pred cl-seq
&rest cl-rest
)
203 "Return true if PREDICATE is true of every element of SEQ or SEQs.
204 \n(fn PREDICATE SEQ...)"
205 (if (or cl-rest
(nlistp cl-seq
))
208 (function (lambda (&rest cl-x
)
209 (or (apply cl-pred cl-x
) (throw 'cl-every nil
))))
211 (while (and cl-seq
(funcall cl-pred
(car cl-seq
)))
212 (setq cl-seq
(cdr cl-seq
)))
216 (defun cl-notany (cl-pred cl-seq
&rest cl-rest
)
217 "Return true if PREDICATE is false of every element of SEQ or SEQs.
218 \n(fn PREDICATE SEQ...)"
219 (not (apply 'cl-some cl-pred cl-seq cl-rest
)))
222 (defun cl-notevery (cl-pred cl-seq
&rest cl-rest
)
223 "Return true if PREDICATE is false of some element of SEQ or SEQs.
224 \n(fn PREDICATE SEQ...)"
225 (not (apply 'cl-every cl-pred cl-seq cl-rest
)))
228 (defun cl--map-keymap-recursively (cl-func-rec cl-map
&optional cl-base
)
230 (setq cl-base
(copy-sequence [0])))
233 (lambda (cl-key cl-bind)
234 (aset cl-base (1- (length cl-base)) cl-key)
235 (if (keymapp cl-bind)
236 (cl--map-keymap-recursively
238 (vconcat cl-base (list 0)))
239 (funcall cl-func-rec cl-base cl-bind))))
243 (defun cl--map-intervals (cl-func &optional cl-what cl-prop cl-start cl-end)
244 (or cl-what (setq cl-what (current-buffer)))
245 (if (bufferp cl-what)
246 (let (cl-mark cl-mark2 (cl-next t) cl-next2)
247 (with-current-buffer cl-what
248 (setq cl-mark (copy-marker (or cl-start (point-min))))
249 (setq cl-mark2 (and cl-end (copy-marker cl-end))))
250 (while (and cl-next (or (not cl-mark2) (< cl-mark cl-mark2)))
251 (setq cl-next (if cl-prop (next-single-property-change
252 cl-mark cl-prop cl-what)
253 (next-property-change cl-mark cl-what))
254 cl-next2 (or cl-next (with-current-buffer cl-what
256 (funcall cl-func (prog1 (marker-position cl-mark)
257 (set-marker cl-mark cl-next2))
258 (if cl-mark2 (min cl-next2 cl-mark2) cl-next2)))
259 (set-marker cl-mark nil) (if cl-mark2 (set-marker cl-mark2 nil)))
260 (or cl-start (setq cl-start 0))
261 (or cl-end (setq cl-end (length cl-what)))
262 (while (< cl-start cl-end)
263 (let ((cl-next (or (if cl-prop (next-single-property-change
264 cl-start cl-prop cl-what)
265 (next-property-change cl-start cl-what))
267 (funcall cl-func cl-start (min cl-next cl-end))
268 (setq cl-start cl-next)))))
271 (defun cl--map-overlays (cl-func &optional cl-buffer cl-start cl-end cl-arg)
272 (or cl-buffer (setq cl-buffer (current-buffer)))
274 (with-current-buffer cl-buffer
275 (setq cl-ovl (overlay-lists))
276 (if cl-start (setq cl-start (copy-marker cl-start)))
277 (if cl-end (setq cl-end (copy-marker cl-end))))
278 (setq cl-ovl (nconc (car cl-ovl) (cdr cl-ovl)))
280 (or (not (overlay-start (car cl-ovl)))
281 (and cl-end (>= (overlay-start (car cl-ovl)) cl-end))
282 (and cl-start (<= (overlay-end (car cl-ovl)) cl-start))
283 (not (funcall cl-func (car cl-ovl) cl-arg))))
284 (setq cl-ovl (cdr cl-ovl)))
285 (if cl-start (set-marker cl-start nil))
286 (if cl-end (set-marker cl-end nil))))
288 ;;; Support for `setf'.
290 (defun cl--set-frame-visible-p (frame val)
291 (cond ((null val) (make-frame-invisible frame))
292 ((eq val 'icon) (iconify-frame frame))
293 (t (make-frame-visible frame)))
300 (defun cl-gcd (&rest args)
301 "Return the greatest common divisor of the arguments."
302 (let ((a (abs (or (pop args) 0))))
304 (let ((b (abs (pop args))))
305 (while (> b 0) (setq b (% a (setq a b))))))
309 (defun cl-lcm (&rest args)
310 "Return the least common multiple of the arguments."
313 (let ((a (abs (or (pop args) 1))))
315 (let ((b (abs (pop args))))
316 (setq a (* (/ a (cl-gcd a b)) b))))
321 "Return the integer square root of the argument."
322 (if (and (integerp x) (> x 0))
323 (let ((g (cond ((<= x 100) 10) ((<= x 10000) 100)
324 ((<= x 1000000) 1000) (t x)))
326 (while (< (setq g2 (/ (+ g (/ x g)) 2)) g)
329 (if (eq x 0) 0 (signal 'arith-error nil))))
332 (defun cl-floor (x &optional y)
333 "Return a list of the floor of X and the fractional part of X.
334 With two arguments, return floor and remainder of their quotient."
335 (let ((q (floor x y)))
336 (list q (- x (if y (* y q) q)))))
339 (defun cl-ceiling (x &optional y)
340 "Return a list of the ceiling of X and the fractional part of X.
341 With two arguments, return ceiling and remainder of their quotient."
342 (let ((res (cl-floor x y)))
343 (if (= (car (cdr res)) 0) res
344 (list (1+ (car res)) (- (car (cdr res)) (or y 1))))))
347 (defun cl-truncate (x &optional y)
348 "Return a list of the integer part of X and the fractional part of X.
349 With two arguments, return truncation and remainder of their quotient."
350 (if (eq (>= x 0) (or (null y) (>= y 0)))
351 (cl-floor x y) (cl-ceiling x y)))
354 (defun cl-round (x &optional y)
355 "Return a list of X rounded to the nearest integer and the remainder.
356 With two arguments, return rounding and remainder of their quotient."
358 (if (and (integerp x) (integerp y))
360 (res (cl-floor (+ x hy) y)))
361 (if (and (= (car (cdr res)) 0)
363 (/= (% (car res) 2) 0))
364 (list (1- (car res)) hy)
365 (list (car res) (- (car (cdr res)) hy))))
366 (let ((q (round (/ x y))))
367 (list q (- x (* q y)))))
368 (if (integerp x) (list x 0)
374 "The remainder of X divided by Y, with the same sign as Y."
375 (nth 1 (cl-floor x y)))
379 "The remainder of X divided by Y, with the same sign as X."
380 (nth 1 (cl-truncate x y)))
384 "Return 1 if X is positive, -1 if negative, 0 if zero."
385 (cond ((> x 0) 1) ((< x 0) -1) (t 0)))
388 (cl-defun cl-parse-integer (string &key start end radix junk-allowed)
389 "Parse integer from the substring of STRING from START to END.
390 STRING may be surrounded by whitespace chars (chars with syntax ` ').
391 Other non-digit chars are considered junk.
392 RADIX is an integer between 2 and 36, the default is 10. Signal
393 an error if the substring between START and END cannot be parsed
394 as an integer unless JUNK-ALLOWED is non-nil."
395 (cl-check-type string string)
396 (let* ((start (or start 0))
397 (len (length string))
399 (radix (or radix 10)))
400 (or (<= start end len)
401 (error "Bad interval: [%d, %d)" start end))
402 (cl-flet ((skip-whitespace ()
403 (while (and (< start end)
404 (= 32 (char-syntax (aref string start))))
405 (setq start (1+ start)))))
407 (let ((sign (cl-case (and (< start end) (aref string start))
408 (?+ (cl-incf start) +1)
409 (?- (cl-incf start) -1)
412 (while (and (< start end)
413 (setq digit (cl-digit-char-p (aref string start) radix)))
414 (setq sum (+ (* (or sum 0) radix) digit)
417 (cond ((and junk-allowed (null sum)) sum)
418 (junk-allowed (* sign sum))
419 ((or (/= start end) (null sum))
420 (error "Not an integer string: `%s'" string))
421 (t (* sign sum)))))))
427 (defun cl-random (lim &optional state)
428 "Return a random nonnegative number less than LIM, an integer or float.
429 Optional second arg STATE is a random-state object."
430 (or state (setq state cl--random-state))
431 ;; Inspired by "ran3" from Numerical Recipes. Additive congruential method.
432 (let ((vec (aref state 3)))
434 (let ((i 0) (j (- 1357335 (% (abs vec) 1357333))) (k 1))
435 (aset state 3 (setq vec (make-vector 55 nil)))
437 (while (> (setq i (% (+ i 21) 55)) 0)
438 (aset vec i (setq j (prog1 k (setq k (- j k))))))
439 (while (< (setq i (1+ i)) 200) (cl-random 2 state))))
440 (let* ((i (aset state 1 (% (1+ (aref state 1)) 55)))
441 (j (aset state 2 (% (1+ (aref state 2)) 55)))
442 (n (logand 8388607 (aset vec i (- (aref vec i) (aref vec j))))))
444 (if (<= lim 512) (% n lim)
445 (if (> lim 8388607) (setq n (+ (lsh n 9) (cl-random 512 state))))
447 (while (< mask (1- lim)) (setq mask (1+ (+ mask mask))))
448 (if (< (setq n (logand n mask)) lim) n (cl-random lim state))))
449 (* (/ n '8388608e0) lim)))))
452 (defun cl-make-random-state (&optional state)
453 "Return a copy of random-state STATE, or of the internal state if omitted.
454 If STATE is t, return a new state object seeded from the time of day."
455 (cond ((null state) (cl-make-random-state cl--random-state))
456 ((vectorp state) (copy-tree state t))
457 ((integerp state) (vector 'cl--random-state-tag -1 30 state))
458 (t (cl-make-random-state (cl--random-time)))))
461 (defun cl-random-state-p (object)
462 "Return t if OBJECT is a random-state object."
463 (and (vectorp object) (= (length object) 4)
464 (eq (aref object 0) 'cl--random-state-tag)))
467 ;; Implementation limits.
469 (defun cl--finite-do (func a b)
471 (let ((res (funcall func a b))) ; check for IEEE infinity
472 (and (numberp res) (/= res (/ res 2)) res))
476 (defun cl-float-limits ()
477 "Initialize the Common Lisp floating-point parameters.
478 This sets the values of: `cl-most-positive-float', `cl-most-negative-float',
479 `cl-least-positive-float', `cl-least-negative-float', `cl-float-epsilon',
480 `cl-float-negative-epsilon', `cl-least-positive-normalized-float', and
481 `cl-least-negative-normalized-float'."
482 (or cl-most-positive-float (not (numberp '2e1))
484 ;; Find maximum exponent (first two loops are optimizations)
485 (while (cl--finite-do '* x x) (setq x (* x x)))
486 (while (cl--finite-do '* x (/ x 2)) (setq x (* x (/ x 2))))
487 (while (cl--finite-do '+ x x) (setq x (+ x x)))
489 ;; Now cl-fill in 1's in the mantissa.
490 (while (and (cl--finite-do '+ x y) (/= (+ x y) x))
491 (setq x (+ x y) y (/ y 2)))
492 (setq cl-most-positive-float x
493 cl-most-negative-float (- x))
494 ;; Divide down until mantissa starts rounding.
495 (setq x (/ x z) y (/ 16 z) x (* x y))
496 (while (condition-case _ (and (= x (* (/ x 2) 2)) (> (/ y 2) 0))
498 (setq x (/ x 2) y (/ y 2)))
499 (setq cl-least-positive-normalized-float y
500 cl-least-negative-normalized-float (- y))
501 ;; Divide down until value underflows to zero.
503 (while (condition-case _ (> (/ x 2) 0) (arith-error nil))
505 (setq cl-least-positive-float x
506 cl-least-negative-float (- x))
508 (while (/= (+ '1e0 x) '1e0) (setq x (/ x 2)))
509 (setq cl-float-epsilon (* x 2))
511 (while (/= (- '1e0 x) '1e0) (setq x (/ x 2)))
512 (setq cl-float-negative-epsilon (* x 2))))
516 ;;; Sequence functions.
519 (defun cl-subseq (seq start &optional end)
520 "Return the subsequence of SEQ from START to END.
521 If END is omitted, it defaults to the length of the sequence.
522 If START or END is negative, it counts from the end."
525 (macroexp-let2 nil new new
526 `(progn (cl-replace ,seq ,new :start1 ,start :end1 ,end)
528 (seq-subseq seq start end))
531 (defalias 'cl-concatenate #'seq-concatenate
532 "Concatenate, into a sequence of type TYPE, the argument SEQUENCEs.
533 \n(fn TYPE SEQUENCE...)")
539 (defun cl-revappend (x y)
540 "Equivalent to (append (reverse X) Y)."
541 (nconc (reverse x) y))
544 (defun cl-nreconc (x y)
545 "Equivalent to (nconc (nreverse X) Y)."
546 (nconc (nreverse x) y))
549 (defun cl-list-length (x)
550 "Return the length of list X. Return nil if list is circular."
551 (let ((n 0) (fast x) (slow x))
552 (while (and (cdr fast) (not (and (eq fast slow) (> n 0))))
553 (setq n (+ n 2) fast (cdr (cdr fast)) slow (cdr slow)))
554 (if fast (if (cdr fast) nil (1+ n)) n)))
557 (defun cl-tailp (sublist list)
558 "Return true if SUBLIST is a tail of LIST."
559 (while (and (consp list) (not (eq sublist list)))
560 (setq list (cdr list)))
561 (if (numberp sublist) (equal sublist list) (eq sublist list)))
566 (defun cl-get (sym tag &optional def)
567 "Return the value of SYMBOL's PROPNAME property, or DEFAULT if none.
568 \n(fn SYMBOL PROPNAME &optional DEFAULT)"
569 (declare (compiler-macro cl--compiler-macro-get)
570 (gv-setter (lambda (store) (ignore def) `(put ,sym ,tag ,store))))
573 ;; Make sure `def' is really absent as opposed to set to nil.
574 (let ((plist (symbol-plist sym)))
575 (while (and plist (not (eq (car plist) tag)))
576 (setq plist (cdr (cdr plist))))
577 (if plist (car (cdr plist)) def)))))
578 (autoload 'cl--compiler-macro-get "cl-macs")
581 (defun cl-getf (plist tag &optional def)
582 "Search PROPLIST for property PROPNAME; return its value or DEFAULT.
583 PROPLIST is a list of the sort returned by `symbol-plist'.
584 \n(fn PROPLIST PROPNAME &optional DEFAULT)"
585 (declare (gv-expander
587 (gv-letplace (getter setter) plist
588 (macroexp-let2* nil ((k tag) (d def))
589 (funcall do `(cl-getf ,getter ,k ,d)
591 (macroexp-let2 nil val v
594 `(cl--set-getf ,getter ,k ,val))
596 (setplist '--cl-getf-symbol-- plist)
597 (or (get '--cl-getf-symbol-- tag)
598 ;; Originally we called cl-get here,
599 ;; but that fails, because cl-get has a compiler macro
600 ;; definition that uses getf!
602 ;; Make sure `def' is really absent as opposed to set to nil.
603 (while (and plist (not (eq (car plist) tag)))
604 (setq plist (cdr (cdr plist))))
605 (if plist (car (cdr plist)) def))))
608 (defun cl--set-getf (plist tag val)
610 (while (and p (not (eq (car p) tag))) (setq p (cdr (cdr p))))
611 (if p (progn (setcar (cdr p) val) plist) (cl-list* tag val plist))))
614 (defun cl--do-remf (plist tag)
615 (let ((p (cdr plist)))
616 (while (and (cdr p) (not (eq (car (cdr p)) tag))) (setq p (cdr (cdr p))))
617 (and (cdr p) (progn (setcdr p (cdr (cdr (cdr p)))) t))))
620 (defun cl-remprop (sym tag)
621 "Remove from SYMBOL's plist the property PROPNAME and its value.
622 \n(fn SYMBOL PROPNAME)"
623 (let ((plist (symbol-plist sym)))
624 (if (and plist (eq tag (car plist)))
625 (progn (setplist sym (cdr (cdr plist))) t)
626 (cl--do-remf plist tag))))
631 (defun cl-fresh-line (&optional stream)
632 "Output a newline unless already at the beginning of a line."
633 (terpri stream 'ensure))
635 ;;; Some debugging aids.
637 (defun cl-prettyprint (form)
638 "Insert a pretty-printed rendition of a Lisp FORM in current buffer."
639 (let ((pt (point)) last)
640 (insert "\n" (prin1-to-string form) "\n")
643 (while (search-forward "(quote " last t)
649 (cl--do-prettyprint)))
651 (defun cl--do-prettyprint ()
652 (skip-chars-forward " ")
654 (let ((skip (or (looking-at "((") (looking-at "(prog")
655 (looking-at "(unwind-protect ")
656 (looking-at "(function (")
657 (looking-at "(cl--block-wrapper ")))
658 (two (or (looking-at "(defun ") (looking-at "(defmacro ")))
659 (let (or (looking-at "(let\\*? ") (looking-at "(while ")))
660 (set (looking-at "(p?set[qf] ")))
664 (and (>= (current-column) 78) (progn (backward-sexp) t))))
668 (or skip (looking-at ")") (cl--do-prettyprint))
669 (or (not two) (looking-at ")") (cl--do-prettyprint))
670 (while (not (looking-at ")"))
671 (if set (setq nl (not nl)))
672 (if nl (insert "\n"))
674 (cl--do-prettyprint))
679 (defun cl-prettyexpand (form &optional full)
680 "Expand macros in FORM and insert the pretty-printed result.
681 Optional argument FULL non-nil means to expand all macros,
682 including `cl-block' and `cl-eval-when'."
683 (message "Expanding...")
684 (let ((cl--compiling-file full)
685 (byte-compile-macro-environment nil))
686 (setq form (macroexpand-all form
687 (and (not full) '((cl-block) (cl-eval-when)))))
688 (message "Formatting...")
689 (prog1 (cl-prettyprint form)
694 (run-hooks 'cl-extra-load-hook)
697 ;; byte-compile-dynamic: t
698 ;; generated-autoload-file: "cl-loaddefs.el"
702 ;;; cl-extra.el ends here