Merge changes from emacs-23 branch
[bpt/emacs.git] / lisp / emacs-lisp / cl-indent.el
1 ;;; cl-indent.el --- enhanced lisp-indent mode
2
3 ;; Copyright (C) 1987, 2000-2011 Free Software Foundation, Inc.
4
5 ;; Author: Richard Mlynarik <mly@eddie.mit.edu>
6 ;; Created: July 1987
7 ;; Maintainer: FSF
8 ;; Keywords: lisp, tools
9 ;; Package: emacs
10
11 ;; This file is part of GNU Emacs.
12
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
17
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
22
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25
26 ;;; Commentary:
27
28 ;; This package supplies a single entry point, common-lisp-indent-function,
29 ;; which performs indentation in the preferred style for Common Lisp code.
30 ;; To enable it:
31 ;;
32 ;; (setq lisp-indent-function 'common-lisp-indent-function)
33
34 ;;; Code:
35
36 (eval-when-compile (require 'cl))
37
38 (defgroup lisp-indent nil
39 "Indentation in Lisp."
40 :group 'lisp)
41
42
43 (defcustom lisp-indent-maximum-backtracking 3
44 "Maximum depth to backtrack out from a sublist for structured indentation.
45 If this variable is 0, no backtracking will occur and forms such as `flet'
46 may not be correctly indented."
47 :type 'integer
48 :group 'lisp-indent)
49
50 (defcustom lisp-tag-indentation 1
51 "Indentation of tags relative to containing list.
52 This variable is used by the function `lisp-indent-tagbody'."
53 :type 'integer
54 :group 'lisp-indent)
55
56 (defcustom lisp-tag-body-indentation 3
57 "Indentation of non-tagged lines relative to containing list.
58 This variable is used by the function `lisp-indent-tagbody' to indent normal
59 lines (lines without tags).
60 The indentation is relative to the indentation of the parenthesis enclosing
61 the special form. If the value is t, the body of tags will be indented
62 as a block at the same indentation as the first s-expression following
63 the tag. In this case, any forms before the first tag are indented
64 by `lisp-body-indent'."
65 :type 'integer
66 :group 'lisp-indent)
67
68 (defcustom lisp-backquote-indentation t
69 "Whether or not to indent backquoted lists as code.
70 If nil, indent backquoted lists as data, i.e., like quoted lists."
71 :type 'boolean
72 :group 'lisp-indent)
73
74
75 (defcustom lisp-loop-keyword-indentation 3
76 "Indentation of loop keywords in extended loop forms."
77 :type 'integer
78 :group 'lisp-indent)
79
80
81 (defcustom lisp-loop-forms-indentation 5
82 "Indentation of forms in extended loop forms."
83 :type 'integer
84 :group 'lisp-indent)
85
86
87 (defcustom lisp-simple-loop-indentation 3
88 "Indentation of forms in simple loop forms."
89 :type 'integer
90 :group 'lisp-indent)
91
92 (defcustom lisp-lambda-list-keyword-alignment nil
93 "Whether to vertically align lambda-list keywords together.
94 If nil (the default), keyworded lambda-list parts are aligned
95 with the initial mandatory arguments, like this:
96
97 \(defun foo (arg1 arg2 &rest rest
98 &key key1 key2)
99 #|...|#)
100
101 If non-nil, alignment is done with the first keyword
102 \(or falls back to the previous case), as in:
103
104 \(defun foo (arg1 arg2 &rest rest
105 &key key1 key2)
106 #|...|#)"
107 :type 'boolean
108 :group 'lisp-indent)
109
110 (defcustom lisp-lambda-list-keyword-parameter-indentation 2
111 "Indentation of lambda list keyword parameters.
112 See `lisp-lambda-list-keyword-parameter-alignment'
113 for more information."
114 :type 'integer
115 :group 'lisp-indent)
116
117 (defcustom lisp-lambda-list-keyword-parameter-alignment nil
118 "Whether to vertically align lambda-list keyword parameters together.
119 If nil (the default), the parameters are aligned
120 with their corresponding keyword, plus the value of
121 `lisp-lambda-list-keyword-parameter-indentation', like this:
122
123 \(defun foo (arg1 arg2 &key key1 key2
124 key3 key4)
125 #|...|#)
126
127 If non-nil, alignment is done with the first parameter
128 \(or falls back to the previous case), as in:
129
130 \(defun foo (arg1 arg2 &key key1 key2
131 key3 key4)
132 #|...|#)"
133 :type 'boolean
134 :group 'lisp-indent)
135
136 \f
137 (defvar lisp-indent-defun-method '(4 &lambda &body)
138 "Defun-like indentation method.
139 This applies when the value of the `common-lisp-indent-function' property
140 is set to `defun'.")
141
142
143 (defun extended-loop-p (loop-start)
144 "True if an extended loop form starts at LOOP-START."
145 (condition-case ()
146 (save-excursion
147 (goto-char loop-start)
148 (forward-char 1)
149 (forward-sexp 2)
150 (backward-sexp 1)
151 (looking-at "\\sw"))
152 (error t)))
153
154
155 (defun common-lisp-loop-part-indentation (indent-point state)
156 "Compute the indentation of loop form constituents."
157 (let* ((loop-indentation (save-excursion
158 (goto-char (elt state 1))
159 (current-column))))
160 (goto-char indent-point)
161 (beginning-of-line)
162 (cond ((not (extended-loop-p (elt state 1)))
163 (+ loop-indentation lisp-simple-loop-indentation))
164 ((looking-at "^\\s-*\\(:?\\sw+\\|;\\)")
165 (+ loop-indentation lisp-loop-keyword-indentation))
166 (t
167 (+ loop-indentation lisp-loop-forms-indentation)))))
168
169
170 ;; Cf (info "(elisp)Specification List")
171 ;;;###autoload
172 (defun common-lisp-indent-function (indent-point state)
173 "Function to indent the arguments of a Lisp function call.
174 This is suitable for use as the value of the variable
175 `lisp-indent-function'. INDENT-POINT is the point at which the
176 indentation function is called, and STATE is the
177 `parse-partial-sexp' state at that position. Browse the
178 `lisp-indent' customize group for options affecting the behavior
179 of this function.
180
181 If the indentation point is in a call to a Lisp function, that
182 function's `common-lisp-indent-function' property specifies how
183 this function should indent it. Possible values for this
184 property are:
185
186 * defun, meaning indent according to `lisp-indent-defun-method';
187 i.e., like (4 &lambda &body), as explained below.
188
189 * any other symbol, meaning a function to call. The function should
190 take the arguments: PATH STATE INDENT-POINT SEXP-COLUMN NORMAL-INDENT.
191 PATH is a list of integers describing the position of point in terms of
192 list-structure with respect to the containing lists. For example, in
193 ((a b c (d foo) f) g), foo has a path of (0 3 1). In other words,
194 to reach foo take the 0th element of the outermost list, then
195 the 3rd element of the next list, and finally the 1st element.
196 STATE and INDENT-POINT are as in the arguments to
197 `common-lisp-indent-function'. SEXP-COLUMN is the column of
198 the open parenthesis of the innermost containing list.
199 NORMAL-INDENT is the column the indentation point was
200 originally in. This function should behave like `lisp-indent-259'.
201
202 * an integer N, meaning indent the first N arguments like
203 function arguments, and any further arguments like a body.
204 This is equivalent to (4 4 ... &body).
205
206 * a list. The list element in position M specifies how to indent the Mth
207 function argument. If there are fewer elements than function arguments,
208 the last list element applies to all remaining arguments. The accepted
209 list elements are:
210
211 * nil, meaning the default indentation.
212
213 * an integer, specifying an explicit indentation.
214
215 * &lambda. Indent the argument (which may be a list) by 4.
216
217 * &rest. When used, this must be the penultimate element. The
218 element after this one applies to all remaining arguments.
219
220 * &body. This is equivalent to &rest lisp-body-indent, i.e., indent
221 all remaining elements by `lisp-body-indent'.
222
223 * &whole. This must be followed by nil, an integer, or a
224 function symbol. This indentation is applied to the
225 associated argument, and as a base indent for all remaining
226 arguments. For example, an integer P means indent this
227 argument by P, and all remaining arguments by P, plus the
228 value specified by their associated list element.
229
230 * a symbol. A function to call, with the 6 arguments specified above.
231
232 * a list, with elements as described above. This applies when the
233 associated function argument is itself a list. Each element of the list
234 specifies how to indent the associated argument.
235
236 For example, the function `case' has an indent property
237 \(4 &rest (&whole 2 &rest 1)), meaning:
238 * indent the first argument by 4.
239 * arguments after the first should be lists, and there may be any number
240 of them. The first list element has an offset of 2, all the rest
241 have an offset of 2+1=3."
242 (if (save-excursion (goto-char (elt state 1))
243 (looking-at "([Ll][Oo][Oo][Pp]"))
244 (common-lisp-loop-part-indentation indent-point state)
245 (common-lisp-indent-function-1 indent-point state)))
246
247
248 (defun common-lisp-indent-function-1 (indent-point state)
249 (let ((normal-indent (current-column)))
250 ;; Walk up list levels until we see something
251 ;; which does special things with subforms.
252 (let ((depth 0)
253 ;; Path describes the position of point in terms of
254 ;; list-structure with respect to containing lists.
255 ;; `foo' has a path of (0 3 1) in `((a b c (d foo) f) g)'.
256 (path ())
257 ;; set non-nil when somebody works out the indentation to use
258 calculated
259 ;; If non-nil, this is an indentation to use
260 ;; if nothing else specifies it more firmly.
261 tentative-calculated
262 (last-point indent-point)
263 ;; the position of the open-paren of the innermost containing list
264 (containing-form-start (elt state 1))
265 ;; the column of the above
266 sexp-column)
267 ;; Move to start of innermost containing list
268 (goto-char containing-form-start)
269 (setq sexp-column (current-column))
270
271 ;; Look over successively less-deep containing forms
272 (while (and (not calculated)
273 (< depth lisp-indent-maximum-backtracking))
274 (let ((containing-sexp (point)))
275 (forward-char 1)
276 (parse-partial-sexp (point) indent-point 1 t)
277 ;; Move to the car of the relevant containing form
278 (let (tem function method tentative-defun)
279 (if (not (looking-at "\\sw\\|\\s_"))
280 ;; This form doesn't seem to start with a symbol
281 (setq function nil method nil)
282 (setq tem (point))
283 (forward-sexp 1)
284 (setq function (downcase (buffer-substring-no-properties
285 tem (point))))
286 (goto-char tem)
287 (setq tem (intern-soft function)
288 method (get tem 'common-lisp-indent-function))
289 (cond ((and (null method)
290 (string-match ":[^:]+" function))
291 ;; The pleblisp package feature
292 (setq function (substring function
293 (1+ (match-beginning 0)))
294 method (get (intern-soft function)
295 'common-lisp-indent-function)))
296 ((and (null method))
297 ;; backwards compatibility
298 (setq method (get tem 'lisp-indent-function)))))
299 (let ((n 0))
300 ;; How far into the containing form is the current form?
301 (if (< (point) indent-point)
302 (while (condition-case ()
303 (progn
304 (forward-sexp 1)
305 (if (>= (point) indent-point)
306 nil
307 (parse-partial-sexp (point)
308 indent-point 1 t)
309 (setq n (1+ n))
310 t))
311 (error nil))))
312 (setq path (cons n path)))
313
314 ;; backwards compatibility.
315 (cond ((null function))
316 ((null method)
317 (when (null (cdr path))
318 ;; (package prefix was stripped off above)
319 (cond ((string-match "\\`def"
320 function)
321 (setq tentative-defun t))
322 ((string-match
323 (eval-when-compile
324 (concat "\\`\\("
325 (regexp-opt '("with" "without" "do"))
326 "\\)-"))
327 function)
328 (setq method '(&lambda &body))))))
329 ;; backwards compatibility. Bletch.
330 ((eq method 'defun)
331 (setq method lisp-indent-defun-method)))
332
333 (cond ((and (or (eq (char-after (1- containing-sexp)) ?\')
334 (and (not lisp-backquote-indentation)
335 (eq (char-after (1- containing-sexp)) ?\`)))
336 (not (eq (char-after (- containing-sexp 2)) ?\#)))
337 ;; No indentation for "'(...)" elements
338 (setq calculated (1+ sexp-column)))
339 ((or (eq (char-after (1- containing-sexp)) ?\,)
340 (and (eq (char-after (1- containing-sexp)) ?\@)
341 (eq (char-after (- containing-sexp 2)) ?\,)))
342 ;; ",(...)" or ",@(...)"
343 (setq calculated normal-indent))
344 ((eq (char-after (1- containing-sexp)) ?\#)
345 ;; "#(...)"
346 (setq calculated (1+ sexp-column)))
347 ((null method)
348 ;; If this looks like a call to a `def...' form,
349 ;; think about indenting it as one, but do it
350 ;; tentatively for cases like
351 ;; (flet ((defunp ()
352 ;; nil)))
353 ;; Set both normal-indent and tentative-calculated.
354 ;; The latter ensures this value gets used
355 ;; if there are no relevant containing constructs.
356 ;; The former ensures this value gets used
357 ;; if there is a relevant containing construct
358 ;; but we are nested within the structure levels
359 ;; that it specifies indentation for.
360 (if tentative-defun
361 (setq tentative-calculated
362 (common-lisp-indent-call-method
363 function lisp-indent-defun-method
364 path state indent-point
365 sexp-column normal-indent)
366 normal-indent tentative-calculated)))
367 ((integerp method)
368 ;; convenient top-level hack.
369 ;; (also compatible with lisp-indent-function)
370 ;; The number specifies how many `distinguished'
371 ;; forms there are before the body starts
372 ;; Equivalent to (4 4 ... &body)
373 (setq calculated (cond ((cdr path)
374 normal-indent)
375 ((<= (car path) method)
376 ;; `distinguished' form
377 (list (+ sexp-column 4)
378 containing-form-start))
379 ((= (car path) (1+ method))
380 ;; first body form.
381 (+ sexp-column lisp-body-indent))
382 (t
383 ;; other body form
384 normal-indent))))
385 (t
386 (setq calculated
387 (common-lisp-indent-call-method
388 function method path state indent-point
389 sexp-column normal-indent)))))
390 (goto-char containing-sexp)
391 (setq last-point containing-sexp)
392 (unless calculated
393 (condition-case ()
394 (progn (backward-up-list 1)
395 (setq depth (1+ depth)))
396 (error (setq depth lisp-indent-maximum-backtracking))))))
397 (or calculated tentative-calculated))))
398
399
400 (defun common-lisp-indent-call-method (function method path state indent-point
401 sexp-column normal-indent)
402 (let ((lisp-indent-error-function function))
403 (if (symbolp method)
404 (funcall method
405 path state indent-point
406 sexp-column normal-indent)
407 (lisp-indent-259 method path state indent-point
408 sexp-column normal-indent))))
409
410 ;; Dynamically bound in common-lisp-indent-call-method.
411 (defvar lisp-indent-error-function)
412
413 (defun lisp-indent-report-bad-format (m)
414 (error "%s has a badly-formed %s property: %s"
415 ;; Love those free variable references!!
416 lisp-indent-error-function 'common-lisp-indent-function m))
417
418
419 ;; Lambda-list indentation is now done in LISP-INDENT-LAMBDA-LIST.
420 ;; See also `lisp-lambda-list-keyword-alignment',
421 ;; `lisp-lambda-list-keyword-parameter-alignment' and
422 ;; `lisp-lambda-list-keyword-parameter-indentation' -- dvl
423
424 (defvar lisp-indent-lambda-list-keywords-regexp
425 "&\\(\
426 optional\\|rest\\|key\\|allow-other-keys\\|aux\\|whole\\|body\\|environment\
427 \\)\\([ \t]\\|$\\)"
428 "Regular expression matching lambda-list keywords.")
429
430 (defun lisp-indent-lambda-list
431 (indent-point sexp-column containing-form-start)
432 (let (limit)
433 (cond ((save-excursion
434 (goto-char indent-point)
435 (beginning-of-line)
436 (skip-chars-forward " \t")
437 (setq limit (point))
438 (looking-at lisp-indent-lambda-list-keywords-regexp))
439 ;; We're facing a lambda-list keyword.
440 (if lisp-lambda-list-keyword-alignment
441 ;; Align to the first keyword if any, or to the beginning of
442 ;; the lambda-list.
443 (save-excursion
444 (goto-char containing-form-start)
445 (save-match-data
446 (if (re-search-forward
447 lisp-indent-lambda-list-keywords-regexp
448 limit t)
449 (progn
450 (goto-char (match-beginning 0))
451 (current-column))
452 (1+ sexp-column))))
453 ;; Align to the beginning of the lambda-list.
454 (1+ sexp-column)))
455 (t
456 ;; Otherwise, align to the first argument of the last lambda-list
457 ;; keyword, the keyword itself, or the beginning of the
458 ;; lambda-list.
459 (save-excursion
460 (goto-char indent-point)
461 (forward-line -1)
462 (end-of-line)
463 (save-match-data
464 (if (re-search-backward lisp-indent-lambda-list-keywords-regexp
465 containing-form-start t)
466 (let* ((keyword-posn
467 (progn
468 (goto-char (match-beginning 0))
469 (current-column)))
470 (indented-keyword-posn
471 (+ keyword-posn
472 lisp-lambda-list-keyword-parameter-indentation)))
473 (goto-char (match-end 0))
474 (skip-chars-forward " \t")
475 (if (eolp)
476 indented-keyword-posn
477 (if lisp-lambda-list-keyword-parameter-alignment
478 (current-column)
479 indented-keyword-posn)))
480 (1+ sexp-column))))))))
481
482 ;; Blame the crufty control structure on dynamic scoping
483 ;; -- not on me!
484 (defun lisp-indent-259
485 (method path state indent-point sexp-column normal-indent)
486 (catch 'exit
487 (let ((p path)
488 (containing-form-start (elt state 1))
489 n tem tail)
490 ;; Isn't tail-recursion wonderful?
491 (while p
492 ;; This while loop is for destructuring.
493 ;; p is set to (cdr p) each iteration.
494 (if (not (consp method)) (lisp-indent-report-bad-format method))
495 (setq n (1- (car p))
496 p (cdr p)
497 tail nil)
498 (while n
499 ;; This while loop is for advancing along a method
500 ;; until the relevant (possibly &rest/&body) pattern
501 ;; is reached.
502 ;; n is set to (1- n) and method to (cdr method)
503 ;; each iteration.
504 (setq tem (car method))
505
506 (or (eq tem 'nil) ;default indentation
507 (eq tem '&lambda) ;lambda list
508 (and (eq tem '&body) (null (cdr method)))
509 (and (eq tem '&rest)
510 (consp (cdr method))
511 (null (cddr method)))
512 (integerp tem) ;explicit indentation specified
513 (and (consp tem) ;destructuring
514 (eq (car tem) '&whole)
515 (or (symbolp (cadr tem))
516 (integerp (cadr tem))))
517 (and (symbolp tem) ;a function to call to do the work.
518 (null (cdr method)))
519 (lisp-indent-report-bad-format method))
520
521 (cond ((and tail (not (consp tem)))
522 ;; indent tail of &rest in same way as first elt of rest
523 (throw 'exit normal-indent))
524 ((eq tem '&body)
525 ;; &body means (&rest <lisp-body-indent>)
526 (throw 'exit
527 (if (and (= n 0) ;first body form
528 (null p)) ;not in subforms
529 (+ sexp-column
530 lisp-body-indent)
531 normal-indent)))
532 ((eq tem '&rest)
533 ;; this pattern holds for all remaining forms
534 (setq tail (> n 0)
535 n 0
536 method (cdr method)))
537 ((> n 0)
538 ;; try next element of pattern
539 (setq n (1- n)
540 method (cdr method))
541 (if (< n 0)
542 ;; Too few elements in pattern.
543 (throw 'exit normal-indent)))
544 ((eq tem 'nil)
545 (throw 'exit (if (consp normal-indent)
546 normal-indent
547 (list normal-indent containing-form-start))))
548 ((eq tem '&lambda)
549 (throw 'exit
550 (cond ((null p)
551 (list (+ sexp-column 4) containing-form-start))
552 ((null (cdr p))
553 ;; Indentation within a lambda-list. -- dvl
554 (list (lisp-indent-lambda-list
555 indent-point
556 sexp-column
557 containing-form-start)
558 containing-form-start))
559 (t
560 normal-indent))))
561 ((integerp tem)
562 (throw 'exit
563 (if (null p) ;not in subforms
564 (list (+ sexp-column tem) containing-form-start)
565 normal-indent)))
566 ((symbolp tem) ;a function to call
567 (throw 'exit
568 (funcall tem path state indent-point
569 sexp-column normal-indent)))
570 (t
571 ;; must be a destructing frob
572 (if (not (null p))
573 ;; descend
574 (setq method (cddr tem)
575 n nil)
576 (setq tem (cadr tem))
577 (throw 'exit
578 (cond (tail
579 normal-indent)
580 ((eq tem 'nil)
581 (list normal-indent
582 containing-form-start))
583 ((integerp tem)
584 (list (+ sexp-column tem)
585 containing-form-start))
586 (t
587 (funcall tem path state indent-point
588 sexp-column normal-indent))))))))))))
589 \f
590 (defun lisp-indent-tagbody (path state indent-point sexp-column normal-indent)
591 (if (not (null (cdr path)))
592 normal-indent
593 (save-excursion
594 (goto-char indent-point)
595 (beginning-of-line)
596 (skip-chars-forward " \t")
597 (list (cond ((looking-at "\\sw\\|\\s_")
598 ;; a tagbody tag
599 (+ sexp-column lisp-tag-indentation))
600 ((integerp lisp-tag-body-indentation)
601 (+ sexp-column lisp-tag-body-indentation))
602 ((eq lisp-tag-body-indentation 't)
603 (condition-case ()
604 (progn (backward-sexp 1) (current-column))
605 (error (1+ sexp-column))))
606 (t (+ sexp-column lisp-body-indent)))
607 ; (cond ((integerp lisp-tag-body-indentation)
608 ; (+ sexp-column lisp-tag-body-indentation))
609 ; ((eq lisp-tag-body-indentation 't)
610 ; normal-indent)
611 ; (t
612 ; (+ sexp-column lisp-body-indent)))
613 (elt state 1)
614 ))))
615
616 (defun lisp-indent-do (path state indent-point sexp-column normal-indent)
617 (if (>= (car path) 3)
618 (let ((lisp-tag-body-indentation lisp-body-indent))
619 (funcall (function lisp-indent-tagbody)
620 path state indent-point sexp-column normal-indent))
621 (funcall (function lisp-indent-259)
622 '((&whole nil &rest
623 ;; the following causes weird indentation
624 ;;(&whole 1 1 2 nil)
625 )
626 (&whole nil &rest 1))
627 path state indent-point sexp-column normal-indent)))
628
629
630 ;; LISP-INDENT-DEFMETHOD now supports the presence of more than one method
631 ;; qualifier and indents the method's lambda list properly. -- dvl
632 (defun lisp-indent-defmethod
633 (path state indent-point sexp-column normal-indent)
634 (lisp-indent-259
635 (let ((nqual 0))
636 (if (and (>= (car path) 3)
637 (save-excursion
638 (beginning-of-defun)
639 (forward-char 1)
640 (forward-sexp 2)
641 (skip-chars-forward " \t\n")
642 (while (looking-at "\\sw\\|\\s_")
643 (incf nqual)
644 (forward-sexp)
645 (skip-chars-forward " \t\n"))
646 (> nqual 0)))
647 (append '(4) (make-list nqual 4) '(&lambda &body))
648 (get 'defun 'common-lisp-indent-function)))
649 path state indent-point sexp-column normal-indent))
650
651
652 (defun lisp-indent-function-lambda-hack (path state indent-point
653 sexp-column normal-indent)
654 ;; indent (function (lambda () <newline> <body-forms>)) kludgily.
655 (if (or (cdr path) ; wtf?
656 (> (car path) 3))
657 ;; line up under previous body form
658 normal-indent
659 ;; line up under function rather than under lambda in order to
660 ;; conserve horizontal space. (Which is what #' is for.)
661 (condition-case ()
662 (save-excursion
663 (backward-up-list 2)
664 (forward-char 1)
665 (if (looking-at "\\(lisp:+\\)?function\\(\\Sw\\|\\S_\\)")
666 (+ lisp-body-indent -1 (current-column))
667 (+ sexp-column lisp-body-indent)))
668 (error (+ sexp-column lisp-body-indent)))))
669
670
671 \f
672 (let ((l '((block 1)
673 (case (4 &rest (&whole 2 &rest 1)))
674 (ccase . case)
675 (ecase . case)
676 (typecase . case)
677 (etypecase . case)
678 (ctypecase . case)
679 (catch 1)
680 (cond (&rest (&whole 2 &rest 1)))
681 (defvar (4 2 2))
682 (defclass (6 4 (&whole 2 &rest 1) (&whole 2 &rest 1)))
683 (defconstant . defvar)
684 (defcustom (4 2 2 2))
685 (defparameter . defvar)
686 (defconst . defcustom)
687 (define-condition . defclass)
688 (define-modify-macro (4 &lambda &body))
689 (defsetf (4 &lambda 4 &body))
690 (defun (4 &lambda &body))
691 (defgeneric (4 &lambda &body))
692 (define-setf-method . defun)
693 (define-setf-expander . defun)
694 (defmacro . defun)
695 (defsubst . defun)
696 (deftype . defun)
697 (defmethod lisp-indent-defmethod)
698 (defpackage (4 2))
699 (defstruct ((&whole 4 &rest (&whole 2 &rest 1))
700 &rest (&whole 2 &rest 1)))
701 (destructuring-bind
702 ((&whole 6 &rest 1) 4 &body))
703 (do lisp-indent-do)
704 (do* . do)
705 (dolist ((&whole 4 2 1) &body))
706 (dotimes . dolist)
707 (eval-when 1)
708 (flet ((&whole 4 &rest (&whole 1 &lambda &body)) &body))
709 (labels . flet)
710 (macrolet . flet)
711 (generic-flet . flet)
712 (generic-labels . flet)
713 (handler-case (4 &rest (&whole 2 &lambda &body)))
714 (restart-case . handler-case)
715 ;; `else-body' style
716 (if (nil nil &body))
717 ;; single-else style (then and else equally indented)
718 (if (&rest nil))
719 (lambda (&lambda &rest lisp-indent-function-lambda-hack))
720 (let ((&whole 4 &rest (&whole 1 1 2)) &body))
721 (let* . let)
722 (compiler-let . let) ;barf
723 (handler-bind . let)
724 (restart-bind . let)
725 (locally 1)
726 ;(loop lisp-indent-loop)
727 (:method (&lambda &body)) ; in `defgeneric'
728 (multiple-value-bind ((&whole 6 &rest 1) 4 &body))
729 (multiple-value-call (4 &body))
730 (multiple-value-prog1 1)
731 (multiple-value-setq (4 2))
732 (multiple-value-setf . multiple-value-setq)
733 (pprint-logical-block (4 2))
734 (print-unreadable-object ((&whole 4 1 &rest 1) &body))
735 ;; Combines the worst features of BLOCK, LET and TAGBODY
736 (prog (&lambda &rest lisp-indent-tagbody))
737 (prog* . prog)
738 (prog1 1)
739 (prog2 2)
740 (progn 0)
741 (progv (4 4 &body))
742 (return 0)
743 (return-from (nil &body))
744 (symbol-macrolet . let)
745 (tagbody lisp-indent-tagbody)
746 (throw 1)
747 (unless 1)
748 (unwind-protect (5 &body))
749 (when 1)
750 (with-accessors . multiple-value-bind)
751 (with-condition-restarts . multiple-value-bind)
752 (with-output-to-string (4 2))
753 (with-slots . multiple-value-bind)
754 (with-standard-io-syntax (2)))))
755 (dolist (el l)
756 (put (car el) 'common-lisp-indent-function
757 (if (symbolp (cdr el))
758 (get (cdr el) 'common-lisp-indent-function)
759 (car (cdr el))))))
760
761 \f
762 ;(defun foo (x)
763 ; (tagbody
764 ; foo
765 ; (bar)
766 ; baz
767 ; (when (losing)
768 ; (with-big-loser
769 ; (yow)
770 ; ((lambda ()
771 ; foo)
772 ; big)))
773 ; (flet ((foo (bar baz zap)
774 ; (zip))
775 ; (zot ()
776 ; quux))
777 ; (do ()
778 ; ((lose)
779 ; (foo 1))
780 ; (quux)
781 ; foo
782 ; (lose))
783 ; (cond ((x)
784 ; (win 1 2
785 ; (foo)))
786 ; (t
787 ; (lose
788 ; 3))))))
789
790
791 ;(put 'while 'common-lisp-indent-function 1)
792 ;(put 'defwrapper'common-lisp-indent-function ...)
793 ;(put 'def 'common-lisp-indent-function ...)
794 ;(put 'defflavor 'common-lisp-indent-function ...)
795 ;(put 'defsubst 'common-lisp-indent-function ...)
796
797 ;(put 'with-restart 'common-lisp-indent-function '((1 4 ((* 1))) (2 &body)))
798 ;(put 'restart-case 'common-lisp-indent-function '((1 4) (* 2 ((0 1) (* 1)))))
799 ;(put 'define-condition 'common-lisp-indent-function '((1 6) (2 6 ((&whole 1))) (3 4 ((&whole 1))) (4 &body)))
800 ;(put 'with-condition-handler 'common-lisp-indent-function '((1 4 ((* 1))) (2 &body)))
801 ;(put 'condition-case 'common-lisp-indent-function '((1 4) (* 2 ((0 1) (1 3) (2 &body)))))
802 ;(put 'defclass 'common-lisp-indent-function '((&whole 2 &rest (&whole 2 &rest 1) &rest (&whole 2 &rest 1)))
803 ;(put 'defgeneric 'common-lisp-indent-function 'defun)
804
805 ;;; cl-indent.el ends here