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