Mercurial > emacs
annotate lisp/progmodes/cc-engine.el @ 21433:25b02305130b
(Man-getpage-in-background): Bind inhibit-eol-conversion
to t before calling start-process or call-process.
author | Karl Heuer <kwzh@gnu.org> |
---|---|
date | Wed, 08 Apr 1998 18:53:13 +0000 |
parents | 5e5fa0a34cb0 |
children | 5b0864259a4b |
rev | line source |
---|---|
18720 | 1 ;;; cc-engine.el --- core syntax guessing engine for CC mode |
2 | |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
3 ;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc. |
18720 | 4 |
5 ;; Authors: 1992-1997 Barry A. Warsaw | |
6 ;; 1987 Dave Detlefs and Stewart Clamen | |
7 ;; 1985 Richard M. Stallman | |
8 ;; Maintainer: cc-mode-help@python.org | |
9 ;; Created: 22-Apr-1997 (split from cc-mode.el) | |
20142 | 10 ;; Version: See cc-mode.el |
18720 | 11 ;; Keywords: c languages oop |
12 | |
13 ;; This file is part of GNU Emacs. | |
14 | |
15 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
16 ;; it under the terms of the GNU General Public License as published by | |
17 ;; the Free Software Foundation; either version 2, or (at your option) | |
18 ;; any later version. | |
19 | |
20 ;; GNU Emacs is distributed in the hope that it will be useful, | |
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 ;; GNU General Public License for more details. | |
24 | |
25 ;; You should have received a copy of the GNU General Public License | |
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
28 ;; Boston, MA 02111-1307, USA. | |
29 | |
30 | |
18844
6b269c4ad2eb
(c-maybe-labelp): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18720
diff
changeset
|
31 ;; KLUDGE ALERT: c-maybe-labelp is used to pass information between |
6b269c4ad2eb
(c-maybe-labelp): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18720
diff
changeset
|
32 ;; c-crosses-statement-barrier-p and c-beginning-of-statement-1. A |
6b269c4ad2eb
(c-maybe-labelp): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18720
diff
changeset
|
33 ;; better way should be implemented, but this will at least shut up |
6b269c4ad2eb
(c-maybe-labelp): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18720
diff
changeset
|
34 ;; the byte compiler. |
6b269c4ad2eb
(c-maybe-labelp): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18720
diff
changeset
|
35 (defvar c-maybe-labelp nil) |
6b269c4ad2eb
(c-maybe-labelp): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18720
diff
changeset
|
36 |
6b269c4ad2eb
(c-maybe-labelp): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18720
diff
changeset
|
37 ;; WARNING WARNING WARNING |
6b269c4ad2eb
(c-maybe-labelp): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18720
diff
changeset
|
38 ;; |
6b269c4ad2eb
(c-maybe-labelp): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18720
diff
changeset
|
39 ;; Be *exceptionally* careful about modifications to this function! |
6b269c4ad2eb
(c-maybe-labelp): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18720
diff
changeset
|
40 ;; Much of CC Mode depends on this Doing The Right Thing. If you |
6b269c4ad2eb
(c-maybe-labelp): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18720
diff
changeset
|
41 ;; break it you will be sorry. If you think you know how this works, |
6b269c4ad2eb
(c-maybe-labelp): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18720
diff
changeset
|
42 ;; you probably don't. No human on Earth does! :-) |
6b269c4ad2eb
(c-maybe-labelp): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18720
diff
changeset
|
43 ;; |
6b269c4ad2eb
(c-maybe-labelp): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18720
diff
changeset
|
44 ;; WARNING WARNING WARNING |
18720 | 45 |
46 (defun c-beginning-of-statement-1 (&optional lim) | |
47 ;; move to the start of the current statement, or the previous | |
48 ;; statement if already at the beginning of one. | |
49 (let ((firstp t) | |
50 (substmt-p t) | |
18844
6b269c4ad2eb
(c-maybe-labelp): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18720
diff
changeset
|
51 donep c-in-literal-cache saved |
18720 | 52 (last-begin (point))) |
53 ;; first check for bare semicolon | |
54 (if (and (progn (c-backward-syntactic-ws lim) | |
55 (eq (char-before) ?\;)) | |
56 (c-safe (progn (forward-char -1) | |
57 (setq saved (point)) | |
58 t)) | |
59 (progn (c-backward-syntactic-ws lim) | |
19251
6a7d40ec4b29
(c-beginning-of-statement-1): When checking for bare semi, don't match
Richard M. Stallman <rms@gnu.org>
parents:
18844
diff
changeset
|
60 (memq (char-before) '(?\; ?{ ?:))) |
18720 | 61 ) |
62 (setq last-begin saved) | |
63 (goto-char last-begin) | |
64 (while (not donep) | |
65 ;; stop at beginning of buffer | |
66 (if (bobp) (setq donep t) | |
67 ;; go backwards one balanced expression, but be careful of | |
68 ;; unbalanced paren being reached | |
69 (if (not (c-safe (progn (backward-sexp 1) t))) | |
70 (progn | |
71 (if firstp | |
72 (backward-up-list 1) | |
73 (goto-char last-begin)) | |
74 ;; skip over any unary operators, or other special | |
75 ;; characters appearing at front of identifier | |
76 (save-excursion | |
77 (c-backward-syntactic-ws lim) | |
78 (skip-chars-backward "-+!*&:.~ \t\n") | |
79 (if (eq (char-before) ?\() | |
80 (setq last-begin (point)))) | |
81 (goto-char last-begin) | |
82 (setq last-begin (point) | |
83 donep t))) | |
84 | |
18844
6b269c4ad2eb
(c-maybe-labelp): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18720
diff
changeset
|
85 (setq c-maybe-labelp nil) |
18720 | 86 ;; see if we're in a literal. if not, then this bufpos may be |
87 ;; a candidate for stopping | |
88 (cond | |
89 ;; CASE 0: did we hit the error condition above? | |
90 (donep) | |
91 ;; CASE 1: are we in a literal? | |
92 ((eq (c-in-literal lim) 'pound) | |
93 (beginning-of-line)) | |
94 ;; CASE 2: some other kind of literal? | |
95 ((c-in-literal lim)) | |
96 ;; CASE 3: are we looking at a conditional keyword? | |
97 ((or (looking-at c-conditional-key) | |
98 (and (eq (char-after) ?\() | |
99 (save-excursion | |
100 (forward-sexp 1) | |
101 (c-forward-syntactic-ws) | |
102 (not (eq (char-after) ?\;))) | |
103 (let ((here (point)) | |
104 (foundp (progn | |
105 (c-backward-syntactic-ws lim) | |
106 (forward-word -1) | |
107 (and lim | |
108 (<= lim (point)) | |
109 (not (c-in-literal lim)) | |
20142 | 110 (not (eq (char-before) ?_)) |
18720 | 111 (looking-at c-conditional-key) |
112 )))) | |
113 ;; did we find a conditional? | |
114 (if (not foundp) | |
115 (goto-char here)) | |
116 foundp))) | |
117 ;; are we in the middle of an else-if clause? | |
118 (if (save-excursion | |
119 (and (not substmt-p) | |
120 (c-safe (progn (forward-sexp -1) t)) | |
121 (looking-at "\\<else\\>[ \t\n]+\\<if\\>") | |
122 (not (c-in-literal lim)))) | |
123 (progn | |
124 (forward-sexp -1) | |
125 (c-backward-to-start-of-if lim))) | |
126 ;; are we sitting at an else clause, that we are not a | |
127 ;; substatement of? | |
128 (if (and (not substmt-p) | |
129 (looking-at "\\<else\\>[^_]")) | |
130 (c-backward-to-start-of-if lim)) | |
131 ;; are we sitting at the while of a do-while? | |
132 (if (and (looking-at "\\<while\\>[^_]") | |
133 (c-backward-to-start-of-do lim)) | |
134 (setq substmt-p nil)) | |
135 (setq last-begin (point) | |
136 donep substmt-p)) | |
137 ;; CASE 4: are we looking at a label? | |
138 ((looking-at c-label-key)) | |
139 ;; CASE 5: is this the first time we're checking? | |
140 (firstp (setq firstp nil | |
141 substmt-p (not (c-crosses-statement-barrier-p | |
142 (point) last-begin)) | |
143 last-begin (point))) | |
144 ;; CASE 6: have we crossed a statement barrier? | |
145 ((c-crosses-statement-barrier-p (point) last-begin) | |
146 (setq donep t)) | |
147 ;; CASE 7: ignore labels | |
18844
6b269c4ad2eb
(c-maybe-labelp): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18720
diff
changeset
|
148 ((and c-maybe-labelp |
18720 | 149 (or (and c-access-key (looking-at c-access-key)) |
150 ;; with switch labels, we have to go back further | |
151 ;; to try to pick up the case or default | |
152 ;; keyword. Potential bogosity alert: we assume | |
153 ;; `case' or `default' is first thing on line | |
154 (let ((here (point))) | |
155 (beginning-of-line) | |
156 (c-forward-syntactic-ws) | |
157 (if (looking-at c-switch-label-key) | |
158 t | |
159 (goto-char here) | |
160 nil)) | |
161 (looking-at c-label-key)))) | |
162 ;; CASE 8: ObjC or Java method def | |
163 ((and c-method-key | |
164 (setq last-begin (c-in-method-def-p))) | |
165 (setq donep t)) | |
166 ;; CASE 9: nothing special | |
167 (t (setq last-begin (point))) | |
168 )))) | |
169 (goto-char last-begin) | |
170 ;; we always do want to skip over non-whitespace modifier | |
171 ;; characters that didn't get skipped above | |
172 (skip-chars-backward "-+!*&:.~" (c-point 'boi)))) | |
173 | |
174 (defun c-end-of-statement-1 () | |
19377
989d0412ada3
(c-end-of-statement-1): Eliminate false hits on important characters
Richard M. Stallman <rms@gnu.org>
parents:
19301
diff
changeset
|
175 (condition-case nil |
989d0412ada3
(c-end-of-statement-1): Eliminate false hits on important characters
Richard M. Stallman <rms@gnu.org>
parents:
19301
diff
changeset
|
176 (let (beg end found) |
18720 | 177 (while (and (not (eobp)) |
19377
989d0412ada3
(c-end-of-statement-1): Eliminate false hits on important characters
Richard M. Stallman <rms@gnu.org>
parents:
19301
diff
changeset
|
178 (progn |
989d0412ada3
(c-end-of-statement-1): Eliminate false hits on important characters
Richard M. Stallman <rms@gnu.org>
parents:
19301
diff
changeset
|
179 (setq beg (point)) |
18720 | 180 (forward-sexp 1) |
19377
989d0412ada3
(c-end-of-statement-1): Eliminate false hits on important characters
Richard M. Stallman <rms@gnu.org>
parents:
19301
diff
changeset
|
181 (setq end (point)) |
989d0412ada3
(c-end-of-statement-1): Eliminate false hits on important characters
Richard M. Stallman <rms@gnu.org>
parents:
19301
diff
changeset
|
182 (goto-char beg) |
989d0412ada3
(c-end-of-statement-1): Eliminate false hits on important characters
Richard M. Stallman <rms@gnu.org>
parents:
19301
diff
changeset
|
183 (setq found nil) |
989d0412ada3
(c-end-of-statement-1): Eliminate false hits on important characters
Richard M. Stallman <rms@gnu.org>
parents:
19301
diff
changeset
|
184 (while (and (not found) |
989d0412ada3
(c-end-of-statement-1): Eliminate false hits on important characters
Richard M. Stallman <rms@gnu.org>
parents:
19301
diff
changeset
|
185 (re-search-forward "[;{}]" end t)) |
989d0412ada3
(c-end-of-statement-1): Eliminate false hits on important characters
Richard M. Stallman <rms@gnu.org>
parents:
19301
diff
changeset
|
186 (if (not (c-in-literal beg)) |
989d0412ada3
(c-end-of-statement-1): Eliminate false hits on important characters
Richard M. Stallman <rms@gnu.org>
parents:
19301
diff
changeset
|
187 (setq found t))) |
989d0412ada3
(c-end-of-statement-1): Eliminate false hits on important characters
Richard M. Stallman <rms@gnu.org>
parents:
19301
diff
changeset
|
188 (not found))) |
989d0412ada3
(c-end-of-statement-1): Eliminate false hits on important characters
Richard M. Stallman <rms@gnu.org>
parents:
19301
diff
changeset
|
189 (goto-char end)) |
989d0412ada3
(c-end-of-statement-1): Eliminate false hits on important characters
Richard M. Stallman <rms@gnu.org>
parents:
19301
diff
changeset
|
190 (re-search-backward "[;{}]") |
18720 | 191 (forward-char 1)) |
19806
dc7a5df6e4b9
(c-end-of-statement-1): Wrap backward-up-list in a c-safe call so no
Richard M. Stallman <rms@gnu.org>
parents:
19377
diff
changeset
|
192 (error |
18720 | 193 (let ((beg (point))) |
19806
dc7a5df6e4b9
(c-end-of-statement-1): Wrap backward-up-list in a c-safe call so no
Richard M. Stallman <rms@gnu.org>
parents:
19377
diff
changeset
|
194 (c-safe (backward-up-list -1)) |
18720 | 195 (let ((end (point))) |
196 (goto-char beg) | |
19806
dc7a5df6e4b9
(c-end-of-statement-1): Wrap backward-up-list in a c-safe call so no
Richard M. Stallman <rms@gnu.org>
parents:
19377
diff
changeset
|
197 (search-forward ";" end 'move))) |
dc7a5df6e4b9
(c-end-of-statement-1): Wrap backward-up-list in a c-safe call so no
Richard M. Stallman <rms@gnu.org>
parents:
19377
diff
changeset
|
198 ))) |
18720 | 199 |
200 | |
201 (defun c-crosses-statement-barrier-p (from to) | |
202 ;; Does buffer positions FROM to TO cross a C statement boundary? | |
203 (let ((here (point)) | |
204 (lim from) | |
205 crossedp) | |
206 (condition-case () | |
207 (progn | |
208 (goto-char from) | |
209 (while (and (not crossedp) | |
210 (< (point) to)) | |
211 (skip-chars-forward "^;{}:" to) | |
212 (if (not (c-in-literal lim)) | |
213 (progn | |
214 (if (memq (char-after) '(?\; ?{ ?})) | |
215 (setq crossedp t) | |
216 (if (eq (char-after) ?:) | |
18844
6b269c4ad2eb
(c-maybe-labelp): Add defvar.
Richard M. Stallman <rms@gnu.org>
parents:
18720
diff
changeset
|
217 (setq c-maybe-labelp t)) |
18720 | 218 (forward-char 1)) |
219 (setq lim (point))) | |
220 (forward-char 1)))) | |
221 (error (setq crossedp nil))) | |
222 (goto-char here) | |
223 crossedp)) | |
224 | |
225 | |
226 ;; Skipping of "syntactic whitespace", defined as lexical whitespace, | |
227 ;; C and C++ style comments, and preprocessor directives. Search no | |
228 ;; farther back or forward than optional LIM. If LIM is omitted, | |
229 ;; `beginning-of-defun' is used for backward skipping, point-max is | |
230 ;; used for forward skipping. | |
231 | |
232 (defun c-forward-syntactic-ws (&optional lim) | |
233 ;; Forward skip of syntactic whitespace for Emacs 19. | |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
234 (let* ((here (point-max)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
235 (hugenum (point-max))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
236 (while (/= here (point)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
237 (setq here (point)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
238 (forward-comment hugenum) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
239 ;; skip preprocessor directives |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
240 (when (and (eq (char-after) ?#) |
18720 | 241 (= (c-point 'boi) (point))) |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
242 (while (eq (char-before (c-point 'eol)) ?\\) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
243 (forward-line 1)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
244 (end-of-line)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
245 ) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
246 (if lim (goto-char (min (point) lim))))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
247 |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
248 (defsubst c-beginning-of-macro (&optional lim) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
249 ;; Go to the beginning of a cpp macro definition. Leaves point at |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
250 ;; the beginning of the macro and returns t if in a cpp macro |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
251 ;; definition, otherwise returns nil and leaves point unchanged. |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
252 ;; `lim' is currently ignored, but the interface requires it. |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
253 (let ((here (point))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
254 (beginning-of-line) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
255 (while (eq (char-before (1- (point))) ?\\) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
256 (forward-line -1)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
257 (back-to-indentation) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
258 (if (eq (char-after) ?#) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
259 t |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
260 (goto-char here) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
261 nil))) |
18720 | 262 |
263 (defun c-backward-syntactic-ws (&optional lim) | |
264 ;; Backward skip over syntactic whitespace for Emacs 19. | |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
265 (let* ((here (point-min)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
266 (hugenum (- (point-max)))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
267 (while (/= here (point)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
268 (setq here (point)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
269 (forward-comment hugenum) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
270 (c-beginning-of-macro)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
271 (if lim (goto-char (max (point) lim))))) |
18720 | 272 |
273 | |
21106
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
274 ;; Moving by tokens, where a token is defined as all symbols and |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
275 ;; identifiers which aren't syntactic whitespace. COUNT specifies the |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
276 ;; number of tokens to move forward; a negative COUNT moves backward. |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
277 ;; If BALANCED is true, move over balanced parens, otherwise move into |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
278 ;; them. Also, if BALANCED is true, never move out of an enclosing |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
279 ;; paren. LIM sets the limit for the movement. Point is always left |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
280 ;; at the beginning of a token or at LIM. Returns the number of |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
281 ;; tokens left to move (positive or negative). If BALANCED is true, a |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
282 ;; move over a balanced paren counts as one. |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
283 |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
284 (defun c-forward-token-1 (&optional count balanced lim) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
285 (let* ((jump-syntax (if balanced |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
286 '(?w ?_ ?\" ?\\ ?/ ?$ ?' ?\( ?\)) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
287 '(?w ?_ ?\" ?\\ ?/ ?$ ?')))) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
288 (or count (setq count 1)) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
289 (condition-case nil |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
290 (while (progn |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
291 (c-forward-syntactic-ws lim) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
292 (> count 0)) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
293 (if (memq (char-syntax (char-after)) jump-syntax) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
294 (goto-char (scan-sexps (point) 1)) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
295 (forward-char)) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
296 (setq count (1- count))) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
297 (error |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
298 (and lim (> (point) lim) (goto-char lim)))) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
299 count)) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
300 |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
301 (defun c-backward-token-1 (&optional count balanced lim) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
302 (let* ((jump-syntax (if balanced |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
303 '(?w ?_ ?\" ?\\ ?/ ?$ ?' ?\( ?\)) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
304 '(?w ?_ ?\" ?\\ ?/ ?$ ?'))) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
305 last) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
306 (or count (setq count 1)) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
307 (condition-case nil |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
308 (while (> count 0) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
309 (setq last (point)) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
310 (c-backward-syntactic-ws lim) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
311 (if (memq (char-syntax (char-before)) jump-syntax) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
312 (goto-char (scan-sexps (point) -1)) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
313 (backward-char)) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
314 (setq count (1- count))) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
315 (error |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
316 (goto-char last) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
317 (and lim (< (point) lim) (goto-char lim)))) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
318 count)) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
319 |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
320 |
18720 | 321 ;; Return `c' if in a C-style comment, `c++' if in a C++ style |
322 ;; comment, `string' if in a string literal, `pound' if on a | |
323 ;; preprocessor line, or nil if not in a comment at all. Optional LIM | |
324 ;; is used as the backward limit of the search. If omitted, or nil, | |
325 ;; `beginning-of-defun' is used." | |
326 | |
327 (defun c-in-literal (&optional lim) | |
328 ;; Determine if point is in a C++ literal. we cache the last point | |
329 ;; calculated if the cache is enabled | |
330 (if (and (boundp 'c-in-literal-cache) | |
331 c-in-literal-cache | |
332 (= (point) (aref c-in-literal-cache 0))) | |
333 (aref c-in-literal-cache 1) | |
334 (let ((rtn (save-excursion | |
335 (let* ((lim (or lim (c-point 'bod))) | |
336 (state (parse-partial-sexp lim (point)))) | |
337 (cond | |
338 ((nth 3 state) 'string) | |
339 ((nth 4 state) (if (nth 7 state) 'c++ 'c)) | |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
340 ((c-beginning-of-macro lim) 'pound) |
18720 | 341 (t nil)))))) |
342 ;; cache this result if the cache is enabled | |
343 (and (boundp 'c-in-literal-cache) | |
344 (setq c-in-literal-cache (vector (point) rtn))) | |
345 rtn))) | |
346 | |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
347 ;; XEmacs has a built-in function that should make this much quicker. |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
348 ;; I don't think we even need the cache, which makes our lives more |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
349 ;; complicated anyway. In this case, lim is ignored. |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
350 (defun c-fast-in-literal (&optional lim) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
351 (let ((context (buffer-syntactic-context))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
352 (cond |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
353 ((eq context 'string) 'string) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
354 ((eq context 'comment) 'c++) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
355 ((eq context 'block-comment) 'c) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
356 ((save-excursion (c-beginning-of-macro lim)) 'pound)))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
357 |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
358 (if (fboundp 'buffer-syntactic-context) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
359 (defalias 'c-in-literal 'c-fast-in-literal)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
360 |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
361 (defun c-literal-limits (&optional lim) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
362 ;; Returns a cons of the beginning and end positions of the comment |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
363 ;; or string surrounding point (including both delimiters), or nil |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
364 ;; if point isn't in one. This is the Emacs 19 version. |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
365 (save-excursion |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
366 (let* ((lim (or lim (c-point 'bod))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
367 (state (parse-partial-sexp lim (point)))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
368 (cond ((nth 3 state) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
369 ;; String. Search backward for the start. |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
370 (while (nth 3 state) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
371 (search-backward (make-string 1 (nth 3 state))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
372 (setq state (parse-partial-sexp lim (point)))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
373 (cons (point) (or (c-safe (forward-sexp 1) (point)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
374 (point-max)))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
375 ((nth 7 state) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
376 ;; C++ comment. Search from bol for the comment starter. |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
377 (beginning-of-line) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
378 (setq state (parse-partial-sexp lim (point)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
379 lim (point)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
380 (while (not (nth 7 state)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
381 (search-forward "//") ; Should never fail. |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
382 (setq state (parse-partial-sexp |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
383 lim (point) nil nil state) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
384 lim (point))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
385 (backward-char 2) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
386 (cons (point) (progn (forward-comment 1) (point)))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
387 ((nth 4 state) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
388 ;; C comment. Search backward for the comment starter. |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
389 (while (nth 4 state) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
390 (search-backward "/*") ; Should never fail. |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
391 (setq state (parse-partial-sexp lim (point)))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
392 (cons (point) (progn (forward-comment 1) (point)))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
393 ((c-safe (nth 4 (parse-partial-sexp ; Can't use prev state due |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
394 lim (1+ (point))))) ; to bug in Emacs 19.34. |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
395 ;; We're standing in a comment starter. |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
396 (backward-char 2) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
397 (cons (point) (progn (forward-comment 1) (point)))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
398 )))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
399 |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
400 (defun c-literal-limits-fast (&optional lim) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
401 ;; Returns a cons of the beginning and end positions of the comment |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
402 ;; or string surrounding point (including both delimiters), or nil |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
403 ;; if point isn't in one. This is for emacsen whose |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
404 ;; `parse-partial-sexp' returns the pos of the comment start. |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
405 (save-excursion |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
406 (let ((state (parse-partial-sexp lim (point)))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
407 (cond ((nth 3 state) ; String. |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
408 (goto-char (nth 8 state)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
409 (cons (point) (or (c-safe (forward-sexp 1) (point)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
410 (point-max)))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
411 ((nth 4 state) ; Comment. |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
412 (goto-char (nth 8 state)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
413 (cons (point) (progn (forward-comment 1) (point)))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
414 ((c-safe |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
415 (nth 4 (parse-partial-sexp ; Works? |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
416 (point) (1+ (point)) nil nil state))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
417 ;; We're in a comment starter. |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
418 (backward-char 2) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
419 (cons (point) (progn (forward-comment 1) (point)))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
420 )))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
421 |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
422 (defun c-collect-line-comments (range) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
423 ;; If the argument is a cons of two buffer positions (such as |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
424 ;; returned by c-literal-limits), and that range contains a C++ |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
425 ;; style line comment, then an extended range is returned that |
21106
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
426 ;; contains all adjacent line comments (i.e. all comments that |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
427 ;; starts in the same column with no empty lines or non-whitespace |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
428 ;; characters between them). Otherwise the argument is returned. |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
429 (save-excursion |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
430 (condition-case nil |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
431 (if (and (consp range) (progn |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
432 (goto-char (car range)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
433 (looking-at "//"))) |
21106
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
434 (let ((col (current-column)) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
435 (beg (point)) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
436 (end (cdr range))) |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
437 (while (and (not (bobp)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
438 (forward-comment -1) |
21106
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
439 (looking-at "//") |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
440 (= col (current-column))) |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
441 (setq beg (point))) |
21106
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
442 (goto-char end) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
443 (while (progn |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
444 (skip-chars-forward " \t") |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
445 (and (looking-at "//") |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
446 (= col (current-column)))) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
447 (forward-comment 1) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
448 (setq end (point))) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
449 (cons beg end)) |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
450 range) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
451 (error range)))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
452 |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
453 |
18720 | 454 |
455 ;; utilities for moving and querying around syntactic elements | |
456 (defvar c-parsing-error nil) | |
457 | |
458 (defun c-parse-state () | |
459 ;; Finds and records all open parens between some important point | |
460 ;; earlier in the file and point. | |
461 ;; | |
462 ;; if there's a state cache, return it | |
463 (setq c-parsing-error nil) | |
464 (if (boundp 'c-state-cache) c-state-cache | |
465 (let* (at-bob | |
466 (pos (save-excursion | |
467 ;; go back 2 bods, but ignore any bogus positions | |
468 ;; returned by beginning-of-defun (i.e. open paren | |
469 ;; in column zero) | |
470 (let ((cnt 2)) | |
471 (while (not (or at-bob (zerop cnt))) | |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
472 (goto-char (c-point 'bod)) |
18720 | 473 (if (eq (char-after) ?\{) |
474 (setq cnt (1- cnt))) | |
475 (if (bobp) | |
476 (setq at-bob t)))) | |
477 (point))) | |
478 (here (save-excursion | |
479 ;;(skip-chars-forward " \t}") | |
480 (point))) | |
481 (last-bod pos) (last-pos pos) | |
482 placeholder state sexp-end) | |
483 ;; cache last bod position | |
484 (while (catch 'backup-bod | |
485 (setq state nil) | |
486 (while (and pos (< pos here)) | |
487 (setq last-pos pos) | |
488 (if (and (setq pos (c-safe (scan-lists pos 1 -1))) | |
489 (<= pos here)) | |
490 (progn | |
491 (setq sexp-end (c-safe (scan-sexps (1- pos) 1))) | |
492 (if (and sexp-end | |
493 (<= sexp-end here)) | |
494 ;; we want to record both the start and end | |
495 ;; of this sexp, but we only want to record | |
496 ;; the last-most of any of them before here | |
497 (progn | |
498 (if (eq (char-after (1- pos)) ?\{) | |
499 (setq state (cons (cons (1- pos) sexp-end) | |
500 (if (consp (car state)) | |
501 (cdr state) | |
502 state)))) | |
503 (setq pos sexp-end)) | |
504 ;; we're contained in this sexp so put pos on | |
505 ;; front of list | |
506 (setq state (cons (1- pos) state)))) | |
507 ;; something bad happened. check to see if we | |
508 ;; crossed an unbalanced close brace. if so, we | |
509 ;; didn't really find the right `important bufpos' | |
510 ;; so lets back up and try again | |
511 (if (and (not pos) (not at-bob) | |
512 (setq placeholder | |
513 (c-safe (scan-lists last-pos 1 1))) | |
514 ;;(char-after (1- placeholder)) | |
515 (<= placeholder here) | |
516 (eq (char-after (1- placeholder)) ?\})) | |
517 (while t | |
518 (setq last-bod (c-safe (scan-lists last-bod -1 1))) | |
519 (if (not last-bod) | |
520 (progn | |
521 ;; bogus, but what can we do here? | |
522 (setq c-parsing-error (1- placeholder)) | |
523 (throw 'backup-bod nil)) | |
524 (setq at-bob (= last-bod (point-min)) | |
525 pos last-bod) | |
526 (if (= (char-after last-bod) ?\{) | |
527 (throw 'backup-bod t))) | |
528 )) ;end-if | |
529 )) ;end-while | |
530 nil)) | |
531 state))) | |
532 | |
533 (defun c-whack-state (bufpos state) | |
534 ;; whack off any state information that appears on STATE which lies | |
535 ;; after the bounds of BUFPOS. | |
536 (let (newstate car) | |
537 (while state | |
538 (setq car (car state) | |
539 state (cdr state)) | |
540 (if (consp car) | |
541 ;; just check the car, because in a balanced brace | |
542 ;; expression, it must be impossible for the corresponding | |
543 ;; close brace to be before point, but the open brace to be | |
544 ;; after. | |
545 (if (<= bufpos (car car)) | |
546 nil ; whack it off | |
547 ;; its possible that the open brace is before bufpos, but | |
548 ;; the close brace is after. In that case, convert this | |
549 ;; to a non-cons element. | |
550 (if (<= bufpos (cdr car)) | |
551 (setq newstate (append newstate (list (car car)))) | |
552 ;; we know that both the open and close braces are | |
553 ;; before bufpos, so we also know that everything else | |
554 ;; on state is before bufpos, so we can glom up the | |
555 ;; whole thing and exit. | |
556 (setq newstate (append newstate (list car) state) | |
557 state nil))) | |
558 (if (<= bufpos car) | |
559 nil ; whack it off | |
560 ;; it's before bufpos, so everything else should too | |
561 (setq newstate (append newstate (list car) state) | |
562 state nil)))) | |
563 newstate)) | |
564 | |
565 (defun c-hack-state (bufpos which state) | |
566 ;; Using BUFPOS buffer position, and WHICH (must be 'open or | |
567 ;; 'close), hack the c-parse-state STATE and return the results. | |
568 (if (eq which 'open) | |
569 (let ((car (car state))) | |
570 (if (or (null car) | |
571 (consp car) | |
572 (/= bufpos car)) | |
573 (cons bufpos state) | |
574 state)) | |
575 (if (not (eq which 'close)) | |
576 (error "c-hack-state, bad argument: %s" which)) | |
577 ;; 'close brace | |
578 (let ((car (car state)) | |
579 (cdr (cdr state))) | |
580 (if (consp car) | |
581 (setq car (car cdr) | |
582 cdr (cdr cdr))) | |
583 ;; TBD: is this test relevant??? | |
584 (if (consp car) | |
585 state ;on error, don't change | |
586 ;; watch out for balanced expr already on cdr of list | |
587 (cons (cons car bufpos) | |
588 (if (consp (car cdr)) | |
589 (cdr cdr) cdr)) | |
590 )))) | |
591 | |
592 (defun c-adjust-state (from to shift state) | |
593 ;; Adjust all points in state that lie in the region FROM..TO by | |
594 ;; SHIFT amount (as would be returned by c-indent-line). | |
595 (mapcar | |
596 (function | |
597 (lambda (e) | |
598 (if (consp e) | |
599 (let ((car (car e)) | |
600 (cdr (cdr e))) | |
601 (if (and (<= from car) (< car to)) | |
602 (setcar e (+ shift car))) | |
603 (if (and (<= from cdr) (< cdr to)) | |
604 (setcdr e (+ shift cdr)))) | |
605 (if (and (<= from e) (< e to)) | |
606 (setq e (+ shift e)))) | |
607 e)) | |
608 state)) | |
609 | |
610 | |
611 (defun c-beginning-of-inheritance-list (&optional lim) | |
612 ;; Go to the first non-whitespace after the colon that starts a | |
613 ;; multiple inheritance introduction. Optional LIM is the farthest | |
614 ;; back we should search. | |
615 (let ((lim (or lim (c-point 'bod))) | |
616 (placeholder (progn | |
617 (back-to-indentation) | |
618 (point)))) | |
619 (c-backward-syntactic-ws lim) | |
620 (while (and (> (point) lim) | |
621 (memq (char-before) '(?, ?:)) | |
622 (progn | |
623 (beginning-of-line) | |
624 (setq placeholder (point)) | |
625 (skip-chars-forward " \t") | |
626 (not (looking-at c-class-key)) | |
627 )) | |
628 (c-backward-syntactic-ws lim)) | |
629 (goto-char placeholder) | |
630 (skip-chars-forward "^:" (c-point 'eol)))) | |
631 | |
632 (defun c-in-method-def-p () | |
633 ;; Return nil if we aren't in a method definition, otherwise the | |
634 ;; position of the initial [+-]. | |
635 (save-excursion | |
636 (beginning-of-line) | |
637 (and c-method-key | |
638 (looking-at c-method-key) | |
639 (point)) | |
640 )) | |
641 | |
642 (defun c-just-after-func-arglist-p (&optional containing) | |
643 ;; Return t if we are between a function's argument list closing | |
644 ;; paren and its opening brace. Note that the list close brace | |
645 ;; could be followed by a "const" specifier or a member init hanging | |
646 ;; colon. Optional CONTAINING is position of containing s-exp open | |
647 ;; brace. If not supplied, point is used as search start. | |
648 (save-excursion | |
649 (c-backward-syntactic-ws) | |
650 (let ((checkpoint (or containing (point)))) | |
651 (goto-char checkpoint) | |
652 ;; could be looking at const specifier | |
653 (if (and (eq (char-before) ?t) | |
654 (forward-word -1) | |
655 (looking-at "\\<const\\>")) | |
656 (c-backward-syntactic-ws) | |
657 ;; otherwise, we could be looking at a hanging member init | |
658 ;; colon | |
659 (goto-char checkpoint) | |
660 (if (and (eq (char-before) ?:) | |
661 (progn | |
662 (forward-char -1) | |
663 (c-backward-syntactic-ws) | |
664 (looking-at "[ \t\n]*:\\([^:]+\\|$\\)"))) | |
665 nil | |
666 (goto-char checkpoint)) | |
667 ) | |
668 (and (eq (char-before) ?\)) | |
669 ;; check if we are looking at a method def | |
670 (or (not c-method-key) | |
671 (progn | |
672 (forward-sexp -1) | |
673 (forward-char -1) | |
674 (c-backward-syntactic-ws) | |
675 (not (or (memq (char-before) '(?- ?+)) | |
676 ;; or a class category | |
677 (progn | |
678 (forward-sexp -2) | |
679 (looking-at c-class-key)) | |
680 ))))) | |
681 ))) | |
682 | |
683 ;; defuns to look backwards for things | |
684 (defun c-backward-to-start-of-do (&optional lim) | |
685 ;; Move to the start of the last "unbalanced" do expression. | |
686 ;; Optional LIM is the farthest back to search. If none is found, | |
687 ;; nil is returned and point is left unchanged, otherwise t is returned. | |
688 (let ((do-level 1) | |
689 (case-fold-search nil) | |
690 (lim (or lim (c-point 'bod))) | |
691 (here (point)) | |
692 foundp) | |
693 (while (not (zerop do-level)) | |
694 ;; we protect this call because trying to execute this when the | |
695 ;; while is not associated with a do will throw an error | |
696 (condition-case nil | |
697 (progn | |
698 (backward-sexp 1) | |
699 (cond | |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
700 ;; break infloop for illegal C code |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
701 ((bobp) (setq do-level 0)) |
18720 | 702 ((memq (c-in-literal lim) '(c c++))) |
703 ((looking-at "while\\b[^_]") | |
704 (setq do-level (1+ do-level))) | |
705 ((looking-at "do\\b[^_]") | |
706 (if (zerop (setq do-level (1- do-level))) | |
707 (setq foundp t))) | |
708 ((<= (point) lim) | |
709 (setq do-level 0) | |
710 (goto-char lim)))) | |
711 (error | |
712 (goto-char lim) | |
713 (setq do-level 0)))) | |
714 (if (not foundp) | |
715 (goto-char here)) | |
716 foundp)) | |
717 | |
718 (defun c-backward-to-start-of-if (&optional lim) | |
719 ;; Move to the start of the last "unbalanced" if and return t. If | |
720 ;; none is found, and we are looking at an if clause, nil is | |
721 ;; returned. If none is found and we are looking at an else clause, | |
722 ;; an error is thrown. | |
723 (let ((if-level 1) | |
724 (here (c-point 'bol)) | |
725 (case-fold-search nil) | |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
726 (lim (or (and (>= (point) lim) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
727 lim) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
728 (c-point 'bod))) |
18720 | 729 (at-if (looking-at "if\\b[^_]"))) |
730 (catch 'orphan-if | |
731 (while (and (not (bobp)) | |
732 (not (zerop if-level))) | |
733 (c-backward-syntactic-ws) | |
734 (condition-case nil | |
735 (backward-sexp 1) | |
736 (error | |
737 (if at-if | |
738 (throw 'orphan-if nil) | |
739 (error "No matching `if' found for `else' on line %d." | |
740 (1+ (count-lines 1 here)))))) | |
741 (cond | |
742 ((looking-at "else\\b[^_]") | |
743 (setq if-level (1+ if-level))) | |
744 ((looking-at "if\\b[^_]") | |
745 ;; check for else if... skip over | |
746 (let ((here (point))) | |
747 (c-safe (forward-sexp -1)) | |
748 (if (looking-at "\\<else\\>[ \t]+\\<if\\>") | |
749 nil | |
750 (setq if-level (1- if-level)) | |
751 (goto-char here)))) | |
752 ((< (point) lim) | |
753 (setq if-level 0) | |
754 (goto-char lim)) | |
755 )) | |
756 t))) | |
757 | |
758 (defun c-skip-conditional () | |
759 ;; skip forward over conditional at point, including any predicate | |
760 ;; statements in parentheses. No error checking is performed. | |
761 (forward-sexp (cond | |
762 ;; else if() | |
763 ((looking-at "\\<else\\>[ \t]+\\<if\\>") 3) | |
764 ;; do, else, try, finally | |
765 ((looking-at "\\<\\(do\\|else\\|try\\|finally\\)\\>") 1) | |
766 ;; for, if, while, switch, catch, synchronized | |
767 (t 2)))) | |
768 | |
769 (defun c-skip-case-statement-forward (state &optional lim) | |
770 ;; skip forward over case/default bodies, with optional maximal | |
771 ;; limit. if no next case body is found, nil is returned and point | |
772 ;; is not moved | |
773 (let ((lim (or lim (point-max))) | |
774 (here (point)) | |
775 donep foundp bufpos | |
776 (safepos (point)) | |
777 (balanced (car state))) | |
778 ;; search until we've passed the limit, or we've found our match | |
779 (while (and (< (point) lim) | |
780 (not donep)) | |
781 (setq safepos (point)) | |
782 ;; see if we can find a case statement, not in a literal | |
783 (if (and (re-search-forward c-switch-label-key lim 'move) | |
784 (setq bufpos (match-beginning 0)) | |
785 (not (c-in-literal safepos)) | |
786 (/= bufpos here)) | |
787 ;; if we crossed into a balanced sexp, we know the case is | |
788 ;; not part of our switch statement, so just bound over the | |
789 ;; sexp and keep looking. | |
790 (if (and (consp balanced) | |
791 (> bufpos (car balanced)) | |
792 (< bufpos (cdr balanced))) | |
793 (goto-char (cdr balanced)) | |
794 (goto-char bufpos) | |
795 (setq donep t | |
796 foundp t)))) | |
797 (if (not foundp) | |
798 (goto-char here)) | |
799 foundp)) | |
800 | |
801 (defun c-search-uplist-for-classkey (brace-state) | |
802 ;; search for the containing class, returning a 2 element vector if | |
803 ;; found. aref 0 contains the bufpos of the class key, and aref 1 | |
804 ;; contains the bufpos of the open brace. | |
805 (if (null brace-state) | |
806 ;; no brace-state means we cannot be inside a class | |
807 nil | |
808 (let ((carcache (car brace-state)) | |
809 search-start search-end) | |
810 (if (consp carcache) | |
811 ;; a cons cell in the first element means that there is some | |
812 ;; balanced sexp before the current bufpos. this we can | |
813 ;; ignore. the nth 1 and nth 2 elements define for us the | |
814 ;; search boundaries | |
815 (setq search-start (nth 2 brace-state) | |
816 search-end (nth 1 brace-state)) | |
817 ;; if the car was not a cons cell then nth 0 and nth 1 define | |
818 ;; for us the search boundaries | |
819 (setq search-start (nth 1 brace-state) | |
820 search-end (nth 0 brace-state))) | |
821 ;; search-end cannot be a cons cell | |
822 (and (consp search-end) | |
823 (error "consp search-end: %s" search-end)) | |
824 ;; if search-end is nil, or if the search-end character isn't an | |
825 ;; open brace, we are definitely not in a class | |
826 (if (or (not search-end) | |
827 (< search-end (point-min)) | |
828 (not (eq (char-after search-end) ?{))) | |
829 nil | |
830 ;; now, we need to look more closely at search-start. if | |
831 ;; search-start is nil, then our start boundary is really | |
832 ;; point-min. | |
833 (if (not search-start) | |
834 (setq search-start (point-min)) | |
835 ;; if search-start is a cons cell, then we can start | |
836 ;; searching from the end of the balanced sexp just ahead of | |
837 ;; us | |
838 (if (consp search-start) | |
839 (setq search-start (cdr search-start)))) | |
840 ;; now we can do a quick regexp search from search-start to | |
841 ;; search-end and see if we can find a class key. watch for | |
842 ;; class like strings in literals | |
843 (save-excursion | |
844 (save-restriction | |
845 (goto-char search-start) | |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
846 (let ((search-key (concat c-class-key "\\|" c-extra-toplevel-key)) |
18720 | 847 foundp class match-end) |
848 (while (and (not foundp) | |
849 (progn | |
850 (c-forward-syntactic-ws) | |
851 (> search-end (point))) | |
852 (re-search-forward search-key search-end t)) | |
853 (setq class (match-beginning 0) | |
854 match-end (match-end 0)) | |
855 (if (c-in-literal search-start) | |
856 nil ; its in a comment or string, ignore | |
857 (goto-char class) | |
858 (skip-chars-forward " \t\n") | |
859 (setq foundp (vector (c-point 'boi) search-end)) | |
860 (cond | |
861 ;; check for embedded keywords | |
862 ((let ((char (char-after (1- class)))) | |
863 (and char | |
864 (memq (char-syntax char) '(?w ?_)))) | |
865 (goto-char match-end) | |
866 (setq foundp nil)) | |
867 ;; make sure we're really looking at the start of a | |
868 ;; class definition, and not a forward decl, return | |
869 ;; arg, template arg list, or an ObjC or Java method. | |
870 ((and c-method-key | |
871 (re-search-forward c-method-key search-end t)) | |
872 (setq foundp nil)) | |
873 ;; Its impossible to define a regexp for this, and | |
874 ;; nearly so to do it programmatically. | |
875 ;; | |
876 ;; ; picks up forward decls | |
877 ;; = picks up init lists | |
878 ;; ) picks up return types | |
879 ;; > picks up templates, but remember that we can | |
880 ;; inherit from templates! | |
881 ((let ((skipchars "^;=)")) | |
882 ;; try to see if we found the `class' keyword | |
883 ;; inside a template arg list | |
884 (save-excursion | |
885 (skip-chars-backward "^<>" search-start) | |
886 (if (eq (char-before) ?<) | |
887 (setq skipchars (concat skipchars ">")))) | |
888 (skip-chars-forward skipchars search-end) | |
889 (/= (point) search-end)) | |
890 (setq foundp nil)) | |
891 ))) | |
892 foundp)) | |
893 ))))) | |
894 | |
895 (defun c-inside-bracelist-p (containing-sexp brace-state) | |
896 ;; return the buffer position of the beginning of the brace list | |
897 ;; statement if we're inside a brace list, otherwise return nil. | |
898 ;; CONTAINING-SEXP is the buffer pos of the innermost containing | |
899 ;; paren. BRACE-STATE is the remainder of the state of enclosing braces | |
900 ;; | |
901 ;; N.B.: This algorithm can potentially get confused by cpp macros | |
902 ;; places in inconvenient locations. Its a trade-off we make for | |
903 ;; speed. | |
904 (or | |
905 ;; this will pick up enum lists | |
21106
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
906 (c-safe |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
907 (save-excursion |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
908 (goto-char containing-sexp) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
909 (forward-sexp -1) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
910 (let (bracepos) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
911 (if (and (or (looking-at "enum[\t\n ]+") |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
912 (progn (forward-sexp -1) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
913 (looking-at "enum[\t\n ]+"))) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
914 (setq bracepos (c-safe (scan-lists (point) 1 -1))) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
915 (not (c-crosses-statement-barrier-p (point) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
916 (- bracepos 2)))) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
917 (point))))) |
18720 | 918 ;; this will pick up array/aggregate init lists, even if they are nested. |
919 (save-excursion | |
21106
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
920 (let (bufpos okp) |
18720 | 921 (while (and (not bufpos) |
922 containing-sexp) | |
923 (if (consp containing-sexp) | |
924 (setq containing-sexp (car brace-state) | |
925 brace-state (cdr brace-state)) | |
21106
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
926 ;; see if the open brace is preceded by a = in this statement |
18720 | 927 (goto-char containing-sexp) |
21106
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
928 (setq okp t) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
929 (while (and (setq okp (= (c-backward-token-1 1 t) 0)) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
930 (not (memq (char-after) '(?= ?{ ?\;))))) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
931 (if (not (and okp (eq (char-after) ?=))) |
18720 | 932 ;; lets see if we're nested. find the most nested |
933 ;; containing brace | |
934 (setq containing-sexp (car brace-state) | |
935 brace-state (cdr brace-state)) | |
936 ;; we've hit the beginning of the aggregate list | |
937 (c-beginning-of-statement-1 (c-most-enclosing-brace brace-state)) | |
938 (setq bufpos (point))) | |
939 )) | |
940 bufpos)) | |
941 )) | |
942 | |
943 | |
944 (defun c-most-enclosing-brace (state) | |
945 ;; return the bufpos of the most enclosing brace that hasn't been | |
946 ;; narrowed out by any enclosing class, or nil if none was found | |
947 (let (enclosingp) | |
948 (while (and state (not enclosingp)) | |
949 (setq enclosingp (car state) | |
950 state (cdr state)) | |
951 (if (consp enclosingp) | |
952 (setq enclosingp nil) | |
953 (if (> (point-min) enclosingp) | |
954 (setq enclosingp nil)) | |
955 (setq state nil))) | |
956 enclosingp)) | |
957 | |
958 (defun c-least-enclosing-brace (state) | |
959 ;; return the bufpos of the least (highest) enclosing brace that | |
960 ;; hasn't been narrowed out by any enclosing class, or nil if none | |
961 ;; was found. | |
962 (c-most-enclosing-brace (nreverse state))) | |
963 | |
964 (defun c-safe-position (bufpos state) | |
965 ;; return the closest known safe position higher up than point | |
966 (let ((safepos nil)) | |
967 (while state | |
968 (setq safepos | |
969 (if (consp (car state)) | |
970 (cdr (car state)) | |
971 (car state))) | |
972 (if (< safepos bufpos) | |
973 (setq state nil) | |
974 (setq state (cdr state)))) | |
975 safepos)) | |
976 | |
977 (defun c-narrow-out-enclosing-class (state lim) | |
978 ;; narrow the buffer so that the enclosing class is hidden | |
979 (let (inclass-p) | |
980 (and state | |
981 (setq inclass-p (c-search-uplist-for-classkey state)) | |
982 (narrow-to-region | |
983 (progn | |
984 (goto-char (1+ (aref inclass-p 1))) | |
985 (skip-chars-forward " \t\n" lim) | |
986 ;; if point is now left of the class opening brace, we're | |
987 ;; hosed, so try a different tact | |
988 (if (<= (point) (aref inclass-p 1)) | |
989 (progn | |
990 (goto-char (1+ (aref inclass-p 1))) | |
991 (c-forward-syntactic-ws lim))) | |
992 (point)) | |
993 ;; end point is the end of the current line | |
994 (progn | |
995 (goto-char lim) | |
996 (c-point 'eol)))) | |
997 ;; return the class vector | |
998 inclass-p)) | |
999 | |
1000 | |
1001 ;; This function implements the main decision tree for determining the | |
1002 ;; syntactic analysis of the current line of code. Yes, it's huge and | |
1003 ;; bloated! | |
1004 | |
1005 (defun c-guess-basic-syntax () | |
1006 (save-excursion | |
1007 (save-restriction | |
1008 (beginning-of-line) | |
1009 (let* ((indent-point (point)) | |
1010 (case-fold-search nil) | |
1011 (fullstate (c-parse-state)) | |
1012 (state fullstate) | |
1013 (in-method-intro-p (and (eq major-mode 'objc-mode) | |
1014 c-method-key | |
1015 (looking-at c-method-key))) | |
1016 literal containing-sexp char-before-ip char-after-ip lim | |
1017 syntax placeholder c-in-literal-cache inswitch-p | |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1018 tmpsymbol keyword injava-inher |
18720 | 1019 ;; narrow out any enclosing class or extern "C" block |
1020 (inclass-p (c-narrow-out-enclosing-class state indent-point)) | |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1021 inenclosing-p) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1022 ;; check for meta top-level enclosing constructs, possible |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1023 ;; extern language definitions, possibly (in C++) namespace |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1024 ;; definitions. |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1025 (save-excursion |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1026 (save-restriction |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1027 (widen) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1028 (if (and inclass-p |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1029 (progn |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1030 (goto-char (aref inclass-p 0)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1031 (looking-at c-extra-toplevel-key))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1032 (let ((enclosing (match-string 1))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1033 (cond |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1034 ((string-equal enclosing "extern") |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1035 (setq inenclosing-p 'extern)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1036 ((string-equal enclosing "namespace") |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1037 (setq inenclosing-p 'namespace)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1038 ))))) |
18720 | 1039 ;; get the buffer position of the most nested opening brace, |
1040 ;; if there is one, and it hasn't been narrowed out | |
1041 (save-excursion | |
1042 (goto-char indent-point) | |
1043 (skip-chars-forward " \t}") | |
1044 (skip-chars-backward " \t") | |
1045 (while (and state | |
1046 (not in-method-intro-p) | |
1047 (not containing-sexp)) | |
1048 (setq containing-sexp (car state) | |
1049 state (cdr state)) | |
1050 (if (consp containing-sexp) | |
1051 ;; if cdr == point, then containing sexp is the brace | |
1052 ;; that opens the sexp we close | |
1053 (if (= (cdr containing-sexp) (point)) | |
1054 (setq containing-sexp (car containing-sexp)) | |
1055 ;; otherwise, ignore this element | |
1056 (setq containing-sexp nil)) | |
1057 ;; ignore the bufpos if its been narrowed out by the | |
1058 ;; containing class | |
1059 (if (<= containing-sexp (point-min)) | |
1060 (setq containing-sexp nil))))) | |
1061 | |
1062 ;; set the limit on the farthest back we need to search | |
1063 (setq lim (or containing-sexp | |
1064 (if (consp (car fullstate)) | |
1065 (cdr (car fullstate)) | |
1066 nil) | |
1067 (point-min))) | |
1068 | |
1069 ;; cache char before and after indent point, and move point to | |
1070 ;; the most likely position to perform the majority of tests | |
1071 (goto-char indent-point) | |
1072 (skip-chars-forward " \t") | |
1073 (setq char-after-ip (char-after)) | |
1074 (c-backward-syntactic-ws lim) | |
1075 (setq char-before-ip (char-before)) | |
1076 (goto-char indent-point) | |
1077 (skip-chars-forward " \t") | |
1078 | |
1079 ;; are we in a literal? | |
1080 (setq literal (c-in-literal lim)) | |
1081 | |
1082 ;; now figure out syntactic qualities of the current line | |
1083 (cond | |
1084 ;; CASE 1: in a string. | |
1085 ((memq literal '(string)) | |
1086 (c-add-syntax 'string (c-point 'bopl))) | |
1087 ;; CASE 2: in a C or C++ style comment. | |
1088 ((memq literal '(c c++)) | |
1089 ;; we need to catch multi-paragraph C comments | |
1090 (while (and (zerop (forward-line -1)) | |
1091 (looking-at "^[ \t]*$"))) | |
1092 (c-add-syntax literal (c-point 'boi))) | |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1093 ;; CASE 3: in a cpp preprocessor macro |
18720 | 1094 ((eq literal 'pound) |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1095 (let ((boi (c-point 'boi)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1096 (macrostart (progn (c-beginning-of-macro lim) (point)))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1097 (setq tmpsymbol (if (= boi macrostart) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1098 'cpp-macro |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1099 'cpp-macro-cont)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1100 (c-add-syntax tmpsymbol macrostart))) |
18720 | 1101 ;; CASE 4: in an objective-c method intro |
1102 (in-method-intro-p | |
1103 (c-add-syntax 'objc-method-intro (c-point 'boi))) | |
1104 ;; CASE 5: Line is at top level. | |
1105 ((null containing-sexp) | |
1106 (cond | |
1107 ;; CASE 5A: we are looking at a defun, class, or | |
1108 ;; inline-inclass method opening brace | |
1109 ((eq char-after-ip ?{) | |
1110 (cond | |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1111 ;; CASE 5A.1: extern language or namespace construct |
18720 | 1112 ((save-excursion |
1113 (goto-char indent-point) | |
1114 (skip-chars-forward " \t") | |
1115 (and (c-safe (progn (backward-sexp 2) t)) | |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1116 (looking-at c-extra-toplevel-key) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1117 (setq keyword (match-string 1) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1118 placeholder (point)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1119 (or (and (string-equal keyword "namespace") |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1120 (setq tmpsymbol 'namespace-open)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1121 (and (string-equal keyword "extern") |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1122 (progn |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1123 (forward-sexp 1) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1124 (c-forward-syntactic-ws) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1125 (eq (char-after) ?\")) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1126 (setq tmpsymbol 'extern-lang-open))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1127 )) |
18720 | 1128 (goto-char placeholder) |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1129 (c-add-syntax tmpsymbol (c-point 'boi))) |
18720 | 1130 ;; CASE 5A.2: we are looking at a class opening brace |
1131 ((save-excursion | |
1132 (goto-char indent-point) | |
1133 (skip-chars-forward " \t{") | |
1134 ;; TBD: watch out! there could be a bogus | |
1135 ;; c-state-cache in place when we get here. we have | |
1136 ;; to go through much chicanery to ignore the cache. | |
1137 ;; But of course, there may not be! BLECH! BOGUS! | |
1138 (let ((decl | |
1139 (if (boundp 'c-state-cache) | |
1140 (let ((old-cache c-state-cache)) | |
1141 (prog2 | |
1142 (makunbound 'c-state-cache) | |
1143 (c-search-uplist-for-classkey (c-parse-state)) | |
1144 (setq c-state-cache old-cache))) | |
1145 (c-search-uplist-for-classkey (c-parse-state)) | |
1146 ))) | |
1147 (and decl | |
1148 (setq placeholder (aref decl 0))) | |
1149 )) | |
1150 (c-add-syntax 'class-open placeholder)) | |
1151 ;; CASE 5A.3: brace list open | |
1152 ((save-excursion | |
1153 (c-beginning-of-statement-1 lim) | |
1154 ;; c-b-o-s could have left us at point-min | |
1155 (and (bobp) | |
1156 (c-forward-syntactic-ws indent-point)) | |
1157 (if (looking-at "typedef[^_]") | |
1158 (progn (forward-sexp 1) | |
1159 (c-forward-syntactic-ws indent-point))) | |
1160 (setq placeholder (c-point 'boi)) | |
1161 (and (or (looking-at "enum[ \t\n]+") | |
21106
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1162 (save-excursion |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1163 (goto-char indent-point) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1164 (while (and (> (point) placeholder) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1165 (= (c-backward-token-1 1 t) 0) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1166 (/= (char-after) ?=))) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1167 (eq (char-after) ?=))) |
18720 | 1168 (save-excursion |
1169 (skip-chars-forward "^;(" indent-point) | |
1170 (not (memq (char-after) '(?\; ?\())) | |
1171 ))) | |
1172 (c-add-syntax 'brace-list-open placeholder)) | |
1173 ;; CASE 5A.4: inline defun open | |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1174 ((and inclass-p (not inenclosing-p)) |
18720 | 1175 (c-add-syntax 'inline-open) |
1176 (c-add-syntax 'inclass (aref inclass-p 0))) | |
1177 ;; CASE 5A.5: ordinary defun open | |
1178 (t | |
1179 (goto-char placeholder) | |
21106
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1180 (if inclass-p |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1181 (c-add-syntax 'defun-open (c-point 'boi)) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1182 (c-add-syntax 'defun-open (c-point 'bol))) |
18720 | 1183 ))) |
1184 ;; CASE 5B: first K&R arg decl or member init | |
1185 ((c-just-after-func-arglist-p) | |
1186 (cond | |
1187 ;; CASE 5B.1: a member init | |
1188 ((or (eq char-before-ip ?:) | |
1189 (eq char-after-ip ?:)) | |
1190 ;; this line should be indented relative to the beginning | |
1191 ;; of indentation for the topmost-intro line that contains | |
1192 ;; the prototype's open paren | |
1193 ;; TBD: is the following redundant? | |
1194 (if (eq char-before-ip ?:) | |
1195 (forward-char -1)) | |
1196 (c-backward-syntactic-ws lim) | |
1197 ;; TBD: is the preceding redundant? | |
1198 (if (eq (char-before) ?:) | |
1199 (progn (forward-char -1) | |
1200 (c-backward-syntactic-ws lim))) | |
1201 (if (eq (char-before) ?\)) | |
1202 (backward-sexp 1)) | |
1203 (setq placeholder (point)) | |
1204 (save-excursion | |
1205 (and (c-safe (backward-sexp 1) t) | |
1206 (looking-at "throw[^_]") | |
1207 (c-safe (backward-sexp 1) t) | |
1208 (setq placeholder (point)))) | |
1209 (goto-char placeholder) | |
1210 (c-add-syntax 'member-init-intro (c-point 'boi)) | |
1211 ;; we don't need to add any class offset since this | |
1212 ;; should be relative to the ctor's indentation | |
1213 ) | |
1214 ;; CASE 5B.2: K&R arg decl intro | |
1215 (c-recognize-knr-p | |
1216 (c-add-syntax 'knr-argdecl-intro (c-point 'boi)) | |
1217 (and inclass-p (c-add-syntax 'inclass (aref inclass-p 0)))) | |
1218 ;; CASE 5B.3: Nether region after a C++ or Java func | |
1219 ;; decl, which could include a `throws' declaration. | |
1220 (t | |
1221 (c-beginning-of-statement-1 lim) | |
1222 (c-add-syntax 'func-decl-cont (c-point 'boi)) | |
1223 ))) | |
1224 ;; CASE 5C: inheritance line. could be first inheritance | |
1225 ;; line, or continuation of a multiple inheritance | |
1226 ((or (and c-baseclass-key (looking-at c-baseclass-key)) | |
1227 (and (or (eq char-before-ip ?:) | |
1228 ;; watch out for scope operator | |
1229 (save-excursion | |
1230 (and (eq char-after-ip ?:) | |
1231 (c-safe (progn (forward-char 1) t)) | |
1232 (not (eq (char-after) ?:)) | |
1233 ))) | |
1234 (save-excursion | |
1235 (c-backward-syntactic-ws lim) | |
1236 (if (eq char-before-ip ?:) | |
1237 (progn | |
1238 (forward-char -1) | |
1239 (c-backward-syntactic-ws lim))) | |
1240 (back-to-indentation) | |
1241 (looking-at c-class-key))) | |
1242 ;; for Java | |
1243 (and (eq major-mode 'java-mode) | |
1244 (let ((fence (save-excursion | |
1245 (c-beginning-of-statement-1 lim) | |
1246 (point))) | |
1247 cont done) | |
1248 (save-excursion | |
1249 (while (not done) | |
1250 (cond ((looking-at c-Java-special-key) | |
1251 (setq injava-inher (cons cont (point)) | |
1252 done t)) | |
1253 ((or (not (c-safe (forward-sexp -1) t)) | |
1254 (<= (point) fence)) | |
1255 (setq done t)) | |
1256 ) | |
1257 (setq cont t))) | |
1258 injava-inher) | |
1259 (not (c-crosses-statement-barrier-p (cdr injava-inher) | |
1260 (point))) | |
1261 )) | |
1262 (cond | |
1263 ;; CASE 5C.1: non-hanging colon on an inher intro | |
1264 ((eq char-after-ip ?:) | |
1265 (c-backward-syntactic-ws lim) | |
1266 (c-add-syntax 'inher-intro (c-point 'boi)) | |
1267 ;; don't add inclass symbol since relative point already | |
1268 ;; contains any class offset | |
1269 ) | |
1270 ;; CASE 5C.2: hanging colon on an inher intro | |
1271 ((eq char-before-ip ?:) | |
1272 (c-add-syntax 'inher-intro (c-point 'boi)) | |
1273 (and inclass-p (c-add-syntax 'inclass (aref inclass-p 0)))) | |
1274 ;; CASE 5C.3: in a Java implements/extends | |
1275 (injava-inher | |
1276 (let ((where (cdr injava-inher)) | |
1277 (cont (car injava-inher))) | |
1278 (goto-char where) | |
1279 (cond ((looking-at "throws[ \t\n]") | |
1280 (c-add-syntax 'func-decl-cont | |
1281 (progn (c-beginning-of-statement-1 lim) | |
1282 (c-point 'boi)))) | |
1283 (cont (c-add-syntax 'inher-cont where)) | |
1284 (t (c-add-syntax 'inher-intro | |
1285 (progn (goto-char (cdr injava-inher)) | |
1286 (c-beginning-of-statement-1 lim) | |
1287 (point)))) | |
1288 ))) | |
1289 ;; CASE 5C.4: a continued inheritance line | |
1290 (t | |
1291 (c-beginning-of-inheritance-list lim) | |
1292 (c-add-syntax 'inher-cont (point)) | |
1293 ;; don't add inclass symbol since relative point already | |
1294 ;; contains any class offset | |
1295 ))) | |
1296 ;; CASE 5D: this could be a top-level compound statement or a | |
1297 ;; member init list continuation | |
1298 ((eq char-before-ip ?,) | |
1299 (goto-char indent-point) | |
1300 (c-backward-syntactic-ws lim) | |
1301 (while (and (< lim (point)) | |
1302 (eq (char-before) ?,)) | |
1303 ;; this will catch member inits with multiple | |
1304 ;; line arglists | |
1305 (forward-char -1) | |
1306 (c-backward-syntactic-ws (c-point 'bol)) | |
1307 (if (eq (char-before) ?\)) | |
1308 (backward-sexp 1)) | |
1309 ;; now continue checking | |
1310 (beginning-of-line) | |
1311 (c-backward-syntactic-ws lim)) | |
1312 (cond | |
1313 ;; CASE 5D.1: hanging member init colon, but watch out | |
1314 ;; for bogus matches on access specifiers inside classes. | |
1315 ((and (eq (char-before) ?:) | |
1316 (save-excursion | |
1317 (forward-word -1) | |
1318 (not (looking-at c-access-key)))) | |
1319 (goto-char indent-point) | |
1320 (c-backward-syntactic-ws lim) | |
1321 (c-safe (backward-sexp 1)) | |
1322 (c-add-syntax 'member-init-cont (c-point 'boi)) | |
1323 ;; we do not need to add class offset since relative | |
1324 ;; point is the member init above us | |
1325 ) | |
1326 ;; CASE 5D.2: non-hanging member init colon | |
1327 ((progn | |
1328 (c-forward-syntactic-ws indent-point) | |
1329 (eq (char-after) ?:)) | |
1330 (skip-chars-forward " \t:") | |
1331 (c-add-syntax 'member-init-cont (point))) | |
1332 ;; CASE 5D.3: perhaps a multiple inheritance line? | |
1333 ((looking-at c-inher-key) | |
1334 (c-add-syntax 'inher-cont (c-point 'boi))) | |
1335 ;; CASE 5D.4: perhaps a template list continuation? | |
1336 ((save-excursion | |
19301
c4d7dd15f7d5
(c-guess-basic-syntax): CASE 5D.4: template argument continuation
Richard M. Stallman <rms@gnu.org>
parents:
19251
diff
changeset
|
1337 (goto-char indent-point) |
18720 | 1338 (skip-chars-backward "^<" lim) |
1339 ;; not sure if this is the right test, but it should | |
1340 ;; be fast and mostly accurate. | |
1341 (and (eq (char-before) ?<) | |
1342 (not (c-in-literal lim)))) | |
19301
c4d7dd15f7d5
(c-guess-basic-syntax): CASE 5D.4: template argument continuation
Richard M. Stallman <rms@gnu.org>
parents:
19251
diff
changeset
|
1343 ;; we can probably indent it just like an arglist-cont |
c4d7dd15f7d5
(c-guess-basic-syntax): CASE 5D.4: template argument continuation
Richard M. Stallman <rms@gnu.org>
parents:
19251
diff
changeset
|
1344 (c-add-syntax 'template-args-cont (point))) |
18720 | 1345 ;; CASE 5D.5: perhaps a top-level statement-cont |
1346 (t | |
1347 (c-beginning-of-statement-1 lim) | |
1348 ;; skip over any access-specifiers | |
1349 (and inclass-p c-access-key | |
1350 (while (looking-at c-access-key) | |
1351 (forward-line 1))) | |
1352 ;; skip over comments, whitespace | |
1353 (c-forward-syntactic-ws indent-point) | |
1354 (c-add-syntax 'statement-cont (c-point 'boi))) | |
1355 )) | |
1356 ;; CASE 5E: we are looking at a access specifier | |
1357 ((and inclass-p | |
1358 c-access-key | |
1359 (looking-at c-access-key)) | |
1360 (c-add-syntax 'access-label (c-point 'bonl)) | |
1361 (c-add-syntax 'inclass (aref inclass-p 0))) | |
21106
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1362 ;; CASE 5F: extern-lang-close or namespace-close? |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1363 ((and inenclosing-p |
18720 | 1364 (eq char-after-ip ?})) |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1365 (setq tmpsymbol (if (eq inenclosing-p 'extern) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1366 'extern-lang-close |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1367 'namespace-close)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1368 (c-add-syntax tmpsymbol (aref inclass-p 0))) |
18720 | 1369 ;; CASE 5G: we are looking at the brace which closes the |
1370 ;; enclosing nested class decl | |
1371 ((and inclass-p | |
1372 (eq char-after-ip ?}) | |
1373 (save-excursion | |
1374 (save-restriction | |
1375 (widen) | |
1376 (forward-char 1) | |
1377 (and | |
1378 (condition-case nil | |
1379 (progn (backward-sexp 1) t) | |
1380 (error nil)) | |
1381 (= (point) (aref inclass-p 1)) | |
1382 )))) | |
1383 (save-restriction | |
1384 (widen) | |
1385 (goto-char (aref inclass-p 0)) | |
1386 (c-add-syntax 'class-close (c-point 'boi)))) | |
1387 ;; CASE 5H: we could be looking at subsequent knr-argdecls | |
1388 ((and c-recognize-knr-p | |
1389 ;; here we essentially use the hack that is used in | |
1390 ;; Emacs' c-mode.el to limit how far back we should | |
1391 ;; look. The assumption is made that argdecls are | |
1392 ;; indented at least one space and that function | |
1393 ;; headers are not indented. | |
1394 (let ((limit (save-excursion | |
1395 (re-search-backward "^[^ \^L\t\n#]" nil 'move) | |
1396 (point)))) | |
1397 (save-excursion | |
1398 (c-backward-syntactic-ws limit) | |
1399 (setq placeholder (point)) | |
1400 (while (and (memq (char-before) '(?\; ?,)) | |
1401 (> (point) limit)) | |
1402 (beginning-of-line) | |
1403 (setq placeholder (point)) | |
1404 (c-backward-syntactic-ws limit)) | |
1405 (and (eq (char-before) ?\)) | |
1406 (or (not c-method-key) | |
1407 (progn | |
1408 (forward-sexp -1) | |
1409 (forward-char -1) | |
1410 (c-backward-syntactic-ws) | |
1411 (not (or (memq (char-before) '(?- ?+)) | |
1412 ;; or a class category | |
1413 (progn | |
1414 (forward-sexp -2) | |
1415 (looking-at c-class-key)) | |
1416 ))))) | |
1417 )) | |
1418 (save-excursion | |
1419 (c-beginning-of-statement-1) | |
1420 (not (looking-at "typedef[ \t\n]+")))) | |
1421 (goto-char placeholder) | |
1422 (c-add-syntax 'knr-argdecl (c-point 'boi))) | |
1423 ;; CASE 5I: we are at the topmost level, make sure we skip | |
1424 ;; back past any access specifiers | |
1425 ((progn | |
1426 (c-backward-syntactic-ws lim) | |
1427 (while (and inclass-p | |
1428 c-access-key | |
1429 (not (bobp)) | |
1430 (save-excursion | |
1431 (c-safe (progn (backward-sexp 1) t)) | |
1432 (looking-at c-access-key))) | |
1433 (backward-sexp 1) | |
1434 (c-backward-syntactic-ws lim)) | |
1435 (or (bobp) | |
1436 (memq (char-before) '(?\; ?\})))) | |
1437 ;; real beginning-of-line could be narrowed out due to | |
1438 ;; enclosure in a class block | |
1439 (save-restriction | |
1440 (widen) | |
1441 (c-add-syntax 'topmost-intro (c-point 'bol)) | |
1442 (if inclass-p | |
1443 (progn | |
1444 (goto-char (aref inclass-p 1)) | |
19251
6a7d40ec4b29
(c-beginning-of-statement-1): When checking for bare semi, don't match
Richard M. Stallman <rms@gnu.org>
parents:
18844
diff
changeset
|
1445 (or (= (point) (c-point 'boi)) |
6a7d40ec4b29
(c-beginning-of-statement-1): When checking for bare semi, don't match
Richard M. Stallman <rms@gnu.org>
parents:
18844
diff
changeset
|
1446 (goto-char (aref inclass-p 0))) |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1447 (cond |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1448 ((eq inenclosing-p 'extern) |
21106
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1449 (c-add-syntax 'inextern-lang (c-point 'boi))) |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1450 ((eq inenclosing-p 'namespace) |
21106
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1451 (c-add-syntax 'innamespace (c-point 'boi))) |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1452 (t (c-add-syntax 'inclass (c-point 'boi)))) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1453 )) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1454 )) |
18720 | 1455 ;; CASE 5J: we are at an ObjC or Java method definition |
1456 ;; continuation line. | |
1457 ((and c-method-key | |
1458 (progn | |
1459 (c-beginning-of-statement-1 lim) | |
1460 (beginning-of-line) | |
1461 (looking-at c-method-key))) | |
1462 (c-add-syntax 'objc-method-args-cont (point))) | |
1463 ;; CASE 5K: we are at a topmost continuation line | |
1464 (t | |
1465 (c-beginning-of-statement-1 lim) | |
1466 (c-forward-syntactic-ws) | |
1467 (c-add-syntax 'topmost-intro-cont (c-point 'boi))) | |
1468 )) ; end CASE 5 | |
1469 ;; CASE 6: line is an expression, not a statement. Most | |
1470 ;; likely we are either in a function prototype or a function | |
1471 ;; call argument list | |
1472 ((not (eq (char-after containing-sexp) ?{)) | |
1473 (c-backward-syntactic-ws containing-sexp) | |
1474 (cond | |
1475 ;; CASE 6A: we are looking at the arglist closing paren | |
1476 ((and (not (eq char-before-ip ?,)) | |
1477 (memq char-after-ip '(?\) ?\]))) | |
1478 (goto-char containing-sexp) | |
1479 (c-add-syntax 'arglist-close (c-point 'boi))) | |
1480 ;; CASE 6B: we are looking at the first argument in an empty | |
1481 ;; argument list. Use arglist-close if we're actually | |
1482 ;; looking at a close paren or bracket. | |
1483 ((memq char-before-ip '(?\( ?\[)) | |
1484 (goto-char containing-sexp) | |
1485 (c-add-syntax 'arglist-intro (c-point 'boi))) | |
1486 ;; CASE 6C: we are inside a conditional test clause. treat | |
1487 ;; these things as statements | |
1488 ((save-excursion | |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1489 (goto-char containing-sexp) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1490 (and (c-safe (progn (forward-sexp -1) t)) |
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1491 (looking-at "\\<for\\>[^_]"))) |
18720 | 1492 (goto-char (1+ containing-sexp)) |
1493 (c-forward-syntactic-ws indent-point) | |
1494 (c-beginning-of-statement-1 containing-sexp) | |
1495 (if (eq char-before-ip ?\;) | |
1496 (c-add-syntax 'statement (point)) | |
1497 (c-add-syntax 'statement-cont (point)) | |
1498 )) | |
1499 ;; CASE 6D: maybe a continued method call. This is the case | |
1500 ;; when we are inside a [] bracketed exp, and what precede | |
1501 ;; the opening bracket is not an identifier. | |
1502 ((and c-method-key | |
1503 (eq (char-after containing-sexp) ?\[) | |
1504 (save-excursion | |
1505 (goto-char (1- containing-sexp)) | |
1506 (c-backward-syntactic-ws (c-point 'bod)) | |
1507 (if (not (looking-at c-symbol-key)) | |
1508 (c-add-syntax 'objc-method-call-cont containing-sexp)) | |
1509 ))) | |
1510 ;; CASE 6E: we are looking at an arglist continuation line, | |
1511 ;; but the preceding argument is on the same line as the | |
1512 ;; opening paren. This case includes multi-line | |
1513 ;; mathematical paren groupings, but we could be on a | |
1514 ;; for-list continuation line | |
1515 ((and (save-excursion | |
1516 (goto-char (1+ containing-sexp)) | |
1517 (skip-chars-forward " \t") | |
1518 (not (eolp))) | |
1519 (save-excursion | |
1520 (c-beginning-of-statement-1 lim) | |
1521 (skip-chars-backward " \t([") | |
1522 (<= (point) containing-sexp))) | |
1523 (goto-char containing-sexp) | |
1524 (c-add-syntax 'arglist-cont-nonempty (c-point 'boi))) | |
1525 ;; CASE 6F: we are looking at just a normal arglist | |
1526 ;; continuation line | |
1527 (t (c-beginning-of-statement-1 containing-sexp) | |
1528 (forward-char 1) | |
1529 (c-forward-syntactic-ws indent-point) | |
1530 (c-add-syntax 'arglist-cont (c-point 'boi))) | |
1531 )) | |
1532 ;; CASE 7: func-local multi-inheritance line | |
1533 ((and c-baseclass-key | |
1534 (save-excursion | |
1535 (goto-char indent-point) | |
1536 (skip-chars-forward " \t") | |
1537 (looking-at c-baseclass-key))) | |
1538 (goto-char indent-point) | |
1539 (skip-chars-forward " \t") | |
1540 (cond | |
1541 ;; CASE 7A: non-hanging colon on an inher intro | |
1542 ((eq char-after-ip ?:) | |
1543 (c-backward-syntactic-ws lim) | |
1544 (c-add-syntax 'inher-intro (c-point 'boi))) | |
1545 ;; CASE 7B: hanging colon on an inher intro | |
1546 ((eq char-before-ip ?:) | |
1547 (c-add-syntax 'inher-intro (c-point 'boi))) | |
1548 ;; CASE 7C: a continued inheritance line | |
1549 (t | |
1550 (c-beginning-of-inheritance-list lim) | |
1551 (c-add-syntax 'inher-cont (point)) | |
1552 ))) | |
1553 ;; CASE 8: we are inside a brace-list | |
1554 ((setq placeholder (c-inside-bracelist-p containing-sexp state)) | |
1555 (cond | |
1556 ;; CASE 8A: brace-list-close brace | |
1557 ((and (eq char-after-ip ?}) | |
1558 (c-safe (progn (forward-char 1) | |
1559 (backward-sexp 1) | |
1560 t)) | |
1561 (= (point) containing-sexp)) | |
1562 (c-add-syntax 'brace-list-close (c-point 'boi))) | |
1563 ;; CASE 8B: we're looking at the first line in a brace-list | |
1564 ((save-excursion | |
1565 (goto-char indent-point) | |
1566 (c-backward-syntactic-ws containing-sexp) | |
1567 (= (point) (1+ containing-sexp))) | |
1568 (goto-char containing-sexp) | |
1569 (c-add-syntax 'brace-list-intro (c-point 'boi)) | |
1570 ) | |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1571 ;;)) ; end CASE 8B |
18720 | 1572 ;; CASE 8C: this is just a later brace-list-entry |
1573 (t (goto-char (1+ containing-sexp)) | |
1574 (c-forward-syntactic-ws indent-point) | |
1575 (if (eq char-after-ip ?{) | |
1576 (c-add-syntax 'brace-list-open (point)) | |
1577 (c-add-syntax 'brace-list-entry (point)) | |
1578 )) ; end CASE 8C | |
1579 )) ; end CASE 8 | |
1580 ;; CASE 9: A continued statement | |
1581 ((and (not (memq char-before-ip '(?\; ?} ?:))) | |
1582 (> (point) | |
1583 (save-excursion | |
1584 (c-beginning-of-statement-1 containing-sexp) | |
1585 (setq placeholder (point)))) | |
1586 (/= placeholder containing-sexp)) | |
1587 (goto-char indent-point) | |
1588 (skip-chars-forward " \t") | |
1589 (let ((after-cond-placeholder | |
1590 (save-excursion | |
1591 (goto-char placeholder) | |
1592 (if (looking-at c-conditional-key) | |
1593 (progn | |
1594 (c-safe (c-skip-conditional)) | |
1595 (c-forward-syntactic-ws) | |
1596 (if (eq (char-after) ?\;) | |
1597 (progn | |
1598 (forward-char 1) | |
1599 (c-forward-syntactic-ws))) | |
1600 (point)) | |
1601 nil)))) | |
1602 (cond | |
1603 ;; CASE 9A: substatement | |
1604 ((and after-cond-placeholder | |
1605 (>= after-cond-placeholder indent-point)) | |
1606 (goto-char placeholder) | |
1607 (if (eq char-after-ip ?{) | |
1608 (c-add-syntax 'substatement-open (c-point 'boi)) | |
1609 (c-add-syntax 'substatement (c-point 'boi)))) | |
1610 ;; CASE 9B: open braces for class or brace-lists | |
1611 ((eq char-after-ip ?{) | |
1612 (cond | |
1613 ;; CASE 9B.1: class-open | |
1614 ((save-excursion | |
1615 (goto-char indent-point) | |
1616 (skip-chars-forward " \t{") | |
1617 (let ((decl (c-search-uplist-for-classkey (c-parse-state)))) | |
1618 (and decl | |
1619 (setq placeholder (aref decl 0))) | |
1620 )) | |
1621 (c-add-syntax 'class-open placeholder)) | |
1622 ;; CASE 9B.2: brace-list-open | |
1623 ((or (save-excursion | |
1624 (goto-char placeholder) | |
1625 (looking-at "\\<enum\\>")) | |
21106
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1626 (save-excursion |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1627 (goto-char indent-point) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1628 (while (and (> (point) placeholder) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1629 (= (c-backward-token-1 1 t) 0) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1630 (/= (char-after) ?=))) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1631 (eq (char-after) ?=))) |
18720 | 1632 (c-add-syntax 'brace-list-open placeholder)) |
1633 ;; CASE 9B.3: catch-all for unknown construct. | |
1634 (t | |
1635 ;; Can and should I add an extensibility hook here? | |
1636 ;; Something like c-recognize-hook so support for | |
1637 ;; unknown constructs could be added. It's probably a | |
1638 ;; losing proposition, so I dunno. | |
1639 (goto-char placeholder) | |
1640 (c-add-syntax 'statement-cont (c-point 'boi)) | |
1641 (c-add-syntax 'block-open)) | |
1642 )) | |
1643 ;; CASE 9C: iostream insertion or extraction operator | |
1644 ((looking-at "<<\\|>>") | |
1645 (goto-char placeholder) | |
1646 (and after-cond-placeholder | |
1647 (goto-char after-cond-placeholder)) | |
1648 (while (and (re-search-forward "<<\\|>>" indent-point 'move) | |
1649 (c-in-literal placeholder))) | |
1650 ;; if we ended up at indent-point, then the first | |
1651 ;; streamop is on a separate line. Indent the line like | |
1652 ;; a statement-cont instead | |
1653 (if (/= (point) indent-point) | |
1654 (c-add-syntax 'stream-op (c-point 'boi)) | |
1655 (c-backward-syntactic-ws lim) | |
1656 (c-add-syntax 'statement-cont (c-point 'boi)))) | |
1657 ;; CASE 9D: continued statement. find the accurate | |
1658 ;; beginning of statement or substatement | |
1659 (t | |
1660 (c-beginning-of-statement-1 after-cond-placeholder) | |
1661 ;; KLUDGE ALERT! c-beginning-of-statement-1 can leave | |
1662 ;; us before the lim we're passing in. It should be | |
1663 ;; fixed, but I'm worried about side-effects at this | |
1664 ;; late date. Fix for v5. | |
1665 (goto-char (or (and after-cond-placeholder | |
1666 (max after-cond-placeholder (point))) | |
1667 (point))) | |
1668 (c-add-syntax 'statement-cont (point))) | |
1669 ))) | |
1670 ;; CASE 10: an else clause? | |
1671 ((looking-at "\\<else\\>[^_]") | |
1672 (c-backward-to-start-of-if containing-sexp) | |
1673 (c-add-syntax 'else-clause (c-point 'boi))) | |
1674 ;; CASE 11: Statement. But what kind? Lets see if its a | |
1675 ;; while closure of a do/while construct | |
1676 ((progn | |
1677 (goto-char indent-point) | |
1678 (skip-chars-forward " \t") | |
1679 (and (looking-at "while\\b[^_]") | |
1680 (save-excursion | |
1681 (c-backward-to-start-of-do containing-sexp) | |
1682 (setq placeholder (point)) | |
1683 (looking-at "do\\b[^_]")) | |
1684 )) | |
1685 (c-add-syntax 'do-while-closure placeholder)) | |
1686 ;; CASE 12: A case or default label | |
1687 ((looking-at c-switch-label-key) | |
1688 (goto-char containing-sexp) | |
1689 ;; check for hanging braces | |
1690 (if (/= (point) (c-point 'boi)) | |
1691 (forward-sexp -1)) | |
1692 (c-add-syntax 'case-label (c-point 'boi))) | |
1693 ;; CASE 13: any other label | |
1694 ((looking-at c-label-key) | |
1695 (goto-char containing-sexp) | |
1696 (c-add-syntax 'label (c-point 'boi))) | |
1697 ;; CASE 14: block close brace, possibly closing the defun or | |
1698 ;; the class | |
1699 ((eq char-after-ip ?}) | |
1700 (let* ((lim (c-safe-position containing-sexp fullstate)) | |
1701 (relpos (save-excursion | |
1702 (goto-char containing-sexp) | |
1703 (if (/= (point) (c-point 'boi)) | |
1704 (c-beginning-of-statement-1 lim)) | |
1705 (c-point 'boi)))) | |
1706 (cond | |
21106
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1707 ;; CASE 14A: does this close an inline or a function in |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1708 ;; an extern block or namespace? |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1709 ((progn |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1710 (goto-char containing-sexp) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1711 (setq placeholder (c-search-uplist-for-classkey state))) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1712 (goto-char (aref placeholder 0)) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1713 (if (looking-at c-extra-toplevel-key) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1714 (c-add-syntax 'defun-close relpos) |
5e5fa0a34cb0
(c-inside-bracelist-p): Fix for enum test.
Richard M. Stallman <rms@gnu.org>
parents:
20914
diff
changeset
|
1715 (c-add-syntax 'inline-close relpos))) |
18720 | 1716 ;; CASE 14B: if there an enclosing brace that hasn't |
1717 ;; been narrowed out by a class, then this is a | |
1718 ;; block-close | |
20914
8f189ffad604
(c-forward-syntactic-ws, c-backward-syntactic-ws):
Richard M. Stallman <rms@gnu.org>
parents:
20142
diff
changeset
|
1719 ((and (not inenclosing-p) |
18720 | 1720 (c-most-enclosing-brace state)) |
1721 (c-add-syntax 'block-close relpos)) | |
1722 ;; CASE 14C: find out whether we're closing a top-level | |
1723 ;; class or a defun | |
1724 (t | |
1725 (save-restriction | |
1726 (narrow-to-region (point-min) indent-point) | |
1727 (let ((decl (c-search-uplist-for-classkey (c-parse-state)))) | |
1728 (if decl | |
1729 (c-add-syntax 'class-close (aref decl 0)) | |
1730 (c-add-syntax 'defun-close relpos))))) | |
1731 ))) | |
1732 ;; CASE 15: statement catchall | |
1733 (t | |
1734 ;; we know its a statement, but we need to find out if it is | |
1735 ;; the first statement in a block | |
1736 (goto-char containing-sexp) | |
1737 (forward-char 1) | |
1738 (c-forward-syntactic-ws indent-point) | |
1739 ;; now skip forward past any case/default clauses we might find. | |
1740 (while (or (c-skip-case-statement-forward fullstate indent-point) | |
1741 (and (looking-at c-switch-label-key) | |
1742 (not inswitch-p))) | |
1743 (setq inswitch-p t)) | |
1744 ;; we want to ignore non-case labels when skipping forward | |
1745 (while (and (looking-at c-label-key) | |
1746 (goto-char (match-end 0))) | |
1747 (c-forward-syntactic-ws indent-point)) | |
1748 (cond | |
1749 ;; CASE 15A: we are inside a case/default clause inside a | |
1750 ;; switch statement. find out if we are at the statement | |
1751 ;; just after the case/default label. | |
1752 ((and inswitch-p | |
1753 (progn | |
1754 (goto-char indent-point) | |
1755 (c-backward-syntactic-ws containing-sexp) | |
1756 (back-to-indentation) | |
1757 (setq placeholder (point)) | |
1758 (looking-at c-switch-label-key))) | |
1759 (goto-char indent-point) | |
1760 (skip-chars-forward " \t") | |
1761 (if (eq (char-after) ?{) | |
1762 (c-add-syntax 'statement-case-open placeholder) | |
1763 (c-add-syntax 'statement-case-intro placeholder))) | |
1764 ;; CASE 15B: continued statement | |
1765 ((eq char-before-ip ?,) | |
1766 (c-add-syntax 'statement-cont (c-point 'boi))) | |
1767 ;; CASE 15C: a question/colon construct? But make sure | |
1768 ;; what came before was not a label, and what comes after | |
1769 ;; is not a globally scoped function call! | |
1770 ((or (and (memq char-before-ip '(?: ??)) | |
1771 (save-excursion | |
1772 (goto-char indent-point) | |
1773 (c-backward-syntactic-ws lim) | |
1774 (back-to-indentation) | |
1775 (not (looking-at c-label-key)))) | |
1776 (and (memq char-after-ip '(?: ??)) | |
1777 (save-excursion | |
1778 (goto-char indent-point) | |
1779 (skip-chars-forward " \t") | |
1780 ;; watch out for scope operator | |
1781 (not (looking-at "::"))))) | |
1782 (c-add-syntax 'statement-cont (c-point 'boi))) | |
1783 ;; CASE 15D: any old statement | |
1784 ((< (point) indent-point) | |
1785 (let ((safepos (c-most-enclosing-brace fullstate)) | |
1786 relpos done) | |
1787 (goto-char indent-point) | |
1788 (c-beginning-of-statement-1 safepos) | |
1789 ;; It is possible we're on the brace that opens a nested | |
1790 ;; function. | |
1791 (if (and (eq (char-after) ?{) | |
1792 (save-excursion | |
1793 (c-backward-syntactic-ws safepos) | |
1794 (not (eq (char-before) ?\;)))) | |
1795 (c-beginning-of-statement-1 safepos)) | |
1796 (if (and inswitch-p | |
1797 (looking-at c-switch-label-key)) | |
1798 (progn | |
1799 (goto-char placeholder) | |
1800 (end-of-line) | |
1801 (forward-sexp -1))) | |
1802 (setq relpos (c-point 'boi)) | |
1803 (while (and (not done) | |
1804 (<= safepos (point)) | |
1805 (/= relpos (point))) | |
1806 (c-beginning-of-statement-1 safepos) | |
1807 (if (= relpos (c-point 'boi)) | |
1808 (setq done t)) | |
1809 (setq relpos (c-point 'boi))) | |
1810 (c-add-syntax 'statement relpos) | |
1811 (if (eq char-after-ip ?{) | |
1812 (c-add-syntax 'block-open)))) | |
1813 ;; CASE 15E: first statement in an inline, or first | |
1814 ;; statement in a top-level defun. we can tell this is it | |
1815 ;; if there are no enclosing braces that haven't been | |
1816 ;; narrowed out by a class (i.e. don't use bod here!) | |
1817 ((save-excursion | |
1818 (save-restriction | |
1819 (widen) | |
1820 (goto-char containing-sexp) | |
1821 (c-narrow-out-enclosing-class state containing-sexp) | |
1822 (not (c-most-enclosing-brace state)))) | |
1823 (goto-char containing-sexp) | |
1824 ;; if not at boi, then defun-opening braces are hung on | |
1825 ;; right side, so we need a different relpos | |
1826 (if (/= (point) (c-point 'boi)) | |
1827 (progn | |
1828 (c-backward-syntactic-ws) | |
1829 (c-safe (forward-sexp (if (eq (char-before) ?\)) | |
1830 -1 -2))) | |
1831 ;; looking at a Java throws clause following a | |
1832 ;; method's parameter list | |
1833 (c-beginning-of-statement-1) | |
1834 )) | |
1835 (c-add-syntax 'defun-block-intro (c-point 'boi))) | |
1836 ;; CASE 15F: first statement in a block | |
1837 (t (goto-char containing-sexp) | |
1838 (if (/= (point) (c-point 'boi)) | |
1839 (c-beginning-of-statement-1 | |
1840 (if (= (point) lim) | |
1841 (c-safe-position (point) state) lim))) | |
1842 (c-add-syntax 'statement-block-intro (c-point 'boi)) | |
1843 (if (eq char-after-ip ?{) | |
1844 (c-add-syntax 'block-open))) | |
1845 )) | |
1846 ) | |
1847 | |
1848 ;; now we need to look at any modifiers | |
1849 (goto-char indent-point) | |
1850 (skip-chars-forward " \t") | |
1851 ;; are we looking at a comment only line? | |
1852 (if (looking-at c-comment-start-regexp) | |
1853 (c-add-syntax 'comment-intro)) | |
1854 ;; we might want to give additional offset to friends (in C++). | |
1855 (if (and (eq major-mode 'c++-mode) | |
1856 (looking-at c-C++-friend-key)) | |
1857 (c-add-syntax 'friend)) | |
1858 ;; return the syntax | |
1859 syntax)))) | |
1860 | |
1861 | |
1862 (defun c-echo-parsing-error () | |
1863 (if (not c-parsing-error) | |
1864 nil | |
1865 (message "unbalanced close brace at bufpos %d -- INDENTATION IS SUSPECT!" | |
1866 c-parsing-error) | |
1867 (ding)) | |
1868 c-parsing-error) | |
1869 | |
1870 ;; indent via syntactic language elements | |
1871 (defun c-indent-line (&optional syntax) | |
1872 ;; indent the current line as C/C++/ObjC code. Optional SYNTAX is the | |
1873 ;; syntactic information for the current line. Returns the amount of | |
1874 ;; indentation change | |
1875 (let* ((c-syntactic-context (or syntax (c-guess-basic-syntax))) | |
1876 (pos (- (point-max) (point))) | |
1877 (indent (apply '+ (mapcar 'c-get-offset c-syntactic-context))) | |
1878 (shift-amt (- (current-indentation) indent))) | |
1879 (and c-echo-syntactic-information-p | |
1880 (not (c-echo-parsing-error)) | |
1881 (message "syntax: %s, indent= %d" c-syntactic-context indent)) | |
1882 (if (zerop shift-amt) | |
1883 nil | |
1884 (delete-region (c-point 'bol) (c-point 'boi)) | |
1885 (beginning-of-line) | |
1886 (indent-to indent)) | |
1887 (if (< (point) (c-point 'boi)) | |
1888 (back-to-indentation) | |
1889 ;; If initial point was within line's indentation, position after | |
1890 ;; the indentation. Else stay at same point in text. | |
1891 (if (> (- (point-max) pos) (point)) | |
1892 (goto-char (- (point-max) pos))) | |
1893 ) | |
1894 (run-hooks 'c-special-indent-hook) | |
1895 shift-amt)) | |
1896 | |
1897 (defun c-show-syntactic-information (arg) | |
1898 "Show syntactic information for current line. | |
1899 With universal argument, inserts the analysis as a comment on that line." | |
1900 (interactive "P") | |
1901 (let ((syntax (c-guess-basic-syntax))) | |
1902 (if (not (consp arg)) | |
1903 (if (not (c-echo-parsing-error)) | |
1904 (message "syntactic analysis: %s" syntax)) | |
1905 (indent-for-comment) | |
1906 (insert (format "%s" syntax)) | |
1907 )) | |
1908 (c-keep-region-active)) | |
1909 | |
1910 | |
1911 (provide 'cc-engine) | |
1912 ;;; cc-engine.el ends here |