Mercurial > emacs
comparison lisp/progmodes/cc-defs.el @ 44728:7a3ac6c387fe
CC Mode update to version 5.29. This is for testing; it's not a released
version.
author | Martin Stjernholm <mast@lysator.liu.se> |
---|---|
date | Mon, 22 Apr 2002 00:35:36 +0000 |
parents | 7a94f1c588c4 |
children | 0d8b17d428b5 |
comparison
equal
deleted
inserted
replaced
44727:3936c522b4d3 | 44728:7a3ac6c387fe |
---|---|
23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | 23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
25 ;; GNU General Public License for more details. | 25 ;; GNU General Public License for more details. |
26 | 26 |
27 ;; You should have received a copy of the GNU General Public License | 27 ;; You should have received a copy of the GNU General Public License |
28 ;; along with this program; see the file COPYING. If not, write to | 28 ;; along with GNU Emacs; see the file COPYING. If not, write to |
29 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 29 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
30 ;; Boston, MA 02111-1307, USA. | 30 ;; Boston, MA 02111-1307, USA. |
31 | 31 |
32 ;;; Commentary: | 32 ;;; Commentary: |
33 | 33 |
55 (not (fboundp 'unless))) | 55 (not (fboundp 'unless))) |
56 (cc-load "cc-mode-19"))) | 56 (cc-load "cc-mode-19"))) |
57 | 57 |
58 ;; Silence the compiler. | 58 ;; Silence the compiler. |
59 (cc-bytecomp-defvar c-enable-xemacs-performance-kludge-p) ; In cc-vars.el | 59 (cc-bytecomp-defvar c-enable-xemacs-performance-kludge-p) ; In cc-vars.el |
60 (cc-bytecomp-defvar c-buffer-is-cc-mode) ; In cc-vars.el | |
60 (cc-bytecomp-defun buffer-syntactic-context-depth) ; XEmacs | 61 (cc-bytecomp-defun buffer-syntactic-context-depth) ; XEmacs |
61 (cc-bytecomp-defun region-active-p) ; XEmacs | 62 (cc-bytecomp-defun region-active-p) ; XEmacs |
62 (cc-bytecomp-defvar zmacs-region-stays) ; XEmacs | 63 (cc-bytecomp-defvar zmacs-region-stays) ; XEmacs |
63 (cc-bytecomp-defvar zmacs-regions) ; XEmacs | 64 (cc-bytecomp-defvar zmacs-regions) ; XEmacs |
64 (cc-bytecomp-defvar mark-active) ; Emacs | 65 (cc-bytecomp-defvar mark-active) ; Emacs |
81 ;; | 82 ;; |
82 ;; bol -- beginning of line | 83 ;; bol -- beginning of line |
83 ;; eol -- end of line | 84 ;; eol -- end of line |
84 ;; bod -- beginning of defun | 85 ;; bod -- beginning of defun |
85 ;; eod -- end of defun | 86 ;; eod -- end of defun |
86 ;; boi -- back to indentation | 87 ;; boi -- beginning of indentation |
87 ;; ionl -- indentation of next line | 88 ;; ionl -- indentation of next line |
88 ;; iopl -- indentation of previous line | 89 ;; iopl -- indentation of previous line |
89 ;; bonl -- beginning of next line | 90 ;; bonl -- beginning of next line |
91 ;; eonl -- end of next line | |
90 ;; bopl -- beginning of previous line | 92 ;; bopl -- beginning of previous line |
93 ;; eopl -- end of previous line | |
91 ;; | 94 ;; |
92 ;; This function does not modify point or mark. | 95 ;; If the referenced position doesn't exist, the closest accessible |
96 ;; point to it is returned. This function does not modify point or | |
97 ;; mark. | |
93 `(save-excursion | 98 `(save-excursion |
94 ,(if point `(goto-char ,point)) | 99 ,(if point `(goto-char ,point)) |
95 ,(if (and (eq (car-safe position) 'quote) | 100 ,(if (and (eq (car-safe position) 'quote) |
96 (symbolp (eval position))) | 101 (symbolp (eval position))) |
97 (let ((position (eval position))) | 102 (let ((position (eval position))) |
98 (cond | 103 (cond |
99 ((eq position 'bol) `(beginning-of-line)) | 104 ((eq position 'bol) `(beginning-of-line)) |
100 ((eq position 'eol) `(end-of-line)) | 105 ((eq position 'eol) `(end-of-line)) |
101 ((eq position 'boi) `(back-to-indentation)) | 106 ((eq position 'boi) `(back-to-indentation)) |
107 ((eq position 'bod) `(c-beginning-of-defun-1)) | |
102 ((eq position 'bonl) `(forward-line 1)) | 108 ((eq position 'bonl) `(forward-line 1)) |
103 ((eq position 'bopl) `(forward-line -1)) | 109 ((eq position 'bopl) `(forward-line -1)) |
104 ((eq position 'bod) `(c-beginning-of-defun-1)) | |
105 ((eq position 'eod) `(c-end-of-defun-1)) | 110 ((eq position 'eod) `(c-end-of-defun-1)) |
111 ((eq position 'eopl) `(progn | |
112 (beginning-of-line) | |
113 (or (bobp) (backward-char)))) | |
114 ((eq position 'eonl) `(progn | |
115 (forward-line 1) | |
116 (end-of-line))) | |
106 ((eq position 'iopl) `(progn | 117 ((eq position 'iopl) `(progn |
107 (forward-line -1) | 118 (forward-line -1) |
108 (back-to-indentation))) | 119 (back-to-indentation))) |
109 ((eq position 'ionl) `(progn | 120 ((eq position 'ionl) `(progn |
110 (forward-line 1) | 121 (forward-line 1) |
114 `(let ((position ,position)) | 125 `(let ((position ,position)) |
115 (cond | 126 (cond |
116 ((eq position 'bol) (beginning-of-line)) | 127 ((eq position 'bol) (beginning-of-line)) |
117 ((eq position 'eol) (end-of-line)) | 128 ((eq position 'eol) (end-of-line)) |
118 ((eq position 'boi) (back-to-indentation)) | 129 ((eq position 'boi) (back-to-indentation)) |
130 ((eq position 'bod) (c-beginning-of-defun-1)) | |
119 ((eq position 'bonl) (forward-line 1)) | 131 ((eq position 'bonl) (forward-line 1)) |
120 ((eq position 'bopl) (forward-line -1)) | 132 ((eq position 'bopl) (forward-line -1)) |
121 ((eq position 'bod) (c-beginning-of-defun-1)) | |
122 ((eq position 'eod) (c-end-of-defun-1)) | 133 ((eq position 'eod) (c-end-of-defun-1)) |
134 ((eq position 'eopl) (progn | |
135 (beginning-of-line) | |
136 (or (bobp) (backward-char)))) | |
137 ((eq position 'eonl) (progn | |
138 (forward-line 1) | |
139 (end-of-line))) | |
123 ((eq position 'iopl) (progn | 140 ((eq position 'iopl) (progn |
124 (forward-line -1) | 141 (forward-line -1) |
125 (back-to-indentation))) | 142 (back-to-indentation))) |
126 ((eq position 'ionl) (progn | 143 ((eq position 'ionl) (progn |
127 (forward-line 1) | 144 (forward-line 1) |
132 (defmacro c-safe (&rest body) | 149 (defmacro c-safe (&rest body) |
133 ;; safely execute BODY, return nil if an error occurred | 150 ;; safely execute BODY, return nil if an error occurred |
134 `(condition-case nil | 151 `(condition-case nil |
135 (progn ,@body) | 152 (progn ,@body) |
136 (error nil))) | 153 (error nil))) |
154 (put 'c-safe 'lisp-indent-function 0) | |
137 | 155 |
138 (defmacro c-forward-sexp (&optional arg) | 156 (defmacro c-forward-sexp (&optional arg) |
139 ;; like forward-sexp except | 157 ;; like forward-sexp except |
140 ;; 1. this is much stripped down from the XEmacs version | 158 ;; 1. this is much stripped down from the XEmacs version |
141 ;; 2. this cannot be used as a command, so we're insulated from | 159 ;; 2. this cannot be used as a command, so we're insulated from |
151 (defmacro c-backward-sexp (&optional arg) | 169 (defmacro c-backward-sexp (&optional arg) |
152 ;; See c-forward-sexp and reverse directions | 170 ;; See c-forward-sexp and reverse directions |
153 (or arg (setq arg 1)) | 171 (or arg (setq arg 1)) |
154 `(c-forward-sexp ,(if (numberp arg) (- arg) `(- ,arg)))) | 172 `(c-forward-sexp ,(if (numberp arg) (- arg) `(- ,arg)))) |
155 | 173 |
174 ;; Wrappers for common scan-lists cases, mainly because it's almost | |
175 ;; impossible to get a feel for how that function works. | |
176 (defmacro c-up-list-forward (pos) | |
177 `(c-safe (scan-lists ,pos 1 1))) | |
178 (defmacro c-up-list-backward (pos) | |
179 `(c-safe (scan-lists ,pos -1 1))) | |
180 (defmacro c-down-list-forward (pos) | |
181 `(c-safe (scan-lists ,pos 1 -1))) | |
182 (defmacro c-down-list-backward (pos) | |
183 `(c-safe (scan-lists ,pos -1 -1))) | |
184 | |
156 (defmacro c-add-syntax (symbol &optional relpos) | 185 (defmacro c-add-syntax (symbol &optional relpos) |
157 ;; a simple macro to append the syntax in symbol to the syntax list. | 186 ;; a simple macro to append the syntax in symbol to the syntax list. |
158 ;; try to increase performance by using this macro | 187 ;; try to increase performance by using this macro |
159 `(setq syntax (cons (cons ,symbol ,relpos) syntax))) | 188 `(let ((relpos-tmp ,relpos)) |
160 | 189 (if relpos-tmp (setq syntactic-relpos relpos-tmp)) |
161 (defmacro c-add-class-syntax (symbol classkey) | 190 (setq syntax (cons (cons ,symbol relpos-tmp) syntax)))) |
162 ;; The inclass and class-close syntactic symbols are added in | 191 |
163 ;; several places and some work is needed to fix everything. | 192 (defmacro c-benign-error (format &rest args) |
164 ;; Therefore it's collected here. This is a macro mostly because | 193 ;; Formats an error message for the echo area and dings, i.e. like |
165 ;; c-add-syntax doesn't work otherwise. | 194 ;; `error' but doesn't abort. |
166 `(save-restriction | 195 `(progn |
167 (widen) | 196 (message ,format ,@args) |
168 (let ((symbol ,symbol) | 197 (ding))) |
169 (classkey ,classkey) | |
170 inexpr) | |
171 (goto-char (aref classkey 1)) | |
172 (if (and (eq symbol 'inclass) (= (point) (c-point 'boi))) | |
173 (c-add-syntax symbol (point)) | |
174 (c-add-syntax symbol (aref classkey 0)) | |
175 (if (and c-inexpr-class-key | |
176 (setq inexpr (c-looking-at-inexpr-block)) | |
177 (/= (cdr inexpr) (c-point 'boi (cdr inexpr)))) | |
178 (c-add-syntax 'inexpr-class)))))) | |
179 | 198 |
180 (defmacro c-update-modeline () | 199 (defmacro c-update-modeline () |
181 ;; set the c-auto-hungry-string for the correct designation on the modeline | 200 ;; set the c-auto-hungry-string for the correct designation on the modeline |
182 `(progn | 201 `(progn |
183 (setq c-auto-hungry-string | 202 (setq c-auto-hungry-string |
194 (progn | 213 (progn |
195 (set-syntax-table ,table) | 214 (set-syntax-table ,table) |
196 ,@code) | 215 ,@code) |
197 (set-syntax-table c-with-syntax-table-orig-table)))) | 216 (set-syntax-table c-with-syntax-table-orig-table)))) |
198 (put 'c-with-syntax-table 'lisp-indent-function 1) | 217 (put 'c-with-syntax-table 'lisp-indent-function 1) |
218 | |
219 (defmacro c-skip-ws-forward (&optional limit) | |
220 "Skip over any whitespace following point. | |
221 This function skips over horizontal and vertical whitespace and line | |
222 continuations." | |
223 (if limit | |
224 `(let ((-limit- (or ,limit (point-max)))) | |
225 (while (progn | |
226 ;; skip-syntax-* doesn't count \n as whitespace.. | |
227 (skip-chars-forward " \t\n\r\f" -limit-) | |
228 (when (and (eq (char-after) ?\\) | |
229 (< (point) -limit-)) | |
230 (forward-char) | |
231 (or (eolp) | |
232 (progn (backward-char) nil)))))) | |
233 '(while (progn | |
234 (skip-chars-forward " \t\n\r\f") | |
235 (when (eq (char-after) ?\\) | |
236 (forward-char) | |
237 (or (eolp) | |
238 (progn (backward-char) nil))))))) | |
239 | |
240 (defmacro c-skip-ws-backward (&optional limit) | |
241 "Skip over any whitespace preceding point. | |
242 This function skips over horizontal and vertical whitespace and line | |
243 continuations." | |
244 (if limit | |
245 `(let ((-limit- (or ,limit (point-min)))) | |
246 (while (progn | |
247 ;; skip-syntax-* doesn't count \n as whitespace.. | |
248 (skip-chars-backward " \t\n\r\f" -limit-) | |
249 (and (eolp) | |
250 (eq (char-before) ?\\) | |
251 (> (point) -limit-))) | |
252 (backward-char))) | |
253 '(while (progn | |
254 (skip-chars-backward " \t\n\r\f") | |
255 (and (eolp) | |
256 (eq (char-before) ?\\))) | |
257 (backward-char)))) | |
258 | |
259 ;; Make edebug understand the macros. | |
260 (eval-after-load "edebug" | |
261 '(progn | |
262 (def-edebug-spec c-paren-re t) | |
263 (def-edebug-spec c-identifier-re t) | |
264 (def-edebug-spec c-point ([&or symbolp form] &optional form)) | |
265 (def-edebug-spec c-safe t) | |
266 (def-edebug-spec c-forward-sexp (&optional [&or numberp form])) | |
267 (def-edebug-spec c-backward-sexp (&optional [&or numberp form])) | |
268 (def-edebug-spec c-up-list-forward t) | |
269 (def-edebug-spec c-up-list-backward t) | |
270 (def-edebug-spec c-down-list-forward t) | |
271 (def-edebug-spec c-down-list-backward t) | |
272 (def-edebug-spec c-add-syntax t) | |
273 (def-edebug-spec c-add-class-syntax t) | |
274 (def-edebug-spec c-benign-error t) | |
275 (def-edebug-spec c-with-syntax-table t) | |
276 (def-edebug-spec c-skip-ws-forward t) | |
277 (def-edebug-spec c-skip-ws-backward t))) | |
199 | 278 |
200 ;;; Inline functions. | 279 ;;; Inline functions. |
201 | 280 |
202 ;; Note: All these after the macros, to be on safe side in avoiding | 281 ;; Note: All these after the macros, to be on safe side in avoiding |
203 ;; bugs where macros are defined too late. These bugs often only show | 282 ;; bugs where macros are defined too late. These bugs often only show |
260 (if (eq (char-after) ?{) | 339 (if (eq (char-after) ?{) |
261 (c-forward-sexp)) | 340 (c-forward-sexp)) |
262 (if (< (point) start) | 341 (if (< (point) start) |
263 (goto-char (point-max))))) | 342 (goto-char (point-max))))) |
264 | 343 |
265 (defsubst c-forward-comment (count) | |
266 ;; Insulation from various idiosyncrasies in implementations of | |
267 ;; `forward-comment'. | |
268 ;; | |
269 ;; Note: Some emacsen considers incorrectly that any line comment | |
270 ;; ending with a backslash continues to the next line. I can't | |
271 ;; think of any way to work around that in a reliable way without | |
272 ;; changing the buffer though. Suggestions welcome. ;) | |
273 ;; | |
274 ;; Another note: When moving backwards over a block comment, there's | |
275 ;; a bug in forward-comment that can make it stop at "/*" inside a | |
276 ;; line comment. Haven't yet found a reasonably cheap way to kludge | |
277 ;; around that one either. :\ | |
278 (let ((here (point))) | |
279 (if (>= count 0) | |
280 (when (forward-comment count) | |
281 ;; Emacs includes the ending newline in a b-style (c++) | |
282 ;; comment, but XEmacs doesn't. We depend on the Emacs | |
283 ;; behavior (which also is symmetric). | |
284 (if (and (eolp) (nth 7 (parse-partial-sexp here (point)))) | |
285 (condition-case nil (forward-char 1))) | |
286 t) | |
287 ;; When we got newline terminated comments, | |
288 ;; forward-comment in all supported emacsen so far will | |
289 ;; stop at eol of each line not ending with a comment when | |
290 ;; moving backwards. The following corrects for it when | |
291 ;; count is -1. The other common case, when count is | |
292 ;; large and negative, works regardless. It's too much | |
293 ;; work to correct for the rest of the cases. | |
294 (skip-chars-backward " \t\n\r\f") | |
295 (if (bobp) | |
296 ;; Some emacsen return t when moving backwards at bob. | |
297 nil | |
298 (re-search-forward "[\n\r]" here t) | |
299 (if (forward-comment count) | |
300 (if (eolp) (forward-comment -1) t)))))) | |
301 | |
302 (defsubst c-intersect-lists (list alist) | 344 (defsubst c-intersect-lists (list alist) |
303 ;; return the element of ALIST that matches the first element found | 345 ;; return the element of ALIST that matches the first element found |
304 ;; in LIST. Uses assq. | 346 ;; in LIST. Uses assq. |
305 (let (match) | 347 (let (match) |
306 (while (and list | 348 (while (and list |
344 ((boundp 'mark-active) mark-active) | 386 ((boundp 'mark-active) mark-active) |
345 ;; fallback; shouldn't get here | 387 ;; fallback; shouldn't get here |
346 (t (mark t)))) | 388 (t (mark t)))) |
347 | 389 |
348 (defsubst c-major-mode-is (mode) | 390 (defsubst c-major-mode-is (mode) |
349 (eq (derived-mode-class major-mode) mode)) | 391 (eq c-buffer-is-cc-mode mode)) |
350 | 392 |
351 | 393 |
352 (cc-provide 'cc-defs) | 394 (cc-provide 'cc-defs) |
353 | 395 |
354 ;;; cc-defs.el ends here | 396 ;;; cc-defs.el ends here |