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