Mercurial > emacs
annotate lisp/progmodes/cc-defs.el @ 25672:68068da11161
(selected_frame): Add external declaration.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Mon, 13 Sep 1999 11:13:45 +0000 |
parents | 5b0864259a4b |
children | 03befb219d03 |
rev | line source |
---|---|
21112
b113342cb7ad
(c-emacs-features): Var moved to cc-vars.el.
Richard M. Stallman <rms@gnu.org>
parents:
20913
diff
changeset
|
1 ;;; cc-defs.el --- compile time definitions for CC Mode |
18720 | 2 |
20913
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
3 ;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc. |
18720 | 4 |
24282 | 5 ;; Authors: 1998 Barry A. Warsaw and Martin Stjernholm |
6 ;; 1992-1997 Barry A. Warsaw | |
18720 | 7 ;; 1987 Dave Detlefs and Stewart Clamen |
8 ;; 1985 Richard M. Stallman | |
24282 | 9 ;; Maintainer: bug-cc-mode@gnu.org |
18720 | 10 ;; Created: 22-Apr-1997 (split from cc-mode.el) |
20141 | 11 ;; Version: See cc-mode.el |
18720 | 12 ;; Keywords: c languages oop |
13 | |
14 ;; This file is part of GNU Emacs. | |
15 | |
16 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
17 ;; it under the terms of the GNU General Public License as published by | |
18 ;; the Free Software Foundation; either version 2, or (at your option) | |
19 ;; any later version. | |
20 | |
21 ;; GNU Emacs is distributed in the hope that it will be useful, | |
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 ;; GNU General Public License for more details. | |
25 | |
26 ;; You should have received a copy of the GNU General Public License | |
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
29 ;; Boston, MA 02111-1307, USA. | |
30 | |
31 | |
24282 | 32 ;; Get all the necessary compile time definitions. |
33 (require 'custom) | |
34 (require 'cc-menus) | |
35 (require 'derived) ;only necessary in Emacs 20 | |
36 | |
37 ;; cc-mode-19.el contains compatibility macros that should be compiled | |
38 ;; in if needed. | |
39 (if (or (not (fboundp 'functionp)) | |
40 (not (condition-case nil | |
41 (progn (char-before) t) | |
42 (error nil))) | |
43 (not (condition-case nil | |
44 (progn (char-after) t) | |
45 (error nil))) | |
46 (not (fboundp 'when)) | |
47 (not (fboundp 'unless))) | |
48 (require 'cc-mode-19)) | |
49 | |
50 | |
18720 | 51 (defsubst c-point (position) |
52 ;; Returns the value of point at certain commonly referenced POSITIONs. | |
53 ;; POSITION can be one of the following symbols: | |
54 ;; | |
55 ;; bol -- beginning of line | |
56 ;; eol -- end of line | |
57 ;; bod -- beginning of defun | |
24282 | 58 ;; eod -- end of defun |
18720 | 59 ;; boi -- back to indentation |
60 ;; ionl -- indentation of next line | |
61 ;; iopl -- indentation of previous line | |
62 ;; bonl -- beginning of next line | |
63 ;; bopl -- beginning of previous line | |
64 ;; | |
65 ;; This function does not modify point or mark. | |
66 (let ((here (point))) | |
67 (cond | |
68 ((eq position 'bol) (beginning-of-line)) | |
69 ((eq position 'eol) (end-of-line)) | |
70 ((eq position 'boi) (back-to-indentation)) | |
71 ((eq position 'bonl) (forward-line 1)) | |
72 ((eq position 'bopl) (forward-line -1)) | |
73 ((eq position 'iopl) | |
74 (forward-line -1) | |
75 (back-to-indentation)) | |
76 ((eq position 'ionl) | |
77 (forward-line 1) | |
78 (back-to-indentation)) | |
24282 | 79 ((eq position 'eod) (c-end-of-defun)) |
20913
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
80 ((eq position 'bod) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
81 (if (and (fboundp 'buffer-syntactic-context-depth) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
82 c-enable-xemacs-performance-kludge-p) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
83 ;; XEmacs only. This can improve the performance of |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
84 ;; c-parse-state to between 3 and 60 times faster when |
24282 | 85 ;; braces are hung. It can also degrade performance by |
86 ;; about as much when braces are not hung. | |
20913
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
87 (let (pos) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
88 (while (not pos) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
89 (save-restriction |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
90 (widen) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
91 (setq pos (scan-lists (point) -1 |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
92 (buffer-syntactic-context-depth) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
93 nil t))) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
94 (cond |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
95 ((bobp) (setq pos (point-min))) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
96 ((not pos) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
97 (let ((distance (skip-chars-backward "^{"))) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
98 ;; unbalanced parenthesis, while illegal C code, |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
99 ;; shouldn't cause an infloop! See unbal.c |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
100 (when (zerop distance) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
101 ;; Punt! |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
102 (beginning-of-defun) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
103 (setq pos (point))))) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
104 ((= pos 0)) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
105 ((not (eq (char-after pos) ?{)) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
106 (goto-char pos) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
107 (setq pos nil)) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
108 )) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
109 (goto-char pos)) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
110 ;; Emacs, which doesn't have buffer-syntactic-context-depth |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
111 ;; |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
112 ;; NOTE: This should be the only explicit use of |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
113 ;; beginning-of-defun in CC Mode. Eventually something better |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
114 ;; than b-o-d will be available and this should be the only |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
115 ;; place the code needs to change. Everything else should use |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
116 ;; (goto-char (c-point 'bod)) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
117 (beginning-of-defun) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
118 ;; if defun-prompt-regexp is non-nil, b-o-d won't leave us at |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
119 ;; the open brace. |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
120 (and defun-prompt-regexp |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
121 (looking-at defun-prompt-regexp) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
122 (goto-char (match-end 0))) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
123 )) |
18720 | 124 (t (error "unknown buffer position requested: %s" position)) |
125 ) | |
126 (prog1 | |
127 (point) | |
128 (goto-char here)))) | |
129 | |
24282 | 130 |
18720 | 131 (defmacro c-safe (&rest body) |
132 ;; safely execute BODY, return nil if an error occurred | |
133 (` (condition-case nil | |
134 (progn (,@ body)) | |
135 (error nil)))) | |
136 | |
24282 | 137 (defmacro c-forward-sexp (&optional arg) |
138 ;; like forward-sexp except | |
139 ;; 1. this is much stripped down from the XEmacs version | |
140 ;; 2. this cannot be used as a command, so we're insulated from | |
141 ;; XEmacs' losing efforts to make forward-sexp more user | |
142 ;; friendly | |
143 ;; 3. Preserves the semantics most of CC Mode is based on | |
144 (or arg (setq arg 1)) | |
145 `(goto-char (or (scan-sexps (point) ,arg) | |
146 ,(if (numberp arg) | |
147 (if (> arg 0) `(point-max) `(point-min)) | |
148 `(if (> ,arg 0) (point-max) (point-min)))))) | |
149 | |
150 (defmacro c-backward-sexp (&optional arg) | |
151 ;; See c-forward-sexp and reverse directions | |
152 (or arg (setq arg 1)) | |
153 `(c-forward-sexp ,(if (numberp arg) (- arg) `(- ,arg)))) | |
154 | |
18720 | 155 (defmacro c-add-syntax (symbol &optional relpos) |
156 ;; a simple macro to append the syntax in symbol to the syntax list. | |
157 ;; try to increase performance by using this macro | |
158 (` (setq syntax (cons (cons (, symbol) (, relpos)) syntax)))) | |
159 | |
160 (defsubst c-auto-newline () | |
161 ;; if auto-newline feature is turned on, insert a newline character | |
162 ;; and return t, otherwise return nil. | |
163 (and c-auto-newline | |
164 (not (c-in-literal)) | |
165 (not (newline)))) | |
166 | |
167 (defsubst c-intersect-lists (list alist) | |
168 ;; return the element of ALIST that matches the first element found | |
169 ;; in LIST. Uses assq. | |
170 (let (match) | |
171 (while (and list | |
172 (not (setq match (assq (car list) alist)))) | |
173 (setq list (cdr list))) | |
174 match)) | |
175 | |
176 (defsubst c-lookup-lists (list alist1 alist2) | |
177 ;; first, find the first entry from LIST that is present in ALIST1, | |
178 ;; then find the entry in ALIST2 for that entry. | |
179 (assq (car (c-intersect-lists list alist1)) alist2)) | |
180 | |
181 (defsubst c-langelem-col (langelem &optional preserve-point) | |
182 ;; convenience routine to return the column of langelem's relpos. | |
183 ;; Leaves point at the relpos unless preserve-point is non-nil. | |
184 (let ((here (point))) | |
185 (goto-char (cdr langelem)) | |
186 (prog1 (current-column) | |
187 (if preserve-point | |
188 (goto-char here)) | |
189 ))) | |
190 | |
191 (defsubst c-update-modeline () | |
192 ;; set the c-auto-hungry-string for the correct designation on the modeline | |
193 (setq c-auto-hungry-string | |
194 (if c-auto-newline | |
195 (if c-hungry-delete-key "/ah" "/a") | |
196 (if c-hungry-delete-key "/h" nil))) | |
197 (force-mode-line-update)) | |
198 | |
199 (defsubst c-keep-region-active () | |
200 ;; Do whatever is necessary to keep the region active in XEmacs. | |
201 ;; Ignore byte-compiler warnings you might see. This is not needed | |
202 ;; for Emacs. | |
203 (and (boundp 'zmacs-region-stays) | |
204 (setq zmacs-region-stays t))) | |
205 | |
24282 | 206 (defsubst c-region-is-active-p () |
207 ;; Return t when the region is active. The determination of region | |
208 ;; activeness is different in both Emacs and XEmacs. | |
209 (cond | |
210 ;; XEmacs | |
211 ((and (fboundp 'region-active-p) | |
212 zmacs-regions) | |
213 (region-active-p)) | |
214 ;; Emacs | |
215 ((boundp 'mark-active) mark-active) | |
216 ;; fallback; shouldn't get here | |
217 (t (mark t)))) | |
218 | |
219 (defsubst c-major-mode-is (mode) | |
220 (eq (derived-mode-class major-mode) mode)) | |
221 | |
18720 | 222 |
223 (provide 'cc-defs) | |
224 ;;; cc-defs.el ends here |