annotate lisp/cc-mode/cc-engine.el @ 165:5a88923fcbfe r20-3b9

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