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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; cc-defs.el --- definitions for CC Mode
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
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Authors: 1992-1997 Barry A. Warsaw
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; 1987 Dave Detlefs and Stewart Clamen
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; 1985 Richard M. Stallman
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; Maintainer: cc-mode-help@python.org
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; Created: 22-Apr-1997 (split from cc-mode.el)
20141
1a85b213eb6d Remove version number.
Karl Heuer <kwzh@gnu.org>
parents: 20140
diff changeset
10 ;; Version: See cc-mode.el
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; Keywords: c languages oop
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; This file is part of GNU Emacs.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; 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
17 ;; the Free Software Foundation; either version 2, or (at your option)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; any later version.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; GNU Emacs is distributed in the hope that it will be useful,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; GNU General Public License for more details.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;; You should have received a copy of the GNU General Public License
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;; 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
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; Boston, MA 02111-1307, USA.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29
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 ;; 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
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 (defconst c-emacs-features
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 (let ((infodock-p (boundp 'infodock-version))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 (comments
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;; XEmacs 19 and beyond use 8-bit modify-syntax-entry flags.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; Emacs 19 uses a 1-bit flag. We will have to set up our
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; syntax tables differently to handle this.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 (let ((table (copy-syntax-table))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 entry)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 (modify-syntax-entry ?a ". 12345678" table)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 (cond
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;; XEmacs 19, and beyond Emacs 19.34
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ((arrayp table)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 (setq entry (aref table ?a))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; In Emacs, table entries are cons cells
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 (if (consp entry) (setq entry (car entry))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; XEmacs 20
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ((fboundp 'get-char-table) (setq entry (get-char-table ?a table)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;; before and including Emacs 19.34
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ((and (fboundp 'char-table-p)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 (char-table-p table))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (setq entry (car (char-table-range table [?a]))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;; incompatible
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 (t (error "CC Mode is incompatible with this version of Emacs")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 (if (= (logand (lsh entry -16) 255) 255)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 '8-bit
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 '1-bit))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 (if infodock-p
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (list comments 'infodock)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 (list comments)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 "A list of features extant in the Emacs you are using.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 There are many flavors of Emacs out there, each with different
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 features supporting those needed by CC Mode. Here's the current
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 supported list, along with the values for this variable:
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 XEmacs 19: (8-bit)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 XEmacs 20: (8-bit)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 Emacs 19: (1-bit)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 Infodock (based on XEmacs) has an additional symbol on this list:
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 'infodock.")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 (defsubst c-point (position)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;; Returns the value of point at certain commonly referenced POSITIONs.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;; POSITION can be one of the following symbols:
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;;
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;; bol -- beginning of line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;; eol -- end of line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 ;; bod -- beginning of defun
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;; boi -- back to indentation
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ;; ionl -- indentation of next line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ;; iopl -- indentation of previous line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 ;; bonl -- beginning of next line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;; bopl -- beginning of previous line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ;;
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;; This function does not modify point or mark.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 (let ((here (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (cond
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 ((eq position 'bol) (beginning-of-line))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 ((eq position 'eol) (end-of-line))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ((eq position 'boi) (back-to-indentation))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ((eq position 'bonl) (forward-line 1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 ((eq position 'bopl) (forward-line -1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 ((eq position 'iopl)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (forward-line -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (back-to-indentation))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 ((eq position 'ionl)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 (forward-line 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
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
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (t (error "unknown buffer position requested: %s" position))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 )
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (prog1
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (point)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (goto-char here))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (defmacro c-safe (&rest body)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 ;; safely execute BODY, return nil if an error occurred
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (` (condition-case nil
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (progn (,@ body))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (error nil))))
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 (defmacro c-add-syntax (symbol &optional relpos)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 ;; 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
162 ;; try to increase performance by using this macro
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 (` (setq syntax (cons (cons (, symbol) (, relpos)) syntax))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (defsubst c-auto-newline ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 ;; if auto-newline feature is turned on, insert a newline character
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 ;; and return t, otherwise return nil.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (and c-auto-newline
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (not (c-in-literal))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (not (newline))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (defsubst c-intersect-lists (list alist)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 ;; return the element of ALIST that matches the first element found
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 ;; in LIST. Uses assq.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (let (match)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (while (and list
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (not (setq match (assq (car list) alist))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (setq list (cdr list)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 match))
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-lookup-lists (list alist1 alist2)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 ;; first, find the first entry from LIST that is present in ALIST1,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 ;; then find the entry in ALIST2 for that entry.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (assq (car (c-intersect-lists list alist1)) alist2))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 (defsubst c-langelem-col (langelem &optional preserve-point)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 ;; convenience routine to return the column of langelem's relpos.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 ;; Leaves point at the relpos unless preserve-point is non-nil.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (let ((here (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (goto-char (cdr langelem))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (prog1 (current-column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 (if preserve-point
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (goto-char here))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 )))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (defsubst c-update-modeline ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 ;; 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
198 (setq c-auto-hungry-string
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (if c-auto-newline
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (if c-hungry-delete-key "/ah" "/a")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (if c-hungry-delete-key "/h" nil)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (force-mode-line-update))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (defsubst c-keep-region-active ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 ;; Do whatever is necessary to keep the region active in XEmacs.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 ;; Ignore byte-compiler warnings you might see. This is not needed
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 ;; for Emacs.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (and (boundp 'zmacs-region-stays)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (setq zmacs-region-stays t)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (provide 'cc-defs)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 ;;; cc-defs.el ends here