Mercurial > emacs
annotate lisp/emacs-lisp/cl-indent.el @ 51921:86bdb37c1d71
(Functions for Key Lookup): Add current-active-maps.
(Scanning Keymaps): Add map-keymaps.
(Defining Menus): Add keymap-prompt.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 14 Jul 2003 16:03:04 +0000 |
parents | ad311d8949c4 |
children | 695cf19ef79e |
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 |
43859
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
3 ;; Copyright (C) 1987, 2000, 2001, 2002 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 |
43859
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
81 (defcustom lisp-backquote-indentation t |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
82 "*Whether or not to indent backquoted lists as code. |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
83 If nil, indent backquoted lists as data, i.e., like quoted lists." |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
84 :type 'boolean |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
85 :group 'lisp-indent) |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
86 |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
87 |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
88 (defcustom lisp-loop-keyword-indentation 3 |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
89 "*Indentation of loop keywords in extended loop forms." |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
90 :type 'integer |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
91 :group 'lisp-indent) |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
92 |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
93 |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
94 (defcustom lisp-loop-forms-indentation 5 |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
95 "*Indentation of forms in extended loop forms." |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
96 :type 'integer |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
97 :group 'lisp-indent) |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
98 |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
99 |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
100 (defcustom lisp-simple-loop-indentation 3 |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
101 "*Indentation of forms in simple loop forms." |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
102 :type 'integer |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
103 :group 'lisp-indent) |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
104 |
257 | 105 |
22212
b95ba3830bc9
(lisp-indent-error-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22180
diff
changeset
|
106 (defvar lisp-indent-error-function) |
22858
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
107 (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
|
108 |
43859
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
109 |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
110 (defun extended-loop-p (loop-start) |
47298
c6dddb2746ee
* emacs-lisp/cl-indent.el (extended-loop-p): Doc fix.
John Paul Wallington <jpw@pobox.com>
parents:
45573
diff
changeset
|
111 "True if an extended loop form starts at LOOP-START." |
43859
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
112 (condition-case () |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
113 (save-excursion |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
114 (goto-char loop-start) |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
115 (forward-char 1) |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
116 (forward-sexp 2) |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
117 (backward-sexp 1) |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
118 (looking-at "\\sw")) |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
119 (error t))) |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
120 |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
121 |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
122 (defun common-lisp-loop-part-indentation (indent-point state) |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
123 "Compute the indentation of loop form constituents." |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
124 (let* ((loop-indentation (save-excursion |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
125 (goto-char (elt state 1)) |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
126 (current-column)))) |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
127 (goto-char indent-point) |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
128 (beginning-of-line) |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
129 (cond ((not (extended-loop-p (elt state 1))) |
43920
af0b9648d018
(common-lisp-loop-part-indentation):
Gerd Moellmann <gerd@gnu.org>
parents:
43859
diff
changeset
|
130 (+ loop-indentation lisp-simple-loop-indentation)) |
43859
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
131 ((looking-at "^\\s-*\\(:?\\sw+\\|;\\)") |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
132 (+ loop-indentation lisp-loop-keyword-indentation)) |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
133 (t |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
134 (+ loop-indentation lisp-loop-forms-indentation))))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47298
diff
changeset
|
135 |
43859
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
136 |
257 | 137 ;;;###autoload |
138 (defun common-lisp-indent-function (indent-point state) | |
43859
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
139 (if (save-excursion (goto-char (elt state 1)) |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
140 (looking-at "([Ll][Oo][Oo][Pp]")) |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
141 (common-lisp-loop-part-indentation indent-point state) |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
142 (common-lisp-indent-function-1 indent-point state))) |
49598
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47298
diff
changeset
|
143 |
0d8b17d428b5
Trailing whitepace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents:
47298
diff
changeset
|
144 |
43859
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
145 (defun common-lisp-indent-function-1 (indent-point state) |
257 | 146 (let ((normal-indent (current-column))) |
147 ;; Walk up list levels until we see something | |
148 ;; which does special things with subforms. | |
149 (let ((depth 0) | |
150 ;; 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
|
151 ;; list-structure with respect to containing lists. |
257 | 152 ;; `foo' has a path of (0 4 1) in `((a b c (d foo) f) g)' |
153 (path ()) | |
154 ;; set non-nil when somebody works out the indentation to use | |
155 calculated | |
45573
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
156 ;; If non-nil, this is an indentation to use |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
157 ;; if nothing else specifies it more firmly. |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
158 tentative-calculated |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
159 (last-point indent-point) |
257 | 160 ;; the position of the open-paren of the innermost containing list |
161 (containing-form-start (elt state 1)) | |
162 ;; the column of the above | |
163 sexp-column) | |
164 ;; Move to start of innermost containing list | |
165 (goto-char containing-form-start) | |
166 (setq sexp-column (current-column)) | |
43859
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
167 |
257 | 168 ;; Look over successively less-deep containing forms |
169 (while (and (not calculated) | |
170 (< depth lisp-indent-maximum-backtracking)) | |
171 (let ((containing-sexp (point))) | |
172 (forward-char 1) | |
173 (parse-partial-sexp (point) indent-point 1 t) | |
174 ;; Move to the car of the relevant containing form | |
45573
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
175 (let (tem function method tentative-defun) |
257 | 176 (if (not (looking-at "\\sw\\|\\s_")) |
177 ;; This form doesn't seem to start with a symbol | |
178 (setq function nil method nil) | |
179 (setq tem (point)) | |
180 (forward-sexp 1) | |
22858
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
181 (setq function (downcase (buffer-substring-no-properties |
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
182 tem (point)))) |
257 | 183 (goto-char tem) |
184 (setq tem (intern-soft function) | |
185 method (get tem 'common-lisp-indent-function)) | |
186 (cond ((and (null method) | |
187 (string-match ":[^:]+" function)) | |
188 ;; The pleblisp package feature | |
189 (setq function (substring function | |
190 (1+ (match-beginning 0))) | |
191 method (get (intern-soft function) | |
192 'common-lisp-indent-function))) | |
193 ((and (null method)) | |
194 ;; backwards compatibility | |
195 (setq method (get tem 'lisp-indent-function))))) | |
196 (let ((n 0)) | |
197 ;; How far into the containing form is the current form? | |
198 (if (< (point) indent-point) | |
199 (while (condition-case () | |
200 (progn | |
201 (forward-sexp 1) | |
202 (if (>= (point) indent-point) | |
203 nil | |
204 (parse-partial-sexp (point) | |
205 indent-point 1 t) | |
206 (setq n (1+ n)) | |
207 t)) | |
208 (error nil)))) | |
209 (setq path (cons n path))) | |
210 | |
211 ;; backwards compatibility. | |
212 (cond ((null function)) | |
213 ((null method) | |
22858
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
214 (when (null (cdr path)) |
45573
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
215 ;; (package prefix was stripped off above) |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
216 (cond ((string-match "\\`def" |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
217 function) |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
218 (setq tentative-defun t)) |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
219 ((string-match "\\`\\(with\\|do\\)-" |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
220 function) |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
221 (setq method '(&lambda &body)))))) |
257 | 222 ;; backwards compatibility. Bletch. |
223 ((eq method 'defun) | |
22858
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
224 (setq method lisp-indent-defun-method))) |
257 | 225 |
43859
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
226 (cond ((and (or (eq (char-after (1- containing-sexp)) ?\') |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
227 (and (not lisp-backquote-indentation) |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
228 (eq (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
|
229 (not (eq (char-after (- containing-sexp 2)) ?\#))) |
257 | 230 ;; No indentation for "'(...)" elements |
231 (setq calculated (1+ sexp-column))) | |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
232 ((or (eq (char-after (1- containing-sexp)) ?\,) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
233 (and (eq (char-after (1- containing-sexp)) ?\@) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
234 (eq (char-after (- containing-sexp 2)) ?\,))) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
235 ;; ",(...)" or ",@(...)" |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
236 (setq calculated normal-indent)) |
26047
e6efd0ace0f3
(common-lisp-indent-function): Use `eq' instead of `eql'.
Gerd Moellmann <gerd@gnu.org>
parents:
23725
diff
changeset
|
237 ((eq (char-after (1- containing-sexp)) ?\#) |
257 | 238 ;; "#(...)" |
239 (setq calculated (1+ sexp-column))) | |
45573
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
240 ((null method) |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
241 ;; If this looks like a call to a `def...' form, |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
242 ;; think about indenting it as one, but do it |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
243 ;; tentatively for cases like |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
244 ;; (flet ((defunp () |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
245 ;; nil))) |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
246 ;; Set both normal-indent and tentative-calculated. |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
247 ;; The latter ensures this value gets used |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
248 ;; if there are no relevant containing constructs. |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
249 ;; The former ensures this value gets used |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
250 ;; if there is a relevant containing construct |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
251 ;; but we are nested within the structure levels |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
252 ;; that it specifies indentation for. |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
253 (if tentative-defun |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
254 (setq tentative-calculated |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
255 (common-lisp-indent-call-method |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
256 function lisp-indent-defun-method |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
257 path state indent-point |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
258 sexp-column normal-indent) |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
259 normal-indent tentative-calculated))) |
257 | 260 ((integerp method) |
261 ;; convenient top-level hack. | |
262 ;; (also compatible with lisp-indent-function) | |
263 ;; The number specifies how many `distinguished' | |
264 ;; forms there are before the body starts | |
265 ;; Equivalent to (4 4 ... &body) | |
266 (setq calculated (cond ((cdr path) | |
267 normal-indent) | |
268 ((<= (car path) method) | |
269 ;; `distinguished' form | |
270 (list (+ sexp-column 4) | |
271 containing-form-start)) | |
272 ((= (car path) (1+ method)) | |
273 ;; first body form. | |
274 (+ sexp-column lisp-body-indent)) | |
275 (t | |
276 ;; other body form | |
277 normal-indent)))) | |
45573
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
278 (t |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
279 (setq calculated |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
280 (common-lisp-indent-call-method |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
281 function method path state indent-point |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
282 sexp-column normal-indent))))) |
257 | 283 (goto-char containing-sexp) |
284 (setq last-point containing-sexp) | |
22858
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
285 (unless calculated |
45573
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
286 (condition-case () |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
287 (progn (backward-up-list 1) |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
288 (setq depth (1+ depth))) |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
289 (error (setq depth lisp-indent-maximum-backtracking)))))) |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
290 (or calculated tentative-calculated)))) |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
291 |
257 | 292 |
45573
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
293 (defun common-lisp-indent-call-method (function method path state indent-point |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
294 sexp-column normal-indent) |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
295 (let ((lisp-indent-error-function function)) |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
296 (if (symbolp method) |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
297 (funcall method |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
298 path state indent-point |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
299 sexp-column normal-indent) |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
300 (lisp-indent-259 method path state indent-point |
54fb43cbbd73
(common-lisp-indent-function-1):
Richard M. Stallman <rms@gnu.org>
parents:
43920
diff
changeset
|
301 sexp-column normal-indent)))) |
257 | 302 |
303 (defun lisp-indent-report-bad-format (m) | |
304 (error "%s has a badly-formed %s property: %s" | |
305 ;; Love those free variable references!! | |
22212
b95ba3830bc9
(lisp-indent-error-function): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22180
diff
changeset
|
306 lisp-indent-error-function 'common-lisp-indent-function m)) |
257 | 307 |
308 ;; Blame the crufty control structure on dynamic scoping | |
309 ;; -- not on me! | |
310 (defun lisp-indent-259 (method path state indent-point | |
311 sexp-column normal-indent) | |
312 (catch 'exit | |
313 (let ((p path) | |
314 (containing-form-start (elt state 1)) | |
315 n tem tail) | |
316 ;; Isn't tail-recursion wonderful? | |
317 (while p | |
318 ;; This while loop is for destructuring. | |
319 ;; p is set to (cdr p) each iteration. | |
320 (if (not (consp method)) (lisp-indent-report-bad-format method)) | |
321 (setq n (1- (car p)) | |
322 p (cdr p) | |
323 tail nil) | |
324 (while n | |
325 ;; This while loop is for advancing along a method | |
326 ;; until the relevant (possibly &rest/&body) pattern | |
327 ;; is reached. | |
328 ;; n is set to (1- n) and method to (cdr method) | |
329 ;; each iteration. | |
330 (setq tem (car method)) | |
331 | |
332 (or (eq tem 'nil) ;default indentation | |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
333 (eq tem '&lambda) ;lambda list |
257 | 334 (and (eq tem '&body) (null (cdr method))) |
335 (and (eq tem '&rest) | |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
336 (consp (cdr method)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
337 (null (cddr method))) |
257 | 338 (integerp tem) ;explicit indentation specified |
339 (and (consp tem) ;destructuring | |
340 (eq (car tem) '&whole) | |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
341 (or (symbolp (cadr tem)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
342 (integerp (cadr tem)))) |
257 | 343 (and (symbolp tem) ;a function to call to do the work. |
344 (null (cdr method))) | |
345 (lisp-indent-report-bad-format method)) | |
346 | |
347 (cond ((and tail (not (consp tem))) | |
348 ;; indent tail of &rest in same way as first elt of rest | |
349 (throw 'exit normal-indent)) | |
350 ((eq tem '&body) | |
351 ;; &body means (&rest <lisp-body-indent>) | |
352 (throw 'exit | |
353 (if (and (= n 0) ;first body form | |
354 (null p)) ;not in subforms | |
355 (+ sexp-column | |
356 lisp-body-indent) | |
357 normal-indent))) | |
358 ((eq tem '&rest) | |
359 ;; this pattern holds for all remaining forms | |
360 (setq tail (> n 0) | |
361 n 0 | |
362 method (cdr method))) | |
363 ((> n 0) | |
364 ;; try next element of pattern | |
365 (setq n (1- n) | |
366 method (cdr method)) | |
367 (if (< n 0) | |
368 ;; Too few elements in pattern. | |
369 (throw 'exit normal-indent))) | |
370 ((eq tem 'nil) | |
371 (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
|
372 ((eq tem '&lambda) |
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
373 (throw 'exit |
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
374 (cond ((null p) |
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
375 (list (+ sexp-column 4) containing-form-start)) |
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
376 ((null (cdr p)) |
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
377 (+ sexp-column 1)) |
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
378 (t normal-indent)))) |
257 | 379 ((integerp tem) |
380 (throw 'exit | |
381 (if (null p) ;not in subforms | |
382 (list (+ sexp-column tem) containing-form-start) | |
383 normal-indent))) | |
384 ((symbolp tem) ;a function to call | |
385 (throw 'exit | |
386 (funcall tem path state indent-point | |
387 sexp-column normal-indent))) | |
388 (t | |
389 ;; must be a destructing frob | |
390 (if (not (null p)) | |
391 ;; descend | |
22858
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
392 (setq method (cddr tem) |
257 | 393 n nil) |
22858
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
394 (setq tem (cadr tem)) |
257 | 395 (throw 'exit |
396 (cond (tail | |
397 normal-indent) | |
398 ((eq tem 'nil) | |
399 (list normal-indent | |
400 containing-form-start)) | |
401 ((integerp tem) | |
402 (list (+ sexp-column tem) | |
403 containing-form-start)) | |
404 (t | |
405 (funcall tem path state indent-point | |
406 sexp-column normal-indent)))))))))))) | |
407 | |
408 (defun lisp-indent-tagbody (path state indent-point sexp-column normal-indent) | |
409 (if (not (null (cdr path))) | |
410 normal-indent | |
411 (save-excursion | |
412 (goto-char indent-point) | |
413 (beginning-of-line) | |
414 (skip-chars-forward " \t") | |
415 (list (cond ((looking-at "\\sw\\|\\s_") | |
416 ;; a tagbody tag | |
417 (+ sexp-column lisp-tag-indentation)) | |
418 ((integerp lisp-tag-body-indentation) | |
419 (+ sexp-column lisp-tag-body-indentation)) | |
420 ((eq lisp-tag-body-indentation 't) | |
421 (condition-case () | |
422 (progn (backward-sexp 1) (current-column)) | |
423 (error (1+ sexp-column)))) | |
424 (t (+ sexp-column lisp-body-indent))) | |
425 ; (cond ((integerp lisp-tag-body-indentation) | |
426 ; (+ sexp-column lisp-tag-body-indentation)) | |
427 ; ((eq lisp-tag-body-indentation 't) | |
428 ; normal-indent) | |
429 ; (t | |
430 ; (+ sexp-column lisp-body-indent))) | |
431 (elt state 1) | |
432 )))) | |
433 | |
434 (defun lisp-indent-do (path state indent-point sexp-column normal-indent) | |
435 (if (>= (car path) 3) | |
436 (let ((lisp-tag-body-indentation lisp-body-indent)) | |
437 (funcall (function lisp-indent-tagbody) | |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
438 path state indent-point sexp-column normal-indent)) |
257 | 439 (funcall (function lisp-indent-259) |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
440 '((&whole nil &rest |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
441 ;; the following causes weird indentation |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
442 ;;(&whole 1 1 2 nil) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
443 ) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
444 (&whole nil &rest 1)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
445 path state indent-point sexp-column normal-indent))) |
257 | 446 |
43859
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
447 |
40952
2ca1b56f3bb1
Indent properly `generic-flet', `generic-labels', `with-accessors',
Sam Steingold <sds@gnu.org>
parents:
38826
diff
changeset
|
448 (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
|
449 normal-indent) |
f2ff22369238
(lisp-indent-defmethod): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
37764
diff
changeset
|
450 "Indentation function defmethod." |
43859
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
451 (lisp-indent-259 (if (and (>= (car path) 3) |
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
452 (null (cdr path)) |
41256
4a78098c3bd7
(lisp-indent-defmethod): At first three elements, act like defun.
Richard M. Stallman <rms@gnu.org>
parents:
40952
diff
changeset
|
453 (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
|
454 (forward-char 1) |
4a78098c3bd7
(lisp-indent-defmethod): At first three elements, act like defun.
Richard M. Stallman <rms@gnu.org>
parents:
40952
diff
changeset
|
455 (forward-sexp 3) |
4a78098c3bd7
(lisp-indent-defmethod): At first three elements, act like defun.
Richard M. Stallman <rms@gnu.org>
parents:
40952
diff
changeset
|
456 (backward-sexp) |
4a78098c3bd7
(lisp-indent-defmethod): At first three elements, act like defun.
Richard M. Stallman <rms@gnu.org>
parents:
40952
diff
changeset
|
457 (looking-at ":"))) |
38826
f2ff22369238
(lisp-indent-defmethod): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
37764
diff
changeset
|
458 '(4 4 (&whole 4 &rest 4) &body) |
f2ff22369238
(lisp-indent-defmethod): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
37764
diff
changeset
|
459 (get 'defun 'common-lisp-indent-function)) |
f2ff22369238
(lisp-indent-defmethod): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
37764
diff
changeset
|
460 path state indent-point sexp-column normal-indent)) |
f2ff22369238
(lisp-indent-defmethod): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
37764
diff
changeset
|
461 |
f2ff22369238
(lisp-indent-defmethod): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
37764
diff
changeset
|
462 |
257 | 463 (defun lisp-indent-function-lambda-hack (path state indent-point |
464 sexp-column normal-indent) | |
465 ;; indent (function (lambda () <newline> <body-forms>)) kludgily. | |
466 (if (or (cdr path) ; wtf? | |
467 (> (car path) 3)) | |
468 ;; line up under previous body form | |
469 normal-indent | |
470 ;; line up under function rather than under lambda in order to | |
471 ;; conserve horizontal space. (Which is what #' is for.) | |
472 (condition-case () | |
473 (save-excursion | |
474 (backward-up-list 2) | |
475 (forward-char 1) | |
476 (if (looking-at "\\(lisp:+\\)?function\\(\\Sw\\|\\S_\\)") | |
477 (+ lisp-body-indent -1 (current-column)) | |
478 (+ sexp-column lisp-body-indent))) | |
479 (error (+ sexp-column lisp-body-indent))))) | |
480 | |
43859
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
481 |
257 | 482 |
483 (let ((l '((block 1) | |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
484 (case (4 &rest (&whole 2 &rest 1))) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
485 (ccase . case) (ecase . case) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
486 (typecase . case) (etypecase . case) (ctypecase . case) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
487 (catch 1) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
488 (cond (&rest (&whole 2 &rest 1))) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
489 (defvar (4 2 2)) |
30651
61c2f9fcb8f6
* emacs-lisp/cl-indent.el (toplevel): Indent `defclass',
Sam Steingold <sds@gnu.org>
parents:
29797
diff
changeset
|
490 (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
|
491 (defconstant . defvar) |
27231
e9725bb98b6e
Add defclass, define-condition, defmethod, symbol-macrolet.
Dave Love <fx@gnu.org>
parents:
26047
diff
changeset
|
492 (defcustom (4 2 2 2)) |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
493 (defparameter . defvar) |
30651
61c2f9fcb8f6
* emacs-lisp/cl-indent.el (toplevel): Indent `defclass',
Sam Steingold <sds@gnu.org>
parents:
29797
diff
changeset
|
494 (defconst . defcustom) |
61c2f9fcb8f6
* emacs-lisp/cl-indent.el (toplevel): Indent `defclass',
Sam Steingold <sds@gnu.org>
parents:
29797
diff
changeset
|
495 (define-condition . defclass) |
42252
63b6d0453539
(define-modify-macro): Better indent spec.
Richard M. Stallman <rms@gnu.org>
parents:
41256
diff
changeset
|
496 (define-modify-macro (4 &lambda &body)) |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
497 (defsetf (4 &lambda 4 &body)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
498 (defun (4 &lambda &body)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
499 (define-setf-method . defun) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
500 (define-setf-expander . defun) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
501 (defmacro . defun) (defsubst . defun) (deftype . defun) |
38826
f2ff22369238
(lisp-indent-defmethod): New function.
Gerd Moellmann <gerd@gnu.org>
parents:
37764
diff
changeset
|
502 (defmethod lisp-indent-defmethod) |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
503 (defpackage (4 2)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
504 (defstruct ((&whole 4 &rest (&whole 2 &rest 1)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
505 &rest (&whole 2 &rest 1))) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
506 (destructuring-bind |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
507 ((&whole 6 &rest 1) 4 &body)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
508 (do lisp-indent-do) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
509 (do* . do) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
510 (dolist ((&whole 4 2 1) &body)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
511 (dotimes . dolist) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
512 (eval-when 1) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
513 (flet ((&whole 4 &rest (&whole 1 &lambda &body)) &body)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
514 (labels . flet) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
515 (macrolet . flet) |
40952
2ca1b56f3bb1
Indent properly `generic-flet', `generic-labels', `with-accessors',
Sam Steingold <sds@gnu.org>
parents:
38826
diff
changeset
|
516 (generic-flet . flet) (generic-labels . flet) |
22858
77090a500417
(lisp-indent-defun-method): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
22756
diff
changeset
|
517 (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
|
518 (restart-case . handler-case) |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
519 ;; `else-body' style |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
520 (if (nil nil &body)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
521 ;; single-else style (then and else equally indented) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
522 (if (&rest nil)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
523 (lambda (&lambda &rest lisp-indent-function-lambda-hack)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
524 (let ((&whole 4 &rest (&whole 1 1 2)) &body)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
525 (let* . let) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
526 (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
|
527 (handler-bind . let) (restart-bind . let) |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
528 (locally 1) |
43859
e8da4031d520
(lisp-loop-keyword-indentation)
Gerd Moellmann <gerd@gnu.org>
parents:
42252
diff
changeset
|
529 ;(loop lisp-indent-loop) |
37764
b1fec0dc2aa1
(toplevel): indent the :method sub-form of `defgeneric' correctly.
Sam Steingold <sds@gnu.org>
parents:
37389
diff
changeset
|
530 (:method (&lambda &body)) ; in `defgeneric' |
30651
61c2f9fcb8f6
* emacs-lisp/cl-indent.el (toplevel): Indent `defclass',
Sam Steingold <sds@gnu.org>
parents:
29797
diff
changeset
|
531 (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
|
532 (multiple-value-call (4 &body)) |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
533 (multiple-value-prog1 1) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
534 (multiple-value-setq (4 2)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
535 (multiple-value-setf . multiple-value-setq) |
27872
277f4365f2fa
Indent `pprint-logical-block' properly.
Gerd Moellmann <gerd@gnu.org>
parents:
27802
diff
changeset
|
536 (pprint-logical-block (4 2)) |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
537 (print-unreadable-object ((&whole 4 1 &rest 1) &body)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
538 ;; Combines the worst features of BLOCK, LET and TAGBODY |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
539 (prog (&lambda &rest lisp-indent-tagbody)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
540 (prog* . prog) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
541 (prog1 1) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
542 (prog2 2) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
543 (progn 0) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
544 (progv (4 4 &body)) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
545 (return 0) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
546 (return-from (nil &body)) |
50700
ad311d8949c4
`symbol-macrolet' is similar to `let', not `multiple-value-bind'.
Sam Steingold <sds@gnu.org>
parents:
49598
diff
changeset
|
547 (symbol-macrolet . let) |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
548 (tagbody lisp-indent-tagbody) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
549 (throw 1) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
550 (unless 1) |
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
551 (unwind-protect (5 &body)) |
22180
485917486caf
Indent `with-standard-io-syntax' correctly.
Richard M. Stallman <rms@gnu.org>
parents:
21750
diff
changeset
|
552 (when 1) |
40952
2ca1b56f3bb1
Indent properly `generic-flet', `generic-labels', `with-accessors',
Sam Steingold <sds@gnu.org>
parents:
38826
diff
changeset
|
553 (with-accessors . multiple-value-bind) |
2ca1b56f3bb1
Indent properly `generic-flet', `generic-labels', `with-accessors',
Sam Steingold <sds@gnu.org>
parents:
38826
diff
changeset
|
554 (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
|
555 (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
|
556 (with-slots . multiple-value-bind) |
22180
485917486caf
Indent `with-standard-io-syntax' correctly.
Richard M. Stallman <rms@gnu.org>
parents:
21750
diff
changeset
|
557 (with-standard-io-syntax (2))))) |
40952
2ca1b56f3bb1
Indent properly `generic-flet', `generic-labels', `with-accessors',
Sam Steingold <sds@gnu.org>
parents:
38826
diff
changeset
|
558 (dolist (el l) |
2ca1b56f3bb1
Indent properly `generic-flet', `generic-labels', `with-accessors',
Sam Steingold <sds@gnu.org>
parents:
38826
diff
changeset
|
559 (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
|
560 (if (symbolp (cdr el)) |
2ca1b56f3bb1
Indent properly `generic-flet', `generic-labels', `with-accessors',
Sam Steingold <sds@gnu.org>
parents:
38826
diff
changeset
|
561 (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
|
562 (car (cdr el)))))) |
257 | 563 |
564 | |
565 ;(defun foo (x) | |
566 ; (tagbody | |
567 ; foo | |
568 ; (bar) | |
569 ; baz | |
570 ; (when (losing) | |
571 ; (with-big-loser | |
572 ; (yow) | |
573 ; ((lambda () | |
574 ; foo) | |
575 ; big))) | |
576 ; (flet ((foo (bar baz zap) | |
577 ; (zip)) | |
578 ; (zot () | |
579 ; quux)) | |
580 ; (do () | |
581 ; ((lose) | |
582 ; (foo 1)) | |
583 ; (quux) | |
584 ; foo | |
585 ; (lose)) | |
586 ; (cond ((x) | |
587 ; (win 1 2 | |
588 ; (foo))) | |
589 ; (t | |
590 ; (lose | |
591 ; 3)))))) | |
29797
3bf98b923af0
handle print-unreadable-object
Sam Steingold <sds@gnu.org>
parents:
27872
diff
changeset
|
592 |
257 | 593 |
594 ;(put 'while 'common-lisp-indent-function 1) | |
595 ;(put 'defwrapper'common-lisp-indent-function ...) | |
596 ;(put 'def 'common-lisp-indent-function ...) | |
597 ;(put 'defflavor 'common-lisp-indent-function ...) | |
598 ;(put 'defsubst 'common-lisp-indent-function ...) | |
599 | |
600 ;(put 'with-restart 'common-lisp-indent-function '((1 4 ((* 1))) (2 &body))) | |
601 ;(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
|
602 ;(put 'define-condition 'common-lisp-indent-function '((1 6) (2 6 ((&whole 1))) (3 4 ((&whole 1))) (4 &body))) |
257 | 603 ;(put 'with-condition-handler 'common-lisp-indent-function '((1 4 ((* 1))) (2 &body))) |
604 ;(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
|
605 ;(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
|
606 ;(put 'defgeneric 'common-lisp-indent-function 'defun) |
257 | 607 |
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
257
diff
changeset
|
608 ;;; cl-indent.el ends here |