45 |
(cc-require 'cc-engine) |
(cc-require 'cc-engine) |
46 |
|
|
47 |
|
|
48 |
;; Standard indentation line-ups |
;; Standard line-up functions |
|
|
|
|
;; Calling convention: |
|
|
;; |
|
|
;; The single argument is a cons cell containing the syntactic symbol |
|
|
;; in the car, and the relpos (a.k.a. anchor position) in the cdr. |
|
|
;; The cdr may be nil for syntactic symbols which doesn't have an |
|
|
;; associated relpos. |
|
49 |
;; |
;; |
50 |
;; Some syntactic symbols provide more information, usually more |
;; See the section "Custom Indentation Functions" in the manual for |
51 |
;; interesting positions. The complete list for the syntactic element |
;; details on the calling convention. |
|
;; (beginning with the symbol itself) is available in |
|
|
;; `c-syntactic-element'. |
|
52 |
|
|
53 |
(defun c-lineup-topmost-intro-cont (langelem) |
(defun c-lineup-topmost-intro-cont (langelem) |
54 |
"Line up declaration continuation lines zero or one indentation step. |
"Line up declaration continuation lines zero or one indentation step. |
82 |
Works with: topmost-intro-cont." |
Works with: topmost-intro-cont." |
83 |
(save-excursion |
(save-excursion |
84 |
(beginning-of-line) |
(beginning-of-line) |
85 |
(c-backward-syntactic-ws (cdr langelem)) |
(c-backward-syntactic-ws (c-langelem-pos langelem)) |
86 |
(if (memq (char-before) '(?} ?,)) |
(if (and (memq (char-before) '(?} ?,)) |
87 |
|
(not (and c-overloadable-operators-regexp |
88 |
|
(c-after-special-operator-id)))) |
89 |
c-basic-offset))) |
c-basic-offset))) |
90 |
|
|
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 |
|
|
139 |
(defun c-lineup-arglist (langelem) |
(defun c-lineup-arglist (langelem) |
140 |
"Line up the current argument line under the first argument. |
"Line up the current argument line under the first argument. |
141 |
|
|
142 |
As a special case, if an argument on the same line as the open |
As a special case, if the indented line is inside a brace block |
143 |
parenthesis starts with a brace block opener, the indentation is |
construct, the indentation is `c-basic-offset' only. This is intended |
144 |
`c-basic-offset' only. This is intended as a \"DWIM\" measure in |
as a \"DWIM\" measure in cases like macros that contains statement |
145 |
cases like macros that contains statement blocks, e.g: |
blocks, e.g: |
146 |
|
|
147 |
A_VERY_LONG_MACRO_NAME ({ |
A_VERY_LONG_MACRO_NAME ({ |
148 |
some (code, with + long, lines * in[it]); |
some (code, with + long, lines * in[it]); |
156 |
|
|
157 |
Works with: arglist-cont-nonempty, arglist-close." |
Works with: arglist-cont-nonempty, arglist-close." |
158 |
(save-excursion |
(save-excursion |
159 |
(goto-char (1+ (elt c-syntactic-element 2))) |
(let ((indent-pos (point))) |
160 |
|
|
161 |
;; Don't stop in the middle of a special brace list opener |
(if (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element)) |
162 |
;; like "({". |
c-basic-offset ; DWIM case. |
|
(when c-special-brace-lists |
|
|
(let ((special-list (c-looking-at-special-brace-list))) |
|
|
(when (and special-list (< (car (car special-list)) (point))) |
|
|
(goto-char (+ (car (car special-list)) 2))))) |
|
|
|
|
|
(let ((savepos (point)) |
|
|
(eol (c-point 'eol))) |
|
|
|
|
|
;; Find out if an argument on the same line starts with an |
|
|
;; unclosed open brace paren. Note similar code in |
|
|
;; `c-lineup-close-paren' and |
|
|
;; `c-lineup-arglist-close-under-paren'. |
|
|
(if (and (c-syntactic-re-search-forward "{" eol t t) |
|
|
(looking-at c-syntactic-eol) |
|
|
(progn (backward-char) |
|
|
(not (c-looking-at-special-brace-list))) |
|
|
(progn (c-backward-syntactic-ws) |
|
|
(or (= (point) savepos) |
|
|
(eq (char-before) ?,)))) |
|
|
c-basic-offset |
|
163 |
|
|
164 |
;; Normal case. Indent to the token after the arglist open paren. |
;; Normal case. Indent to the token after the arglist open paren. |
165 |
(goto-char savepos) |
(goto-char (c-langelem-2nd-pos c-syntactic-element)) |
166 |
(c-forward-syntactic-ws) |
(if (and c-special-brace-lists |
167 |
(when (< (point) eol) |
(c-looking-at-special-brace-list)) |
168 |
(goto-char savepos) |
;; Skip a special brace list opener like "({". |
169 |
(skip-chars-forward " \t")) |
(progn (c-forward-token-2) |
170 |
(vector (current-column)))))) |
(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))))))) |
178 |
|
|
179 |
;; Contributed by Kevin Ryde <user42@zip.com.au>. |
;; Contributed by Kevin Ryde <user42@zip.com.au>. |
180 |
(defun c-lineup-argcont (elem) |
(defun c-lineup-argcont (elem) |
200 |
;; isn't, go back to the last position in it. We do this by |
;; 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 |
;; stepping back over open parens until we get to the open paren |
202 |
;; of our argument list. |
;; of our argument list. |
203 |
(let ((open-paren (elt c-syntactic-element 2)) |
(let ((open-paren (c-langelem-2nd-pos c-syntactic-element)) |
204 |
(paren-state (c-parse-state))) |
(paren-state (c-parse-state))) |
205 |
(while (not (eq (car paren-state) open-paren)) |
(while (not (eq (car paren-state) open-paren)) |
206 |
(unless (consp (car paren-state)) ;; ignore matched braces |
(unless (consp (car paren-state)) ;; ignore matched braces |
261 |
arglist-cont-nonempty to line up all lines inside a parenthesis under |
arglist-cont-nonempty to line up all lines inside a parenthesis under |
262 |
the open paren. |
the open paren. |
263 |
|
|
264 |
As a special case, if a brace block is opened at the same line as the |
As a special case, if a brace block construct starts at the same line |
265 |
open parenthesis of the argument list, the indentation is |
as the open parenthesis of the argument list, the indentation is |
266 |
`c-basic-offset' only. See `c-lineup-arglist' for further discussion |
`c-basic-offset' only. See `c-lineup-arglist' for further discussion |
267 |
of this \"DWIM\" measure. |
of this \"DWIM\" measure. |
268 |
|
|
269 |
Works with: Almost all symbols, but are typically most useful on |
Works with: Almost all symbols, but are typically most useful on |
270 |
arglist-close, brace-list-close, arglist-cont and arglist-cont-nonempty." |
arglist-close, brace-list-close, arglist-cont and arglist-cont-nonempty." |
271 |
(save-excursion |
(save-excursion |
272 |
(let (special-list paren-start savepos) |
(if (memq (c-langelem-sym langelem) |
273 |
(if (memq (car langelem) '(arglist-cont-nonempty arglist-close)) |
'(arglist-cont-nonempty arglist-close)) |
274 |
(goto-char (elt c-syntactic-element 2)) |
(goto-char (c-langelem-2nd-pos c-syntactic-element)) |
275 |
(beginning-of-line) |
(beginning-of-line) |
276 |
(c-go-up-list-backward)) |
(c-go-up-list-backward)) |
277 |
|
|
278 |
(if (and c-special-brace-lists |
(if (save-excursion (c-block-in-arglist-dwim (point))) |
279 |
(setq special-list (c-looking-at-special-brace-list))) |
c-basic-offset ; DWIM case. |
|
;; Don't stop in the middle of a special brace list opener |
|
|
;; like "({". |
|
|
(progn |
|
|
(setq paren-start (car (car special-list))) |
|
|
(goto-char (+ paren-start 2))) |
|
|
(setq paren-start (point)) |
|
|
(forward-char 1)) |
|
|
|
|
|
(setq savepos (point)) |
|
|
;; Find out if an argument on the same line starts with an |
|
|
;; unclosed open brace paren. Note similar code in |
|
|
;; `c-lineup-arglist' and `c-lineup-close-paren'. |
|
|
(if (and (c-syntactic-re-search-forward "{" (c-point 'eol) t t) |
|
|
(looking-at c-syntactic-eol) |
|
|
(progn (backward-char) |
|
|
(not (c-looking-at-special-brace-list))) |
|
|
(progn (c-backward-syntactic-ws) |
|
|
(or (= (point) savepos) |
|
|
(eq (char-before) ?,)))) |
|
|
c-basic-offset |
|
280 |
|
|
281 |
;; Normal case. Indent to the arglist open paren. |
;; Normal case. Indent to the arglist open paren. |
282 |
(goto-char paren-start) |
(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)))))) |
(vector (current-column)))))) |
289 |
|
|
290 |
(defun c-lineup-arglist-operators (langelem) |
(defun c-lineup-arglist-operators (langelem) |
291 |
"Line up lines starting with an infix operator under the open paren. |
"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 |
Return nil on lines that don't start with an operator, to leave those |
293 |
cases to other lineup functions. Example: |
cases to other line-up functions. Example: |
294 |
|
|
295 |
if ( x < 10 |
if ( x < 10 |
296 |
|| at_limit (x, <- c-lineup-arglist-operators |
|| at_limit (x, <- c-lineup-arglist-operators |
298 |
) |
) |
299 |
|
|
300 |
Since this function doesn't do anything for lines without an infix |
Since this function doesn't do anything for lines without an infix |
301 |
operator you typically want to use it together with some other lineup |
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 |
settings, e.g. as follows \(the arglist-close setting is just a |
303 |
suggestion to get a consistent style): |
suggestion to get a consistent style): |
304 |
|
|
323 |
char ** int, char ** |
char ** int, char ** |
324 |
) <-> ) <- c-lineup-close-paren |
) <-> ) <- c-lineup-close-paren |
325 |
|
|
326 |
As a special case, if a brace block is opened at the same line as the |
As a special case, if a brace block construct starts at the same line |
327 |
open parenthesis of the argument list, the indentation is |
as the open parenthesis of the argument list, the indentation is |
328 |
`c-basic-offset' instead of the open paren column. See |
`c-basic-offset' instead of the open paren column. See |
329 |
`c-lineup-arglist' for further discussion of this \"DWIM\" measure. |
`c-lineup-arglist' for further discussion of this \"DWIM\" measure. |
330 |
|
|
331 |
Works with: All *-close symbols." |
Works with: All *-close symbols." |
332 |
(save-excursion |
(save-excursion |
333 |
(beginning-of-line) |
(if (memq (c-langelem-sym langelem) |
334 |
(c-go-up-list-backward) |
'(arglist-cont-nonempty arglist-close)) |
335 |
|
(goto-char (c-langelem-2nd-pos c-syntactic-element)) |
336 |
(let ((spec (c-looking-at-special-brace-list)) savepos argstart) |
(beginning-of-line) |
337 |
(if spec (goto-char (car (car spec)))) |
(c-go-up-list-backward)) |
|
(setq savepos (point)) |
|
|
(forward-char 1) |
|
|
(when spec |
|
|
(c-forward-syntactic-ws) |
|
|
(forward-char 1)) |
|
|
|
|
|
(if (looking-at c-syntactic-eol) |
|
|
;; The arglist is "empty". |
|
|
0 |
|
|
|
|
|
;; Find out if an argument on the same line starts with an |
|
|
;; unclosed open brace paren. Note similar code in |
|
|
;; `c-lineup-arglist' and |
|
|
;; `c-lineup-arglist-close-under-paren'. |
|
|
(setq argstart (point)) |
|
|
(if (and (c-syntactic-re-search-forward "{" (c-point 'eol) t t) |
|
|
(looking-at c-syntactic-eol) |
|
|
(progn (backward-char) |
|
|
(not (c-looking-at-special-brace-list))) |
|
|
(progn (c-backward-syntactic-ws) |
|
|
(or (= (point) argstart) |
|
|
(eq (char-before) ?,)))) |
|
|
c-basic-offset |
|
338 |
|
|
339 |
;; Normal case. Indent to the arglist open paren. |
(let (special-list arglist-start) |
340 |
(goto-char savepos) |
(if (and c-special-brace-lists |
341 |
(vector (current-column))))))) |
(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))))))) |
361 |
|
|
362 |
(defun c-lineup-streamop (langelem) |
(defun c-lineup-streamop (langelem) |
363 |
"Line up C++ stream operators under each other. |
"Line up C++ stream operators under each other. |
364 |
|
|
365 |
Works with: stream-op." |
Works with: stream-op." |
366 |
(save-excursion |
(save-excursion |
367 |
(goto-char (cdr langelem)) |
(goto-char (c-langelem-pos langelem)) |
368 |
(re-search-forward "<<\\|>>" (c-point 'eol) 'move) |
(re-search-forward "<<\\|>>" (c-point 'eol) 'move) |
369 |
(goto-char (match-beginning 0)) |
(goto-char (match-beginning 0)) |
370 |
(vector (current-column)))) |
(vector (current-column)))) |
391 |
(let* ((eol (c-point 'eol)) |
(let* ((eol (c-point 'eol)) |
392 |
(here (point)) |
(here (point)) |
393 |
(char-after-ip (char-after))) |
(char-after-ip (char-after))) |
394 |
(if (cdr langelem) (goto-char (cdr langelem))) |
(if (c-langelem-pos langelem) |
395 |
|
(goto-char (c-langelem-pos langelem))) |
396 |
|
|
397 |
;; This kludge is necessary to support both inher-cont and |
;; This kludge is necessary to support both inher-cont and |
398 |
;; member-init-cont, since they have different anchor positions. |
;; member-init-cont, since they have different anchor positions. |
425 |
|
|
426 |
Works with: inher-cont." |
Works with: inher-cont." |
427 |
(save-excursion |
(save-excursion |
428 |
(goto-char (cdr langelem)) |
(goto-char (c-langelem-pos langelem)) |
429 |
(forward-word 1) |
(forward-word 1) |
430 |
(if (looking-at "[ \t]*$") |
(if (looking-at "[ \t]*$") |
431 |
c-basic-offset |
c-basic-offset |
449 |
(save-excursion |
(save-excursion |
450 |
(let* ((lim (1- (c-point 'bol))) |
(let* ((lim (1- (c-point 'bol))) |
451 |
(throws (catch 'done |
(throws (catch 'done |
452 |
(goto-char (cdr langelem)) |
(goto-char (c-langelem-pos langelem)) |
453 |
(while (zerop (c-forward-token-2 1 t lim)) |
(while (zerop (c-forward-token-2 1 t lim)) |
454 |
(if (looking-at "throws\\>[^_]") |
(if (looking-at "throws\\>[^_]") |
455 |
(throw 'done t)))))) |
(throw 'done t)))))) |
547 |
;; matches comment-start-skip, and choose whichever is |
;; matches comment-start-skip, and choose whichever is |
548 |
;; longest. |
;; longest. |
549 |
(max (save-excursion |
(max (save-excursion |
550 |
(goto-char (1+ (cdr langelem))) |
(goto-char (1+ (c-langelem-pos langelem))) |
551 |
(if (and (match-string 0) |
(if (and (match-string 0) |
552 |
(looking-at (regexp-quote (match-string 0)))) |
(looking-at (regexp-quote (match-string 0)))) |
553 |
(- (match-end 0) (match-beginning 0)) |
(- (match-end 0) (match-beginning 0)) |
554 |
0)) |
0)) |
555 |
(save-excursion |
(save-excursion |
556 |
(goto-char (cdr langelem)) |
(goto-char (c-langelem-pos langelem)) |
557 |
(looking-at comment-start-skip) |
(looking-at comment-start-skip) |
558 |
(- (or (match-end 1) |
(- (or (match-end 1) |
559 |
(save-excursion |
(save-excursion |
567 |
;; a nonempty comment prefix. Treat it as free form text |
;; a nonempty comment prefix. Treat it as free form text |
568 |
;; and don't change the indentation. |
;; and don't change the indentation. |
569 |
(vector (current-column)) |
(vector (current-column)) |
570 |
(forward-line -1) |
;; Go back to the previous non-blank line, if any. |
571 |
(back-to-indentation) |
(while |
572 |
(if (>= (cdr langelem) (point)) |
(progn |
573 |
;; On the second line in the comment. |
(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)) |
579 |
(if (zerop prefixlen) |
(if (zerop prefixlen) |
580 |
;; No nonempty comment prefix. Align after comment |
;; No nonempty comment prefix. Align after comment |
581 |
;; starter. |
;; starter. |
582 |
(progn |
(progn |
583 |
|
(looking-at comment-start-skip) |
584 |
(goto-char (match-end 0)) |
(goto-char (match-end 0)) |
585 |
;; The following should not be necessary, since |
;; The following should not be necessary, since |
586 |
;; comment-start-skip should match everything (i.e. |
;; comment-start-skip should match everything (i.e. |
596 |
;; Javadoc style comments. |
;; Javadoc style comments. |
597 |
(if (> starterlen prefixlen) |
(if (> starterlen prefixlen) |
598 |
(progn |
(progn |
599 |
(goto-char (cdr langelem)) |
(goto-char (c-langelem-pos langelem)) |
600 |
(vector (1+ (current-column)))) |
(vector (1+ (current-column)))) |
601 |
(goto-char (+ (cdr langelem) starterlen 1)) |
(goto-char (+ (c-langelem-pos langelem) starterlen 1)) |
602 |
(vector (- (current-column) prefixlen)))) |
(vector (- (current-column) prefixlen)))) |
603 |
;; Not on the second line in the comment. If the previous |
;; We didn't start on the first non-blank continuation line. If the |
604 |
;; line has a nonempty comment prefix, align with it. |
;; previous line has a nonempty comment prefix, align with it. |
605 |
;; Otherwise, align with the previous nonempty line, but |
;; Otherwise, align with the previous nonempty line, but align the |
606 |
;; align the comment ender with the starter. |
;; comment ender with the starter. |
607 |
(when (or (not (looking-at c-current-comment-prefix)) |
(when (or (not (looking-at c-current-comment-prefix)) |
608 |
(eq (match-beginning 0) (match-end 0))) |
(eq (match-beginning 0) (match-end 0))) |
609 |
(goto-char here) |
(goto-char here) |
610 |
(back-to-indentation) |
(back-to-indentation) |
611 |
(if (looking-at (concat "\\(" c-current-comment-prefix "\\)\\*/")) |
(if (looking-at (concat "\\(" c-current-comment-prefix "\\)\\*/")) |
612 |
(goto-char (cdr langelem)) |
(goto-char (c-langelem-pos langelem)) |
613 |
(while (and (zerop (forward-line -1)) |
(while (and (zerop (forward-line -1)) |
614 |
(looking-at "^[ \t]*$"))) |
(looking-at "^[ \t]*$"))) |
615 |
(back-to-indentation) |
(back-to-indentation) |
616 |
(if (< (point) (cdr langelem)) |
(if (< (point) (c-langelem-pos langelem)) |
617 |
;; Align with the comment starter rather than |
;; Align with the comment starter rather than |
618 |
;; with the code before it. |
;; with the code before it. |
619 |
(goto-char (cdr langelem))))) |
(goto-char (c-langelem-pos langelem))))) |
620 |
(vector (current-column))))))) |
(vector (current-column))))))) |
621 |
|
|
622 |
(defun c-lineup-comment (langelem) |
(defun c-lineup-comment (langelem) |
681 |
returned. This makes the function usable in list expressions. |
returned. This makes the function usable in list expressions. |
682 |
|
|
683 |
Works with: The `statement' syntactic symbol." |
Works with: The `statement' syntactic symbol." |
684 |
(if (eq (char-after (cdr langelem)) ?{) |
(if (eq (char-after (c-langelem-pos langelem)) ?{) |
685 |
(save-excursion |
(save-excursion |
686 |
(if (cdr langelem) (goto-char (cdr langelem))) |
(if (c-langelem-pos langelem) |
687 |
|
(goto-char (c-langelem-pos langelem))) |
688 |
(forward-char 1) |
(forward-char 1) |
689 |
(skip-chars-forward " \t") |
(skip-chars-forward " \t") |
690 |
(unless (eolp) |
(unless (eolp) |
691 |
(vector (current-column)))))) |
(vector (current-column)))))) |
692 |
|
|
693 |
(defun c-lineup-math (langelem) |
(defun c-lineup-assignments (langelem) |
694 |
"Line up the current line after the equal sign on the first line in |
"Line up the current line after the assignment operator on the first |
695 |
the statement. If there isn't any, indent with `c-basic-offset'. If |
line in the statement. If there isn't any, return nil to allow |
696 |
the current line contains an equal sign too, try to align it with the |
stacking with other line-up functions. If the current line contains |
697 |
first one. |
an assignment operator too, try to align it with the first one. |
698 |
|
|
699 |
Works with: topmost-intro-cont, statement-cont, arglist-cont, |
Works with: topmost-intro-cont, statement-cont, arglist-cont, |
700 |
arglist-cont-nonempty." |
arglist-cont-nonempty." |
701 |
(let (startpos endpos equalp) |
(let (startpos endpos equalp) |
702 |
|
|
703 |
(if (eq (car langelem) 'arglist-cont-nonempty) |
(if (eq (c-langelem-sym langelem) 'arglist-cont-nonempty) |
704 |
;; If it's an arglist-cont-nonempty then we're only interested |
;; 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 |
;; in equal signs outside it. We don't search for a "=" on |
706 |
;; the current line since that'd have a different nesting |
;; the current line since that'd have a different nesting |
707 |
;; compared to the one we should align with. |
;; compared to the one we should align with. |
708 |
(save-excursion |
(save-excursion |
709 |
(save-restriction |
(save-restriction |
710 |
(setq endpos (nth 2 c-syntactic-element)) |
(setq endpos (c-langelem-2nd-pos c-syntactic-element)) |
711 |
(narrow-to-region (cdr langelem) endpos) |
(narrow-to-region (c-langelem-pos langelem) endpos) |
712 |
(if (setq startpos (c-up-list-backward endpos)) |
(if (setq startpos (c-up-list-backward endpos)) |
713 |
(setq startpos (1+ startpos)) |
(setq startpos (1+ startpos)) |
714 |
(setq startpos (cdr langelem))))) |
(setq startpos (c-langelem-pos langelem))))) |
715 |
|
|
716 |
(setq startpos (cdr langelem) |
(setq startpos (c-langelem-pos langelem) |
717 |
endpos (point)) |
endpos (point)) |
718 |
|
|
719 |
;; Find a syntactically relevant and unnested "=" token on the |
;; Find a syntactically relevant and unnested "=" token on the |
744 |
(eolp))) |
(eolp))) |
745 |
;; There's no equal sign on the line, or there is one but |
;; There's no equal sign on the line, or there is one but |
746 |
;; nothing follows it. |
;; nothing follows it. |
747 |
c-basic-offset |
nil |
748 |
|
|
749 |
;; calculate indentation column after equals and ws, unless |
;; calculate indentation column after equals and ws, unless |
750 |
;; our line contains an equals sign |
;; our line contains an equals sign |
756 |
(vector (- (current-column) equalp))) |
(vector (- (current-column) equalp))) |
757 |
))) |
))) |
758 |
|
|
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 |
|
|
770 |
(defun c-lineup-cascaded-calls (langelem) |
(defun c-lineup-cascaded-calls (langelem) |
771 |
"Line up \"cascaded calls\" under each other. |
"Line up \"cascaded calls\" under each other. |
772 |
If the line begins with \"->\" or \".\" and the preceding line ends |
If the line begins with \"->\" or \".\" and the preceding line ends |
783 |
Works with: topmost-intro-cont, statement-cont, arglist-cont, |
Works with: topmost-intro-cont, statement-cont, arglist-cont, |
784 |
arglist-cont-nonempty." |
arglist-cont-nonempty." |
785 |
|
|
786 |
(if (and (eq (car langelem) 'arglist-cont-nonempty) |
(if (and (eq (c-langelem-sym langelem) 'arglist-cont-nonempty) |
787 |
(not (eq (nth 2 c-syntactic-element) |
(not (eq (c-langelem-2nd-pos c-syntactic-element) |
788 |
(c-most-enclosing-brace (c-parse-state))))) |
(c-most-enclosing-brace (c-parse-state))))) |
789 |
;; The innermost open paren is not our one, so don't do |
;; The innermost open paren is not our one, so don't do |
790 |
;; anything. This can occur for arglist-cont-nonempty with |
;; anything. This can occur for arglist-cont-nonempty with |
795 |
(back-to-indentation) |
(back-to-indentation) |
796 |
(let ((operator (and (looking-at "->\\|\\.") |
(let ((operator (and (looking-at "->\\|\\.") |
797 |
(regexp-quote (match-string 0)))) |
(regexp-quote (match-string 0)))) |
798 |
(stmt-start (cdr langelem)) col) |
(stmt-start (c-langelem-pos langelem)) col) |
799 |
|
|
800 |
(when (and operator |
(when (and operator |
801 |
(looking-at operator) |
(looking-at operator) |
822 |
\"string.\"; <- c-lineup-string-cont |
\"string.\"; <- c-lineup-string-cont |
823 |
|
|
824 |
Nil is returned in other situations, to allow stacking with other |
Nil is returned in other situations, to allow stacking with other |
825 |
lineup functions. |
line-up functions. |
826 |
|
|
827 |
Works with: topmost-intro-cont, statement-cont, arglist-cont, |
Works with: topmost-intro-cont, statement-cont, arglist-cont, |
828 |
arglist-cont-nonempty." |
arglist-cont-nonempty." |
857 |
Go to the position right after the message receiver, and if you are at |
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 |
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 |
from the opening bracket; otherwise you are looking at the first |
860 |
character of the first method call argument, so lineup the current |
character of the first method call argument, so line up the current |
861 |
line with it. |
line with it. |
862 |
|
|
863 |
Works with: objc-method-call-cont." |
Works with: objc-method-call-cont." |
864 |
(save-excursion |
(save-excursion |
865 |
(let* ((extra (save-excursion |
(let* ((extra (save-excursion |
866 |
(back-to-indentation) |
(back-to-indentation) |
867 |
(c-backward-syntactic-ws (cdr langelem)) |
(c-backward-syntactic-ws (c-langelem-pos langelem)) |
868 |
(if (eq (char-before) ?:) |
(if (eq (char-before) ?:) |
869 |
(- c-basic-offset) |
(- c-basic-offset) |
870 |
0))) |
0))) |
871 |
(open-bracket-pos (cdr langelem)) |
(open-bracket-pos (c-langelem-pos langelem)) |
872 |
(open-bracket-col (progn |
(open-bracket-col (progn |
873 |
(goto-char open-bracket-pos) |
(goto-char open-bracket-pos) |
874 |
(current-column))) |
(current-column))) |
892 |
(let* ((here (c-point 'boi)) |
(let* ((here (c-point 'boi)) |
893 |
(curcol (progn (goto-char here) (current-column))) |
(curcol (progn (goto-char here) (current-column))) |
894 |
(eol (c-point 'eol)) |
(eol (c-point 'eol)) |
895 |
(relpos (cdr langelem)) |
(relpos (c-langelem-pos langelem)) |
896 |
(first-col-column (progn |
(first-col-column (progn |
897 |
(goto-char relpos) |
(goto-char relpos) |
898 |
(skip-chars-forward "^:" eol) |
(skip-chars-forward "^:" eol) |
916 |
(let* ((here (c-point 'boi)) |
(let* ((here (c-point 'boi)) |
917 |
(curcol (progn (goto-char here) (current-column))) |
(curcol (progn (goto-char here) (current-column))) |
918 |
(eol (c-point 'eol)) |
(eol (c-point 'eol)) |
919 |
(relpos (cdr langelem)) |
(relpos (c-langelem-pos langelem)) |
920 |
(prev-col-column (progn |
(prev-col-column (progn |
921 |
(skip-chars-backward "^:" relpos) |
(skip-chars-backward "^:" relpos) |
922 |
(and (eq (char-before) ?:) |
(and (eq (char-before) ?:) |
955 |
containing-sexp)))))) |
containing-sexp)))))) |
956 |
(when res |
(when res |
957 |
(goto-char (cdr res)) |
(goto-char (cdr res)) |
958 |
(- (current-column) |
(vector (current-column)))))) |
|
(progn |
|
|
(back-to-indentation) |
|
|
(current-column))))))) |
|
959 |
|
|
960 |
(defun c-lineup-whitesmith-in-block (langelem) |
(defun c-lineup-whitesmith-in-block (langelem) |
961 |
"Line up lines inside a block in whitesmith style. |
"Line up lines inside a block in Whitesmith style. |
962 |
It's done in a way that works both when the opening brace hangs and |
It's done in a way that works both when the opening brace hangs and |
963 |
when it doesn't. E.g: |
when it doesn't. E.g: |
964 |
|
|
971 |
In the first case the indentation is kept unchanged, in the |
In the first case the indentation is kept unchanged, in the |
972 |
second `c-basic-offset' is added. |
second `c-basic-offset' is added. |
973 |
|
|
974 |
Works with: defun-close, defun-block-intro, block-close, |
Works with: defun-close, defun-block-intro, inline-close, block-close, |
975 |
brace-list-close, brace-list-intro, statement-block-intro and all in* |
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." |
symbols, e.g. inclass and inextern-lang." |
978 |
(save-excursion |
(save-excursion |
979 |
(+ (progn |
(if (and (c-go-up-list-backward) |
980 |
(back-to-indentation) |
(= (point) (c-point 'boi))) |
981 |
(if (eq (char-syntax (char-after)) ?\() |
nil |
982 |
c-basic-offset |
c-basic-offset))) |
983 |
0)) |
|
984 |
(progn |
(defun c-lineup-after-whitesmith-blocks (langelem) |
985 |
(goto-char (cdr langelem)) |
"Compensate for Whitesmith style indentation of blocks. |
986 |
(back-to-indentation) |
Due to the way CC Mode calculates anchor positions for normal lines |
987 |
(if (eq (char-syntax (char-after)) ?\() |
inside blocks, this function is necessary for those lines to get |
988 |
0 |
correct Whitesmith style indentation. Consider the following |
989 |
c-basic-offset))))) |
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 |
|
|
1023 |
(defun c-lineup-cpp-define (langelem) |
(defun c-lineup-cpp-define (langelem) |
1024 |
"Line up macro continuation lines according to the indentation of |
"Line up macro continuation lines according to the indentation of |
1116 |
The \"x\" line is aligned to the text after the \":\" on the \"w\" line, and |
The \"x\" line is aligned to the text after the \":\" on the \"w\" line, and |
1117 |
similarly \"z\" under \"y\". |
similarly \"z\" under \"y\". |
1118 |
|
|
1119 |
This is done only in an \"asm\" or \"__asm__\" block, and only to those |
This is done only in an \"asm\" or \"__asm__\" block, and only to |
1120 |
lines mentioned. Anywhere else nil is returned. The usual arrangement is |
those lines mentioned. Anywhere else nil is returned. The usual |
1121 |
to have this routine as an extra feature at the start of arglist lineups, e.g. |
arrangement is to have this routine as an extra feature at the start |
1122 |
|
of arglist line-ups, e.g. |
1123 |
|
|
1124 |
(c-lineup-gcc-asm-reg c-lineup-arglist) |
(c-lineup-gcc-asm-reg c-lineup-arglist) |
1125 |
|
|
1135 |
;; This can occur for arglist-cont-nonempty with nested arglist |
;; This can occur for arglist-cont-nonempty with nested arglist |
1136 |
;; starts on the same line. |
;; starts on the same line. |
1137 |
(or (not (eq (car elem) 'arglist-cont-nonempty)) |
(or (not (eq (car elem) 'arglist-cont-nonempty)) |
1138 |
(eq (elt c-syntactic-element 2) |
(eq (c-langelem-2nd-pos c-syntactic-element) |
1139 |
(c-most-enclosing-brace (c-parse-state)))) |
(c-most-enclosing-brace (c-parse-state)))) |
1140 |
|
|
1141 |
;; Find the ":" to align to. Look for this first so as to quickly |
;; Find the ":" to align to. Look for this first so as to quickly |
1176 |
(let (langelem) |
(let (langelem) |
1177 |
(if (and (eq syntax 'block-close) |
(if (and (eq syntax 'block-close) |
1178 |
(setq langelem (assq 'block-close c-syntactic-context)) |
(setq langelem (assq 'block-close c-syntactic-context)) |
1179 |
(progn (goto-char (elt langelem 1)) |
(progn (goto-char (c-langelem-pos langelem)) |
1180 |
(if (eq (char-after) ?{) |
(if (eq (char-after) ?{) |
1181 |
(c-safe (c-forward-sexp -1))) |
(c-safe (c-forward-sexp -1))) |
1182 |
(looking-at "\\<do\\>[^_]"))) |
(looking-at "\\<do\\>[^_]"))) |
1183 |
'(before) |
'(before) |
1184 |
'(before after))))) |
'(before after))))) |
1185 |
|
|
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 |
|
|
1197 |
(defun c-gnu-impose-minimum () |
(defun c-gnu-impose-minimum () |
1198 |
"Imposes a minimum indentation for lines inside code blocks. |
"Imposes a minimum indentation for lines inside code blocks. |
1199 |
The variable `c-label-minimum-indentation' specifies the minimum |
The variable `c-label-minimum-indentation' specifies the minimum |