Mercurial > emacs
annotate lisp/progmodes/cc-defs.el @ 22097:67273fd206b7
(browse-url-temp-dir): Use temporary-file-directory.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 16 May 1998 17:35:23 +0000 |
parents | b113342cb7ad |
children | 5b0864259a4b |
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 |
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 (defsubst c-point (position) | |
32 ;; Returns the value of point at certain commonly referenced POSITIONs. | |
33 ;; POSITION can be one of the following symbols: | |
34 ;; | |
35 ;; bol -- beginning of line | |
36 ;; eol -- end of line | |
37 ;; bod -- beginning of defun | |
38 ;; boi -- back to indentation | |
39 ;; ionl -- indentation of next line | |
40 ;; iopl -- indentation of previous line | |
41 ;; bonl -- beginning of next line | |
42 ;; bopl -- beginning of previous line | |
43 ;; | |
44 ;; This function does not modify point or mark. | |
45 (let ((here (point))) | |
46 (cond | |
47 ((eq position 'bol) (beginning-of-line)) | |
48 ((eq position 'eol) (end-of-line)) | |
49 ((eq position 'boi) (back-to-indentation)) | |
50 ((eq position 'bonl) (forward-line 1)) | |
51 ((eq position 'bopl) (forward-line -1)) | |
52 ((eq position 'iopl) | |
53 (forward-line -1) | |
54 (back-to-indentation)) | |
55 ((eq position 'ionl) | |
56 (forward-line 1) | |
57 (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
|
58 ((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
|
59 (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
|
60 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
|
61 ;; 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
|
62 ;; 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
|
63 ;; 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
|
64 ;; 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
|
65 ;; 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
|
66 (let (pos) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
67 (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
|
68 (save-restriction |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
69 (widen) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
70 (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
|
71 (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
|
72 nil t))) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
73 (cond |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
74 ((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
|
75 ((not pos) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
76 (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
|
77 ;; 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
|
78 ;; 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
|
79 (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
|
80 ;; Punt! |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
81 (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
|
82 (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
|
83 ((= pos 0)) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
84 ((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
|
85 (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
|
86 (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
|
87 )) |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
88 (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
|
89 ;; 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
|
90 ;; |
c7ee864ae985
(c-point): In XEmacs, use scan-lists + buffer-syntactic-context-depth.
Richard M. Stallman <rms@gnu.org>
parents:
20141
diff
changeset
|
91 ;; 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
|
92 ;; 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
|
93 ;; 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
|
94 ;; 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
|
95 ;; (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
|
96 (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
|
97 ;; 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
|
98 ;; 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
|
99 (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
|
100 (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
|
101 (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
|
102 )) |
18720 | 103 (t (error "unknown buffer position requested: %s" position)) |
104 ) | |
105 (prog1 | |
106 (point) | |
107 (goto-char here)))) | |
108 | |
109 (defmacro c-safe (&rest body) | |
110 ;; safely execute BODY, return nil if an error occurred | |
111 (` (condition-case nil | |
112 (progn (,@ body)) | |
113 (error nil)))) | |
114 | |
115 (defmacro c-add-syntax (symbol &optional relpos) | |
116 ;; a simple macro to append the syntax in symbol to the syntax list. | |
117 ;; try to increase performance by using this macro | |
118 (` (setq syntax (cons (cons (, symbol) (, relpos)) syntax)))) | |
119 | |
120 (defsubst c-auto-newline () | |
121 ;; if auto-newline feature is turned on, insert a newline character | |
122 ;; and return t, otherwise return nil. | |
123 (and c-auto-newline | |
124 (not (c-in-literal)) | |
125 (not (newline)))) | |
126 | |
127 (defsubst c-intersect-lists (list alist) | |
128 ;; return the element of ALIST that matches the first element found | |
129 ;; in LIST. Uses assq. | |
130 (let (match) | |
131 (while (and list | |
132 (not (setq match (assq (car list) alist)))) | |
133 (setq list (cdr list))) | |
134 match)) | |
135 | |
136 (defsubst c-lookup-lists (list alist1 alist2) | |
137 ;; first, find the first entry from LIST that is present in ALIST1, | |
138 ;; then find the entry in ALIST2 for that entry. | |
139 (assq (car (c-intersect-lists list alist1)) alist2)) | |
140 | |
141 (defsubst c-langelem-col (langelem &optional preserve-point) | |
142 ;; convenience routine to return the column of langelem's relpos. | |
143 ;; Leaves point at the relpos unless preserve-point is non-nil. | |
144 (let ((here (point))) | |
145 (goto-char (cdr langelem)) | |
146 (prog1 (current-column) | |
147 (if preserve-point | |
148 (goto-char here)) | |
149 ))) | |
150 | |
151 (defsubst c-update-modeline () | |
152 ;; set the c-auto-hungry-string for the correct designation on the modeline | |
153 (setq c-auto-hungry-string | |
154 (if c-auto-newline | |
155 (if c-hungry-delete-key "/ah" "/a") | |
156 (if c-hungry-delete-key "/h" nil))) | |
157 (force-mode-line-update)) | |
158 | |
159 (defsubst c-keep-region-active () | |
160 ;; Do whatever is necessary to keep the region active in XEmacs. | |
161 ;; Ignore byte-compiler warnings you might see. This is not needed | |
162 ;; for Emacs. | |
163 (and (boundp 'zmacs-region-stays) | |
164 (setq zmacs-region-stays t))) | |
165 | |
166 | |
167 (provide 'cc-defs) | |
168 ;;; cc-defs.el ends here |