Mercurial > emacs
annotate lisp/progmodes/cc-align.el @ 88179:43ed67124917
(rmail-process-new-messages): Require rmailkwd.
(rmail-ignored-headers): Add "Original-Recipient"
author | Henrik Enberg <henrik.enberg@telia.com> |
---|---|
date | Tue, 17 Jan 2006 02:35:36 +0000 |
parents | d7ddb3e565de |
children |
rev | line source |
---|---|
18720 | 1 ;;; cc-align.el --- custom indentation functions for CC Mode |
2 | |
88155 | 3 ;; Copyright (C) 1985,1987,1992-2003, 2004, 2005 Free Software Foundation, Inc. |
18720 | 4 |
88155 | 5 ;; Authors: 1998- Martin Stjernholm |
6 ;; 1992-1999 Barry A. Warsaw | |
18720 | 7 ;; 1987 Dave Detlefs and Stewart Clamen |
8 ;; 1985 Richard M. Stallman | |
24282 | 9 ;; Maintainer: bug-cc-mode@gnu.org |
18720 | 10 ;; Created: 22-Apr-1997 (split from cc-mode.el) |
20141 | 11 ;; Version: See cc-mode.el |
18720 | 12 ;; Keywords: c languages oop |
13 | |
14 ;; This file is part of GNU Emacs. | |
15 | |
16 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
17 ;; it under the terms of the GNU General Public License as published by | |
18 ;; the Free Software Foundation; either version 2, or (at your option) | |
19 ;; any later version. | |
20 | |
21 ;; GNU Emacs is distributed in the hope that it will be useful, | |
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 ;; GNU General Public License for more details. | |
25 | |
26 ;; You should have received a copy of the GNU General Public License | |
88155 | 27 ;; along with this program; see the file COPYING. If not, write to |
28 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
29 ;; Boston, MA 02110-1301, USA. | |
18720 | 30 |
38422
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36920
diff
changeset
|
31 ;;; Commentary: |
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36920
diff
changeset
|
32 |
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36920
diff
changeset
|
33 ;;; Code: |
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36920
diff
changeset
|
34 |
18720 | 35 (eval-when-compile |
26817 | 36 (let ((load-path |
36920 | 37 (if (and (boundp 'byte-compile-dest-file) |
38 (stringp byte-compile-dest-file)) | |
39 (cons (file-name-directory byte-compile-dest-file) load-path) | |
26817 | 40 load-path))) |
88155 | 41 (load "cc-bytecomp" nil t))) |
36920 | 42 |
43 (cc-require 'cc-defs) | |
44 (cc-require 'cc-vars) | |
45 (cc-require 'cc-engine) | |
18720 | 46 |
47 | |
88155 | 48 ;; Standard line-up functions |
49 ;; | |
50 ;; See the section "Custom Indentation Functions" in the manual for | |
51 ;; details on the calling convention. | |
26817 | 52 |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
53 (defun c-lineup-topmost-intro-cont (langelem) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
54 "Line up declaration continuation lines zero or one indentation step. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
55 For lines in the \"header\" of a definition, zero is used. For other |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
56 lines, `c-basic-offset' is added to the indentation. E.g: |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
57 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
58 int |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
59 neg (int i) <- c-lineup-topmost-intro-cont |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
60 { |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
61 return -i; |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
62 } |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
63 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
64 struct |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
65 larch <- c-lineup-topmost-intro-cont |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
66 { |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
67 double height; |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
68 } |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
69 the_larch, <- c-lineup-topmost-intro-cont |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
70 another_larch; <- c-lineup-topmost-intro-cont |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
71 <--> c-basic-offset |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
72 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
73 struct larch |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
74 the_larch, <- c-lineup-topmost-intro-cont |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
75 another_larch; <- c-lineup-topmost-intro-cont |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
76 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
77 \(This function is mainly provided to mimic the behavior of CC Mode |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
78 5.28 and earlier where this case wasn't handled consistently so that |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
79 these lines could be analyzed as either topmost-intro-cont or |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
80 statement-cont.) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
81 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
82 Works with: topmost-intro-cont." |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
83 (save-excursion |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
84 (beginning-of-line) |
88155 | 85 (c-backward-syntactic-ws (c-langelem-pos langelem)) |
86 (if (and (memq (char-before) '(?} ?,)) | |
87 (not (and c-overloadable-operators-regexp | |
88 (c-after-special-operator-id)))) | |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
89 c-basic-offset))) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
90 |
88155 | 91 (defun c-block-in-arglist-dwim (arglist-start) |
92 ;; This function implements the DWIM to avoid far indentation of | |
93 ;; brace block constructs in arguments in `c-lineup-arglist' etc. | |
94 ;; Return non-nil if a brace block construct is detected within the | |
95 ;; arglist starting at ARGLIST-START. | |
96 | |
97 (or | |
98 ;; Check if the syntactic context contains any of the symbols for | |
99 ;; in-expression constructs. This can both save the work that we | |
100 ;; have to do below, and it also detect the brace list constructs | |
101 ;; that `c-looking-at-inexpr-block' currently misses (they are | |
102 ;; recognized by `c-inside-bracelist-p' instead). | |
103 (assq 'inexpr-class c-syntactic-context) | |
104 (assq 'inexpr-statement c-syntactic-context) | |
105 (assq 'inlambda c-syntactic-context) | |
106 | |
107 (save-restriction | |
108 ;; Search for open braces from the arglist start to the end of the | |
109 ;; line. | |
110 (narrow-to-region arglist-start (c-point 'eol arglist-start)) | |
111 | |
112 (goto-char arglist-start) | |
113 (while (and (c-syntactic-re-search-forward "{" nil t) | |
114 (progn | |
115 (backward-char) | |
116 (or | |
117 ;; Ignore starts of special brace lists. | |
118 (and c-special-brace-lists | |
119 (save-restriction | |
120 (widen) | |
121 (c-looking-at-special-brace-list))) | |
122 ;; Ignore complete blocks. | |
123 (c-safe (c-forward-sexp) t)))) | |
124 (forward-char)) | |
125 | |
126 (looking-at "{")) | |
127 | |
128 (let (containing-sexp) | |
129 (goto-char arglist-start) | |
130 ;; `c-syntactic-eol' always matches somewhere on the line. | |
131 (re-search-forward c-syntactic-eol) | |
132 (goto-char (match-beginning 0)) | |
133 (c-forward-syntactic-ws) | |
134 (setq containing-sexp (c-most-enclosing-brace (c-parse-state))) | |
135 (c-looking-at-inexpr-block | |
136 (c-safe-position (or containing-sexp (point)) c-state-cache) | |
137 containing-sexp)))) | |
138 | |
18720 | 139 (defun c-lineup-arglist (langelem) |
26817 | 140 "Line up the current argument line under the first argument. |
141 | |
88155 | 142 As a special case, if the indented line is inside a brace block |
143 construct, the indentation is `c-basic-offset' only. This is intended | |
144 as a \"DWIM\" measure in cases like macros that contains statement | |
145 blocks, e.g: | |
146 | |
147 A_VERY_LONG_MACRO_NAME ({ | |
148 some (code, with + long, lines * in[it]); | |
149 }); | |
150 <--> c-basic-offset | |
151 | |
152 This is motivated partly because it's more in line with how code | |
153 blocks are handled, and partly since it approximates the behavior of | |
154 earlier CC Mode versions, which due to inaccurate analysis tended to | |
155 indent such cases this way. | |
156 | |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
157 Works with: arglist-cont-nonempty, arglist-close." |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
158 (save-excursion |
88155 | 159 (let ((indent-pos (point))) |
160 | |
161 (if (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)) | |
162 c-basic-offset ; DWIM case. | |
163 | |
164 ;; Normal case. Indent to the token after the arglist open paren. | |
165 (goto-char (c-langelem-2nd-pos c-syntactic-element)) | |
166 (if (and c-special-brace-lists | |
167 (c-looking-at-special-brace-list)) | |
168 ;; Skip a special brace list opener like "({". | |
169 (progn (c-forward-token-2) | |
170 (forward-char)) | |
171 (forward-char)) | |
172 (let ((arglist-content-start (point))) | |
173 (c-forward-syntactic-ws) | |
174 (when (< (point) indent-pos) | |
175 (goto-char arglist-content-start) | |
176 (skip-chars-forward " \t")) | |
177 (vector (current-column))))))) | |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
178 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
179 ;; Contributed by Kevin Ryde <user42@zip.com.au>. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
180 (defun c-lineup-argcont (elem) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
181 "Line up a continued argument. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
182 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
183 foo (xyz, aaa + bbb + ccc |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
184 + ddd + eee + fff); <- c-lineup-argcont |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
185 |
88155 | 186 Only continuation lines like this are touched, nil is returned on lines |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
187 which are the start of an argument. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
188 |
88155 | 189 Within a gcc asm block, \":\" is recognized as an argument separator, |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
190 but of course only between operand specifications, not in the expressions |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
191 for the operands. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
192 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
193 Works with: arglist-cont, arglist-cont-nonempty." |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
194 |
18720 | 195 (save-excursion |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
196 (beginning-of-line) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
197 |
88155 | 198 (when (eq (car elem) 'arglist-cont-nonempty) |
199 ;; Our argument list might not be the innermost one. If it | |
200 ;; isn't, go back to the last position in it. We do this by | |
201 ;; stepping back over open parens until we get to the open paren | |
202 ;; of our argument list. | |
203 (let ((open-paren (c-langelem-2nd-pos c-syntactic-element)) | |
204 (paren-state (c-parse-state))) | |
205 (while (not (eq (car paren-state) open-paren)) | |
206 (unless (consp (car paren-state)) ;; ignore matched braces | |
207 (goto-char (car paren-state))) | |
208 (setq paren-state (cdr paren-state))))) | |
209 | |
210 (let ((start (point)) c) | |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
211 |
88155 | 212 (when (bolp) |
213 ;; Previous line ending in a comma means we're the start of an | |
214 ;; argument. This should quickly catch most cases not for us. | |
215 ;; This case is only applicable if we're the innermost arglist. | |
216 (c-backward-syntactic-ws) | |
217 (setq c (char-before))) | |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
218 |
88155 | 219 (unless (eq c ?,) |
220 ;; In a gcc asm, ":" on the previous line means the start of an | |
221 ;; argument. And lines starting with ":" are not for us, don't | |
222 ;; want them to indent to the preceding operand. | |
223 (let ((gcc-asm (save-excursion | |
224 (goto-char start) | |
225 (c-in-gcc-asm-p)))) | |
226 (unless (and gcc-asm | |
227 (or (eq c ?:) | |
228 (save-excursion | |
229 (goto-char start) | |
230 (looking-at "[ \t]*:")))) | |
231 | |
232 (c-lineup-argcont-scan (if gcc-asm ?:)) | |
233 (vector (current-column)))))))) | |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
234 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
235 (defun c-lineup-argcont-scan (&optional other-match) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
236 ;; Find the start of an argument, for `c-lineup-argcont'. |
88155 | 237 (when (zerop (c-backward-token-2 1 t)) |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
238 (let ((c (char-after))) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
239 (if (or (eq c ?,) (eq c other-match)) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
240 (progn |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
241 (forward-char) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
242 (c-forward-syntactic-ws)) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
243 (c-lineup-argcont-scan other-match))))) |
18720 | 244 |
245 (defun c-lineup-arglist-intro-after-paren (langelem) | |
88155 | 246 "Line up a line to just after the open paren of the surrounding paren |
247 or brace block. | |
26817 | 248 |
249 Works with: defun-block-intro, brace-list-intro, | |
250 statement-block-intro, statement-case-intro, arglist-intro." | |
18720 | 251 (save-excursion |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
252 (beginning-of-line) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
253 (backward-up-list 1) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
254 (skip-chars-forward " \t" (c-point 'eol)) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
255 (vector (1+ (current-column))))) |
18720 | 256 |
257 (defun c-lineup-arglist-close-under-paren (langelem) | |
88155 | 258 "Line up a line under the enclosing open paren. |
259 Normally used to line up a closing paren in the same column as its | |
260 corresponding open paren, but can also be used with arglist-cont and | |
261 arglist-cont-nonempty to line up all lines inside a parenthesis under | |
262 the open paren. | |
263 | |
264 As a special case, if a brace block construct starts at the same line | |
265 as the open parenthesis of the argument list, the indentation is | |
266 `c-basic-offset' only. See `c-lineup-arglist' for further discussion | |
267 of this \"DWIM\" measure. | |
268 | |
269 Works with: Almost all symbols, but are typically most useful on | |
270 arglist-close, brace-list-close, arglist-cont and arglist-cont-nonempty." | |
271 (save-excursion | |
272 (if (memq (c-langelem-sym langelem) | |
273 '(arglist-cont-nonempty arglist-close)) | |
274 (goto-char (c-langelem-2nd-pos c-syntactic-element)) | |
275 (beginning-of-line) | |
276 (c-go-up-list-backward)) | |
277 | |
278 (if (save-excursion (c-block-in-arglist-dwim (point))) | |
279 c-basic-offset ; DWIM case. | |
26817 | 280 |
88155 | 281 ;; Normal case. Indent to the arglist open paren. |
282 (let (special-list) | |
283 (if (and c-special-brace-lists | |
284 (setq special-list (c-looking-at-special-brace-list))) | |
285 ;; Cope if we're in the middle of a special brace list | |
286 ;; opener like "({". | |
287 (goto-char (car (car special-list)))) | |
288 (vector (current-column)))))) | |
289 | |
290 (defun c-lineup-arglist-operators (langelem) | |
291 "Line up lines starting with an infix operator under the open paren. | |
292 Return nil on lines that don't start with an operator, to leave those | |
293 cases to other line-up functions. Example: | |
294 | |
295 if ( x < 10 | |
296 || at_limit (x, <- c-lineup-arglist-operators | |
297 list) <- c-lineup-arglist-operators returns nil | |
298 ) | |
299 | |
300 Since this function doesn't do anything for lines without an infix | |
301 operator you typically want to use it together with some other line-up | |
302 settings, e.g. as follows \(the arglist-close setting is just a | |
303 suggestion to get a consistent style): | |
304 | |
305 \(c-set-offset 'arglist-cont '(c-lineup-arglist-operators 0)) | |
306 \(c-set-offset 'arglist-cont-nonempty '(c-lineup-arglist-operators | |
307 c-lineup-arglist)) | |
308 \(c-set-offset 'arglist-close '(c-lineup-arglist-close-under-paren)) | |
309 | |
310 Works with: arglist-cont, arglist-cont-nonempty." | |
18720 | 311 (save-excursion |
88155 | 312 (back-to-indentation) |
313 (when (looking-at "[-+|&*%<>=]\\|\\(/[^/*]\\)") | |
314 ;; '-' can be both an infix and a prefix operator, but I'm lazy now.. | |
315 (c-lineup-arglist-close-under-paren langelem)))) | |
18720 | 316 |
20911 | 317 (defun c-lineup-close-paren (langelem) |
26817 | 318 "Line up the closing paren under its corresponding open paren if the |
319 open paren is followed by code. If the open paren ends its line, no | |
320 indentation is added. E.g: | |
321 | |
322 main (int, main ( | |
323 char ** int, char ** | |
324 ) <-> ) <- c-lineup-close-paren | |
325 | |
88155 | 326 As a special case, if a brace block construct starts at the same line |
327 as the open parenthesis of the argument list, the indentation is | |
328 `c-basic-offset' instead of the open paren column. See | |
329 `c-lineup-arglist' for further discussion of this \"DWIM\" measure. | |
330 | |
331 Works with: All *-close symbols." | |
20911 | 332 (save-excursion |
88155 | 333 (if (memq (c-langelem-sym langelem) |
334 '(arglist-cont-nonempty arglist-close)) | |
335 (goto-char (c-langelem-2nd-pos c-syntactic-element)) | |
336 (beginning-of-line) | |
337 (c-go-up-list-backward)) | |
338 | |
339 (let (special-list arglist-start) | |
340 (if (and c-special-brace-lists | |
341 (setq special-list (c-looking-at-special-brace-list))) | |
342 ;; Cope if we're in the middle of a special brace list | |
343 ;; opener like "({". | |
344 (progn | |
345 (goto-char (setq arglist-start (car (car special-list)))) | |
346 (c-forward-token-2) | |
347 (forward-char)) | |
348 (setq arglist-start (point)) | |
349 (forward-char)) | |
350 | |
351 (cond ((looking-at c-syntactic-eol) | |
352 0) ; The arglist is "empty". | |
353 | |
354 ((c-block-in-arglist-dwim (point)) | |
355 c-basic-offset) ; DWIM case. | |
356 | |
357 (t | |
358 ;; Normal case. Indent to the arglist open paren. | |
359 (goto-char arglist-start) | |
360 (vector (current-column))))))) | |
20911 | 361 |
18720 | 362 (defun c-lineup-streamop (langelem) |
26817 | 363 "Line up C++ stream operators under each other. |
364 | |
365 Works with: stream-op." | |
18720 | 366 (save-excursion |
88155 | 367 (goto-char (c-langelem-pos langelem)) |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
368 (re-search-forward "<<\\|>>" (c-point 'eol) 'move) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
369 (goto-char (match-beginning 0)) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
370 (vector (current-column)))) |
18720 | 371 |
372 (defun c-lineup-multi-inher (langelem) | |
30407
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
373 "Line up the classes in C++ multiple inheritance clauses and member |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
374 initializers under each other. E.g: |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
375 |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
376 class Foo: Foo::Foo (int a, int b): |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
377 public Cyphr, Cyphr (a), |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
378 public Bar <-> Bar (b) <- c-lineup-multi-inher |
26817 | 379 |
30407
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
380 class Foo Foo::Foo (int a, int b) |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
381 : public Cyphr, : Cyphr (a), |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
382 public Bar <-> Bar (b) <- c-lineup-multi-inher |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
383 |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
384 class Foo Foo::Foo (int a, int b) |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
385 : public Cyphr : Cyphr (a) |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
386 , public Bar <-> , Bar (b) <- c-lineup-multi-inher |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
387 |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
388 Works with: inher-cont, member-init-cont." |
18720 | 389 (save-excursion |
88155 | 390 (back-to-indentation) |
30407
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
391 (let* ((eol (c-point 'eol)) |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
392 (here (point)) |
88155 | 393 (char-after-ip (char-after))) |
394 (if (c-langelem-pos langelem) | |
395 (goto-char (c-langelem-pos langelem))) | |
30407
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
396 |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
397 ;; This kludge is necessary to support both inher-cont and |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
398 ;; member-init-cont, since they have different anchor positions. |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
399 (c-backward-syntactic-ws) |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
400 (when (eq (char-before) ?:) |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
401 (backward-char) |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
402 (c-backward-syntactic-ws)) |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
403 |
88155 | 404 (c-syntactic-re-search-forward ":" eol 'move) |
405 (if (looking-at c-syntactic-eol) | |
406 (c-forward-syntactic-ws here) | |
407 (if (eq char-after-ip ?,) | |
408 (backward-char) | |
409 (skip-chars-forward " \t" eol))) | |
410 (if (< (point) here) | |
411 (vector (current-column))) | |
18720 | 412 ))) |
413 | |
414 (defun c-lineup-java-inher (langelem) | |
26817 | 415 "Line up Java implements and extends declarations. |
88155 | 416 If class names follow on the same line as the implements/extends |
26817 | 417 keyword, they are lined up under each other. Otherwise, they are |
418 indented by adding `c-basic-offset' to the column of the keyword. | |
419 E.g: | |
420 | |
421 class Foo class Foo | |
422 extends extends Cyphr, | |
423 Bar <-> Bar <- c-lineup-java-inher | |
424 <--> c-basic-offset | |
425 | |
426 Works with: inher-cont." | |
18720 | 427 (save-excursion |
88155 | 428 (goto-char (c-langelem-pos langelem)) |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
429 (forward-word 1) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
430 (if (looking-at "[ \t]*$") |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
431 c-basic-offset |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
432 (c-forward-syntactic-ws) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
433 (vector (current-column))))) |
18720 | 434 |
435 (defun c-lineup-java-throws (langelem) | |
26817 | 436 "Line up Java throws declarations. |
88155 | 437 If exception names follow on the same line as the throws keyword, |
26817 | 438 they are lined up under each other. Otherwise, they are indented by |
439 adding `c-basic-offset' to the column of the throws keyword. The | |
440 throws keyword itself is also indented by `c-basic-offset' from the | |
441 function declaration start if it doesn't hang. E.g: | |
442 | |
443 int foo() int foo() throws Cyphr, | |
444 throws <-> Bar, <- c-lineup-java-throws | |
445 Bar <-> Vlod <- c-lineup-java-throws | |
446 <--><--> c-basic-offset | |
447 | |
448 Works with: func-decl-cont." | |
18720 | 449 (save-excursion |
26817 | 450 (let* ((lim (1- (c-point 'bol))) |
451 (throws (catch 'done | |
88155 | 452 (goto-char (c-langelem-pos langelem)) |
453 (while (zerop (c-forward-token-2 1 t lim)) | |
26817 | 454 (if (looking-at "throws\\>[^_]") |
455 (throw 'done t)))))) | |
456 (if throws | |
88155 | 457 (if (zerop (c-forward-token-2 1 nil (c-point 'eol))) |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
458 (vector (current-column)) |
26817 | 459 (back-to-indentation) |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
460 (vector (+ (current-column) c-basic-offset))) |
26817 | 461 c-basic-offset)))) |
18720 | 462 |
20911 | 463 (defun c-indent-one-line-block (langelem) |
26817 | 464 "Indent a one line block `c-basic-offset' extra. |
465 E.g: | |
466 | |
467 if (n > 0) if (n > 0) | |
468 {m+=n; n=0;} <-> { <- c-indent-one-line-block | |
469 <--> c-basic-offset m+=n; n=0; | |
470 } | |
471 | |
36920 | 472 The block may use any kind of parenthesis character. nil is returned |
473 if the line doesn't start with a one line block, which makes the | |
474 function usable in list expressions. | |
26817 | 475 |
476 Work with: Almost all syntactic symbols, but most useful on *-open." | |
20911 | 477 (save-excursion |
26817 | 478 (let ((eol (c-point 'eol))) |
479 (back-to-indentation) | |
480 (if (and (eq (char-syntax (char-after)) ?\() | |
24282 | 481 (c-safe (progn (c-forward-sexp) t)) |
26817 | 482 (<= (point) eol)) |
20911 | 483 c-basic-offset |
26817 | 484 nil)))) |
485 | |
486 (defun c-indent-multi-line-block (langelem) | |
487 "Indent a multi line block `c-basic-offset' extra. | |
488 E.g: | |
489 | |
490 int *foo[] = { int *foo[] = { | |
491 NULL, NULL, | |
492 {17}, <-> { <- c-indent-multi-line-block | |
493 17 | |
494 } | |
495 <--> c-basic-offset | |
496 | |
36920 | 497 The block may use any kind of parenthesis character. nil is returned |
498 if the line doesn't start with a multi line block, which makes the | |
499 function usable in list expressions. | |
26817 | 500 |
501 Work with: Almost all syntactic symbols, but most useful on *-open." | |
502 (save-excursion | |
503 (let ((eol (c-point 'eol))) | |
504 (back-to-indentation) | |
505 (if (and (eq (char-syntax (char-after)) ?\() | |
506 (or (not (c-safe (progn (c-forward-sexp) t))) | |
507 (> (point) eol))) | |
508 c-basic-offset | |
509 nil)))) | |
20911 | 510 |
18720 | 511 (defun c-lineup-C-comments (langelem) |
26817 | 512 "Line up C block comment continuation lines. |
36920 | 513 Various heuristics are used to handle many of the common comment |
26817 | 514 styles. Some examples: |
515 | |
516 /* /** /* /* text /* /** | |
517 * text * text text text ** text ** text | |
518 */ */ */ */ */ */ | |
519 | |
520 /********************************************************************* | |
521 * text | |
522 ********************************************************************/ | |
523 | |
524 /********************************************************************* | |
525 Free form text comments: | |
526 In comments with a long delimiter line at the start, the indentation | |
527 is kept unchanged for lines that start with an empty comment line | |
528 prefix. The delimiter line is whatever matches the | |
529 `comment-start-skip' regexp. | |
530 *********************************************************************/ | |
531 | |
532 The variable `c-comment-prefix-regexp' is used to recognize the | |
533 comment line prefix, e.g. the `*' that usually starts every line | |
534 inside a comment. | |
535 | |
536 Works with: The `c' syntactic symbol." | |
18720 | 537 (save-excursion |
26817 | 538 (let* ((here (point)) |
539 (prefixlen (progn (back-to-indentation) | |
36920 | 540 (if (looking-at c-current-comment-prefix) |
26817 | 541 (- (match-end 0) (point)) |
542 0))) | |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
543 (starterlen |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
544 ;; Get the length of the comment starter, not including |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
545 ;; the first '/'. We check if the comment prefix matched |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
546 ;; on the current line matches the starter or if it |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
547 ;; matches comment-start-skip, and choose whichever is |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
548 ;; longest. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
549 (max (save-excursion |
88155 | 550 (goto-char (1+ (c-langelem-pos langelem))) |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
551 (if (and (match-string 0) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
552 (looking-at (regexp-quote (match-string 0)))) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
553 (- (match-end 0) (match-beginning 0)) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
554 0)) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
555 (save-excursion |
88155 | 556 (goto-char (c-langelem-pos langelem)) |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
557 (looking-at comment-start-skip) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
558 (- (or (match-end 1) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
559 (save-excursion |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
560 (goto-char (match-end 0)) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
561 (skip-chars-backward " \t") |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
562 (point))) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
563 (point) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
564 1))))) |
26817 | 565 (if (and (> starterlen 10) (zerop prefixlen)) |
566 ;; The comment has a long starter and the line doesn't have | |
567 ;; a nonempty comment prefix. Treat it as free form text | |
568 ;; and don't change the indentation. | |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
569 (vector (current-column)) |
88155 | 570 ;; Go back to the previous non-blank line, if any. |
571 (while | |
572 (progn | |
573 (forward-line -1) | |
574 (back-to-indentation) | |
575 (and (> (point) (c-langelem-pos langelem)) | |
576 (looking-at "[ \t]*$")))) | |
577 ;; Is the starting line the first continuation line with content? | |
578 (if (>= (c-langelem-pos langelem) (point)) | |
26817 | 579 (if (zerop prefixlen) |
580 ;; No nonempty comment prefix. Align after comment | |
581 ;; starter. | |
18720 | 582 (progn |
88155 | 583 (looking-at comment-start-skip) |
26817 | 584 (goto-char (match-end 0)) |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
585 ;; The following should not be necessary, since |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
586 ;; comment-start-skip should match everything (i.e. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
587 ;; typically whitespace) that leads up to the text. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
588 ;;(if (looking-at "\\([ \t]+\\).+$") |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
589 ;; ;; Align with the text that hangs after the |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
590 ;; ;; comment starter. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
591 ;; (goto-char (match-end 1))) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
592 (vector (current-column))) |
26817 | 593 ;; How long is the comment starter? if greater than the |
594 ;; length of the comment prefix, align left. if less | |
595 ;; than or equal, align right. this should also pick up | |
596 ;; Javadoc style comments. | |
597 (if (> starterlen prefixlen) | |
598 (progn | |
88155 | 599 (goto-char (c-langelem-pos langelem)) |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
600 (vector (1+ (current-column)))) |
88155 | 601 (goto-char (+ (c-langelem-pos langelem) starterlen 1)) |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
602 (vector (- (current-column) prefixlen)))) |
88155 | 603 ;; We didn't start on the first non-blank continuation line. If the |
604 ;; previous line has a nonempty comment prefix, align with it. | |
605 ;; Otherwise, align with the previous nonempty line, but align the | |
606 ;; comment ender with the starter. | |
36920 | 607 (when (or (not (looking-at c-current-comment-prefix)) |
26817 | 608 (eq (match-beginning 0) (match-end 0))) |
609 (goto-char here) | |
610 (back-to-indentation) | |
36920 | 611 (if (looking-at (concat "\\(" c-current-comment-prefix "\\)\\*/")) |
88155 | 612 (goto-char (c-langelem-pos langelem)) |
26817 | 613 (while (and (zerop (forward-line -1)) |
614 (looking-at "^[ \t]*$"))) | |
615 (back-to-indentation) | |
88155 | 616 (if (< (point) (c-langelem-pos langelem)) |
26817 | 617 ;; Align with the comment starter rather than |
618 ;; with the code before it. | |
88155 | 619 (goto-char (c-langelem-pos langelem))))) |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
620 (vector (current-column))))))) |
18720 | 621 |
622 (defun c-lineup-comment (langelem) | |
26817 | 623 "Line up a comment start according to `c-comment-only-line-offset'. |
624 If the comment is lined up with a comment starter on the previous | |
625 line, that alignment is preserved. | |
626 | |
627 Works with: comment-intro." | |
18720 | 628 (save-excursion |
629 (back-to-indentation) | |
36920 | 630 (let ((col (current-column))) |
18720 | 631 (cond |
26817 | 632 ;; CASE 1: preserve aligned comments |
633 ((save-excursion | |
88155 | 634 (and (c-backward-single-comment) |
26817 | 635 (= col (current-column)))) |
36920 | 636 (vector col)) ; Return an absolute column. |
18720 | 637 ;; indent as specified by c-comment-only-line-offset |
638 ((not (bolp)) | |
639 (or (car-safe c-comment-only-line-offset) | |
640 c-comment-only-line-offset)) | |
641 (t | |
642 (or (cdr-safe c-comment-only-line-offset) | |
643 (car-safe c-comment-only-line-offset) | |
644 -1000)) ;jam it against the left side | |
645 )))) | |
646 | |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
647 (defun c-lineup-knr-region-comment (langelem) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
648 "Line up a comment in the \"K&R region\" with the declaration. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
649 That is the region between the function or class header and the |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
650 beginning of the block. E.g: |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
651 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
652 int main() |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
653 /* This is the main function. */ <- c-lineup-knr-region-comment |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
654 { |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
655 return 0; |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
656 } |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
657 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
658 Return nil if called in any other situation, to be useful in list |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
659 expressions. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
660 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
661 Works with: comment-intro." |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
662 (when (or (assq 'topmost-intro-cont c-syntactic-context) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
663 (assq 'func-decl-cont c-syntactic-context) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
664 (assq 'knr-argdecl-intro c-syntactic-context) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
665 (assq 'lambda-intro-cont c-syntactic-context)) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
666 (save-excursion |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
667 (beginning-of-line) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
668 (c-beginning-of-statement-1) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
669 (vector (current-column))))) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
670 |
18720 | 671 (defun c-lineup-runin-statements (langelem) |
26817 | 672 "Line up statements when the first statement is on the same line as |
673 the block opening brace. E.g: | |
674 | |
675 int main() | |
676 { puts (\"Hello world!\"); | |
677 return 0; <- c-lineup-runin-statements | |
678 } | |
679 | |
680 If there is no statement after the opening brace to align with, nil is | |
681 returned. This makes the function usable in list expressions. | |
682 | |
683 Works with: The `statement' syntactic symbol." | |
88155 | 684 (if (eq (char-after (c-langelem-pos langelem)) ?{) |
18720 | 685 (save-excursion |
88155 | 686 (if (c-langelem-pos langelem) |
687 (goto-char (c-langelem-pos langelem))) | |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
688 (forward-char 1) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
689 (skip-chars-forward " \t") |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
690 (unless (eolp) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
691 (vector (current-column)))))) |
18720 | 692 |
88155 | 693 (defun c-lineup-assignments (langelem) |
694 "Line up the current line after the assignment operator on the first | |
695 line in the statement. If there isn't any, return nil to allow | |
696 stacking with other line-up functions. If the current line contains | |
697 an assignment operator too, try to align it with the first one. | |
698 | |
699 Works with: topmost-intro-cont, statement-cont, arglist-cont, | |
700 arglist-cont-nonempty." | |
701 (let (startpos endpos equalp) | |
702 | |
703 (if (eq (c-langelem-sym langelem) 'arglist-cont-nonempty) | |
704 ;; If it's an arglist-cont-nonempty then we're only interested | |
705 ;; in equal signs outside it. We don't search for a "=" on | |
706 ;; the current line since that'd have a different nesting | |
707 ;; compared to the one we should align with. | |
708 (save-excursion | |
709 (save-restriction | |
710 (setq endpos (c-langelem-2nd-pos c-syntactic-element)) | |
711 (narrow-to-region (c-langelem-pos langelem) endpos) | |
712 (if (setq startpos (c-up-list-backward endpos)) | |
713 (setq startpos (1+ startpos)) | |
714 (setq startpos (c-langelem-pos langelem))))) | |
26817 | 715 |
88155 | 716 (setq startpos (c-langelem-pos langelem) |
717 endpos (point)) | |
718 | |
719 ;; Find a syntactically relevant and unnested "=" token on the | |
720 ;; current line. equalp is in that case set to the number of | |
721 ;; columns to left shift the current line to align it with the | |
722 ;; goal column. | |
723 (save-excursion | |
724 (beginning-of-line) | |
725 (when (c-syntactic-re-search-forward | |
726 c-assignment-op-regexp | |
727 (c-point 'eol) t t t) | |
728 (setq equalp (- (or (match-beginning 1) | |
729 (match-end 0)) | |
730 (c-point 'boi)))))) | |
731 | |
732 (save-excursion | |
733 (goto-char startpos) | |
734 (if (or (if (c-syntactic-re-search-forward | |
735 c-assignment-op-regexp | |
736 (min endpos (c-point 'eol)) t t t) | |
737 (progn | |
738 (goto-char (or (match-beginning 1) | |
739 (match-end 0))) | |
740 nil) | |
741 t) | |
24282 | 742 (save-excursion |
743 (c-forward-syntactic-ws (c-point 'eol)) | |
744 (eolp))) | |
88155 | 745 ;; There's no equal sign on the line, or there is one but |
746 ;; nothing follows it. | |
747 nil | |
748 | |
18720 | 749 ;; calculate indentation column after equals and ws, unless |
750 ;; our line contains an equals sign | |
751 (if (not equalp) | |
752 (progn | |
753 (skip-chars-forward " \t") | |
754 (setq equalp 0))) | |
88155 | 755 |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
756 (vector (- (current-column) equalp))) |
18720 | 757 ))) |
758 | |
88155 | 759 (defun c-lineup-math (langelem) |
760 "Like `c-lineup-assignments' but indent with `c-basic-offset' if no | |
761 assignment operator was found on the first line. I.e. this function | |
762 is the same as specifying a list (c-lineup-assignments +). It's | |
763 provided for compatibility with old configurations. | |
764 | |
765 Works with: topmost-intro-cont, statement-cont, arglist-cont, | |
766 arglist-cont-nonempty." | |
767 (or (c-lineup-assignments langelem) | |
768 c-basic-offset)) | |
769 | |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
770 (defun c-lineup-cascaded-calls (langelem) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
771 "Line up \"cascaded calls\" under each other. |
88155 | 772 If the line begins with \"->\" or \".\" and the preceding line ends |
773 with one or more function calls preceded by the same token, then the | |
774 arrow is lined up with the first of those tokens. E.g: | |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
775 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
776 result = proc->add(17)->add(18) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
777 ->add(19) + <- c-lineup-cascaded-calls |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
778 offset; <- c-lineup-cascaded-calls (inactive) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
779 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
780 In any other situation nil is returned to allow use in list |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
781 expressions. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
782 |
88155 | 783 Works with: topmost-intro-cont, statement-cont, arglist-cont, |
784 arglist-cont-nonempty." | |
785 | |
786 (if (and (eq (c-langelem-sym langelem) 'arglist-cont-nonempty) | |
787 (not (eq (c-langelem-2nd-pos c-syntactic-element) | |
788 (c-most-enclosing-brace (c-parse-state))))) | |
789 ;; The innermost open paren is not our one, so don't do | |
790 ;; anything. This can occur for arglist-cont-nonempty with | |
791 ;; nested arglist starts on the same line. | |
792 nil | |
793 | |
794 (save-excursion | |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
795 (back-to-indentation) |
88155 | 796 (let ((operator (and (looking-at "->\\|\\.") |
797 (regexp-quote (match-string 0)))) | |
798 (stmt-start (c-langelem-pos langelem)) col) | |
799 | |
800 (when (and operator | |
801 (looking-at operator) | |
802 (zerop (c-backward-token-2 1 t stmt-start)) | |
803 (eq (char-after) ?\() | |
804 (zerop (c-backward-token-2 2 t stmt-start)) | |
805 (looking-at operator)) | |
806 (setq col (current-column)) | |
807 | |
808 (while (and (zerop (c-backward-token-2 1 t stmt-start)) | |
809 (eq (char-after) ?\() | |
810 (zerop (c-backward-token-2 2 t stmt-start)) | |
811 (looking-at operator)) | |
812 (setq col (current-column))) | |
813 | |
814 (vector col)))))) | |
815 | |
816 (defun c-lineup-string-cont (langelem) | |
817 "Line up a continued string under the one it continues. | |
818 A continued string in this sense is where a string literal follows | |
819 directly after another one. E.g: | |
820 | |
821 result = prefix + \"A message \" | |
822 \"string.\"; <- c-lineup-string-cont | |
823 | |
824 Nil is returned in other situations, to allow stacking with other | |
825 line-up functions. | |
826 | |
827 Works with: topmost-intro-cont, statement-cont, arglist-cont, | |
828 arglist-cont-nonempty." | |
829 (save-excursion | |
830 (back-to-indentation) | |
831 (and (looking-at "\\s\"") | |
832 (let ((quote (char-after)) pos) | |
833 (while (and (progn (c-backward-syntactic-ws) | |
834 (eq (char-before) quote)) | |
835 (c-safe (c-backward-sexp) t) | |
836 (/= (setq pos (point)) (c-point 'boi)))) | |
837 (when pos | |
838 (goto-char pos) | |
839 (vector (current-column))))))) | |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
840 |
26817 | 841 (defun c-lineup-template-args (langelem) |
842 "Line up template argument lines under the first argument. | |
843 To allow this function to be used in a list expression, nil is | |
844 returned if there's no template argument on the first line. | |
845 | |
846 Works with: template-args-cont." | |
847 (save-excursion | |
848 (c-with-syntax-table c++-template-syntax-table | |
849 (beginning-of-line) | |
850 (backward-up-list 1) | |
851 (if (and (eq (char-after) ?<) | |
88155 | 852 (zerop (c-forward-token-2 1 nil (c-point 'eol)))) |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
853 (vector (current-column)))))) |
26817 | 854 |
18720 | 855 (defun c-lineup-ObjC-method-call (langelem) |
88155 | 856 "Line up selector args as Emacs Lisp mode does with function args: |
26817 | 857 Go to the position right after the message receiver, and if you are at |
858 the end of the line, indent the current line c-basic-offset columns | |
859 from the opening bracket; otherwise you are looking at the first | |
88155 | 860 character of the first method call argument, so line up the current |
26817 | 861 line with it. |
862 | |
863 Works with: objc-method-call-cont." | |
18720 | 864 (save-excursion |
865 (let* ((extra (save-excursion | |
866 (back-to-indentation) | |
88155 | 867 (c-backward-syntactic-ws (c-langelem-pos langelem)) |
18720 | 868 (if (eq (char-before) ?:) |
869 (- c-basic-offset) | |
870 0))) | |
88155 | 871 (open-bracket-pos (c-langelem-pos langelem)) |
18720 | 872 (open-bracket-col (progn |
873 (goto-char open-bracket-pos) | |
874 (current-column))) | |
875 (target-col (progn | |
876 (forward-char) | |
24282 | 877 (c-forward-sexp) |
18720 | 878 (skip-chars-forward " \t") |
879 (if (eolp) | |
880 (+ open-bracket-col c-basic-offset) | |
881 (current-column)))) | |
882 ) | |
883 (- target-col open-bracket-col extra)))) | |
884 | |
885 (defun c-lineup-ObjC-method-args (langelem) | |
26817 | 886 "Line up the colons that separate args. |
887 The colon on the current line is aligned with the one on the first | |
888 line. | |
889 | |
890 Works with: objc-method-args-cont." | |
18720 | 891 (save-excursion |
892 (let* ((here (c-point 'boi)) | |
893 (curcol (progn (goto-char here) (current-column))) | |
894 (eol (c-point 'eol)) | |
88155 | 895 (relpos (c-langelem-pos langelem)) |
18720 | 896 (first-col-column (progn |
897 (goto-char relpos) | |
898 (skip-chars-forward "^:" eol) | |
899 (and (eq (char-after) ?:) | |
900 (current-column))))) | |
901 (if (not first-col-column) | |
902 c-basic-offset | |
903 (goto-char here) | |
904 (skip-chars-forward "^:" eol) | |
905 (if (eq (char-after) ?:) | |
906 (+ curcol (- first-col-column (current-column))) | |
907 c-basic-offset))))) | |
908 | |
909 (defun c-lineup-ObjC-method-args-2 (langelem) | |
26817 | 910 "Line up the colons that separate args. |
911 The colon on the current line is aligned with the one on the previous | |
912 line. | |
913 | |
914 Works with: objc-method-args-cont." | |
18720 | 915 (save-excursion |
916 (let* ((here (c-point 'boi)) | |
917 (curcol (progn (goto-char here) (current-column))) | |
918 (eol (c-point 'eol)) | |
88155 | 919 (relpos (c-langelem-pos langelem)) |
18720 | 920 (prev-col-column (progn |
921 (skip-chars-backward "^:" relpos) | |
922 (and (eq (char-before) ?:) | |
923 (- (current-column) 1))))) | |
924 (if (not prev-col-column) | |
925 c-basic-offset | |
926 (goto-char here) | |
927 (skip-chars-forward "^:" eol) | |
928 (if (eq (char-after) ?:) | |
929 (+ curcol (- prev-col-column (current-column))) | |
930 c-basic-offset))))) | |
931 | |
24282 | 932 (defun c-lineup-inexpr-block (langelem) |
26817 | 933 "Line up the block for constructs that use a block inside an expression, |
934 e.g. anonymous classes in Java and lambda functions in Pike. The body | |
935 is aligned with the start of the header, e.g. with the \"new\" or | |
936 \"lambda\" keyword. Returns nil if the block isn't part of such a | |
937 construct. | |
938 | |
939 Works with: inlambda, inexpr-statement, inexpr-class." | |
24282 | 940 (save-excursion |
941 (back-to-indentation) | |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
942 (let* ((paren-state (c-parse-state)) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
943 (containing-sexp (c-most-enclosing-brace paren-state)) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
944 (res (or (c-looking-at-inexpr-block |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
945 (c-safe-position containing-sexp paren-state) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
946 containing-sexp) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
947 (and containing-sexp |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
948 (progn (goto-char containing-sexp) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
949 (eq (char-after) ?{)) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
950 (progn (setq containing-sexp |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
951 (c-most-enclosing-brace paren-state |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
952 (point))) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
953 (c-looking-at-inexpr-block |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
954 (c-safe-position containing-sexp paren-state) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
955 containing-sexp)))))) |
26817 | 956 (when res |
24282 | 957 (goto-char (cdr res)) |
88155 | 958 (vector (current-column)))))) |
24282 | 959 |
26817 | 960 (defun c-lineup-whitesmith-in-block (langelem) |
88155 | 961 "Line up lines inside a block in Whitesmith style. |
26817 | 962 It's done in a way that works both when the opening brace hangs and |
963 when it doesn't. E.g: | |
964 | |
965 something | |
966 { something { | |
967 foo; <-> foo; <- c-lineup-whitesmith-in-block | |
968 } } | |
969 <--> c-basic-offset | |
970 | |
971 In the first case the indentation is kept unchanged, in the | |
972 second `c-basic-offset' is added. | |
973 | |
88155 | 974 Works with: defun-close, defun-block-intro, inline-close, block-close, |
975 brace-list-close, brace-list-intro, statement-block-intro, | |
976 arglist-intro, arglist-cont-nonempty, arglist-close, and all in* | |
977 symbols, e.g. inclass and inextern-lang." | |
26817 | 978 (save-excursion |
88155 | 979 (if (and (c-go-up-list-backward) |
980 (= (point) (c-point 'boi))) | |
981 nil | |
26817 | 982 c-basic-offset))) |
983 | |
88155 | 984 (defun c-lineup-after-whitesmith-blocks (langelem) |
985 "Compensate for Whitesmith style indentation of blocks. | |
986 Due to the way CC Mode calculates anchor positions for normal lines | |
987 inside blocks, this function is necessary for those lines to get | |
988 correct Whitesmith style indentation. Consider the following | |
989 examples: | |
990 | |
991 int foo() | |
992 { | |
993 int foo() { | |
994 { a; | |
995 a; } | |
996 x; <-> x; <- c-lineup-after-whitesmith-blocks | |
997 | |
998 The fact that the line with \"x\" is preceded by a Whitesmith style | |
999 indented block in one case and not the other should not affect its | |
1000 indentation. But since CC Mode in cases like this uses the | |
1001 indentation of the preceding statement as anchor position, the \"x\" | |
1002 would in the rightmost case be indented too much if the offset for | |
1003 `statement' was set simply to zero. | |
1004 | |
1005 This lineup function corrects for this situation by detecting if the | |
1006 anchor position is at an open paren character. In that case, it | |
1007 instead indents relative to the surrounding block just like | |
1008 `c-lineup-whitesmith-in-block'. | |
1009 | |
1010 Works with: brace-list-entry, brace-entry-open, statement, | |
1011 arglist-cont." | |
1012 (save-excursion | |
1013 (goto-char (c-langelem-pos langelem)) | |
1014 (when (looking-at "\\s\(") | |
1015 (if (c-go-up-list-backward) | |
1016 (let ((pos (point))) | |
1017 (back-to-indentation) | |
1018 (if (= pos (point)) | |
1019 (vector (current-column)) | |
1020 (vector (+ (current-column) c-basic-offset)))) | |
1021 (vector 0))))) | |
1022 | |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1023 (defun c-lineup-cpp-define (langelem) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1024 "Line up macro continuation lines according to the indentation of |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1025 the construct preceding the macro. E.g: |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1026 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1027 v beg of preceding constr v beg of preceding constr |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1028 int dribble() { |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1029 const char msg[] = if (!running) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1030 \"Some text.\"; error(\"Not running!\"); |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1031 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1032 #define X(A, B) \ #define X(A, B) \ |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1033 do { \ <-> do { \ <- c-lineup-cpp-define |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1034 printf (A, B); \ printf (A, B); \ |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1035 } while (0) } while (0) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1036 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1037 If `c-syntactic-indentation-in-macros' is non-nil, the function |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1038 returns the relative indentation to the macro start line to allow |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1039 accumulation with other offsets. E.g. in the following cases, |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1040 cpp-define-intro is combined with the statement-block-intro that comes |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1041 from the \"do {\" that hangs on the \"#define\" line: |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1042 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1043 int dribble() { |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1044 const char msg[] = if (!running) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1045 \"Some text.\"; error(\"Not running!\"); |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1046 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1047 #define X(A, B) do { \ #define X(A, B) do { \ |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1048 printf (A, B); \ <-> printf (A, B); \ <- c-lineup-cpp-define |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1049 this->refs++; \ this->refs++; \ |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1050 } while (0) <-> } while (0) <- c-lineup-cpp-define |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1051 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1052 The relative indentation returned by `c-lineup-cpp-define' is zero and |
88155 | 1053 two, respectively, in these two examples. They are then added to the |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1054 two column indentation that statement-block-intro gives in both cases |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1055 here. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1056 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1057 If the relative indentation is zero, then nil is returned instead. |
88155 | 1058 That is useful in a list expression to specify the default indentation |
1059 on the top level. | |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1060 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1061 If `c-syntactic-indentation-in-macros' is nil then this function keeps |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1062 the current indentation, except for empty lines \(ignoring the ending |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1063 backslash) where it takes the indentation from the closest preceding |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1064 nonempty line in the macro. If there's no such line in the macro then |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1065 the indentation is taken from the construct preceding it, as described |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1066 above. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1067 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1068 Works with: cpp-define-intro." |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1069 (let (offset) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1070 (if c-syntactic-indentation-in-macros |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1071 ;; Go to the macro start and do a syntactic analysis of it. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1072 ;; Then remove the cpp-macro element it should contain and |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1073 ;; calculate the indentation it then would get. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1074 (save-excursion |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1075 (c-beginning-of-macro) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1076 (setq offset (- (c-get-syntactic-indentation |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1077 (delete '(cpp-macro) (c-guess-basic-syntax))) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1078 (save-excursion |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1079 (back-to-indentation) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1080 (current-column)))) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1081 (if (zerop offset) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1082 nil |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1083 offset)) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1084 ;; Do not indent syntactically inside the macro. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1085 (save-excursion |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1086 (let ((macro-start-line (save-excursion |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1087 (goto-char (c-query-macro-start)) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1088 (beginning-of-line) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1089 (point)))) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1090 (beginning-of-line) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1091 ;; Check every line while inside the macro. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1092 (while (and (> (point) macro-start-line) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1093 (looking-at "[ \t]*\\\\?$") |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1094 (= (forward-line -1) 0))) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1095 (if (<= (point) macro-start-line) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1096 ;; If we've stepped out of the macro we take the |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1097 ;; syntactic offset. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1098 (setq offset (c-get-syntactic-indentation |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1099 (delete '(cpp-macro) (c-guess-basic-syntax)))) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1100 (setq offset (current-indentation))) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1101 (if (zerop offset) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1102 nil |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1103 (vector offset))))))) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1104 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1105 ;; Contributed by Kevin Ryde <user42@zip.com.au>. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1106 (defun c-lineup-gcc-asm-reg (elem) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1107 "Line up a gcc asm register under one on a previous line. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1108 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1109 asm (\"foo %1, %0\\n\" |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1110 \"bar %0, %1\" |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1111 : \"=r\" (w), |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1112 \"=r\" (x) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1113 : \"0\" (y), |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1114 \"1\" (z)); |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1115 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1116 The \"x\" line is aligned to the text after the \":\" on the \"w\" line, and |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1117 similarly \"z\" under \"y\". |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1118 |
88155 | 1119 This is done only in an \"asm\" or \"__asm__\" block, and only to |
1120 those lines mentioned. Anywhere else nil is returned. The usual | |
1121 arrangement is to have this routine as an extra feature at the start | |
1122 of arglist line-ups, e.g. | |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1123 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1124 (c-lineup-gcc-asm-reg c-lineup-arglist) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1125 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1126 Works with: arglist-cont, arglist-cont-nonempty." |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1127 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1128 (let ((orig-pos (point)) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1129 alignto) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1130 (save-excursion |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1131 (and |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1132 c-opt-asm-stmt-key |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1133 |
88155 | 1134 ;; Don't do anything if the innermost open paren isn't our one. |
1135 ;; This can occur for arglist-cont-nonempty with nested arglist | |
1136 ;; starts on the same line. | |
1137 (or (not (eq (car elem) 'arglist-cont-nonempty)) | |
1138 (eq (c-langelem-2nd-pos c-syntactic-element) | |
1139 (c-most-enclosing-brace (c-parse-state)))) | |
1140 | |
44728
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1141 ;; Find the ":" to align to. Look for this first so as to quickly |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1142 ;; eliminate pretty much all cases which are not for us. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1143 (re-search-backward "^[ \t]*:[ \t]*\\(.\\)?" (cdr elem) t) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1144 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1145 ;; Must have something after the ":". |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1146 (setq alignto (match-beginning 1)) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1147 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1148 ;; Don't touch ":" lines themselves. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1149 (progn (goto-char orig-pos) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1150 (beginning-of-line) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1151 (not (looking-at "^[ \t]*:"))) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1152 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1153 ;; Only operate in an asm statement. |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1154 (progn (goto-char orig-pos) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1155 (c-in-gcc-asm-p)) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1156 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1157 (vector (progn (goto-char alignto) (current-column))))))) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1158 |
20911 | 1159 (defun c-lineup-dont-change (langelem) |
26817 | 1160 "Do not change the indentation of the current line. |
1161 | |
1162 Works with: Any syntactic symbol." | |
20911 | 1163 (save-excursion |
1164 (back-to-indentation) | |
36920 | 1165 (vector (current-column)))) |
20911 | 1166 |
1167 | |
18720 | 1168 (defun c-snug-do-while (syntax pos) |
1169 "Dynamically calculate brace hanginess for do-while statements. | |
1170 Using this function, `while' clauses that end a `do-while' block will | |
1171 remain on the same line as the brace that closes that block. | |
1172 | |
1173 See `c-hanging-braces-alist' for how to utilize this function as an | |
1174 ACTION associated with `block-close' syntax." | |
1175 (save-excursion | |
1176 (let (langelem) | |
1177 (if (and (eq syntax 'block-close) | |
1178 (setq langelem (assq 'block-close c-syntactic-context)) | |
88155 | 1179 (progn (goto-char (c-langelem-pos langelem)) |
18720 | 1180 (if (eq (char-after) ?{) |
24282 | 1181 (c-safe (c-forward-sexp -1))) |
18720 | 1182 (looking-at "\\<do\\>[^_]"))) |
1183 '(before) | |
1184 '(before after))))) | |
1185 | |
88155 | 1186 (defun c-snug-1line-defun-close (syntax pos) |
1187 "Determine the brace hanginess for an AWK defun-close. | |
1188 If the action/function being closed is a one-liner, keep it so. Otherwise put | |
1189 the closing brace on its own line." | |
1190 (save-excursion | |
1191 (goto-char pos) | |
1192 (if (> (c-point 'bol) | |
1193 (progn (up-list -1) (point))) | |
1194 '(before after) | |
1195 '(after)))) | |
1196 | |
18720 | 1197 (defun c-gnu-impose-minimum () |
88155 | 1198 "Imposes a minimum indentation for lines inside code blocks. |
18720 | 1199 The variable `c-label-minimum-indentation' specifies the minimum |
1200 indentation amount." | |
88155 | 1201 |
1202 (when (and (not | |
1203 ;; Don't adjust macro or comment-only lines. | |
1204 (or (assq 'cpp-macro c-syntactic-context) | |
1205 (assq 'comment-intro c-syntactic-context))) | |
1206 (c-intersect-lists c-inside-block-syms c-syntactic-context) | |
18720 | 1207 (save-excursion |
1208 (back-to-indentation) | |
88155 | 1209 (< (current-column) c-label-minimum-indentation))) |
1210 (c-shift-line-indentation (- c-label-minimum-indentation | |
1211 (current-indentation))))) | |
18720 | 1212 |
1213 | |
1214 ;; Useful for c-hanging-semi&comma-criteria | |
26817 | 1215 |
18720 | 1216 (defun c-semi&comma-inside-parenlist () |
20911 | 1217 "Controls newline insertion after semicolons in parenthesis lists. |
18720 | 1218 If a comma was inserted, no determination is made. If a semicolon was |
1219 inserted inside a parenthesis list, no newline is added otherwise a | |
1220 newline is added. In either case, checking is stopped. This supports | |
1221 exactly the old newline insertion behavior." | |
1222 ;; newline only after semicolon, but only if that semicolon is not | |
1223 ;; inside a parenthesis list (e.g. a for loop statement) | |
1224 (if (not (eq last-command-char ?\;)) | |
1225 nil ; continue checking | |
1226 (if (condition-case nil | |
1227 (save-excursion | |
1228 (up-list -1) | |
1229 (not (eq (char-after) ?\())) | |
1230 (error t)) | |
1231 t | |
1232 'stop))) | |
1233 | |
20911 | 1234 ;; Suppresses newlines before non-blank lines |
1235 (defun c-semi&comma-no-newlines-before-nonblanks () | |
1236 "Controls newline insertion after semicolons. | |
1237 If a comma was inserted, no determination is made. If a semicolon was | |
1238 inserted, and the following line is not blank, no newline is inserted. | |
1239 Otherwise, no determination is made." | |
1240 (save-excursion | |
1241 (if (and (= last-command-char ?\;) | |
1242 ;;(/= (point-max) | |
1243 ;; (save-excursion (skip-syntax-forward " ") (point)) | |
1244 (zerop (forward-line 1)) | |
88155 | 1245 (bolp) ; forward-line has funny behavior at eob. |
20911 | 1246 (not (looking-at "^[ \t]*$"))) |
1247 'stop | |
1248 nil))) | |
1249 | |
1250 ;; Suppresses new lines after semicolons in one-liners methods | |
1251 (defun c-semi&comma-no-newlines-for-oneline-inliners () | |
1252 "Controls newline insertion after semicolons for some one-line methods. | |
1253 If a comma was inserted, no determination is made. Newlines are | |
1254 suppressed in one-liners, if the line is an in-class inline function. | |
1255 For other semicolon contexts, no determination is made." | |
1256 (let ((syntax (c-guess-basic-syntax)) | |
1257 (bol (save-excursion | |
1258 (if (c-safe (up-list -1) t) | |
1259 (c-point 'bol) | |
1260 -1)))) | |
1261 (if (and (eq last-command-char ?\;) | |
1262 (eq (car (car syntax)) 'inclass) | |
1263 (eq (car (car (cdr syntax))) 'topmost-intro) | |
1264 (= (c-point 'bol) bol)) | |
1265 'stop | |
1266 nil))) | |
1267 | |
18720 | 1268 |
36920 | 1269 (cc-provide 'cc-align) |
38422
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36920
diff
changeset
|
1270 |
88155 | 1271 ;;; arch-tag: 4d71ed28-bf51-4509-a148-f39669669a2e |
18720 | 1272 ;;; cc-align.el ends here |