annotate lisp/progmodes/cc-defs.el @ 26760:c55415d59073

*** empty log message ***
author Dave Love <fx@gnu.org>
date Tue, 07 Dec 1999 20:11:42 +0000
parents 5b0864259a4b
children 03befb219d03
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
5 ;; Authors: 1998 Barry A. Warsaw and Martin Stjernholm
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
6 ;; 1992-1997 Barry A. Warsaw
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; 1987 Dave Detlefs and Stewart Clamen
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; 1985 Richard M. Stallman
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
9 ;; Maintainer: bug-cc-mode@gnu.org
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; Created: 22-Apr-1997 (split from cc-mode.el)
20141
1a85b213eb6d Remove version number.
Karl Heuer <kwzh@gnu.org>
parents: 20140
diff changeset
11 ;; Version: See cc-mode.el
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; Keywords: c languages oop
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; This file is part of GNU Emacs.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is free software; you can redistribute it and/or modify
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; it under the terms of the GNU General Public License as published by
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; the Free Software Foundation; either version 2, or (at your option)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; any later version.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; GNU Emacs is distributed in the hope that it will be useful,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; GNU General Public License for more details.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;; You should have received a copy of the GNU General Public License
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; Boston, MA 02111-1307, USA.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
32 ;; Get all the necessary compile time definitions.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
33 (require 'custom)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
34 (require 'cc-menus)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
35 (require 'derived) ;only necessary in Emacs 20
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
36
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
37 ;; cc-mode-19.el contains compatibility macros that should be compiled
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
38 ;; in if needed.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
39 (if (or (not (fboundp 'functionp))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
40 (not (condition-case nil
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
41 (progn (char-before) t)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
42 (error nil)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
43 (not (condition-case nil
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
44 (progn (char-after) t)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
45 (error nil)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
46 (not (fboundp 'when))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
47 (not (fboundp 'unless)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
48 (require 'cc-mode-19))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
49
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
50
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 (defsubst c-point (position)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;; Returns the value of point at certain commonly referenced POSITIONs.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;; POSITION can be one of the following symbols:
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;;
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;; bol -- beginning of line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;; eol -- end of line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;; bod -- beginning of defun
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
58 ;; eod -- end of defun
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;; boi -- back to indentation
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;; ionl -- indentation of next line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;; iopl -- indentation of previous line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;; bonl -- beginning of next line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;; bopl -- beginning of previous line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;;
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;; This function does not modify point or mark.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 (let ((here (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (cond
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ((eq position 'bol) (beginning-of-line))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ((eq position 'eol) (end-of-line))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ((eq position 'boi) (back-to-indentation))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ((eq position 'bonl) (forward-line 1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ((eq position 'bopl) (forward-line -1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ((eq position 'iopl)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (forward-line -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (back-to-indentation))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ((eq position 'ionl)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 (forward-line 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 (back-to-indentation))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
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
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
85 ;; braces are hung. It can also degrade performance by
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
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
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 (t (error "unknown buffer position requested: %s" position))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 )
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (prog1
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 (point)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 (goto-char here))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
130
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (defmacro c-safe (&rest body)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 ;; safely execute BODY, return nil if an error occurred
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (` (condition-case nil
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (progn (,@ body))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (error nil))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
137 (defmacro c-forward-sexp (&optional arg)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
138 ;; like forward-sexp except
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
139 ;; 1. this is much stripped down from the XEmacs version
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
140 ;; 2. this cannot be used as a command, so we're insulated from
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
141 ;; XEmacs' losing efforts to make forward-sexp more user
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
142 ;; friendly
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
143 ;; 3. Preserves the semantics most of CC Mode is based on
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
144 (or arg (setq arg 1))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
145 `(goto-char (or (scan-sexps (point) ,arg)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
146 ,(if (numberp arg)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
147 (if (> arg 0) `(point-max) `(point-min))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
148 `(if (> ,arg 0) (point-max) (point-min))))))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
149
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
150 (defmacro c-backward-sexp (&optional arg)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
151 ;; See c-forward-sexp and reverse directions
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
152 (or arg (setq arg 1))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
153 `(c-forward-sexp ,(if (numberp arg) (- arg) `(- ,arg))))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
154
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (defmacro c-add-syntax (symbol &optional relpos)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 ;; a simple macro to append the syntax in symbol to the syntax list.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 ;; try to increase performance by using this macro
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (` (setq syntax (cons (cons (, symbol) (, relpos)) syntax))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (defsubst c-auto-newline ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 ;; if auto-newline feature is turned on, insert a newline character
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 ;; and return t, otherwise return nil.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (and c-auto-newline
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (not (c-in-literal))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (not (newline))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (defsubst c-intersect-lists (list alist)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 ;; return the element of ALIST that matches the first element found
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 ;; in LIST. Uses assq.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (let (match)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (while (and list
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (not (setq match (assq (car list) alist))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (setq list (cdr list)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 match))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (defsubst c-lookup-lists (list alist1 alist2)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 ;; first, find the first entry from LIST that is present in ALIST1,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 ;; then find the entry in ALIST2 for that entry.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (assq (car (c-intersect-lists list alist1)) alist2))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (defsubst c-langelem-col (langelem &optional preserve-point)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 ;; convenience routine to return the column of langelem's relpos.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 ;; Leaves point at the relpos unless preserve-point is non-nil.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (let ((here (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (goto-char (cdr langelem))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (prog1 (current-column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (if preserve-point
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (goto-char here))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 )))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (defsubst c-update-modeline ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 ;; set the c-auto-hungry-string for the correct designation on the modeline
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (setq c-auto-hungry-string
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 (if c-auto-newline
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (if c-hungry-delete-key "/ah" "/a")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (if c-hungry-delete-key "/h" nil)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (force-mode-line-update))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (defsubst c-keep-region-active ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 ;; Do whatever is necessary to keep the region active in XEmacs.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 ;; Ignore byte-compiler warnings you might see. This is not needed
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 ;; for Emacs.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (and (boundp 'zmacs-region-stays)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (setq zmacs-region-stays t)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
206 (defsubst c-region-is-active-p ()
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
207 ;; Return t when the region is active. The determination of region
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
208 ;; activeness is different in both Emacs and XEmacs.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
209 (cond
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
210 ;; XEmacs
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
211 ((and (fboundp 'region-active-p)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
212 zmacs-regions)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
213 (region-active-p))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
214 ;; Emacs
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
215 ((boundp 'mark-active) mark-active)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
216 ;; fallback; shouldn't get here
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
217 (t (mark t))))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
218
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
219 (defsubst c-major-mode-is (mode)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
220 (eq (derived-mode-class major-mode) mode))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21112
diff changeset
221
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (provide 'cc-defs)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 ;;; cc-defs.el ends here