Mercurial > emacs
annotate lisp/emacs-lisp/cl-indent.el @ 41484:eaf240f87223
(decipher-mode): Remove make-local-hook.
author | Pavel Janík <Pavel@Janik.cz> |
---|---|
date | Sun, 25 Nov 2001 11:32:23 +0000 |
parents | 4a78098c3bd7 |
children | 63b6d0453539 |
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 |
37389
3061b65a9897
(toplevel): Comment out the spec
Gerd Moellmann <gerd@gnu.org>
parents:
34187
diff
changeset
|
3 ;; Copyright (C) 1987, 2000, 2001 Free Software Foundation, Inc. |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
4 |
14040 | 5 ;; Author: Richard Mlynarik <mly@eddie.mit.edu> |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
6 ;; Created: July 1987 |
845 | 7 ;; Maintainer: FSF |
8 ;; Keywords: lisp, tools | |
9 | |
257 | 10 ;; This file is part of GNU Emacs. |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
13 ;; 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
|
14 ;; the Free Software Foundation; either version 2, or (at your option) |
257 | 15 ;; any later version. |
16 | |
17 ;; GNU Emacs is distributed in the hope that it will be useful, | |
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 ;; GNU General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
14169 | 23 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
25 ;; Boston, MA 02111-1307, USA. | |
257 | 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 |
2307
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
29 ;; This package supplies a single entry point, common-lisp-indent-function, |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
30 ;; which performs indentation in the preferred style for Common Lisp code. |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
31 ;; To enable it: |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
32 ;; |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
33 ;; (setq lisp-indent-function 'common-lisp-indent-function) |
10e417efb12a
Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
845
diff
changeset
|
34 |
257 | 35 ;;>> TODO |
36 ;; :foo | |
37 ;; bar | |
38 ;; :baz | |
39 ;; zap | |
40 ;; &key (like &body)?? | |
41 | |
42 ;; &rest 1 in lambda-lists doesn't work | |
43 ;; -- really want (foo bar | |
44 ;; baz) | |
45 ;; not (foo bar | |
46 ;; baz) | |
47 ;; Need something better than &rest for such cases | |
48 | |
807
4f28bd14272c
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
49 ;;; Code: |
257 | 50 |
17413
9fa0ed8da0b1
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
51 (defgroup lisp-indent nil |
9fa0ed8da0b1
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
52 "Indentation in Lisp" |
9fa0ed8da0b1
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
53 :group 'lisp) |
9fa0ed8da0b1
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
54 |
9fa0ed8da0b1
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
55 |
9fa0ed8da0b1
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
56 (defcustom lisp-indent-maximum-backtracking 3 |
257 | 57 "*Maximum depth to backtrack out from a sublist for structured indentation. |
58 If this variable is 0, no backtracking will occur and forms such as flet | |
17413
9fa0ed8da0b1
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
59 may not be correctly indented." |
9fa0ed8da0b1
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
60 :type 'integer |
9fa0ed8da0b1
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
61 :group 'lisp-indent) |
257 | 62 |
17413
9fa0ed8da0b1
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
63 (defcustom lisp-tag-indentation 1 |
257 | 64 "*Indentation of tags relative to containing list. |
17413
9fa0ed8da0b1
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
65 This variable is used by the function `lisp-indent-tagbody'." |
9fa0ed8da0b1
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
66 :type 'integer |
9fa0ed8da0b1
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
67 :group 'lisp-indent) |
257 | 68 |
17413
9fa0ed8da0b1
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
69 (defcustom lisp-tag-body-indentation 3 |
257 | 70 "*Indentation of non-tagged lines relative to containing list. |
71 This variable is used by the function `lisp-indent-tagbody' to indent normal | |
72 lines (lines without tags). | |
73 The indentation is relative to the indentation of the parenthesis enclosing | |
74 the special form. If the value is t, the body of tags will be indented | |
75 as a block at the same indentation as the first s-expression following | |
76 the tag. In this case, any forms before the first tag are indented | |
17413
9fa0ed8da0b1
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
77 by `lisp-body-indent'." |
9fa0ed8da0b1
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
78 :type 'integer |
9fa0ed8da0b1
Add defgroup's; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
14169
diff
changeset
|
79 :group 'lisp-indent) |
257 | 80 |
81 | |
22212
b95ba3830bc9
(lisp-indent-error-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22180
diff
changeset
|
82 (defvar lisp-indent-error-function) |
22858
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
83 (defvar lisp-indent-defun-method '(4 &lambda &body)) |
22212
b95ba3830bc9
(lisp-indent-error-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22180
diff
changeset
|
84 |
257 | 85 ;;;###autoload |
86 (defun common-lisp-indent-function (indent-point state) | |
87 (let ((normal-indent (current-column))) | |
88 ;; Walk up list levels until we see something | |
89 ;; which does special things with subforms. | |
90 (let ((depth 0) | |
91 ;; Path describes the position of point in terms of | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
2307
diff
changeset
|
92 ;; list-structure with respect to containing lists. |
257 | 93 ;; `foo' has a path of (0 4 1) in `((a b c (d foo) f) g)' |
94 (path ()) | |
95 ;; set non-nil when somebody works out the indentation to use | |
96 calculated | |
97 (last-point indent-point) | |
98 ;; the position of the open-paren of the innermost containing list | |
99 (containing-form-start (elt state 1)) | |
100 ;; the column of the above | |
101 sexp-column) | |
102 ;; Move to start of innermost containing list | |
103 (goto-char containing-form-start) | |
104 (setq sexp-column (current-column)) | |
105 ;; Look over successively less-deep containing forms | |
106 (while (and (not calculated) | |
107 (< depth lisp-indent-maximum-backtracking)) | |
108 (let ((containing-sexp (point))) | |
109 (forward-char 1) | |
110 (parse-partial-sexp (point) indent-point 1 t) | |
111 ;; Move to the car of the relevant containing form | |
112 (let (tem function method) | |
113 (if (not (looking-at "\\sw\\|\\s_")) | |
114 ;; This form doesn't seem to start with a symbol | |
115 (setq function nil method nil) | |
116 (setq tem (point)) | |
117 (forward-sexp 1) | |
22858
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
118 (setq function (downcase (buffer-substring-no-properties |
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
119 tem (point)))) |
257 | 120 (goto-char tem) |
121 (setq tem (intern-soft function) | |
122 method (get tem 'common-lisp-indent-function)) | |
123 (cond ((and (null method) | |
124 (string-match ":[^:]+" function)) | |
125 ;; The pleblisp package feature | |
126 (setq function (substring function | |
127 (1+ (match-beginning 0))) | |
128 method (get (intern-soft function) | |
129 'common-lisp-indent-function))) | |
130 ((and (null method)) | |
131 ;; backwards compatibility | |
132 (setq method (get tem 'lisp-indent-function))))) | |
133 (let ((n 0)) | |
134 ;; How far into the containing form is the current form? | |
135 (if (< (point) indent-point) | |
136 (while (condition-case () | |
137 (progn | |
138 (forward-sexp 1) | |
139 (if (>= (point) indent-point) | |
140 nil | |
141 (parse-partial-sexp (point) | |
142 indent-point 1 t) | |
143 (setq n (1+ n)) | |
144 t)) | |
145 (error nil)))) | |
146 (setq path (cons n path))) | |
147 | |
148 ;; backwards compatibility. | |
149 (cond ((null function)) | |
150 ((null method) | |
22858
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
151 (when (null (cdr path)) |
257 | 152 ;; (package prefix was stripped off above) |
153 (setq method (cond ((string-match "\\`def" | |
154 function) | |
22858
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
155 lisp-indent-defun-method) |
257 | 156 ((string-match "\\`\\(with\\|do\\)-" |
157 function) | |
22858
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
158 '(&lambda &body)))))) |
257 | 159 ;; backwards compatibility. Bletch. |
160 ((eq method 'defun) | |
22858
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
161 (setq method lisp-indent-defun-method))) |
257 | 162 |
163 (cond ((and (memq (char-after (1- containing-sexp)) '(?\' ?\`)) | |
26047
e6efd0ace0f3
(common-lisp-indent-function): Use `eq' instead of `eql'.
Gerd Moellmann <gerd@gnu.org>
parents:
23725
diff
changeset
|
164 (not (eq (char-after (- containing-sexp 2)) ?\#))) |
257 | 165 ;; No indentation for "'(...)" elements |
166 (setq calculated (1+ sexp-column))) | |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
167 ((or (eq (char-after (1- containing-sexp)) ?\,) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
168 (and (eq (char-after (1- containing-sexp)) ?\@) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
169 (eq (char-after (- containing-sexp 2)) ?\,))) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
170 ;; ",(...)" or ",@(...)" |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
171 (setq calculated normal-indent)) |
26047
e6efd0ace0f3
(common-lisp-indent-function): Use `eq' instead of `eql'.
Gerd Moellmann <gerd@gnu.org>
parents:
23725
diff
changeset
|
172 ((eq (char-after (1- containing-sexp)) ?\#) |
257 | 173 ;; "#(...)" |
174 (setq calculated (1+ sexp-column))) | |
175 ((null method)) | |
176 ((integerp method) | |
177 ;; convenient top-level hack. | |
178 ;; (also compatible with lisp-indent-function) | |
179 ;; The number specifies how many `distinguished' | |
180 ;; forms there are before the body starts | |
181 ;; Equivalent to (4 4 ... &body) | |
182 (setq calculated (cond ((cdr path) | |
183 normal-indent) | |
184 ((<= (car path) method) | |
185 ;; `distinguished' form | |
186 (list (+ sexp-column 4) | |
187 containing-form-start)) | |
188 ((= (car path) (1+ method)) | |
189 ;; first body form. | |
190 (+ sexp-column lisp-body-indent)) | |
191 (t | |
192 ;; other body form | |
193 normal-indent)))) | |
194 ((symbolp method) | |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
195 (let ((lisp-indent-error-function function)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
196 (setq calculated (funcall method |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
197 path state indent-point |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
198 sexp-column normal-indent)))) |
257 | 199 (t |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
200 (let ((lisp-indent-error-function function)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
201 (setq calculated (lisp-indent-259 |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
202 method path state indent-point |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
203 sexp-column normal-indent)))))) |
257 | 204 (goto-char containing-sexp) |
205 (setq last-point containing-sexp) | |
22858
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
206 (unless calculated |
257 | 207 (condition-case () |
208 (progn (backward-up-list 1) | |
209 (setq depth (1+ depth))) | |
210 (error (setq depth lisp-indent-maximum-backtracking)))))) | |
211 calculated))) | |
212 | |
213 | |
214 (defun lisp-indent-report-bad-format (m) | |
215 (error "%s has a badly-formed %s property: %s" | |
216 ;; Love those free variable references!! | |
22212
b95ba3830bc9
(lisp-indent-error-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22180
diff
changeset
|
217 lisp-indent-error-function 'common-lisp-indent-function m)) |
257 | 218 |
219 ;; Blame the crufty control structure on dynamic scoping | |
220 ;; -- not on me! | |
221 (defun lisp-indent-259 (method path state indent-point | |
222 sexp-column normal-indent) | |
223 (catch 'exit | |
224 (let ((p path) | |
225 (containing-form-start (elt state 1)) | |
226 n tem tail) | |
227 ;; Isn't tail-recursion wonderful? | |
228 (while p | |
229 ;; This while loop is for destructuring. | |
230 ;; p is set to (cdr p) each iteration. | |
231 (if (not (consp method)) (lisp-indent-report-bad-format method)) | |
232 (setq n (1- (car p)) | |
233 p (cdr p) | |
234 tail nil) | |
235 (while n | |
236 ;; This while loop is for advancing along a method | |
237 ;; until the relevant (possibly &rest/&body) pattern | |
238 ;; is reached. | |
239 ;; n is set to (1- n) and method to (cdr method) | |
240 ;; each iteration. | |
241 (setq tem (car method)) | |
242 | |
243 (or (eq tem 'nil) ;default indentation | |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
244 (eq tem '&lambda) ;lambda list |
257 | 245 (and (eq tem '&body) (null (cdr method))) |
246 (and (eq tem '&rest) | |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
247 (consp (cdr method)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
248 (null (cddr method))) |
257 | 249 (integerp tem) ;explicit indentation specified |
250 (and (consp tem) ;destructuring | |
251 (eq (car tem) '&whole) | |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
252 (or (symbolp (cadr tem)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
253 (integerp (cadr tem)))) |
257 | 254 (and (symbolp tem) ;a function to call to do the work. |
255 (null (cdr method))) | |
256 (lisp-indent-report-bad-format method)) | |
257 | |
258 (cond ((and tail (not (consp tem))) | |
259 ;; indent tail of &rest in same way as first elt of rest | |
260 (throw 'exit normal-indent)) | |
261 ((eq tem '&body) | |
262 ;; &body means (&rest <lisp-body-indent>) | |
263 (throw 'exit | |
264 (if (and (= n 0) ;first body form | |
265 (null p)) ;not in subforms | |
266 (+ sexp-column | |
267 lisp-body-indent) | |
268 normal-indent))) | |
269 ((eq tem '&rest) | |
270 ;; this pattern holds for all remaining forms | |
271 (setq tail (> n 0) | |
272 n 0 | |
273 method (cdr method))) | |
274 ((> n 0) | |
275 ;; try next element of pattern | |
276 (setq n (1- n) | |
277 method (cdr method)) | |
278 (if (< n 0) | |
279 ;; Too few elements in pattern. | |
280 (throw 'exit normal-indent))) | |
281 ((eq tem 'nil) | |
282 (throw 'exit (list normal-indent containing-form-start))) | |
22858
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
283 ((eq tem '&lambda) |
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
284 (throw 'exit |
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
285 (cond ((null p) |
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
286 (list (+ sexp-column 4) containing-form-start)) |
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
287 ((null (cdr p)) |
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
288 (+ sexp-column 1)) |
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
289 (t normal-indent)))) |
257 | 290 ((integerp tem) |
291 (throw 'exit | |
292 (if (null p) ;not in subforms | |
293 (list (+ sexp-column tem) containing-form-start) | |
294 normal-indent))) | |
295 ((symbolp tem) ;a function to call | |
296 (throw 'exit | |
297 (funcall tem path state indent-point | |
298 sexp-column normal-indent))) | |
299 (t | |
300 ;; must be a destructing frob | |
301 (if (not (null p)) | |
302 ;; descend | |
22858
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
303 (setq method (cddr tem) |
257 | 304 n nil) |
22858
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
305 (setq tem (cadr tem)) |
257 | 306 (throw 'exit |
307 (cond (tail | |
308 normal-indent) | |
309 ((eq tem 'nil) | |
310 (list normal-indent | |
311 containing-form-start)) | |
312 ((integerp tem) | |
313 (list (+ sexp-column tem) | |
314 containing-form-start)) | |
315 (t | |
316 (funcall tem path state indent-point | |
317 sexp-column normal-indent)))))))))))) | |
318 | |
319 (defun lisp-indent-tagbody (path state indent-point sexp-column normal-indent) | |
320 (if (not (null (cdr path))) | |
321 normal-indent | |
322 (save-excursion | |
323 (goto-char indent-point) | |
324 (beginning-of-line) | |
325 (skip-chars-forward " \t") | |
326 (list (cond ((looking-at "\\sw\\|\\s_") | |
327 ;; a tagbody tag | |
328 (+ sexp-column lisp-tag-indentation)) | |
329 ((integerp lisp-tag-body-indentation) | |
330 (+ sexp-column lisp-tag-body-indentation)) | |
331 ((eq lisp-tag-body-indentation 't) | |
332 (condition-case () | |
333 (progn (backward-sexp 1) (current-column)) | |
334 (error (1+ sexp-column)))) | |
335 (t (+ sexp-column lisp-body-indent))) | |
336 ; (cond ((integerp lisp-tag-body-indentation) | |
337 ; (+ sexp-column lisp-tag-body-indentation)) | |
338 ; ((eq lisp-tag-body-indentation 't) | |
339 ; normal-indent) | |
340 ; (t | |
341 ; (+ sexp-column lisp-body-indent))) | |
342 (elt state 1) | |
343 )))) | |
344 | |
345 (defun lisp-indent-do (path state indent-point sexp-column normal-indent) | |
346 (if (>= (car path) 3) | |
347 (let ((lisp-tag-body-indentation lisp-body-indent)) | |
348 (funcall (function lisp-indent-tagbody) | |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
349 path state indent-point sexp-column normal-indent)) |
257 | 350 (funcall (function lisp-indent-259) |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
351 '((&whole nil &rest |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
352 ;; the following causes weird indentation |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
353 ;;(&whole 1 1 2 nil) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
354 ) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
355 (&whole nil &rest 1)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
356 path state indent-point sexp-column normal-indent))) |
257 | 357 |
40952
2ca1b56f3bb1
Indent properly `generic-flet', `generic-labels', `with-accessors',
Sam Steingold <sds@gnu.org>
parents:
38826
diff
changeset
|
358 (defun lisp-indent-defmethod (path state indent-point sexp-column |
38826
f2ff22369238
(lisp-indent-defmethod): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
37764
diff
changeset
|
359 normal-indent) |
f2ff22369238
(lisp-indent-defmethod): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
37764
diff
changeset
|
360 "Indentation function defmethod." |
41256
4a78098c3bd7
(lisp-indent-defmethod): At first three elements, act like defun.
Richard M. Stallman <rms@gnu.org>
parents:
40952
diff
changeset
|
361 (lisp-indent-259 (if (and (>= (first path) 3) |
4a78098c3bd7
(lisp-indent-defmethod): At first three elements, act like defun.
Richard M. Stallman <rms@gnu.org>
parents:
40952
diff
changeset
|
362 (null (rest path)) |
4a78098c3bd7
(lisp-indent-defmethod): At first three elements, act like defun.
Richard M. Stallman <rms@gnu.org>
parents:
40952
diff
changeset
|
363 (save-excursion (goto-char (elt state 1)) |
4a78098c3bd7
(lisp-indent-defmethod): At first three elements, act like defun.
Richard M. Stallman <rms@gnu.org>
parents:
40952
diff
changeset
|
364 (forward-char 1) |
4a78098c3bd7
(lisp-indent-defmethod): At first three elements, act like defun.
Richard M. Stallman <rms@gnu.org>
parents:
40952
diff
changeset
|
365 (forward-sexp 3) |
4a78098c3bd7
(lisp-indent-defmethod): At first three elements, act like defun.
Richard M. Stallman <rms@gnu.org>
parents:
40952
diff
changeset
|
366 (backward-sexp) |
4a78098c3bd7
(lisp-indent-defmethod): At first three elements, act like defun.
Richard M. Stallman <rms@gnu.org>
parents:
40952
diff
changeset
|
367 (looking-at ":"))) |
38826
f2ff22369238
(lisp-indent-defmethod): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
37764
diff
changeset
|
368 '(4 4 (&whole 4 &rest 4) &body) |
f2ff22369238
(lisp-indent-defmethod): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
37764
diff
changeset
|
369 (get 'defun 'common-lisp-indent-function)) |
f2ff22369238
(lisp-indent-defmethod): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
37764
diff
changeset
|
370 path state indent-point sexp-column normal-indent)) |
f2ff22369238
(lisp-indent-defmethod): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
37764
diff
changeset
|
371 |
f2ff22369238
(lisp-indent-defmethod): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
37764
diff
changeset
|
372 |
257 | 373 (defun lisp-indent-function-lambda-hack (path state indent-point |
374 sexp-column normal-indent) | |
375 ;; indent (function (lambda () <newline> <body-forms>)) kludgily. | |
376 (if (or (cdr path) ; wtf? | |
377 (> (car path) 3)) | |
378 ;; line up under previous body form | |
379 normal-indent | |
380 ;; line up under function rather than under lambda in order to | |
381 ;; conserve horizontal space. (Which is what #' is for.) | |
382 (condition-case () | |
383 (save-excursion | |
384 (backward-up-list 2) | |
385 (forward-char 1) | |
386 (if (looking-at "\\(lisp:+\\)?function\\(\\Sw\\|\\S_\\)") | |
387 (+ lisp-body-indent -1 (current-column)) | |
388 (+ sexp-column lisp-body-indent))) | |
389 (error (+ sexp-column lisp-body-indent))))) | |
390 | |
391 | |
392 (let ((l '((block 1) | |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
393 (case (4 &rest (&whole 2 &rest 1))) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
394 (ccase . case) (ecase . case) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
395 (typecase . case) (etypecase . case) (ctypecase . case) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
396 (catch 1) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
397 (cond (&rest (&whole 2 &rest 1))) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
398 (defvar (4 2 2)) |
30651
61c2f9fcb8f6
* emacs-lisp/cl-indent.el (toplevel): Indent `defclass',
Sam Steingold <sds@gnu.org>
parents:
29797
diff
changeset
|
399 (defclass (6 4 (&whole 2 &rest 1) (&whole 2 &rest 1))) |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
400 (defconstant . defvar) |
27231
e9725bb98b6e
Add defclass, define-condition, defmethod, symbol-macrolet.
Dave Love <fx@gnu.org>
parents:
26047
diff
changeset
|
401 (defcustom (4 2 2 2)) |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
402 (defparameter . defvar) |
30651
61c2f9fcb8f6
* emacs-lisp/cl-indent.el (toplevel): Indent `defclass',
Sam Steingold <sds@gnu.org>
parents:
29797
diff
changeset
|
403 (defconst . defcustom) |
61c2f9fcb8f6
* emacs-lisp/cl-indent.el (toplevel): Indent `defclass',
Sam Steingold <sds@gnu.org>
parents:
29797
diff
changeset
|
404 (define-condition . defclass) |
61c2f9fcb8f6
* emacs-lisp/cl-indent.el (toplevel): Indent `defclass',
Sam Steingold <sds@gnu.org>
parents:
29797
diff
changeset
|
405 (define-modify-macro (4 &body)) |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
406 (defsetf (4 &lambda 4 &body)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
407 (defun (4 &lambda &body)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
408 (define-setf-method . defun) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
409 (define-setf-expander . defun) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
410 (defmacro . defun) (defsubst . defun) (deftype . defun) |
38826
f2ff22369238
(lisp-indent-defmethod): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
37764
diff
changeset
|
411 (defmethod lisp-indent-defmethod) |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
412 (defpackage (4 2)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
413 (defstruct ((&whole 4 &rest (&whole 2 &rest 1)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
414 &rest (&whole 2 &rest 1))) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
415 (destructuring-bind |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
416 ((&whole 6 &rest 1) 4 &body)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
417 (do lisp-indent-do) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
418 (do* . do) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
419 (dolist ((&whole 4 2 1) &body)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
420 (dotimes . dolist) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
421 (eval-when 1) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
422 (flet ((&whole 4 &rest (&whole 1 &lambda &body)) &body)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
423 (labels . flet) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
424 (macrolet . flet) |
40952
2ca1b56f3bb1
Indent properly `generic-flet', `generic-labels', `with-accessors',
Sam Steingold <sds@gnu.org>
parents:
38826
diff
changeset
|
425 (generic-flet . flet) (generic-labels . flet) |
22858
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
426 (handler-case (4 &rest (&whole 2 &lambda &body))) |
22756
6103b46f200a
Indent `restart-case', `handler-bind' and `restart-bind' correctly.
Richard M. Stallman <rms@gnu.org>
parents:
22731
diff
changeset
|
427 (restart-case . handler-case) |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
428 ;; `else-body' style |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
429 (if (nil nil &body)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
430 ;; single-else style (then and else equally indented) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
431 (if (&rest nil)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
432 (lambda (&lambda &rest lisp-indent-function-lambda-hack)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
433 (let ((&whole 4 &rest (&whole 1 1 2)) &body)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
434 (let* . let) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
435 (compiler-let . let) ;barf |
22756
6103b46f200a
Indent `restart-case', `handler-bind' and `restart-bind' correctly.
Richard M. Stallman <rms@gnu.org>
parents:
22731
diff
changeset
|
436 (handler-bind . let) (restart-bind . let) |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
437 (locally 1) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
438 ;(loop ...) |
37764
b1fec0dc2aa1
(toplevel): indent the :method sub-form of `defgeneric' correctly.
Sam Steingold <sds@gnu.org>
parents:
37389
diff
changeset
|
439 (:method (&lambda &body)) ; in `defgeneric' |
30651
61c2f9fcb8f6
* emacs-lisp/cl-indent.el (toplevel): Indent `defclass',
Sam Steingold <sds@gnu.org>
parents:
29797
diff
changeset
|
440 (multiple-value-bind ((&whole 6 &rest 1) 4 &body)) |
61c2f9fcb8f6
* emacs-lisp/cl-indent.el (toplevel): Indent `defclass',
Sam Steingold <sds@gnu.org>
parents:
29797
diff
changeset
|
441 (multiple-value-call (4 &body)) |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
442 (multiple-value-prog1 1) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
443 (multiple-value-setq (4 2)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
444 (multiple-value-setf . multiple-value-setq) |
27872
277f4365f2fa
Indent `pprint-logical-block' properly.
Gerd Moellmann <gerd@gnu.org>
parents:
27802
diff
changeset
|
445 (pprint-logical-block (4 2)) |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
446 (print-unreadable-object ((&whole 4 1 &rest 1) &body)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
447 ;; Combines the worst features of BLOCK, LET and TAGBODY |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
448 (prog (&lambda &rest lisp-indent-tagbody)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
449 (prog* . prog) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
450 (prog1 1) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
451 (prog2 2) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
452 (progn 0) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
453 (progv (4 4 &body)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
454 (return 0) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
455 (return-from (nil &body)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
456 (symbol-macrolet . multiple-value-bind) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
457 (tagbody lisp-indent-tagbody) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
458 (throw 1) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
459 (unless 1) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
460 (unwind-protect (5 &body)) |
22180
485917486caf
Indent `with-standard-io-syntax' correctly.
Richard M. Stallman <rms@gnu.org>
parents:
21750
diff
changeset
|
461 (when 1) |
40952
2ca1b56f3bb1
Indent properly `generic-flet', `generic-labels', `with-accessors',
Sam Steingold <sds@gnu.org>
parents:
38826
diff
changeset
|
462 (with-accessors . multiple-value-bind) |
2ca1b56f3bb1
Indent properly `generic-flet', `generic-labels', `with-accessors',
Sam Steingold <sds@gnu.org>
parents:
38826
diff
changeset
|
463 (with-condition-restarts . multiple-value-bind) |
23725
222d58586999
indent `with-output-to-string' as a CL
Karl Heuer <kwzh@gnu.org>
parents:
22913
diff
changeset
|
464 (with-output-to-string (4 2)) |
30651
61c2f9fcb8f6
* emacs-lisp/cl-indent.el (toplevel): Indent `defclass',
Sam Steingold <sds@gnu.org>
parents:
29797
diff
changeset
|
465 (with-slots . multiple-value-bind) |
22180
485917486caf
Indent `with-standard-io-syntax' correctly.
Richard M. Stallman <rms@gnu.org>
parents:
21750
diff
changeset
|
466 (with-standard-io-syntax (2))))) |
40952
2ca1b56f3bb1
Indent properly `generic-flet', `generic-labels', `with-accessors',
Sam Steingold <sds@gnu.org>
parents:
38826
diff
changeset
|
467 (dolist (el l) |
2ca1b56f3bb1
Indent properly `generic-flet', `generic-labels', `with-accessors',
Sam Steingold <sds@gnu.org>
parents:
38826
diff
changeset
|
468 (put (car el) 'common-lisp-indent-function |
2ca1b56f3bb1
Indent properly `generic-flet', `generic-labels', `with-accessors',
Sam Steingold <sds@gnu.org>
parents:
38826
diff
changeset
|
469 (if (symbolp (cdr el)) |
2ca1b56f3bb1
Indent properly `generic-flet', `generic-labels', `with-accessors',
Sam Steingold <sds@gnu.org>
parents:
38826
diff
changeset
|
470 (get (cdr el) 'common-lisp-indent-function) |
2ca1b56f3bb1
Indent properly `generic-flet', `generic-labels', `with-accessors',
Sam Steingold <sds@gnu.org>
parents:
38826
diff
changeset
|
471 (car (cdr el)))))) |
257 | 472 |
473 | |
474 ;(defun foo (x) | |
475 ; (tagbody | |
476 ; foo | |
477 ; (bar) | |
478 ; baz | |
479 ; (when (losing) | |
480 ; (with-big-loser | |
481 ; (yow) | |
482 ; ((lambda () | |
483 ; foo) | |
484 ; big))) | |
485 ; (flet ((foo (bar baz zap) | |
486 ; (zip)) | |
487 ; (zot () | |
488 ; quux)) | |
489 ; (do () | |
490 ; ((lose) | |
491 ; (foo 1)) | |
492 ; (quux) | |
493 ; foo | |
494 ; (lose)) | |
495 ; (cond ((x) | |
496 ; (win 1 2 | |
497 ; (foo))) | |
498 ; (t | |
499 ; (lose | |
500 ; 3)))))) | |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
501 |
257 | 502 |
503 ;(put 'while 'common-lisp-indent-function 1) | |
504 ;(put 'defwrapper'common-lisp-indent-function ...) | |
505 ;(put 'def 'common-lisp-indent-function ...) | |
506 ;(put 'defflavor 'common-lisp-indent-function ...) | |
507 ;(put 'defsubst 'common-lisp-indent-function ...) | |
508 | |
509 ;(put 'with-restart 'common-lisp-indent-function '((1 4 ((* 1))) (2 &body))) | |
510 ;(put 'restart-case 'common-lisp-indent-function '((1 4) (* 2 ((0 1) (* 1))))) | |
34187
e2fb02d21aee
Remove erroneous spec for condition-case.
Dave Love <fx@gnu.org>
parents:
30651
diff
changeset
|
511 ;(put 'define-condition 'common-lisp-indent-function '((1 6) (2 6 ((&whole 1))) (3 4 ((&whole 1))) (4 &body))) |
257 | 512 ;(put 'with-condition-handler 'common-lisp-indent-function '((1 4 ((* 1))) (2 &body))) |
513 ;(put 'condition-case 'common-lisp-indent-function '((1 4) (* 2 ((0 1) (1 3) (2 &body))))) | |
34187
e2fb02d21aee
Remove erroneous spec for condition-case.
Dave Love <fx@gnu.org>
parents:
30651
diff
changeset
|
514 ;(put 'defclass 'common-lisp-indent-function '((&whole 2 &rest (&whole 2 &rest 1) &rest (&whole 2 &rest 1))) |
e2fb02d21aee
Remove erroneous spec for condition-case.
Dave Love <fx@gnu.org>
parents:
30651
diff
changeset
|
515 ;(put 'defgeneric 'common-lisp-indent-function 'defun) |
257 | 516 |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
257
diff
changeset
|
517 ;;; cl-indent.el ends here |