Comment change.
[bpt/emacs.git] / lisp / progmodes / cc-defs.el
CommitLineData
785eecbb
RS
1;;; cc-defs.el --- definitions for CC Mode
2
3;; Copyright (C) 1985,87,92,93,94,95,96,97 Free Software Foundation, Inc.
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)
e76df57d 10;; Version: 5.15
785eecbb
RS
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\f
31;; Figure out what features this Emacs has
32(defconst c-emacs-features
33 (let ((infodock-p (boundp 'infodock-version))
34 (comments
35 ;; XEmacs 19 and beyond use 8-bit modify-syntax-entry flags.
36 ;; Emacs 19 uses a 1-bit flag. We will have to set up our
37 ;; syntax tables differently to handle this.
38 (let ((table (copy-syntax-table))
39 entry)
40 (modify-syntax-entry ?a ". 12345678" table)
41 (cond
42 ;; XEmacs 19, and beyond Emacs 19.34
43 ((arrayp table)
44 (setq entry (aref table ?a))
45 ;; In Emacs, table entries are cons cells
46 (if (consp entry) (setq entry (car entry))))
47 ;; XEmacs 20
48 ((fboundp 'get-char-table) (setq entry (get-char-table ?a table)))
49 ;; before and including Emacs 19.34
50 ((and (fboundp 'char-table-p)
51 (char-table-p table))
52 (setq entry (car (char-table-range table [?a]))))
53 ;; incompatible
54 (t (error "CC Mode is incompatible with this version of Emacs")))
55 (if (= (logand (lsh entry -16) 255) 255)
56 '8-bit
57 '1-bit))))
58 (if infodock-p
59 (list comments 'infodock)
60 (list comments)))
61 "A list of features extant in the Emacs you are using.
62There are many flavors of Emacs out there, each with different
63features supporting those needed by CC Mode. Here's the current
64supported list, along with the values for this variable:
65
66 XEmacs 19: (8-bit)
67 XEmacs 20: (8-bit)
68 Emacs 19: (1-bit)
69
70Infodock (based on XEmacs) has an additional symbol on this list:
71'infodock.")
72
73
74\f
75(defsubst c-point (position)
76 ;; Returns the value of point at certain commonly referenced POSITIONs.
77 ;; POSITION can be one of the following symbols:
78 ;;
79 ;; bol -- beginning of line
80 ;; eol -- end of line
81 ;; bod -- beginning of defun
82 ;; boi -- back to indentation
83 ;; ionl -- indentation of next line
84 ;; iopl -- indentation of previous line
85 ;; bonl -- beginning of next line
86 ;; bopl -- beginning of previous line
87 ;;
88 ;; This function does not modify point or mark.
89 (let ((here (point)))
90 (cond
91 ((eq position 'bol) (beginning-of-line))
92 ((eq position 'eol) (end-of-line))
93 ((eq position 'bod)
94 (beginning-of-defun)
95 ;; if defun-prompt-regexp is non-nil, b-o-d won't leave us at
96 ;; the open brace.
97 (and defun-prompt-regexp
98 (looking-at defun-prompt-regexp)
99 (goto-char (match-end 0)))
100 )
101 ((eq position 'boi) (back-to-indentation))
102 ((eq position 'bonl) (forward-line 1))
103 ((eq position 'bopl) (forward-line -1))
104 ((eq position 'iopl)
105 (forward-line -1)
106 (back-to-indentation))
107 ((eq position 'ionl)
108 (forward-line 1)
109 (back-to-indentation))
110 (t (error "unknown buffer position requested: %s" position))
111 )
112 (prog1
113 (point)
114 (goto-char here))))
115
116(defmacro c-safe (&rest body)
117 ;; safely execute BODY, return nil if an error occurred
118 (` (condition-case nil
119 (progn (,@ body))
120 (error nil))))
121
122(defmacro c-add-syntax (symbol &optional relpos)
123 ;; a simple macro to append the syntax in symbol to the syntax list.
124 ;; try to increase performance by using this macro
125 (` (setq syntax (cons (cons (, symbol) (, relpos)) syntax))))
126
127(defsubst c-auto-newline ()
128 ;; if auto-newline feature is turned on, insert a newline character
129 ;; and return t, otherwise return nil.
130 (and c-auto-newline
131 (not (c-in-literal))
132 (not (newline))))
133
134(defsubst c-intersect-lists (list alist)
135 ;; return the element of ALIST that matches the first element found
136 ;; in LIST. Uses assq.
137 (let (match)
138 (while (and list
139 (not (setq match (assq (car list) alist))))
140 (setq list (cdr list)))
141 match))
142
143(defsubst c-lookup-lists (list alist1 alist2)
144 ;; first, find the first entry from LIST that is present in ALIST1,
145 ;; then find the entry in ALIST2 for that entry.
146 (assq (car (c-intersect-lists list alist1)) alist2))
147
148(defsubst c-langelem-col (langelem &optional preserve-point)
149 ;; convenience routine to return the column of langelem's relpos.
150 ;; Leaves point at the relpos unless preserve-point is non-nil.
151 (let ((here (point)))
152 (goto-char (cdr langelem))
153 (prog1 (current-column)
154 (if preserve-point
155 (goto-char here))
156 )))
157
158(defsubst c-update-modeline ()
159 ;; set the c-auto-hungry-string for the correct designation on the modeline
160 (setq c-auto-hungry-string
161 (if c-auto-newline
162 (if c-hungry-delete-key "/ah" "/a")
163 (if c-hungry-delete-key "/h" nil)))
164 (force-mode-line-update))
165
166(defsubst c-keep-region-active ()
167 ;; Do whatever is necessary to keep the region active in XEmacs.
168 ;; Ignore byte-compiler warnings you might see. This is not needed
169 ;; for Emacs.
170 (and (boundp 'zmacs-region-stays)
171 (setq zmacs-region-stays t)))
172
785eecbb
RS
173\f
174(provide 'cc-defs)
175;;; cc-defs.el ends here