Mercurial > emacs
annotate lisp/progmodes/cc-align.el @ 63837:51976224295a
*** empty log message ***
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Wed, 29 Jun 2005 08:06:10 +0000 |
parents | 1975a7b1ec5f |
children | 629afbe74e61 b7da78284d4c |
rev | line source |
---|---|
18720 | 1 ;;; cc-align.el --- custom indentation functions for CC Mode |
2 | |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
3 ;; Copyright (C) 1985,1987,1992-2003 Free Software Foundation, Inc. |
18720 | 4 |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
5 ;; Authors: 1998- Martin Stjernholm |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
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 | |
62641
27b53b1903b6
2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents:
56646
diff
changeset
|
27 ;; along with this program; see the file COPYING. If not, write to |
27b53b1903b6
2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents:
56646
diff
changeset
|
28 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
27b53b1903b6
2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents:
56646
diff
changeset
|
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))) |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
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 | |
48 ;; Standard indentation line-ups | |
26817 | 49 |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
50 ;; Calling convention: |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
51 ;; |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
52 ;; The single argument is a cons cell containing the syntactic symbol |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
53 ;; in the car, and the relpos (a.k.a. anchor position) in the cdr. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
54 ;; The cdr may be nil for syntactic symbols which doesn't have an |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
55 ;; associated relpos. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
56 ;; |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
57 ;; Some syntactic symbols provide more information, usually more |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
58 ;; interesting positions. The complete list for the syntactic element |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
59 ;; (beginning with the symbol itself) is available in |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
60 ;; `c-syntactic-element'. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
61 |
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
|
62 (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
|
63 "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
|
64 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
|
65 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
|
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 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
|
68 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
|
69 { |
7a3ac6c387fe
CC Mode 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 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
|
71 } |
7a3ac6c387fe
CC Mode 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 |
7a3ac6c387fe
CC Mode 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 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 { |
7a3ac6c387fe
CC Mode 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 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
|
77 } |
7a3ac6c387fe
CC Mode 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 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
|
79 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
|
80 <--> 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
|
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 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
|
83 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
|
84 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
|
85 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
86 \(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
|
87 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
|
88 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
|
89 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
|
90 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
91 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
|
92 (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
|
93 (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
|
94 (c-backward-syntactic-ws (cdr 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
|
95 (if (memq (char-before) '(?} ?,)) |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
96 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
|
97 |
18720 | 98 (defun c-lineup-arglist (langelem) |
26817 | 99 "Line up the current argument line under the first argument. |
100 | |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
101 As a special case, if an argument on the same line as the open |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
102 parenthesis starts with a brace block opener, the indentation is |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
103 `c-basic-offset' only. This is intended as a \"DWIM\" measure in |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
104 cases like macros that contains statement blocks, e.g: |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
105 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
106 A_VERY_LONG_MACRO_NAME ({ |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
107 some (code, with + long, lines * in[it]); |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
108 }); |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
109 <--> c-basic-offset |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
110 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
111 This is motivated partly because it's more in line with how code |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
112 blocks are handled, and partly since it approximates the behavior of |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
113 earlier CC Mode versions, which due to inaccurate analysis tended to |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
114 indent such cases this way. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
115 |
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
|
116 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
|
117 (save-excursion |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
118 (goto-char (1+ (elt c-syntactic-element 2))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
119 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
120 ;; Don't stop in the middle of a special brace list opener |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
121 ;; like "({". |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
122 (when c-special-brace-lists |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
123 (let ((special-list (c-looking-at-special-brace-list))) |
56646
b7446b6f097d
Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents:
53073
diff
changeset
|
124 (when (and special-list (< (car (car special-list)) (point))) |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
125 (goto-char (+ (car (car special-list)) 2))))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
126 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
127 (let ((savepos (point)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
128 (eol (c-point 'eol))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
129 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
130 ;; Find out if an argument on the same line starts with an |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
131 ;; unclosed open brace paren. Note similar code in |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
132 ;; `c-lineup-close-paren' and |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
133 ;; `c-lineup-arglist-close-under-paren'. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
134 (if (and (c-syntactic-re-search-forward "{" eol t t) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
135 (looking-at c-syntactic-eol) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
136 (progn (backward-char) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
137 (not (c-looking-at-special-brace-list))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
138 (progn (c-backward-syntactic-ws) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
139 (or (= (point) savepos) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
140 (eq (char-before) ?,)))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
141 c-basic-offset |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
142 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
143 ;; Normal case. Indent to the token after the arglist open paren. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
144 (goto-char savepos) |
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
|
145 (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
|
146 (when (< (point) eol) |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
147 (goto-char savepos) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
148 (skip-chars-forward " \t")) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
149 (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
|
150 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
151 ;; 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
|
152 (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
|
153 "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
|
154 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
155 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
|
156 + 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
|
157 |
50860
4fd35ed09e9b
(c-lineup-argcont, c-lineup-gcc-asm-reg): Don't quote nil and t in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
44728
diff
changeset
|
158 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
|
159 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
|
160 |
63516
1975a7b1ec5f
(c-lineup-argcont): Fix spelling in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
62641
diff
changeset
|
161 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
|
162 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
|
163 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
|
164 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
165 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
|
166 |
18720 | 167 (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
|
168 (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
|
169 |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
170 (when (eq (car elem) 'arglist-cont-nonempty) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
171 ;; Our argument list might not be the innermost one. If it |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
172 ;; isn't, go back to the last position in it. We do this by |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
173 ;; stepping back over open parens until we get to the open paren |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
174 ;; of our argument list. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
175 (let ((open-paren (elt c-syntactic-element 2)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
176 (paren-state (c-parse-state))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
177 (while (not (eq (car paren-state) open-paren)) |
62641
27b53b1903b6
2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents:
56646
diff
changeset
|
178 (unless (consp (car paren-state)) ;; ignore matched braces |
27b53b1903b6
2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents:
56646
diff
changeset
|
179 (goto-char (car paren-state))) |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
180 (setq paren-state (cdr paren-state))))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
181 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
182 (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
|
183 |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
184 (when (bolp) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
185 ;; Previous line ending in a comma means we're the start of an |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
186 ;; argument. This should quickly catch most cases not for us. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
187 ;; This case is only applicable if we're the innermost arglist. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
188 (c-backward-syntactic-ws) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
189 (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
|
190 |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
191 (unless (eq c ?,) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
192 ;; In a gcc asm, ":" on the previous line means the start of an |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
193 ;; argument. And lines starting with ":" are not for us, don't |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
194 ;; want them to indent to the preceding operand. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
195 (let ((gcc-asm (save-excursion |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
196 (goto-char start) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
197 (c-in-gcc-asm-p)))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
198 (unless (and gcc-asm |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
199 (or (eq c ?:) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
200 (save-excursion |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
201 (goto-char start) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
202 (looking-at "[ \t]*:")))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
203 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
204 (c-lineup-argcont-scan (if gcc-asm ?:)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
205 (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
|
206 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
207 (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
|
208 ;; Find the start of an argument, for `c-lineup-argcont'. |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
209 (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
|
210 (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
|
211 (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
|
212 (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
|
213 (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
|
214 (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
|
215 (c-lineup-argcont-scan other-match))))) |
18720 | 216 |
217 (defun c-lineup-arglist-intro-after-paren (langelem) | |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
218 "Line up a line to just after the open paren of the surrounding paren |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
219 or brace block. |
26817 | 220 |
221 Works with: defun-block-intro, brace-list-intro, | |
222 statement-block-intro, statement-case-intro, arglist-intro." | |
18720 | 223 (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
|
224 (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
|
225 (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
|
226 (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
|
227 (vector (1+ (current-column))))) |
18720 | 228 |
229 (defun c-lineup-arglist-close-under-paren (langelem) | |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
230 "Line up a line under the enclosing open paren. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
231 Normally used to line up a closing paren in the same column as its |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
232 corresponding open paren, but can also be used with arglist-cont and |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
233 arglist-cont-nonempty to line up all lines inside a parenthesis under |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
234 the open paren. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
235 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
236 As a special case, if a brace block is opened at the same line as the |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
237 open parenthesis of the argument list, the indentation is |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
238 `c-basic-offset' only. See `c-lineup-arglist' for further discussion |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
239 of this \"DWIM\" measure. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
240 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
241 Works with: Almost all symbols, but are typically most useful on |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
242 arglist-close, brace-list-close, arglist-cont and arglist-cont-nonempty." |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
243 (save-excursion |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
244 (let (special-list paren-start savepos) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
245 (if (memq (car langelem) '(arglist-cont-nonempty arglist-close)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
246 (goto-char (elt c-syntactic-element 2)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
247 (beginning-of-line) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
248 (c-go-up-list-backward)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
249 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
250 (if (and c-special-brace-lists |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
251 (setq special-list (c-looking-at-special-brace-list))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
252 ;; Don't stop in the middle of a special brace list opener |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
253 ;; like "({". |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
254 (progn |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
255 (setq paren-start (car (car special-list))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
256 (goto-char (+ paren-start 2))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
257 (setq paren-start (point)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
258 (forward-char 1)) |
26817 | 259 |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
260 (setq savepos (point)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
261 ;; Find out if an argument on the same line starts with an |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
262 ;; unclosed open brace paren. Note similar code in |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
263 ;; `c-lineup-arglist' and `c-lineup-close-paren'. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
264 (if (and (c-syntactic-re-search-forward "{" (c-point 'eol) t t) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
265 (looking-at c-syntactic-eol) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
266 (progn (backward-char) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
267 (not (c-looking-at-special-brace-list))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
268 (progn (c-backward-syntactic-ws) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
269 (or (= (point) savepos) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
270 (eq (char-before) ?,)))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
271 c-basic-offset |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
272 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
273 ;; Normal case. Indent to the arglist open paren. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
274 (goto-char paren-start) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
275 (vector (current-column)))))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
276 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
277 (defun c-lineup-arglist-operators (langelem) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
278 "Line up lines starting with an infix operator under the open paren. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
279 Return nil on lines that don't start with an operator, to leave those |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
280 cases to other lineup functions. Example: |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
281 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
282 if ( x < 10 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
283 || at_limit (x, <- c-lineup-arglist-operators |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
284 list) <- c-lineup-arglist-operators returns nil |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
285 ) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
286 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
287 Since this function doesn't do anything for lines without an infix |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
288 operator you typically want to use it together with some other lineup |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
289 settings, e.g. as follows \(the arglist-close setting is just a |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
290 suggestion to get a consistent style): |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
291 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
292 \(c-set-offset 'arglist-cont '(c-lineup-arglist-operators 0)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
293 \(c-set-offset 'arglist-cont-nonempty '(c-lineup-arglist-operators |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
294 c-lineup-arglist)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
295 \(c-set-offset 'arglist-close '(c-lineup-arglist-close-under-paren)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
296 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
297 Works with: arglist-cont, arglist-cont-nonempty." |
18720 | 298 (save-excursion |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
299 (back-to-indentation) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
300 (when (looking-at "[-+|&*%<>=]\\|\\(/[^/*]\\)") |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
301 ;; '-' can be both an infix and a prefix operator, but I'm lazy now.. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
302 (c-lineup-arglist-close-under-paren langelem)))) |
18720 | 303 |
20911 | 304 (defun c-lineup-close-paren (langelem) |
26817 | 305 "Line up the closing paren under its corresponding open paren if the |
306 open paren is followed by code. If the open paren ends its line, no | |
307 indentation is added. E.g: | |
308 | |
309 main (int, main ( | |
310 char ** int, char ** | |
311 ) <-> ) <- c-lineup-close-paren | |
312 | |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
313 As a special case, if a brace block is opened at the same line as the |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
314 open parenthesis of the argument list, the indentation is |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
315 `c-basic-offset' instead of the open paren column. See |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
316 `c-lineup-arglist' for further discussion of this \"DWIM\" measure. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
317 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
318 Works with: All *-close symbols." |
20911 | 319 (save-excursion |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
320 (beginning-of-line) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
321 (c-go-up-list-backward) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
322 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
323 (let ((spec (c-looking-at-special-brace-list)) savepos argstart) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
324 (if spec (goto-char (car (car spec)))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
325 (setq savepos (point)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
326 (forward-char 1) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
327 (when spec |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
328 (c-forward-syntactic-ws) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
329 (forward-char 1)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
330 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
331 (if (looking-at c-syntactic-eol) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
332 ;; The arglist is "empty". |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
333 0 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
334 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
335 ;; Find out if an argument on the same line starts with an |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
336 ;; unclosed open brace paren. Note similar code in |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
337 ;; `c-lineup-arglist' and |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
338 ;; `c-lineup-arglist-close-under-paren'. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
339 (setq argstart (point)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
340 (if (and (c-syntactic-re-search-forward "{" (c-point 'eol) t t) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
341 (looking-at c-syntactic-eol) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
342 (progn (backward-char) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
343 (not (c-looking-at-special-brace-list))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
344 (progn (c-backward-syntactic-ws) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
345 (or (= (point) argstart) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
346 (eq (char-before) ?,)))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
347 c-basic-offset |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
348 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
349 ;; Normal case. Indent to the arglist open paren. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
350 (goto-char savepos) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
351 (vector (current-column))))))) |
20911 | 352 |
18720 | 353 (defun c-lineup-streamop (langelem) |
26817 | 354 "Line up C++ stream operators under each other. |
355 | |
356 Works with: stream-op." | |
18720 | 357 (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
|
358 (goto-char (cdr 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
|
359 (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
|
360 (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
|
361 (vector (current-column)))) |
18720 | 362 |
363 (defun c-lineup-multi-inher (langelem) | |
30407
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
364 "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
|
365 initializers under each other. E.g: |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
366 |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
367 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
|
368 public Cyphr, Cyphr (a), |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
369 public Bar <-> Bar (b) <- c-lineup-multi-inher |
26817 | 370 |
30407
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
371 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
|
372 : public Cyphr, : Cyphr (a), |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
373 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
|
374 |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
375 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
|
376 : public Cyphr : Cyphr (a) |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
377 , 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
|
378 |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
379 Works with: inher-cont, member-init-cont." |
18720 | 380 (save-excursion |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
381 (back-to-indentation) |
30407
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
382 (let* ((eol (c-point 'eol)) |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
383 (here (point)) |
56646
b7446b6f097d
Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents:
53073
diff
changeset
|
384 (char-after-ip (char-after))) |
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
|
385 (if (cdr langelem) (goto-char (cdr langelem))) |
30407
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
386 |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
387 ;; 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
|
388 ;; 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
|
389 (c-backward-syntactic-ws) |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
390 (when (eq (char-before) ?:) |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
391 (backward-char) |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
392 (c-backward-syntactic-ws)) |
b88ff2eabd4e
(c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents:
26817
diff
changeset
|
393 |
56646
b7446b6f097d
Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents:
53073
diff
changeset
|
394 (c-syntactic-re-search-forward ":" eol 'move) |
b7446b6f097d
Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents:
53073
diff
changeset
|
395 (if (looking-at c-syntactic-eol) |
b7446b6f097d
Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents:
53073
diff
changeset
|
396 (c-forward-syntactic-ws here) |
b7446b6f097d
Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents:
53073
diff
changeset
|
397 (if (eq char-after-ip ?,) |
b7446b6f097d
Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents:
53073
diff
changeset
|
398 (backward-char) |
b7446b6f097d
Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents:
53073
diff
changeset
|
399 (skip-chars-forward " \t" eol))) |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
400 (if (< (point) here) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
401 (vector (current-column))) |
18720 | 402 ))) |
403 | |
404 (defun c-lineup-java-inher (langelem) | |
26817 | 405 "Line up Java implements and extends declarations. |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
406 If class names follow on the same line as the implements/extends |
26817 | 407 keyword, they are lined up under each other. Otherwise, they are |
408 indented by adding `c-basic-offset' to the column of the keyword. | |
409 E.g: | |
410 | |
411 class Foo class Foo | |
412 extends extends Cyphr, | |
413 Bar <-> Bar <- c-lineup-java-inher | |
414 <--> c-basic-offset | |
415 | |
416 Works with: inher-cont." | |
18720 | 417 (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
|
418 (goto-char (cdr 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
|
419 (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
|
420 (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
|
421 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
|
422 (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
|
423 (vector (current-column))))) |
18720 | 424 |
425 (defun c-lineup-java-throws (langelem) | |
26817 | 426 "Line up Java throws declarations. |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
427 If exception names follow on the same line as the throws keyword, |
26817 | 428 they are lined up under each other. Otherwise, they are indented by |
429 adding `c-basic-offset' to the column of the throws keyword. The | |
430 throws keyword itself is also indented by `c-basic-offset' from the | |
431 function declaration start if it doesn't hang. E.g: | |
432 | |
433 int foo() int foo() throws Cyphr, | |
434 throws <-> Bar, <- c-lineup-java-throws | |
435 Bar <-> Vlod <- c-lineup-java-throws | |
436 <--><--> c-basic-offset | |
437 | |
438 Works with: func-decl-cont." | |
18720 | 439 (save-excursion |
26817 | 440 (let* ((lim (1- (c-point 'bol))) |
441 (throws (catch 'done | |
442 (goto-char (cdr langelem)) | |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
443 (while (zerop (c-forward-token-2 1 t lim)) |
26817 | 444 (if (looking-at "throws\\>[^_]") |
445 (throw 'done t)))))) | |
446 (if throws | |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
447 (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
|
448 (vector (current-column)) |
26817 | 449 (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
|
450 (vector (+ (current-column) c-basic-offset))) |
26817 | 451 c-basic-offset)))) |
18720 | 452 |
20911 | 453 (defun c-indent-one-line-block (langelem) |
26817 | 454 "Indent a one line block `c-basic-offset' extra. |
455 E.g: | |
456 | |
457 if (n > 0) if (n > 0) | |
458 {m+=n; n=0;} <-> { <- c-indent-one-line-block | |
459 <--> c-basic-offset m+=n; n=0; | |
460 } | |
461 | |
36920 | 462 The block may use any kind of parenthesis character. nil is returned |
463 if the line doesn't start with a one line block, which makes the | |
464 function usable in list expressions. | |
26817 | 465 |
466 Work with: Almost all syntactic symbols, but most useful on *-open." | |
20911 | 467 (save-excursion |
26817 | 468 (let ((eol (c-point 'eol))) |
469 (back-to-indentation) | |
470 (if (and (eq (char-syntax (char-after)) ?\() | |
24282 | 471 (c-safe (progn (c-forward-sexp) t)) |
26817 | 472 (<= (point) eol)) |
20911 | 473 c-basic-offset |
26817 | 474 nil)))) |
475 | |
476 (defun c-indent-multi-line-block (langelem) | |
477 "Indent a multi line block `c-basic-offset' extra. | |
478 E.g: | |
479 | |
480 int *foo[] = { int *foo[] = { | |
481 NULL, NULL, | |
482 {17}, <-> { <- c-indent-multi-line-block | |
483 17 | |
484 } | |
485 <--> c-basic-offset | |
486 | |
36920 | 487 The block may use any kind of parenthesis character. nil is returned |
488 if the line doesn't start with a multi line block, which makes the | |
489 function usable in list expressions. | |
26817 | 490 |
491 Work with: Almost all syntactic symbols, but most useful on *-open." | |
492 (save-excursion | |
493 (let ((eol (c-point 'eol))) | |
494 (back-to-indentation) | |
495 (if (and (eq (char-syntax (char-after)) ?\() | |
496 (or (not (c-safe (progn (c-forward-sexp) t))) | |
497 (> (point) eol))) | |
498 c-basic-offset | |
499 nil)))) | |
20911 | 500 |
18720 | 501 (defun c-lineup-C-comments (langelem) |
26817 | 502 "Line up C block comment continuation lines. |
36920 | 503 Various heuristics are used to handle many of the common comment |
26817 | 504 styles. Some examples: |
505 | |
506 /* /** /* /* text /* /** | |
507 * text * text text text ** text ** text | |
508 */ */ */ */ */ */ | |
509 | |
510 /********************************************************************* | |
511 * text | |
512 ********************************************************************/ | |
513 | |
514 /********************************************************************* | |
515 Free form text comments: | |
516 In comments with a long delimiter line at the start, the indentation | |
517 is kept unchanged for lines that start with an empty comment line | |
518 prefix. The delimiter line is whatever matches the | |
519 `comment-start-skip' regexp. | |
520 *********************************************************************/ | |
521 | |
522 The variable `c-comment-prefix-regexp' is used to recognize the | |
523 comment line prefix, e.g. the `*' that usually starts every line | |
524 inside a comment. | |
525 | |
526 Works with: The `c' syntactic symbol." | |
18720 | 527 (save-excursion |
26817 | 528 (let* ((here (point)) |
529 (prefixlen (progn (back-to-indentation) | |
36920 | 530 (if (looking-at c-current-comment-prefix) |
26817 | 531 (- (match-end 0) (point)) |
532 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
|
533 (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
|
534 ;; 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
|
535 ;; 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
|
536 ;; 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
|
537 ;; 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
|
538 ;; 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
|
539 (max (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
|
540 (goto-char (1+ (cdr 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
|
541 (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
|
542 (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
|
543 (- (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
|
544 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
|
545 (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
|
546 (goto-char (cdr 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
|
547 (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
|
548 (- (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
|
549 (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
|
550 (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
|
551 (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
|
552 (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
|
553 (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
|
554 1))))) |
26817 | 555 (if (and (> starterlen 10) (zerop prefixlen)) |
556 ;; The comment has a long starter and the line doesn't have | |
557 ;; a nonempty comment prefix. Treat it as free form text | |
558 ;; 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
|
559 (vector (current-column)) |
26817 | 560 (forward-line -1) |
561 (back-to-indentation) | |
562 (if (>= (cdr langelem) (point)) | |
563 ;; On the second line in the comment. | |
564 (if (zerop prefixlen) | |
565 ;; No nonempty comment prefix. Align after comment | |
566 ;; starter. | |
18720 | 567 (progn |
26817 | 568 (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
|
569 ;; 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
|
570 ;; 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
|
571 ;; 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
|
572 ;;(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
|
573 ;; ;; 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
|
574 ;; ;; 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
|
575 ;; (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
|
576 (vector (current-column))) |
26817 | 577 ;; How long is the comment starter? if greater than the |
578 ;; length of the comment prefix, align left. if less | |
579 ;; than or equal, align right. this should also pick up | |
580 ;; Javadoc style comments. | |
581 (if (> starterlen prefixlen) | |
582 (progn | |
18720 | 583 (goto-char (cdr 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
|
584 (vector (1+ (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
|
585 (goto-char (+ (cdr langelem) starterlen 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
|
586 (vector (- (current-column) prefixlen)))) |
26817 | 587 ;; Not on the second line in the comment. If the previous |
588 ;; line has a nonempty comment prefix, align with it. | |
589 ;; Otherwise, align with the previous nonempty line, but | |
590 ;; align the comment ender with the starter. | |
36920 | 591 (when (or (not (looking-at c-current-comment-prefix)) |
26817 | 592 (eq (match-beginning 0) (match-end 0))) |
593 (goto-char here) | |
594 (back-to-indentation) | |
36920 | 595 (if (looking-at (concat "\\(" c-current-comment-prefix "\\)\\*/")) |
26817 | 596 (goto-char (cdr langelem)) |
597 (while (and (zerop (forward-line -1)) | |
598 (looking-at "^[ \t]*$"))) | |
599 (back-to-indentation) | |
600 (if (< (point) (cdr langelem)) | |
601 ;; Align with the comment starter rather than | |
602 ;; with the code before it. | |
603 (goto-char (cdr 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
|
604 (vector (current-column))))))) |
18720 | 605 |
606 (defun c-lineup-comment (langelem) | |
26817 | 607 "Line up a comment start according to `c-comment-only-line-offset'. |
608 If the comment is lined up with a comment starter on the previous | |
609 line, that alignment is preserved. | |
610 | |
611 Works with: comment-intro." | |
18720 | 612 (save-excursion |
613 (back-to-indentation) | |
36920 | 614 (let ((col (current-column))) |
18720 | 615 (cond |
26817 | 616 ;; CASE 1: preserve aligned comments |
617 ((save-excursion | |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
618 (and (c-backward-single-comment) |
26817 | 619 (= col (current-column)))) |
36920 | 620 (vector col)) ; Return an absolute column. |
18720 | 621 ;; indent as specified by c-comment-only-line-offset |
622 ((not (bolp)) | |
623 (or (car-safe c-comment-only-line-offset) | |
624 c-comment-only-line-offset)) | |
625 (t | |
626 (or (cdr-safe c-comment-only-line-offset) | |
627 (car-safe c-comment-only-line-offset) | |
628 -1000)) ;jam it against the left side | |
629 )))) | |
630 | |
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
|
631 (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
|
632 "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
|
633 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
|
634 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
|
635 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
636 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
|
637 /* 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
|
638 { |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
639 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
|
640 } |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
641 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
642 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
|
643 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
|
644 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
645 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
|
646 (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
|
647 (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
|
648 (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
|
649 (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
|
650 (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
|
651 (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
|
652 (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
|
653 (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
|
654 |
18720 | 655 (defun c-lineup-runin-statements (langelem) |
26817 | 656 "Line up statements when the first statement is on the same line as |
657 the block opening brace. E.g: | |
658 | |
659 int main() | |
660 { puts (\"Hello world!\"); | |
661 return 0; <- c-lineup-runin-statements | |
662 } | |
663 | |
664 If there is no statement after the opening brace to align with, nil is | |
665 returned. This makes the function usable in list expressions. | |
666 | |
667 Works with: The `statement' syntactic symbol." | |
18720 | 668 (if (eq (char-after (cdr langelem)) ?{) |
669 (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
|
670 (if (cdr langelem) (goto-char (cdr 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
|
671 (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
|
672 (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
|
673 (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
|
674 (vector (current-column)))))) |
18720 | 675 |
676 (defun c-lineup-math (langelem) | |
26817 | 677 "Line up the current line after the equal sign on the first line in |
678 the statement. If there isn't any, indent with `c-basic-offset'. If | |
679 the current line contains an equal sign too, try to align it with the | |
680 first one. | |
681 | |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
682 Works with: topmost-intro-cont, statement-cont, arglist-cont, |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
683 arglist-cont-nonempty." |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
684 (let (startpos endpos equalp) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
685 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
686 (if (eq (car langelem) 'arglist-cont-nonempty) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
687 ;; If it's an arglist-cont-nonempty then we're only interested |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
688 ;; in equal signs outside it. We don't search for a "=" on |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
689 ;; the current line since that'd have a different nesting |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
690 ;; compared to the one we should align with. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
691 (save-excursion |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
692 (save-restriction |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
693 (setq endpos (nth 2 c-syntactic-element)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
694 (narrow-to-region (cdr langelem) endpos) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
695 (if (setq startpos (c-up-list-backward endpos)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
696 (setq startpos (1+ startpos)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
697 (setq startpos (cdr langelem))))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
698 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
699 (setq startpos (cdr langelem) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
700 endpos (point)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
701 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
702 ;; Find a syntactically relevant and unnested "=" token on the |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
703 ;; current line. equalp is in that case set to the number of |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
704 ;; columns to left shift the current line to align it with the |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
705 ;; goal column. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
706 (save-excursion |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
707 (beginning-of-line) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
708 (when (c-syntactic-re-search-forward |
52341
6a060e586596
(c-lineup-math): Don't align the operators "!=", "<=" and ">=" as assignment
Martin Stjernholm <mast@lysator.liu.se>
parents:
51714
diff
changeset
|
709 c-assignment-op-regexp |
6a060e586596
(c-lineup-math): Don't align the operators "!=", "<=" and ">=" as assignment
Martin Stjernholm <mast@lysator.liu.se>
parents:
51714
diff
changeset
|
710 (c-point 'eol) t t t) |
6a060e586596
(c-lineup-math): Don't align the operators "!=", "<=" and ">=" as assignment
Martin Stjernholm <mast@lysator.liu.se>
parents:
51714
diff
changeset
|
711 (setq equalp (- (or (match-beginning 1) |
6a060e586596
(c-lineup-math): Don't align the operators "!=", "<=" and ">=" as assignment
Martin Stjernholm <mast@lysator.liu.se>
parents:
51714
diff
changeset
|
712 (match-end 0)) |
6a060e586596
(c-lineup-math): Don't align the operators "!=", "<=" and ">=" as assignment
Martin Stjernholm <mast@lysator.liu.se>
parents:
51714
diff
changeset
|
713 (c-point 'boi)))))) |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
714 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
715 (save-excursion |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
716 (goto-char startpos) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
717 (if (or (if (c-syntactic-re-search-forward |
52341
6a060e586596
(c-lineup-math): Don't align the operators "!=", "<=" and ">=" as assignment
Martin Stjernholm <mast@lysator.liu.se>
parents:
51714
diff
changeset
|
718 c-assignment-op-regexp |
6a060e586596
(c-lineup-math): Don't align the operators "!=", "<=" and ">=" as assignment
Martin Stjernholm <mast@lysator.liu.se>
parents:
51714
diff
changeset
|
719 (min endpos (c-point 'eol)) t t t) |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
720 (progn |
52341
6a060e586596
(c-lineup-math): Don't align the operators "!=", "<=" and ">=" as assignment
Martin Stjernholm <mast@lysator.liu.se>
parents:
51714
diff
changeset
|
721 (goto-char (or (match-beginning 1) |
6a060e586596
(c-lineup-math): Don't align the operators "!=", "<=" and ">=" as assignment
Martin Stjernholm <mast@lysator.liu.se>
parents:
51714
diff
changeset
|
722 (match-end 0))) |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
723 nil) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
724 t) |
24282 | 725 (save-excursion |
726 (c-forward-syntactic-ws (c-point 'eol)) | |
727 (eolp))) | |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
728 ;; There's no equal sign on the line, or there is one but |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
729 ;; nothing follows it. |
18720 | 730 c-basic-offset |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
731 |
18720 | 732 ;; calculate indentation column after equals and ws, unless |
733 ;; our line contains an equals sign | |
734 (if (not equalp) | |
735 (progn | |
736 (skip-chars-forward " \t") | |
737 (setq equalp 0))) | |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
738 |
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
|
739 (vector (- (current-column) equalp))) |
18720 | 740 ))) |
741 | |
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
|
742 (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
|
743 "Line up \"cascaded calls\" under each other. |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
744 If the line begins with \"->\" or \".\" and the preceding line ends |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
745 with one or more function calls preceded by the same token, then the |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
746 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
|
747 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
748 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
|
749 ->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
|
750 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
|
751 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
752 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
|
753 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
|
754 |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
755 Works with: topmost-intro-cont, statement-cont, arglist-cont, |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
756 arglist-cont-nonempty." |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
757 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
758 (if (and (eq (car langelem) 'arglist-cont-nonempty) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
759 (not (eq (nth 2 c-syntactic-element) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
760 (c-most-enclosing-brace (c-parse-state))))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
761 ;; The innermost open paren is not our one, so don't do |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
762 ;; anything. This can occur for arglist-cont-nonempty with |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
763 ;; nested arglist starts on the same line. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
764 nil |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
765 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
766 (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
|
767 (back-to-indentation) |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
768 (let ((operator (and (looking-at "->\\|\\.") |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
769 (regexp-quote (match-string 0)))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
770 (stmt-start (cdr langelem)) col) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
771 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
772 (when (and operator |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
773 (looking-at operator) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
774 (zerop (c-backward-token-2 1 t stmt-start)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
775 (eq (char-after) ?\() |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
776 (zerop (c-backward-token-2 2 t stmt-start)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
777 (looking-at operator)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
778 (setq col (current-column)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
779 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
780 (while (and (zerop (c-backward-token-2 1 t stmt-start)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
781 (eq (char-after) ?\() |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
782 (zerop (c-backward-token-2 2 t stmt-start)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
783 (looking-at operator)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
784 (setq col (current-column))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
785 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
786 (vector col)))))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
787 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
788 (defun c-lineup-string-cont (langelem) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
789 "Line up a continued string under the one it continues. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
790 A continued string in this sense is where a string literal follows |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
791 directly after another one. E.g: |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
792 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
793 result = prefix + \"A message \" |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
794 \"string.\"; <- c-lineup-string-cont |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
795 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
796 Nil is returned in other situations, to allow stacking with other |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
797 lineup functions. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
798 |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
799 Works with: topmost-intro-cont, statement-cont, arglist-cont, |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
800 arglist-cont-nonempty." |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
801 (save-excursion |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
802 (back-to-indentation) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
803 (and (looking-at "\\s\"") |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
804 (let ((quote (char-after)) pos) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
805 (while (and (progn (c-backward-syntactic-ws) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
806 (eq (char-before) quote)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
807 (c-safe (c-backward-sexp) t) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
808 (/= (setq pos (point)) (c-point 'boi)))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
809 (when pos |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
810 (goto-char pos) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
811 (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
|
812 |
26817 | 813 (defun c-lineup-template-args (langelem) |
814 "Line up template argument lines under the first argument. | |
815 To allow this function to be used in a list expression, nil is | |
816 returned if there's no template argument on the first line. | |
817 | |
818 Works with: template-args-cont." | |
819 (save-excursion | |
820 (c-with-syntax-table c++-template-syntax-table | |
821 (beginning-of-line) | |
822 (backward-up-list 1) | |
823 (if (and (eq (char-after) ?<) | |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
824 (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
|
825 (vector (current-column)))))) |
26817 | 826 |
18720 | 827 (defun c-lineup-ObjC-method-call (langelem) |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
828 "Line up selector args as Emacs Lisp mode does with function args: |
26817 | 829 Go to the position right after the message receiver, and if you are at |
830 the end of the line, indent the current line c-basic-offset columns | |
831 from the opening bracket; otherwise you are looking at the first | |
832 character of the first method call argument, so lineup the current | |
833 line with it. | |
834 | |
835 Works with: objc-method-call-cont." | |
18720 | 836 (save-excursion |
837 (let* ((extra (save-excursion | |
838 (back-to-indentation) | |
839 (c-backward-syntactic-ws (cdr langelem)) | |
840 (if (eq (char-before) ?:) | |
841 (- c-basic-offset) | |
842 0))) | |
843 (open-bracket-pos (cdr langelem)) | |
844 (open-bracket-col (progn | |
845 (goto-char open-bracket-pos) | |
846 (current-column))) | |
847 (target-col (progn | |
848 (forward-char) | |
24282 | 849 (c-forward-sexp) |
18720 | 850 (skip-chars-forward " \t") |
851 (if (eolp) | |
852 (+ open-bracket-col c-basic-offset) | |
853 (current-column)))) | |
854 ) | |
855 (- target-col open-bracket-col extra)))) | |
856 | |
857 (defun c-lineup-ObjC-method-args (langelem) | |
26817 | 858 "Line up the colons that separate args. |
859 The colon on the current line is aligned with the one on the first | |
860 line. | |
861 | |
862 Works with: objc-method-args-cont." | |
18720 | 863 (save-excursion |
864 (let* ((here (c-point 'boi)) | |
865 (curcol (progn (goto-char here) (current-column))) | |
866 (eol (c-point 'eol)) | |
867 (relpos (cdr langelem)) | |
868 (first-col-column (progn | |
869 (goto-char relpos) | |
870 (skip-chars-forward "^:" eol) | |
871 (and (eq (char-after) ?:) | |
872 (current-column))))) | |
873 (if (not first-col-column) | |
874 c-basic-offset | |
875 (goto-char here) | |
876 (skip-chars-forward "^:" eol) | |
877 (if (eq (char-after) ?:) | |
878 (+ curcol (- first-col-column (current-column))) | |
879 c-basic-offset))))) | |
880 | |
881 (defun c-lineup-ObjC-method-args-2 (langelem) | |
26817 | 882 "Line up the colons that separate args. |
883 The colon on the current line is aligned with the one on the previous | |
884 line. | |
885 | |
886 Works with: objc-method-args-cont." | |
18720 | 887 (save-excursion |
888 (let* ((here (c-point 'boi)) | |
889 (curcol (progn (goto-char here) (current-column))) | |
890 (eol (c-point 'eol)) | |
891 (relpos (cdr langelem)) | |
892 (prev-col-column (progn | |
893 (skip-chars-backward "^:" relpos) | |
894 (and (eq (char-before) ?:) | |
895 (- (current-column) 1))))) | |
896 (if (not prev-col-column) | |
897 c-basic-offset | |
898 (goto-char here) | |
899 (skip-chars-forward "^:" eol) | |
900 (if (eq (char-after) ?:) | |
901 (+ curcol (- prev-col-column (current-column))) | |
902 c-basic-offset))))) | |
903 | |
24282 | 904 (defun c-lineup-inexpr-block (langelem) |
26817 | 905 "Line up the block for constructs that use a block inside an expression, |
906 e.g. anonymous classes in Java and lambda functions in Pike. The body | |
907 is aligned with the start of the header, e.g. with the \"new\" or | |
908 \"lambda\" keyword. Returns nil if the block isn't part of such a | |
909 construct. | |
910 | |
911 Works with: inlambda, inexpr-statement, inexpr-class." | |
24282 | 912 (save-excursion |
913 (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
|
914 (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
|
915 (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
|
916 (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
|
917 (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
|
918 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
|
919 (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
|
920 (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
|
921 (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
|
922 (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
|
923 (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
|
924 (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
|
925 (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
|
926 (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
|
927 containing-sexp)))))) |
26817 | 928 (when res |
24282 | 929 (goto-char (cdr res)) |
930 (- (current-column) | |
931 (progn | |
932 (back-to-indentation) | |
933 (current-column))))))) | |
934 | |
26817 | 935 (defun c-lineup-whitesmith-in-block (langelem) |
936 "Line up lines inside a block in whitesmith style. | |
937 It's done in a way that works both when the opening brace hangs and | |
938 when it doesn't. E.g: | |
939 | |
940 something | |
941 { something { | |
942 foo; <-> foo; <- c-lineup-whitesmith-in-block | |
943 } } | |
944 <--> c-basic-offset | |
945 | |
946 In the first case the indentation is kept unchanged, in the | |
947 second `c-basic-offset' is added. | |
948 | |
949 Works with: defun-close, defun-block-intro, block-close, | |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
950 brace-list-close, brace-list-intro, statement-block-intro and all in* |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
951 symbols, e.g. inclass and inextern-lang." |
26817 | 952 (save-excursion |
56646
b7446b6f097d
Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents:
53073
diff
changeset
|
953 (+ (progn |
b7446b6f097d
Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents:
53073
diff
changeset
|
954 (back-to-indentation) |
b7446b6f097d
Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents:
53073
diff
changeset
|
955 (if (eq (char-syntax (char-after)) ?\() |
b7446b6f097d
Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents:
53073
diff
changeset
|
956 c-basic-offset |
b7446b6f097d
Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents:
53073
diff
changeset
|
957 0)) |
b7446b6f097d
Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents:
53073
diff
changeset
|
958 (progn |
b7446b6f097d
Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents:
53073
diff
changeset
|
959 (goto-char (cdr langelem)) |
b7446b6f097d
Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents:
53073
diff
changeset
|
960 (back-to-indentation) |
b7446b6f097d
Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents:
53073
diff
changeset
|
961 (if (eq (char-syntax (char-after)) ?\() |
b7446b6f097d
Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents:
53073
diff
changeset
|
962 0 |
b7446b6f097d
Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents:
53073
diff
changeset
|
963 c-basic-offset))))) |
26817 | 964 |
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
|
965 (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
|
966 "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
|
967 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
|
968 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
969 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
|
970 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
|
971 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
|
972 \"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
|
973 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
974 #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
|
975 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
|
976 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
|
977 } 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
|
978 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
979 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
|
980 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
|
981 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
|
982 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
|
983 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
|
984 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
985 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
|
986 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
|
987 \"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
|
988 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
989 #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
|
990 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
|
991 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
|
992 } 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
|
993 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
994 The relative indentation returned by `c-lineup-cpp-define' is zero and |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
995 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
|
996 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
|
997 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
|
998 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
999 If the relative indentation is zero, then nil is returned instead. |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
1000 That is useful in a list expression to specify the default indentation |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
1001 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
|
1002 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1003 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
|
1004 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
|
1005 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
|
1006 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
|
1007 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
|
1008 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
|
1009 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1010 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
|
1011 (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
|
1012 (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
|
1013 ;; 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
|
1014 ;; 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
|
1015 ;; 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
|
1016 (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
|
1017 (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
|
1018 (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
|
1019 (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
|
1020 (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
|
1021 (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
|
1022 (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
|
1023 (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
|
1024 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
|
1025 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
|
1026 ;; 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
|
1027 (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
|
1028 (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
|
1029 (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
|
1030 (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
|
1031 (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
|
1032 (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
|
1033 ;; 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
|
1034 (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
|
1035 (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
|
1036 (= (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
|
1037 (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
|
1038 ;; 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
|
1039 ;; 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
|
1040 (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
|
1041 (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
|
1042 (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
|
1043 (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
|
1044 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
|
1045 (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
|
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 ;; 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
|
1048 (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
|
1049 "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
|
1050 |
7a3ac6c387fe
CC Mode 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 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
|
1052 \"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
|
1053 : \"=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
|
1054 \"=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
|
1055 : \"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
|
1056 \"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
|
1057 |
7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents:
38422
diff
changeset
|
1058 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
|
1059 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
|
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 This is done only in an \"asm\" or \"__asm__\" block, and only to those |
50860
4fd35ed09e9b
(c-lineup-argcont, c-lineup-gcc-asm-reg): Don't quote nil and t in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
44728
diff
changeset
|
1062 lines mentioned. Anywhere else nil is returned. The usual arrangement is |
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
|
1063 to have this routine as an extra feature at the start of arglist lineups, 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
|
1064 |
7a3ac6c387fe
CC Mode 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 (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
|
1066 |
7a3ac6c387fe
CC Mode 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 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
|
1068 |
7a3ac6c387fe
CC Mode 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 ((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
|
1070 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
|
1071 (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
|
1072 (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 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
|
1074 |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
1075 ;; Don't do anything if the innermost open paren isn't our one. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
1076 ;; This can occur for arglist-cont-nonempty with nested arglist |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
1077 ;; starts on the same line. |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
1078 (or (not (eq (car elem) 'arglist-cont-nonempty)) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
1079 (eq (elt c-syntactic-element 2) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
1080 (c-most-enclosing-brace (c-parse-state)))) |
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
1081 |
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
|
1082 ;; 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
|
1083 ;; 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
|
1084 (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
|
1085 |
7a3ac6c387fe
CC Mode 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 ;; 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
|
1087 (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
|
1088 |
7a3ac6c387fe
CC Mode 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 ;; 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
|
1090 (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
|
1091 (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
|
1092 (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
|
1093 |
7a3ac6c387fe
CC Mode 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 ;; 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
|
1095 (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
|
1096 (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
|
1097 |
7a3ac6c387fe
CC Mode 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 (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
|
1099 |
20911 | 1100 (defun c-lineup-dont-change (langelem) |
26817 | 1101 "Do not change the indentation of the current line. |
1102 | |
1103 Works with: Any syntactic symbol." | |
20911 | 1104 (save-excursion |
1105 (back-to-indentation) | |
36920 | 1106 (vector (current-column)))) |
20911 | 1107 |
1108 | |
18720 | 1109 (defun c-snug-do-while (syntax pos) |
1110 "Dynamically calculate brace hanginess for do-while statements. | |
1111 Using this function, `while' clauses that end a `do-while' block will | |
1112 remain on the same line as the brace that closes that block. | |
1113 | |
1114 See `c-hanging-braces-alist' for how to utilize this function as an | |
1115 ACTION associated with `block-close' syntax." | |
1116 (save-excursion | |
1117 (let (langelem) | |
1118 (if (and (eq syntax 'block-close) | |
1119 (setq langelem (assq 'block-close c-syntactic-context)) | |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
1120 (progn (goto-char (elt langelem 1)) |
18720 | 1121 (if (eq (char-after) ?{) |
24282 | 1122 (c-safe (c-forward-sexp -1))) |
18720 | 1123 (looking-at "\\<do\\>[^_]"))) |
1124 '(before) | |
1125 '(before after))))) | |
1126 | |
1127 (defun c-gnu-impose-minimum () | |
53073
49f65e04ba8e
CC Mode update (5.30.8).
Martin Stjernholm <mast@lysator.liu.se>
parents:
52401
diff
changeset
|
1128 "Imposes a minimum indentation for lines inside code blocks. |
18720 | 1129 The variable `c-label-minimum-indentation' specifies the minimum |
1130 indentation amount." | |
51714
bc91cbf50c24
Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents:
50860
diff
changeset
|
1131 |
53073
49f65e04ba8e
CC Mode update (5.30.8).
Martin Stjernholm <mast@lysator.liu.se>
parents:
52401
diff
changeset
|
1132 (when (and (not |
49f65e04ba8e
CC Mode update (5.30.8).
Martin Stjernholm <mast@lysator.liu.se>
parents:
52401
diff
changeset
|
1133 ;; Don't adjust macro or comment-only lines. |
49f65e04ba8e
CC Mode update (5.30.8).
Martin Stjernholm <mast@lysator.liu.se>
parents:
52401
diff
changeset
|
1134 (or (assq 'cpp-macro c-syntactic-context) |
49f65e04ba8e
CC Mode update (5.30.8).
Martin Stjernholm <mast@lysator.liu.se>
parents:
52401
diff
changeset
|
1135 (assq 'comment-intro c-syntactic-context))) |
49f65e04ba8e
CC Mode update (5.30.8).
Martin Stjernholm <mast@lysator.liu.se>
parents:
52401
diff
changeset
|
1136 (c-intersect-lists c-inside-block-syms c-syntactic-context) |
49f65e04ba8e
CC Mode update (5.30.8).
Martin Stjernholm <mast@lysator.liu.se>
parents:
52401
diff
changeset
|
1137 (save-excursion |
49f65e04ba8e
CC Mode update (5.30.8).
Martin Stjernholm <mast@lysator.liu.se>
parents:
52401
diff
changeset
|
1138 (back-to-indentation) |
49f65e04ba8e
CC Mode update (5.30.8).
Martin Stjernholm <mast@lysator.liu.se>
parents:
52401
diff
changeset
|
1139 (< (current-column) c-label-minimum-indentation))) |
49f65e04ba8e
CC Mode update (5.30.8).
Martin Stjernholm <mast@lysator.liu.se>
parents:
52401
diff
changeset
|
1140 (c-shift-line-indentation (- c-label-minimum-indentation |
49f65e04ba8e
CC Mode update (5.30.8).
Martin Stjernholm <mast@lysator.liu.se>
parents:
52401
diff
changeset
|
1141 (current-indentation))))) |
18720 | 1142 |
1143 | |
1144 ;; Useful for c-hanging-semi&comma-criteria | |
26817 | 1145 |
18720 | 1146 (defun c-semi&comma-inside-parenlist () |
20911 | 1147 "Controls newline insertion after semicolons in parenthesis lists. |
18720 | 1148 If a comma was inserted, no determination is made. If a semicolon was |
1149 inserted inside a parenthesis list, no newline is added otherwise a | |
1150 newline is added. In either case, checking is stopped. This supports | |
1151 exactly the old newline insertion behavior." | |
1152 ;; newline only after semicolon, but only if that semicolon is not | |
1153 ;; inside a parenthesis list (e.g. a for loop statement) | |
1154 (if (not (eq last-command-char ?\;)) | |
1155 nil ; continue checking | |
1156 (if (condition-case nil | |
1157 (save-excursion | |
1158 (up-list -1) | |
1159 (not (eq (char-after) ?\())) | |
1160 (error t)) | |
1161 t | |
1162 'stop))) | |
1163 | |
20911 | 1164 ;; Suppresses newlines before non-blank lines |
1165 (defun c-semi&comma-no-newlines-before-nonblanks () | |
1166 "Controls newline insertion after semicolons. | |
1167 If a comma was inserted, no determination is made. If a semicolon was | |
1168 inserted, and the following line is not blank, no newline is inserted. | |
1169 Otherwise, no determination is made." | |
1170 (save-excursion | |
1171 (if (and (= last-command-char ?\;) | |
1172 ;;(/= (point-max) | |
1173 ;; (save-excursion (skip-syntax-forward " ") (point)) | |
1174 (zerop (forward-line 1)) | |
62641
27b53b1903b6
2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents:
56646
diff
changeset
|
1175 (bolp) ; forward-line has funny behavior at eob. |
20911 | 1176 (not (looking-at "^[ \t]*$"))) |
1177 'stop | |
1178 nil))) | |
1179 | |
1180 ;; Suppresses new lines after semicolons in one-liners methods | |
1181 (defun c-semi&comma-no-newlines-for-oneline-inliners () | |
1182 "Controls newline insertion after semicolons for some one-line methods. | |
1183 If a comma was inserted, no determination is made. Newlines are | |
1184 suppressed in one-liners, if the line is an in-class inline function. | |
1185 For other semicolon contexts, no determination is made." | |
1186 (let ((syntax (c-guess-basic-syntax)) | |
1187 (bol (save-excursion | |
1188 (if (c-safe (up-list -1) t) | |
1189 (c-point 'bol) | |
1190 -1)))) | |
1191 (if (and (eq last-command-char ?\;) | |
1192 (eq (car (car syntax)) 'inclass) | |
1193 (eq (car (car (cdr syntax))) 'topmost-intro) | |
1194 (= (c-point 'bol) bol)) | |
1195 'stop | |
1196 nil))) | |
1197 | |
18720 | 1198 |
36920 | 1199 (cc-provide 'cc-align) |
38422
7a94f1c588c4
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
36920
diff
changeset
|
1200 |
52401 | 1201 ;;; arch-tag: 4d71ed28-bf51-4509-a148-f39669669a2e |
18720 | 1202 ;;; cc-align.el ends here |