Mercurial > emacs
annotate lisp/progmodes/cc-defs.el @ 21020:f7ace8487b28
(auto_save_1): Pass new arg to Fwrite_region.
(Fwrite_region): New arg CONFIRM. If non-nil, confirm overwriting.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 02 Mar 1998 19:08:05 +0000 |
parents | c7ee864ae985 |
children | b113342cb7ad |
rev | line source |
---|---|
18720 | 1 ;;; cc-defs.el --- definitions for CC Mode |
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 |
5 ;; Authors: 1992-1997 Barry A. Warsaw | |
6 ;; 1987 Dave Detlefs and Stewart Clamen | |
7 ;; 1985 Richard M. Stallman | |
8 ;; Maintainer: cc-mode-help@python.org | |
9 ;; Created: 22-Apr-1997 (split from cc-mode.el) | |
20141 | 10 ;; Version: See cc-mode.el |
18720 | 11 ;; Keywords: c languages oop |
12 | |
13 ;; This file is part of GNU Emacs. | |
14 | |
15 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
16 ;; it under the terms of the GNU General Public License as published by | |
17 ;; the Free Software Foundation; either version 2, or (at your option) | |
18 ;; any later version. | |
19 | |
20 ;; GNU Emacs is distributed in the hope that it will be useful, | |
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 ;; GNU General Public License for more details. | |
24 | |
25 ;; You should have received a copy of the GNU General Public License | |
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
28 ;; Boston, MA 02111-1307, USA. | |
29 | |
30 | |
31 ;; Figure out what features this Emacs has | |
20913
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
32 ;;;###autoload |
18720 | 33 (defconst c-emacs-features |
34 (let ((infodock-p (boundp 'infodock-version)) | |
35 (comments | |
36 ;; XEmacs 19 and beyond use 8-bit modify-syntax-entry flags. | |
37 ;; Emacs 19 uses a 1-bit flag. We will have to set up our | |
38 ;; syntax tables differently to handle this. | |
39 (let ((table (copy-syntax-table)) | |
40 entry) | |
41 (modify-syntax-entry ?a ". 12345678" table) | |
42 (cond | |
43 ;; XEmacs 19, and beyond Emacs 19.34 | |
44 ((arrayp table) | |
45 (setq entry (aref table ?a)) | |
46 ;; In Emacs, table entries are cons cells | |
47 (if (consp entry) (setq entry (car entry)))) | |
48 ;; XEmacs 20 | |
49 ((fboundp 'get-char-table) (setq entry (get-char-table ?a table))) | |
50 ;; before and including Emacs 19.34 | |
51 ((and (fboundp 'char-table-p) | |
52 (char-table-p table)) | |
53 (setq entry (car (char-table-range table [?a])))) | |
54 ;; incompatible | |
55 (t (error "CC Mode is incompatible with this version of Emacs"))) | |
56 (if (= (logand (lsh entry -16) 255) 255) | |
57 '8-bit | |
58 '1-bit)))) | |
59 (if infodock-p | |
60 (list comments 'infodock) | |
61 (list comments))) | |
62 "A list of features extant in the Emacs you are using. | |
63 There are many flavors of Emacs out there, each with different | |
64 features supporting those needed by CC Mode. Here's the current | |
65 supported list, along with the values for this variable: | |
66 | |
67 XEmacs 19: (8-bit) | |
68 XEmacs 20: (8-bit) | |
69 Emacs 19: (1-bit) | |
70 | |
71 Infodock (based on XEmacs) has an additional symbol on this list: | |
72 'infodock.") | |
73 | |
74 | |
75 | |
76 (defsubst c-point (position) | |
77 ;; Returns the value of point at certain commonly referenced POSITIONs. | |
78 ;; POSITION can be one of the following symbols: | |
79 ;; | |
80 ;; bol -- beginning of line | |
81 ;; eol -- end of line | |
82 ;; bod -- beginning of defun | |
83 ;; boi -- back to indentation | |
84 ;; ionl -- indentation of next line | |
85 ;; iopl -- indentation of previous line | |
86 ;; bonl -- beginning of next line | |
87 ;; bopl -- beginning of previous line | |
88 ;; | |
89 ;; This function does not modify point or mark. | |
90 (let ((here (point))) | |
91 (cond | |
92 ((eq position 'bol) (beginning-of-line)) | |
93 ((eq position 'eol) (end-of-line)) | |
94 ((eq position 'boi) (back-to-indentation)) | |
95 ((eq position 'bonl) (forward-line 1)) | |
96 ((eq position 'bopl) (forward-line -1)) | |
97 ((eq position 'iopl) | |
98 (forward-line -1) | |
99 (back-to-indentation)) | |
100 ((eq position 'ionl) | |
101 (forward-line 1) | |
102 (back-to-indentation)) | |
20913
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
103 ((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
|
104 (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
|
105 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
|
106 ;; 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
|
107 ;; c-parse-state to between 3 and 60 times faster when |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
108 ;; braces are hung. It can cause c-parse-state to be |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
109 ;; slightly slower when braces are not hung, but general |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
110 ;; editing appears to be still about as fast. |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
111 (let (pos) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
112 (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
|
113 (save-restriction |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
114 (widen) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
115 (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
|
116 (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
|
117 nil t))) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
118 (cond |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
119 ((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
|
120 ((not pos) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
121 (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
|
122 ;; 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
|
123 ;; 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
|
124 (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
|
125 ;; Punt! |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
126 (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
|
127 (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
|
128 ((= pos 0)) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
129 ((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
|
130 (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
|
131 (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
|
132 )) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
133 (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
|
134 ;; 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
|
135 ;; |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
136 ;; 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
|
137 ;; 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
|
138 ;; 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
|
139 ;; 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
|
140 ;; (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
|
141 (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
|
142 ;; 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
|
143 ;; 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
|
144 (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
|
145 (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
|
146 (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
|
147 )) |
18720 | 148 (t (error "unknown buffer position requested: %s" position)) |
149 ) | |
150 (prog1 | |
151 (point) | |
152 (goto-char here)))) | |
153 | |
154 (defmacro c-safe (&rest body) | |
155 ;; safely execute BODY, return nil if an error occurred | |
156 (` (condition-case nil | |
157 (progn (,@ body)) | |
158 (error nil)))) | |
159 | |
160 (defmacro c-add-syntax (symbol &optional relpos) | |
161 ;; a simple macro to append the syntax in symbol to the syntax list. | |
162 ;; try to increase performance by using this macro | |
163 (` (setq syntax (cons (cons (, symbol) (, relpos)) syntax)))) | |
164 | |
165 (defsubst c-auto-newline () | |
166 ;; if auto-newline feature is turned on, insert a newline character | |
167 ;; and return t, otherwise return nil. | |
168 (and c-auto-newline | |
169 (not (c-in-literal)) | |
170 (not (newline)))) | |
171 | |
172 (defsubst c-intersect-lists (list alist) | |
173 ;; return the element of ALIST that matches the first element found | |
174 ;; in LIST. Uses assq. | |
175 (let (match) | |
176 (while (and list | |
177 (not (setq match (assq (car list) alist)))) | |
178 (setq list (cdr list))) | |
179 match)) | |
180 | |
181 (defsubst c-lookup-lists (list alist1 alist2) | |
182 ;; first, find the first entry from LIST that is present in ALIST1, | |
183 ;; then find the entry in ALIST2 for that entry. | |
184 (assq (car (c-intersect-lists list alist1)) alist2)) | |
185 | |
186 (defsubst c-langelem-col (langelem &optional preserve-point) | |
187 ;; convenience routine to return the column of langelem's relpos. | |
188 ;; Leaves point at the relpos unless preserve-point is non-nil. | |
189 (let ((here (point))) | |
190 (goto-char (cdr langelem)) | |
191 (prog1 (current-column) | |
192 (if preserve-point | |
193 (goto-char here)) | |
194 ))) | |
195 | |
196 (defsubst c-update-modeline () | |
197 ;; set the c-auto-hungry-string for the correct designation on the modeline | |
198 (setq c-auto-hungry-string | |
199 (if c-auto-newline | |
200 (if c-hungry-delete-key "/ah" "/a") | |
201 (if c-hungry-delete-key "/h" nil))) | |
202 (force-mode-line-update)) | |
203 | |
204 (defsubst c-keep-region-active () | |
205 ;; Do whatever is necessary to keep the region active in XEmacs. | |
206 ;; Ignore byte-compiler warnings you might see. This is not needed | |
207 ;; for Emacs. | |
208 (and (boundp 'zmacs-region-stays) | |
209 (setq zmacs-region-stays t))) | |
210 | |
211 | |
212 (provide 'cc-defs) | |
213 ;;; cc-defs.el ends here |