annotate lisp/cc-mode/cc-defs.el @ 181:bfd6434d15b3 r20-3b17

Import from CVS: tag r20-3b17
author cvs
date Mon, 13 Aug 2007 09:53:19 +0200
parents 6075d714658b
children e121b013d1f0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
171
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
1 ;;; cc-defs.el --- definitions for CC Mode
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
2
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985,87,92,93,94,95,96,97 Free Software Foundation, Inc.
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
4
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
5 ;; Authors: 1992-1997 Barry A. Warsaw
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
6 ;; 1987 Dave Detlefs and Stewart Clamen
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
7 ;; 1985 Richard M. Stallman
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
8 ;; Maintainer: cc-mode-help@python.org
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
9 ;; Created: 22-Apr-1997 (split from cc-mode.el)
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 177
diff changeset
10 ;; Version: 5.15
171
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
11 ;; Keywords: c languages oop
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
12
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
13 ;; This file is part of GNU Emacs.
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
14
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
16 ;; it under the terms of the GNU General Public License as published by
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
17 ;; the Free Software Foundation; either version 2, or (at your option)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
18 ;; any later version.
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
19
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
20 ;; GNU Emacs is distributed in the hope that it will be useful,
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
23 ;; GNU General Public License for more details.
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
24
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
25 ;; You should have received a copy of the GNU General Public License
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
28 ;; Boston, MA 02111-1307, USA.
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
29
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
30
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
31 ;; Figure out what features this Emacs has
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
32 (defconst c-emacs-features
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
33 (let ((infodock-p (boundp 'infodock-version))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
34 (comments
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
35 ;; XEmacs 19 and beyond use 8-bit modify-syntax-entry flags.
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
36 ;; Emacs 19 uses a 1-bit flag. We will have to set up our
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
37 ;; syntax tables differently to handle this.
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
38 (let ((table (copy-syntax-table))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
39 entry)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
40 (modify-syntax-entry ?a ". 12345678" table)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
41 (cond
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
42 ;; XEmacs 19, and beyond Emacs 19.34
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
43 ((arrayp table)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
44 (setq entry (aref table ?a))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
45 ;; In Emacs, table entries are cons cells
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
46 (if (consp entry) (setq entry (car entry))))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
47 ;; XEmacs 20
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
48 ((fboundp 'get-char-table) (setq entry (get-char-table ?a table)))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
49 ;; before and including Emacs 19.34
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
50 ((and (fboundp 'char-table-p)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
51 (char-table-p table))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
52 (setq entry (car (char-table-range table [?a]))))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
53 ;; incompatible
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
54 (t (error "CC Mode is incompatible with this version of Emacs")))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
55 (if (= (logand (lsh entry -16) 255) 255)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
56 '8-bit
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
57 '1-bit))))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
58 (if infodock-p
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
59 (list comments 'infodock)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
60 (list comments)))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
61 "A list of features extant in the Emacs you are using.
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
62 There are many flavors of Emacs out there, each with different
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
63 features supporting those needed by CC Mode. Here's the current
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
64 supported list, along with the values for this variable:
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
65
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
66 XEmacs 19: (8-bit)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
67 XEmacs 20: (8-bit)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
68 Emacs 19: (1-bit)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
69
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
70 Infodock (based on XEmacs) has an additional symbol on this list:
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
71 'infodock.")
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
72
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
73
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
74
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
75 (defsubst c-point (position)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
76 ;; Returns the value of point at certain commonly referenced POSITIONs.
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
77 ;; POSITION can be one of the following symbols:
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
78 ;;
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
79 ;; bol -- beginning of line
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
80 ;; eol -- end of line
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
81 ;; bod -- beginning of defun
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
82 ;; boi -- back to indentation
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
83 ;; ionl -- indentation of next line
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
84 ;; iopl -- indentation of previous line
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
85 ;; bonl -- beginning of next line
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
86 ;; bopl -- beginning of previous line
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
87 ;;
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
88 ;; This function does not modify point or mark.
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
89 (let ((here (point)))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
90 (cond
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
91 ((eq position 'bol) (beginning-of-line))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
92 ((eq position 'eol) (end-of-line))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
93 ((eq position 'bod)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
94 (beginning-of-defun)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
95 ;; if defun-prompt-regexp is non-nil, b-o-d won't leave us at
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
96 ;; the open brace.
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
97 (and defun-prompt-regexp
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
98 (looking-at defun-prompt-regexp)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
99 (goto-char (match-end 0)))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
100 )
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
101 ((eq position 'boi) (back-to-indentation))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
102 ((eq position 'bonl) (forward-line 1))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
103 ((eq position 'bopl) (forward-line -1))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
104 ((eq position 'iopl)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
105 (forward-line -1)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
106 (back-to-indentation))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
107 ((eq position 'ionl)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
108 (forward-line 1)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
109 (back-to-indentation))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
110 (t (error "unknown buffer position requested: %s" position))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
111 )
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
112 (prog1
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
113 (point)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
114 (goto-char here))))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
115
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
116 (defmacro c-safe (&rest body)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
117 ;; safely execute BODY, return nil if an error occurred
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
118 (` (condition-case nil
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
119 (progn (,@ body))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
120 (error nil))))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
121
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
122 (defmacro c-add-syntax (symbol &optional relpos)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
123 ;; a simple macro to append the syntax in symbol to the syntax list.
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
124 ;; try to increase performance by using this macro
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
125 (` (setq syntax (cons (cons (, symbol) (, relpos)) syntax))))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
126
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
127 (defsubst c-auto-newline ()
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
128 ;; if auto-newline feature is turned on, insert a newline character
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
129 ;; and return t, otherwise return nil.
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
130 (and c-auto-newline
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
131 (not (c-in-literal))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
132 (not (newline))))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
133
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
134 (defsubst c-intersect-lists (list alist)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
135 ;; return the element of ALIST that matches the first element found
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
136 ;; in LIST. Uses assq.
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
137 (let (match)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
138 (while (and list
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
139 (not (setq match (assq (car list) alist))))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
140 (setq list (cdr list)))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
141 match))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
142
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
143 (defsubst c-lookup-lists (list alist1 alist2)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
144 ;; first, find the first entry from LIST that is present in ALIST1,
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
145 ;; then find the entry in ALIST2 for that entry.
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
146 (assq (car (c-intersect-lists list alist1)) alist2))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
147
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
148 (defsubst c-langelem-col (langelem &optional preserve-point)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
149 ;; convenience routine to return the column of langelem's relpos.
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
150 ;; Leaves point at the relpos unless preserve-point is non-nil.
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
151 (let ((here (point)))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
152 (goto-char (cdr langelem))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
153 (prog1 (current-column)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
154 (if preserve-point
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
155 (goto-char here))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
156 )))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
157
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
158 (defsubst c-update-modeline ()
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
159 ;; set the c-auto-hungry-string for the correct designation on the modeline
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
160 (setq c-auto-hungry-string
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
161 (if c-auto-newline
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
162 (if c-hungry-delete-key "/ah" "/a")
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
163 (if c-hungry-delete-key "/h" nil)))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
164 (force-mode-line-update))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
165
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
166 (defsubst c-keep-region-active ()
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
167 ;; Do whatever is necessary to keep the region active in XEmacs.
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
168 ;; Ignore byte-compiler warnings you might see. This is not needed
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
169 ;; for Emacs.
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
170 (and (boundp 'zmacs-region-stays)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
171 (setq zmacs-region-stays t)))
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
172
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
173
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
174 (provide 'cc-defs)
929b76928fce Import from CVS: tag r20-3b12
cvs
parents:
diff changeset
175 ;;; cc-defs.el ends here