annotate lisp/emacs-lisp/cl-indent.el @ 828:4b56424868f6

*** empty log message ***
author Eric S. Raymond <esr@snark.thyrsus.com>
date Tue, 21 Jul 1992 07:57:59 +0000
parents e694e0879463
children 213978acbc1e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 257
diff changeset
1 ;;; cl-indent.el --- enhanced lisp-indent mode
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 257
diff changeset
2
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
3 ;; Author: Richard Mlynark <mly@eddie.mit.edu>
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
4 ;; Maintainer: FSF
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
5 ;; Last-Modified: 09 May 1991
811
e694e0879463 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
6 ;; Keywords: lisp, tools
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
7
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
8 ;; Copyright (C) 1987 Free Software Foundation, Inc.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9 ;; Written by Richard Mlynarik July 1987
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11 ;; This file is part of GNU Emacs.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 ;; GNU Emacs is free software; you can redistribute it and/or modify
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
14 ;; it under the terms of the GNU General Public License as published by
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
15 ;; the Free Software Foundation; either version 2, or (at your option)
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16 ;; any later version.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 ;; GNU Emacs is distributed in the hope that it will be useful,
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21 ;; GNU General Public License for more details.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 ;; You should have received a copy of the GNU General Public License
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 ;; along with GNU Emacs; see the file COPYING. If not, write to
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
26
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
27 ;;; Commentary:
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
28
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 ;;>> TODO
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 ;; :foo
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 ;; bar
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 ;; :baz
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 ;; zap
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 ;; &key (like &body)??
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 ;; &rest 1 in lambda-lists doesn't work
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 ;; -- really want (foo bar
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 ;; baz)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 ;; not (foo bar
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 ;; baz)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 ;; Need something better than &rest for such cases
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
43 ;;; Code:
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 ;;; Hairy lisp indentation.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 (defvar lisp-indent-maximum-backtracking 3
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 "*Maximum depth to backtrack out from a sublist for structured indentation.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 If this variable is 0, no backtracking will occur and forms such as flet
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 may not be correctly indented.")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 (defvar lisp-tag-indentation 1
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53 "*Indentation of tags relative to containing list.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 This variable is used by the function `lisp-indent-tagbody'.")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 (defvar lisp-tag-body-indentation 3
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 "*Indentation of non-tagged lines relative to containing list.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 This variable is used by the function `lisp-indent-tagbody' to indent normal
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 lines (lines without tags).
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 The indentation is relative to the indentation of the parenthesis enclosing
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 the special form. If the value is t, the body of tags will be indented
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 as a block at the same indentation as the first s-expression following
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 the tag. In this case, any forms before the first tag are indented
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 by `lisp-body-indent'.")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 ;;;###autoload
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 (defun common-lisp-indent-function (indent-point state)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 (let ((normal-indent (current-column)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 ;; Walk up list levels until we see something
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 ;; which does special things with subforms.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 (let ((depth 0)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 ;; Path describes the position of point in terms of
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 ;; list-structure with respect to contining lists.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 ;; `foo' has a path of (0 4 1) in `((a b c (d foo) f) g)'
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 (path ())
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 ;; set non-nil when somebody works out the indentation to use
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 calculated
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 (last-point indent-point)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 ;; the position of the open-paren of the innermost containing list
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 (containing-form-start (elt state 1))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 ;; the column of the above
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 sexp-column)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 ;; Move to start of innermost containing list
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 (goto-char containing-form-start)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 (setq sexp-column (current-column))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 ;; Look over successively less-deep containing forms
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 (while (and (not calculated)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 (< depth lisp-indent-maximum-backtracking))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 (let ((containing-sexp (point)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 (forward-char 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 (parse-partial-sexp (point) indent-point 1 t)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 ;; Move to the car of the relevant containing form
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 (let (tem function method)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 (if (not (looking-at "\\sw\\|\\s_"))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 ;; This form doesn't seem to start with a symbol
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 (setq function nil method nil)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98 (setq tem (point))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 (forward-sexp 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 (setq function (downcase (buffer-substring tem (point))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 (goto-char tem)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 (setq tem (intern-soft function)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 method (get tem 'common-lisp-indent-function))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 (cond ((and (null method)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 (string-match ":[^:]+" function))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 ;; The pleblisp package feature
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 (setq function (substring function
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 (1+ (match-beginning 0)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 method (get (intern-soft function)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 'common-lisp-indent-function)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 ((and (null method))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 ;; backwards compatibility
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 (setq method (get tem 'lisp-indent-function)))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 (let ((n 0))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 ;; How far into the containing form is the current form?
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 (if (< (point) indent-point)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 (while (condition-case ()
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 (progn
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 (forward-sexp 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 (if (>= (point) indent-point)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 nil
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 (parse-partial-sexp (point)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 indent-point 1 t)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 (setq n (1+ n))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 t))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 (error nil))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 (setq path (cons n path)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 ;; backwards compatibility.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130 (cond ((null function))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 ((null method)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 (if (null (cdr path))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 ;; (package prefix was stripped off above)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 (setq method (cond ((string-match "\\`def"
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 function)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 '(4 (&whole 4 &rest 1) &body))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 ((string-match "\\`\\(with\\|do\\)-"
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 function)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 '(4 &body))))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 ;; backwards compatibility. Bletch.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 ((eq method 'defun)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 (setq method '(4 (&whole 4 &rest 1) &body))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 (cond ((and (memq (char-after (1- containing-sexp)) '(?\' ?\`))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 (not (eql (char-after (- containing-sexp 2)) ?\#)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 ;; No indentation for "'(...)" elements
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 (setq calculated (1+ sexp-column)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 ((or (eql (char-after (1- containing-sexp)) ?\,)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 (and (eql (char-after (1- containing-sexp)) ?\@)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 (eql (char-after (- containing-sexp 2)) ?\,)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 ;; ",(...)" or ",@(...)"
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 (setq calculated normal-indent))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 ((eql (char-after (1- containing-sexp)) ?\#)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 ;; "#(...)"
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 (setq calculated (1+ sexp-column)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 ((null method))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 ((integerp method)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 ;; convenient top-level hack.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 ;; (also compatible with lisp-indent-function)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 ;; The number specifies how many `distinguished'
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 ;; forms there are before the body starts
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 ;; Equivalent to (4 4 ... &body)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 (setq calculated (cond ((cdr path)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 normal-indent)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 ((<= (car path) method)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 ;; `distinguished' form
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 (list (+ sexp-column 4)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 containing-form-start))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 ((= (car path) (1+ method))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 ;; first body form.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 (+ sexp-column lisp-body-indent))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 (t
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 ;; other body form
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 normal-indent))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 ((symbolp method)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 (setq calculated (funcall method
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 path state indent-point
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 sexp-column normal-indent)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 (t
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 (setq calculated (lisp-indent-259
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 method path state indent-point
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 sexp-column normal-indent)))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 (goto-char containing-sexp)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 (setq last-point containing-sexp)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 (if (not calculated)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 (condition-case ()
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 (progn (backward-up-list 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 (setq depth (1+ depth)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 (error (setq depth lisp-indent-maximum-backtracking))))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 calculated)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 (defun lisp-indent-report-bad-format (m)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 (error "%s has a badly-formed %s property: %s"
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 ;; Love those free variable references!!
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196 function 'common-lisp-indent-function m))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 ;; Blame the crufty control structure on dynamic scoping
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199 ;; -- not on me!
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200 (defun lisp-indent-259 (method path state indent-point
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 sexp-column normal-indent)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 (catch 'exit
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 (let ((p path)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 (containing-form-start (elt state 1))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205 n tem tail)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 ;; Isn't tail-recursion wonderful?
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 (while p
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 ;; This while loop is for destructuring.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 ;; p is set to (cdr p) each iteration.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210 (if (not (consp method)) (lisp-indent-report-bad-format method))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 (setq n (1- (car p))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 p (cdr p)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 tail nil)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 (while n
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 ;; This while loop is for advancing along a method
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216 ;; until the relevant (possibly &rest/&body) pattern
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 ;; is reached.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 ;; n is set to (1- n) and method to (cdr method)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219 ;; each iteration.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 (setq tem (car method))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 (or (eq tem 'nil) ;default indentation
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 ; (eq tem '&lambda) ;abbrev for (&whole 4 (&rest 1))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 (and (eq tem '&body) (null (cdr method)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 (and (eq tem '&rest)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 (consp (cdr method)) (null (cdr (cdr method))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 (integerp tem) ;explicit indentation specified
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 (and (consp tem) ;destructuring
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 (eq (car tem) '&whole)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 (or (symbolp (car (cdr tem)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 (integerp (car (cdr tem)))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 (and (symbolp tem) ;a function to call to do the work.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 (null (cdr method)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 (lisp-indent-report-bad-format method))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236 (cond ((and tail (not (consp tem)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 ;; indent tail of &rest in same way as first elt of rest
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 (throw 'exit normal-indent))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 ((eq tem '&body)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 ;; &body means (&rest <lisp-body-indent>)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 (throw 'exit
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 (if (and (= n 0) ;first body form
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 (null p)) ;not in subforms
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 (+ sexp-column
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 lisp-body-indent)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 normal-indent)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 ((eq tem '&rest)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 ;; this pattern holds for all remaining forms
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 (setq tail (> n 0)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 n 0
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 method (cdr method)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 ((> n 0)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 ;; try next element of pattern
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 (setq n (1- n)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 method (cdr method))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 (if (< n 0)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 ;; Too few elements in pattern.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 (throw 'exit normal-indent)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 ((eq tem 'nil)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 (throw 'exit (list normal-indent containing-form-start)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 ; ((eq tem '&lambda)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 ; ;; abbrev for (&whole 4 &rest 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 ; (throw 'exit
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 ; (cond ((null p)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 ; (list (+ sexp-column 4) containing-form-start))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 ; ((null (cdr p))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 ; (+ sexp-column 1))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 ; (t normal-indent))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 ((integerp tem)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 (throw 'exit
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 (if (null p) ;not in subforms
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 (list (+ sexp-column tem) containing-form-start)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 normal-indent)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 ((symbolp tem) ;a function to call
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 (throw 'exit
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 (funcall tem path state indent-point
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 sexp-column normal-indent)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 (t
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 ;; must be a destructing frob
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 (if (not (null p))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 ;; descend
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 (setq method (cdr (cdr tem))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 n nil)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 (setq tem (car (cdr tem)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 (throw 'exit
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 (cond (tail
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 normal-indent)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 ((eq tem 'nil)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 (list normal-indent
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 containing-form-start))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 ((integerp tem)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 (list (+ sexp-column tem)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
293 containing-form-start))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 (t
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 (funcall tem path state indent-point
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 sexp-column normal-indent))))))))))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 (defun lisp-indent-tagbody (path state indent-point sexp-column normal-indent)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 (if (not (null (cdr path)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
300 normal-indent
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 (goto-char indent-point)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 (beginning-of-line)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 (skip-chars-forward " \t")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 (list (cond ((looking-at "\\sw\\|\\s_")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 ;; a tagbody tag
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307 (+ sexp-column lisp-tag-indentation))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308 ((integerp lisp-tag-body-indentation)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 (+ sexp-column lisp-tag-body-indentation))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 ((eq lisp-tag-body-indentation 't)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 (condition-case ()
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 (progn (backward-sexp 1) (current-column))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 (error (1+ sexp-column))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 (t (+ sexp-column lisp-body-indent)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 ; (cond ((integerp lisp-tag-body-indentation)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 ; (+ sexp-column lisp-tag-body-indentation))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 ; ((eq lisp-tag-body-indentation 't)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318 ; normal-indent)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 ; (t
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 ; (+ sexp-column lisp-body-indent)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 (elt state 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 ))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
323
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
324 (defun lisp-indent-do (path state indent-point sexp-column normal-indent)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 (if (>= (car path) 3)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326 (let ((lisp-tag-body-indentation lisp-body-indent))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327 (funcall (function lisp-indent-tagbody)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328 path state indent-point sexp-column normal-indent))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 (funcall (function lisp-indent-259)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 '((&whole nil &rest
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 ;; the following causes wierd indentation
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 ;;(&whole 1 1 2 nil)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 )
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334 (&whole nil &rest 1))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
335 path state indent-point sexp-column normal-indent)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
336
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337 (defun lisp-indent-function-lambda-hack (path state indent-point
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338 sexp-column normal-indent)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339 ;; indent (function (lambda () <newline> <body-forms>)) kludgily.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
340 (if (or (cdr path) ; wtf?
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
341 (> (car path) 3))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
342 ;; line up under previous body form
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 normal-indent
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 ;; line up under function rather than under lambda in order to
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 ;; conserve horizontal space. (Which is what #' is for.)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346 (condition-case ()
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
348 (backward-up-list 2)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349 (forward-char 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 (if (looking-at "\\(lisp:+\\)?function\\(\\Sw\\|\\S_\\)")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351 (+ lisp-body-indent -1 (current-column))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 (+ sexp-column lisp-body-indent)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
353 (error (+ sexp-column lisp-body-indent)))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
356 (let ((l '((block 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 (catch 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 (case (4 &rest (&whole 2 &rest 1)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359 (ccase . case) (ecase . case)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
360 (typecase . case) (etypecase . case) (ctypecase . case)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 (catch 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 (cond (&rest (&whole 2 &rest 1)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363 (block 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 (defvar (4 2 2))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365 (defconstant . defvar) (defparameter . defvar)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366 (define-modify-macro
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 (4 &body))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 (define-setf-method
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369 (4 (&whole 4 &rest 1) &body))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 (defsetf (4 (&whole 4 &rest 1) 4 &body))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 (defun (4 (&whole 4 &rest 1) &body))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 (defmacro . defun) (deftype . defun)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 (defstruct ((&whole 4 &rest (&whole 2 &rest 1))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374 &rest (&whole 2 &rest 1)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 (destructuring-bind
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 ((&whole 6 &rest 1) 4 &body))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377 (do lisp-indent-do)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378 (do* . do)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379 (dolist ((&whole 4 2 1) &body))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380 (dotimes . dolist)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381 (eval-when 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382 (flet ((&whole 4 &rest (&whole 1 (&whole 4 &rest 1) &body))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
383 &body))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384 (labels . flet)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385 (macrolet . flet)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386 ;; `else-body' style
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387 (if (nil nil &body))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 ;; single-else style (then and else equally indented)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389 (if (&rest nil))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 ;(lambda ((&whole 4 &rest 1) &body))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391 (lambda ((&whole 4 &rest 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 &rest lisp-indent-function-lambda-hack))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393 (let ((&whole 4 &rest (&whole 1 1 2)) &body))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394 (let* . let)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395 (compiler-let . let) ;barf
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396 (locally 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 ;(loop ...)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398 (multiple-value-bind
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399 ((&whole 6 &rest 1) 4 &body))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400 (multiple-value-call
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
401 (4 &body))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
402 (multiple-value-list 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
403 (multiple-value-prog1 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
404 (multiple-value-setq
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
405 (4 2))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
406 ;; Combines the worst features of BLOCK, LET and TAGBODY
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407 (prog ((&whole 4 &rest 1) &rest lisp-indent-tagbody))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408 (prog* . prog)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 (prog1 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410 (prog2 2)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411 (progn 0)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
412 (progv (4 4 &body))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413 (return 0)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
414 (return-from (nil &body))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415 (tagbody lisp-indent-tagbody)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
416 (throw 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
417 (unless 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
418 (unwind-protect
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
419 (5 &body))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
420 (when 1))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
421 (while l
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
422 (put (car (car l)) 'common-lisp-indent-function
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
423 (if (symbolp (cdr (car l)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
424 (get (cdr (car l)) 'common-lisp-indent-function)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425 (car (cdr (car l)))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
426 (setq l (cdr l))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429 ;(defun foo (x)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
430 ; (tagbody
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431 ; foo
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432 ; (bar)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 ; baz
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
434 ; (when (losing)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
435 ; (with-big-loser
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436 ; (yow)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437 ; ((lambda ()
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
438 ; foo)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
439 ; big)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
440 ; (flet ((foo (bar baz zap)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
441 ; (zip))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
442 ; (zot ()
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
443 ; quux))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
444 ; (do ()
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
445 ; ((lose)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
446 ; (foo 1))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
447 ; (quux)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
448 ; foo
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
449 ; (lose))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
450 ; (cond ((x)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
451 ; (win 1 2
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
452 ; (foo)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
453 ; (t
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
454 ; (lose
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
455 ; 3))))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
456
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
457
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458 ;(put 'while 'common-lisp-indent-function 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
459 ;(put 'defwrapper'common-lisp-indent-function ...)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
460 ;(put 'def 'common-lisp-indent-function ...)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
461 ;(put 'defflavor 'common-lisp-indent-function ...)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462 ;(put 'defsubst 'common-lisp-indent-function ...)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
463
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
464 ;(put 'with-restart 'common-lisp-indent-function '((1 4 ((* 1))) (2 &body)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
465 ;(put 'restart-case 'common-lisp-indent-function '((1 4) (* 2 ((0 1) (* 1)))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
466 ;(put 'define-condition 'common-lisp-indent-function '((1 6) (2 6 ((* 1))) (3 4 ((* 1))) (4 &body)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
467 ;(put 'with-condition-handler 'common-lisp-indent-function '((1 4 ((* 1))) (2 &body)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
468 ;(put 'condition-case 'common-lisp-indent-function '((1 4) (* 2 ((0 1) (1 3) (2 &body)))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
469
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
470
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
471 ;;;; Turn it on.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
472 ;(setq lisp-indent-function 'common-lisp-indent-function)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
473
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
474 ;; To disable this stuff, (setq lisp-indent-function 'lisp-indent-function)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
475
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 257
diff changeset
476 ;;; cl-indent.el ends here