annotate lisp/modes/cc-mode.el @ 157:6b37e6ddd302 r20-3b5

Import from CVS: tag r20-3b5
author cvs
date Mon, 13 Aug 2007 09:40:41 +0200
parents 43dd3413c7c7
children 3bb7ccffb0c0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1 ;;; cc-mode.el --- major mode for editing C, C++, Objective-C, and Java code
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
3 ;; Copyright (C) 1985,87,92,93,94,95,96,97 Free Software Foundation, Inc.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5 ;; Authors: 1992-1997 Barry A. Warsaw
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; 1987 Dave Detlefs and Stewart Clamen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; 1985 Richard M. Stallman
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; Created: a long, long, time ago. adapted from the original c-mode.el
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
9 ;; Version: 4.390-x
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
10 ;; Last Modified: 1997/04/02 15:46:35
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; Keywords: c languages oop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; NOTE: Read the commentary below for the right way to submit bug reports!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; NOTE: See the accompanying texinfo manual for details on using this mode!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; along with GNU Emacs; see the file COPYING. If not, write to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; Boston, MA 02111-1307, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
35 ;; This package provides GNU Emacs major modes for editing C, C++,
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
36 ;; Objective-C, and Java code. As of the latest Emacs and XEmacs
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
37 ;; releases, it is the default package for editing these languages.
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
38 ;; This package is called "CC Mode", and should be spelled exactly
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
39 ;; this way. It supports K&R and ANSI C, ANSI C++, Objective-C, and
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
40 ;; Java, with a consistent indentation model across all modes. This
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
41 ;; indentation model is intuitive and very flexible, so that almost
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
42 ;; any desired style of indentation can be supported. Installation,
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
43 ;; usage, and programming details are contained in an accompanying
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
44 ;; texinfo manual.
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
45
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
46 ;; CC Mode's immediate ancestors were, c++-mode.el, cplus-md.el, and
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
47 ;; cplus-md1.el..
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
49 ;; NOTE: This mode does not perform font-locking (a.k.a syntactic
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
50 ;; coloring, keyword highlighting, etc.) for any of the supported
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
51 ;; modes. Typically this is done by a package called font-lock.el
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
52 ;; which I do *not* maintain. You should contact the Emacs
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
53 ;; maintainers for questions about coloring or highlighting in any
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
54 ;; language mode.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
55
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; To submit bug reports, type "C-c C-b". These will be sent to
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
57 ;; bug-gnu-emacs@prep.ai.mit.edu as well as cc-mode-help@python.org,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
58 ;; and I'll read about them there (the former is mirrored as the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
59 ;; Usenet newsgroup gnu.emacs.bug). Questions can sent to
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
60 ;; help-gnu-emacs@prep.ai.mit.edu (mirrored as gnu.emacs.help) and/or
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
61 ;; cc-mode-help@python.org. Please do not send bugs or questions to
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
62 ;; my personal account.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;; YOU CAN IGNORE ALL BYTE-COMPILER WARNINGS. They are the result of
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
65 ;; the cross-Emacsen support. GNU Emacs 19 (from the FSF), GNU XEmacs
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
66 ;; 19 (formerly Lucid Emacs), and GNU Emacs 18 all do things
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
67 ;; differently and there's no way to shut the byte-compiler up at the
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
68 ;; necessary granularity. Let me say this again: YOU CAN IGNORE ALL
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;; BYTE-COMPILER WARNINGS (you'd be surprised at how many people don't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;; follow this advice :-).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;; Many, many thanks go out to all the folks on the beta test list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;; Without their patience, testing, insight, code contributions, and
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
74 ;; encouragement CC Mode would be a far inferior package.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
75
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
76 ;; You can get the latest version of CC Mode, including PostScript
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
77 ;; documentation and separate individual files from:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;;
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
79 ;; http://www.python.org/ftp/emacs/
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
80
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
81 ;; Or if you don't have access to the World Wide Web, through
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
82 ;; anonymous ftp from:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
83 ;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
84 ;; ftp://ftp.python.org/pub/emacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
86 ;; Customization added by Hrvoje Niksic <hniksic@srce.hr>
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
87
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;; user definable variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
94 (defgroup cc-mode nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
95 "Major mode for editing C, C++, Objective-C, and Java code"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
96 :group 'c
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
97 :prefix "c-")
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
98
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
99 (defgroup cc-style nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
100 "Styles for cc mode"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
101 :prefix "c-"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
102 :group 'cc-mode)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
103
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
104 (defgroup cc-indent nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
105 "Indentation of cc-mode"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
106 :prefix "c-"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
107 :group 'cc-mode)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
108
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
109 (defgroup cc-syntax nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
110 "Syntactical analysis performed by cc-mode"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
111 :prefix "c-"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
112 :group 'cc-mode)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
113
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
114 (defgroup cc-comment nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
115 "Handling of comments by cc-mode"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
116 :prefix "c-"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
117 :group 'cc-mode)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
118
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
119 (defgroup cc-auto nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
120 "Auto-insertion features of cc-mode"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
121 :prefix "c-"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
122 :group 'cc-mode)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
123
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
124
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
125 (defcustom c-inhibit-startup-warnings-p nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
126 "*If non-nil, inhibits start up compatibility warnings."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
127 :type 'boolean
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
128 :group 'cc-mode)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
129 (defcustom c-strict-syntax-p nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 "*If non-nil, all syntactic symbols must be found in `c-offsets-alist'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 If the syntactic symbol for a particular line does not match a symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 in the offsets alist, an error is generated, otherwise no error is
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
133 reported and the syntactic symbol is ignored."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
134 :type 'boolean
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
135 :group 'cc-syntax)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
136 (defcustom c-echo-syntactic-information-p nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
137 "*If non-nil, syntactic info is echoed when the line is indented."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
138 :type 'boolean
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
139 :group 'cc-syntax)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
140 (defcustom c-basic-offset 4
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
141 "*Amount of basic offset used by + and - symbols in `c-offsets-alist'."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
142 :type 'integer
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
143 :group 'cc-indent)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
144
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
145 (defcustom c-offsets-alist
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 '((string . -1000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (c . c-lineup-C-comments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (defun-open . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (defun-close . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (defun-block-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (class-open . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (class-close . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (inline-open . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (inline-close . 0)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
155 (func-decl-cont . +)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (knr-argdecl-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (knr-argdecl . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (topmost-intro . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (topmost-intro-cont . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (member-init-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (member-init-cont . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (inher-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (inher-cont . c-lineup-multi-inher)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (block-open . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (block-close . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (brace-list-open . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (brace-list-close . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (brace-list-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (brace-list-entry . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (statement . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 ;; some people might prefer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ;;(statement . c-lineup-runin-statements)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (statement-cont . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;; some people might prefer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ;;(statement-cont . c-lineup-math)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (statement-block-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (statement-case-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (statement-case-open . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (substatement . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (substatement-open . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (case-label . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (access-label . -)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (label . 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (do-while-closure . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (else-clause . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (comment-intro . c-lineup-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (arglist-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (arglist-cont . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (arglist-cont-nonempty . c-lineup-arglist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (arglist-close . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (stream-op . c-lineup-streamop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (inclass . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (cpp-macro . -1000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (friend . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (objc-method-intro . -1000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (objc-method-args-cont . c-lineup-ObjC-method-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (objc-method-call-cont . c-lineup-ObjC-method-call)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
198 (extern-lang-open . 0)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
199 (extern-lang-close . 0)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
200 (inextern-lang . +)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 "*Association list of syntactic element symbols and indentation offsets.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 As described below, each cons cell in this list has the form:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (SYNTACTIC-SYMBOL . OFFSET)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
207 When a line is indented, CC Mode first determines the syntactic
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 context of the line by generating a list of symbols called syntactic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 elements. This list can contain more than one syntactic element and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 the global variable `c-syntactic-context' contains the context list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 for the line being indented. Each element in this list is actually a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 cons cell of the syntactic symbol and a buffer position. This buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 position is called the relative indent point for the line. Some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 syntactic symbols may not have a relative indent point associated with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
217 After the syntactic context list for a line is generated, CC Mode
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 calculates the absolute indentation for the line by looking at each
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 syntactic element in the list. First, it compares the syntactic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 element against the SYNTACTIC-SYMBOL's in `c-offsets-alist'. When it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 finds a match, it adds the OFFSET to the column of the relative indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 point. The sum of this calculation for each element in the syntactic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 list is the absolute offset for line being indented.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 If the syntactic element does not match any in the `c-offsets-alist',
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
226 an error is generated if `c-strict-syntax-p' is non-nil, otherwise the
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
227 element is ignored.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 Actually, OFFSET can be an integer, a function, a variable, or one of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 the following symbols: `+', `-', `++', `--', `*', or `/'. These
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 latter designate positive or negative multiples of `c-basic-offset',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 respectively: *1, *-1, *2, *-2, *0.5, and *-0.5. If OFFSET is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 function, it is called with a single argument containing the cons of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 the syntactic element symbol and the relative indent point. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 function should return an integer offset.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 Here is the current list of valid syntactic element symbols:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 string -- inside multi-line string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 c -- inside a multi-line C style block comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 defun-open -- brace that opens a function definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 defun-close -- brace that closes a function definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 defun-block-intro -- the first line in a top-level defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 class-open -- brace that opens a class definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 class-close -- brace that closes a class definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 inline-open -- brace that opens an in-class inline method
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 inline-close -- brace that closes an in-class inline method
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
248 func-decl-cont -- the nether region between a function
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
249 declaration and the defun opening brace.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
250 In C++ and Java, this can include `throws'
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
251 declarations
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 knr-argdecl-intro -- first line of a K&R C argument declaration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 knr-argdecl -- subsequent lines in a K&R C argument declaration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 topmost-intro -- the first line in a topmost construct definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 topmost-intro-cont -- topmost definition continuation lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 member-init-intro -- first line in a member initialization list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 member-init-cont -- subsequent member initialization list lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 inher-intro -- first line of a multiple inheritance list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 inher-cont -- subsequent multiple inheritance lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 block-open -- statement block open brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 block-close -- statement block close brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 brace-list-open -- open brace of an enum or static array list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 brace-list-close -- close brace of an enum or static array list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 brace-list-intro -- first line in an enum or static array list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 brace-list-entry -- subsequent lines in an enum or static array list
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
266 statement -- a C (or like) statement
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
267 statement-cont -- a continuation of a C (or like) statement
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 statement-block-intro -- the first line in a new statement block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 statement-case-intro -- the first line in a case `block'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 statement-case-open -- the first line in a case block starting with brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 substatement -- the first line after an if/while/for/do/else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 substatement-open -- the brace that opens a substatement block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 case-label -- a case or default label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 access-label -- C++ private/protected/public access label
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
275 label -- any non-special C (or like) label
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 do-while-closure -- the `while' that ends a do/while construct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 else-clause -- the `else' of an if/else construct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 comment-intro -- a line containing only a comment introduction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 arglist-intro -- the first line in an argument list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 arglist-cont -- subsequent argument list lines when no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 arguments follow on the same line as the
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
282 arglist opening paren
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 arglist-cont-nonempty -- subsequent argument list lines when at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 least one argument follows on the same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 line as the arglist opening paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 arglist-close -- the solo close paren of an argument list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 stream-op -- lines continuing a stream operator construct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 inclass -- the construct is nested inside a class definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 cpp-macro -- the start of a cpp macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 friend -- a C++ friend declaration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 objc-method-intro -- the first line of an Objective-C method definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 objc-method-args-cont -- lines continuing an Objective-C method definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 objc-method-call-cont -- lines continuing an Objective-C method call
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
294 extern-lang-open -- brace that opens an external language block
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
295 extern-lang-close -- brace that closes an external language block
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
296 inextern-lang -- analogous to `inclass' syntactic symbol
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
297 "
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
298 :type '(repeat (cons symbol sexp))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
299 :group 'cc-syntax
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
300 :group 'cc-indent)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
301
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
302 (defcustom c-tab-always-indent t
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 "*Controls the operation of the TAB key.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 If t, hitting TAB always just indents the current line. If nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 hitting TAB indents the current line if point is at the left margin or
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
306 in the line's indentation, otherwise it insert a `real' tab character
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
307 \(see note\). If other than nil or t, then tab is inserted only
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
308 within literals -- defined as comments and strings -- and inside
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
309 preprocessor directives, but line is always reindented.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
311 Note: The value of `indent-tabs-mode' will determine whether a real
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
312 tab character will be inserted, or the equivalent number of space.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
313 When inserting a tab, actually the function stored in the variable
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
314 `c-insert-tab-function' is called.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
315
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
316 Note: indentation of lines containing only comments is also controlled
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
317 by the `c-comment-only-line-offset' variable."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
318 :type '(choice (const :tag "on" t)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
319 (const :tag "off" nil)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
320 (const :tag "insert within literals" other))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
321 :group 'cc-indent)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
322
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
323 (defcustom c-insert-tab-function 'insert-tab
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
324 "*Function used when inserting a tab for \\[TAB].
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
325 Only used when `c-tab-always-indent' indicates a `real' tab character
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
326 should be inserted. Value must be a function taking no arguments."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
327 :type 'function
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
328 :group 'cc-indent)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
329
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
330 (defcustom c-comment-only-line-offset 0
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 "*Extra offset for line which contains only the start of a comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 Can contain an integer or a cons cell of the form:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 Where NON-ANCHORED-OFFSET is the amount of offset given to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 the amount of offset to give column-zero anchored comment-only lines.
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
339 Just an integer as value is equivalent to (<val> . -1000)."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
340 :type '(choice integer
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
341 (cons integer integer))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
342 :group 'cc-comment)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
343
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
344 (defcustom c-indent-comments-syntactically-p nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 "*Specifies how comment-only lines should be indented.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 When this variable is non-nil, comment-only lines are indented
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 according to syntactic analysis via `c-offsets-alist', even when
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
348 \\[indent-for-comment] is used."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
349 :type 'boolean
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
350 :group 'cc-indent
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
351 :group 'cc-comment)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
352
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
353 (defcustom c-cleanup-list '(scope-operator)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 "*List of various C/C++/ObjC constructs to \"clean up\".
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
355 These clean ups only take place when the auto-newline feature is
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
356 turned on, as evidenced by the `/a' or `/ah' appearing next to the
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
357 mode name. Valid symbols are:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 brace-else-brace -- cleans up `} else {' constructs by placing entire
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
360 construct on a single line. This clean up
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
361 only takes place when there is nothing but
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
362 white space between the braces and the `else'.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
363 Clean up occurs when the open-brace after the
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
364 `else' is typed.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
365 brace-elseif-brace -- similar to brace-else-brace, but cleans up
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
366 `} else if {' constructs.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 empty-defun-braces -- cleans up empty defun braces by placing the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 braces on the same line. Clean up occurs when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 the defun closing brace is typed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 defun-close-semi -- cleans up the terminating semi-colon on defuns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 by placing the semi-colon on the same line as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 the closing brace. Clean up occurs when the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 semi-colon is typed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 list-close-comma -- cleans up commas following braces in array
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 and aggregate initializers. Clean up occurs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 when the comma is typed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 scope-operator -- cleans up double colons which may designate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 a C++ scope operator split across multiple
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 lines. Note that certain C++ constructs can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 generate ambiguous situations. This clean up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 only takes place when there is nothing but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 whitespace between colons. Clean up occurs
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
383 when the second colon is typed."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
384 :type '(repeat (choice (const brace-else-brace) (const brace-elseif-brace)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
385 (const empty-defun-braces) (const defun-close-semi)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
386 (const list-close-comma) (const scope-operator)))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
387 :group 'cc-auto)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
388
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
389 (defcustom c-hanging-braces-alist '((brace-list-open)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
390 (substatement-open after)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
391 (block-close . c-snug-do-while)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
392 (extern-lang-open after)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
393 )
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 "*Controls the insertion of newlines before and after braces.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 This variable contains an association list with elements of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 following form: (SYNTACTIC-SYMBOL . ACTION).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 When a brace (either opening or closing) is inserted, the syntactic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 context it defines is looked up in this list, and if found, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 associated ACTION is used to determine where newlines are inserted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 If the context is not found, the default is to insert a newline both
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 before and after the brace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 SYNTACTIC-SYMBOL can be any of: defun-open, defun-close, class-open,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 class-close, inline-open, inline-close, block-open, block-close,
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
406 substatement-open, statement-case-open, extern-lang-open,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
407 extern-lang-close, brace-list-open, brace-list-close,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
408 brace-list-intro, or brace-list-entry. See `c-offsets-alist' for
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
409 details.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 ACTION can be either a function symbol or a list containing any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 combination of the symbols `before' or `after'. If the list is empty,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 no newlines are inserted either before or after the brace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 When ACTION is a function symbol, the function is called with a two
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 arguments: the syntactic symbol for the brace and the buffer position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 at which the brace was inserted. The function must return a list as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 described in the preceding paragraph. Note that during the call to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 the function, the variable `c-syntactic-context' is set to the entire
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
420 syntactic context for the brace line."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
421 :type '(repeat (cons symbol (choice (const nil)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
422 (repeat (choice (const before)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
423 (const after)))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
424 function
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
425 )))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
426 :group 'cc-auto)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
427
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
428 (defcustom c-hanging-colons-alist nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 "*Controls the insertion of newlines before and after certain colons.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 This variable contains an association list with elements of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 following form: (SYNTACTIC-SYMBOL . ACTION).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 See the variable `c-hanging-braces-alist' for the semantics of this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 variable. Note however that making ACTION a function symbol is
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
435 currently not supported for this variable."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
436 :type '(repeat (cons symbol (choice (repeat (choice (const before)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
437 (const after)))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
438 )))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
439 :group 'cc-auto)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
440
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
441 (defcustom c-hanging-semi&comma-criteria '(c-semi&comma-inside-parenlist)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 "*List of functions that decide whether to insert a newline or not.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 The functions in this list are called, in order, whenever the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 auto-newline minor mode is activated (as evidenced by a `/a' or `/ah'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 string in the mode line), and a semicolon or comma is typed (see
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 `c-electric-semi&comma'). Each function in this list is called with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 no arguments, and should return one of the following values:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 nil -- no determination made, continue checking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 'stop -- do not insert a newline, and stop checking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (anything else) -- insert a newline, and stop checking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 If every function in the list is called with no determination made,
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
454 then no newline is inserted."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
455 :type '(repeat function)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
456 :group 'cc-auto)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
457
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
458 (defcustom c-hanging-comment-ender-p t
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
459 "*Controls what \\[fill-paragraph] does to C block comment enders.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
460 When set to nil, C block comment enders are left on their own line.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
461 When set to t, block comment enders will be placed at the end of the
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
462 previous line (i.e. they `hang' on that line)."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
463 :type 'boolean
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
464 :group 'cc-comment)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
465
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
466 (defcustom c-hanging-comment-starter-p t
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
467 "*Controls what \\[fill-paragraph] does to C block comment starters.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
468 When set to nil, C block comment starters are left on their own line.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
469 When set to t, text that follows a block comment starter will be
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
470 placed on the same line as the block comment starter (i.e. the text
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
471 `hangs' on that line)."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
472 :type 'boolean
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
473 :group 'cc-comment)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
474
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
475 (defcustom c-backslash-column 48
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
476 "*Column to insert backslashes when macroizing a region."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
477 :type 'integer
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
478 :group 'cc-mode)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
479 (defcustom c-special-indent-hook nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 "*Hook for user defined special indentation adjustments.
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
481 This hook gets called after a line is indented by the mode."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
482 :type 'hook
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
483 :group 'cc-indent)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
484 (defcustom c-delete-function (if (fboundp 'backspace-or-delete)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
485 'backspace-or-delete
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
486 'backward-delete-char-untabify)
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
487 "*Function called by `c-electric-delete' when deleting characters."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
488 :type 'function
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
489 :group 'cc-mode)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
490 (defcustom c-electric-pound-behavior nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 "*List of behaviors for electric pound insertion.
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
492 Only currently supported behavior is `alignleft'."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
493 :type '(repeat (choice (const alignleft)))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
494 :group 'cc-auto)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
495
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
496 (defcustom c-label-minimum-indentation 1
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
497 "*Minimum indentation for lines inside of top-level constructs.
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
498 This variable typically only affects code using the `gnu' style, which
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
499 mandates a minimum of one space in front of every line inside
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
500 top-level constructs. Specifically, the function
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
501 `c-gnu-impose-minimum' on your `c-special-indent-hook' is what
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
502 enforces this."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
503 :type 'integer
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
504 :group 'cc-indent)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
505
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
506 (defcustom c-progress-interval 5
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 "*Interval used to update progress status during long re-indentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 If a number, percentage complete gets updated after each interval of
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
509 that many seconds. Set to nil to inhibit updating. This is only
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
510 useful for Emacs 19."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
511 :type 'integer
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
512 :group 'cc-indent)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
514 (defconst c-style-alist
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 '(("gnu"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (c-basic-offset . 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (c-comment-only-line-offset . (0 . 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (c-offsets-alist . ((statement-block-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (knr-argdecl-intro . 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (substatement-open . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (label . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (statement-case-open . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (statement-cont . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (arglist-intro . c-lineup-arglist-intro-after-paren)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (arglist-close . c-lineup-arglist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 ))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
527 (c-special-indent-hook . c-gnu-impose-minimum)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 ("k&r"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (c-basic-offset . 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (c-comment-only-line-offset . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (c-offsets-alist . ((statement-block-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (knr-argdecl-intro . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (substatement-open . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (label . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (statement-cont . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 ("bsd"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (c-basic-offset . 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (c-comment-only-line-offset . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (c-offsets-alist . ((statement-block-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (knr-argdecl-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (substatement-open . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (label . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (statement-cont . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 ("stroustrup"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (c-basic-offset . 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (c-comment-only-line-offset . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (c-offsets-alist . ((statement-block-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (substatement-open . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (label . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (statement-cont . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 ("whitesmith"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (c-basic-offset . 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (c-comment-only-line-offset . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (c-offsets-alist . ((statement-block-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (knr-argdecl-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (substatement-open . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (label . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (statement-cont . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 ("ellemtel"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (c-basic-offset . 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (c-comment-only-line-offset . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (c-hanging-braces-alist . ((substatement-open before after)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (c-offsets-alist . ((topmost-intro . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (topmost-intro-cont . 0)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
575 (substatement . +)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (substatement-open . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (case-label . +)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
578 (access-label . -)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
579 (inclass . ++)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (inline-open . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 )
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
583 ("linux"
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
584 (c-basic-offset . 8)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
585 (c-comment-only-line-offset . 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
586 (c-hanging-braces-alist . ((brace-list-open)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
587 (substatement-open after)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
588 (block-close . c-snug-do-while)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
589 (c-cleanup-list . (brace-else-brace))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
590 (c-offsets-alist . ((statement-block-intro . +)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
591 (knr-argdecl-intro . 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
592 (substatement-open . 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
593 (label . 0)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
594 (statement-cont . +)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
595 ))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
596 )
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
597 ("python"
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
598 (indent-tabs-mode . t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
599 (c-basic-offset . 8)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
600 (c-offsets-alist . ((substatement-open . 0)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
601 ))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
602 (c-hanging-braces-alist . ((brace-list-open)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
603 (brace-list-intro)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
604 (brace-list-close)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
605 (substatement-open after)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
606 (block-close . c-snug-do-while)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
607 ))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
608 )
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 ("java"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (c-basic-offset . 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (c-comment-only-line-offset . (0 . 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (c-offsets-alist . ((statement-block-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (knr-argdecl-intro . 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (substatement-open . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (label . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (statement-case-open . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (statement-cont . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (arglist-intro . c-lineup-arglist-intro-after-paren)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (arglist-close . c-lineup-arglist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (access-label . 0)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
621 (inher-cont . c-lineup-java-inher)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 "Styles of Indentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 Elements of this alist are of the form:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 where STYLE-STRING is a short descriptive string used to select a
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
632 style, VARIABLE is any CC Mode variable, and VALUE is the intended
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 value for that variable when using the selected style.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 There is one special case when VARIABLE is `c-offsets-alist'. In this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 case, the VALUE is a list containing elements of the form:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (SYNTACTIC-SYMBOL . VALUE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 as described in `c-offsets-alist'. These are passed directly to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 `c-set-offset' so there is no need to set every syntactic symbol in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 your style, only those that are different from the default.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 Note that all styles inherit from the `cc-mode' style, which is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 computed at the time the mode is loaded.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
647 (defcustom c-file-style nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 "*Variable interface for setting style via File Local Variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 In a file's Local Variable section, you can set this variable to a
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
650 string suitable for `c-set-style'. When the file is visited, CC Mode
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 will set the style of the file to this value automatically.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 Note that file style settings are applied before file offset settings
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
654 as designated in the variable `c-file-offsets'."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
655 :type '(repeat (cons regexp (string :tag "Style")))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
656 :group 'cc-style)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
657
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
658 (defcustom c-file-offsets nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 "*Variable interface for setting offsets via File Local Variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 In a file's Local Variable section, you can set this variable to an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 association list similar to the values allowed in `c-offsets-alist'.
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
662 When the file is visited, CC Mode will institute these offset settings
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 automatically.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 Note that file offset settings are applied after file style settings
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
666 as designated in the variable `c-file-style'."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
667 :type '(repeat (cons regexp (string :tag "Style")))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
668 :group 'cc-indent)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
669
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
670 (defcustom c-site-default-style "gnu"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 "Default style for your site.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 To change the default style at your site, you can set this variable to
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
673 any style defined in `c-style-alist'. However, if CC Mode is usually
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 loaded into your Emacs at compile time, you will need to set this
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
675 variable in the `site-init.el' file before CC Mode is loaded, then
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
676 re-dump Emacs."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
677 :type 'string
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
678 :group 'cc-style)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
679
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
680 (defcustom c-style-variables-are-local-p t
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
681 "*Whether style variables should be buffer local by default.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
682 If non-nil, then all indentation style related variables will be made
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
683 buffer local by default. If nil, they will remain global. Variables
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
684 are made buffer local when this file is loaded, and once buffer
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
685 localized, they cannot be made global again.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
686
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
687 The list of variables to buffer localize are:
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
688 c-offsets-alist
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
689 c-basic-offset
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
690 c-file-style
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
691 c-file-offsets
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
692 c-comment-only-line-offset
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
693 c-cleanup-list
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
694 c-hanging-braces-alist
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
695 c-hanging-colons-alist
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
696 c-hanging-comment-starter-p
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
697 c-hanging-comment-ender-p
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
698 c-backslash-column
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
699 c-label-minimum-indentation
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
700 c-special-indent-hook
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
701 c-indentation-style"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
702 :type 'boolean
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
703 :group 'cc-style)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
704
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
705
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
706 (defcustom c-mode-hook nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
707 "*Hook called by `c-mode'."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
708 :type 'hook
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
709 :group 'cc-mode)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
710 (defcustom c++-mode-hook nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
711 "*Hook called by `c++-mode'."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
712 :type 'hook
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
713 :group 'cc-mode)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
714 (defcustom objc-mode-hook nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
715 "*Hook called by `objc-mode'."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
716 :type 'hook
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
717 :group 'cc-mode)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
718 (defcustom java-mode-hook nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
719 "*Hook called by `java-mode'."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
720 :type 'hook
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
721 :group 'cc-mode)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
722
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
723 (defcustom c-mode-common-hook nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
724 "*Hook called by all CC Mode modes for common initializations."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
725 :type 'hook
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 118
diff changeset
726 :group 'cc-mode)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (defvar c-mode-menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 '(["Comment Out Region" comment-region (mark)]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 ["Macro Expand Region" c-macro-expand (mark)]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 ["Backslashify" c-backslash-region (mark)]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 ["Indent Expression" c-indent-exp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (memq (following-char) '(?\( ?\[ ?\{))]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 ["Indent Line" c-indent-command t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 ["Fill Comment Paragraph" c-fill-paragraph t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 ["Up Conditional" c-up-conditional t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 ["Backward Conditional" c-backward-conditional t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 ["Forward Conditional" c-forward-conditional t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 ["Backward Statement" c-beginning-of-statement t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 ["Forward Statement" c-end-of-statement t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 )
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
742 "Basic XEmacs 19 menu for C/C++/ObjC/Java modes.")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
743
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
744
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
745 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
746 ;; NO USER DEFINABLE VARIABLES BEYOND THIS POINT
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
747
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
748 ;; imenu integration
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (defvar cc-imenu-c++-generic-expression
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (`
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 ((nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (concat
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
754 "^" ; beginning of line is required
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
755 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>"
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
756 "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; type specs; there can be no
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
757 "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; more than 3 tokens, right?
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
759 "\\(" ; last type spec including */&
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 "[a-zA-Z0-9_:]+"
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
761 "\\([ \t]*[*&]+[ \t]*\\|[ \t]+\\)" ; either ptr/ref sign or ws
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
762 "\\)?" ; if there is a last type spec
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
763 "\\(" ; name, take into the imenu entry
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
764 "[a-zA-Z0-9_:~]+" ; member func, ctor or dtor...
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
765 ; (may not contain * because then
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
766 ; "a::operator char*" would
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
767 ; become "char*"!)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 "\\|"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 "\\([a-zA-Z0-9_:~]*::\\)?operator"
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
770 "[^a-zA-Z1-9_][^(]*" ; ...or operator
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 " \\)"
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
772 "[ \t]*([^)]*)[ \t\n]*[^ ;]" ; require something other than
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
773 ; a `;' after the (...) to
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
774 ; avoid prototypes. Can't
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
775 ; catch cases with () inside
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
776 ; the parentheses surrounding
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
777 ; the parameters. e.g.:
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
778 ; "int foo(int a=bar()) {...}"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 )) 6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 ("Class"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (, (concat
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
783 "^" ; beginning of line is required
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 "class[ \t]+"
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
786 "\\([a-zA-Z0-9_]+\\)" ; the string we want to get
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 "[ \t]*[:{]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 )) 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 "Imenu generic expression for C++ mode. See `imenu-generic-expression'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 (defvar cc-imenu-c-generic-expression
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 cc-imenu-c++-generic-expression
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 "Imenu generic expression for C mode. See `imenu-generic-expression'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
795 ;(defvar cc-imenu-objc-generic-expression
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
796 ; ())
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
797 ; Please contribute one!
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
798
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
799 (defvar cc-imenu-java-generic-expression
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
800 (`
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
801 ((nil
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
802 (,
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
803 (concat
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
804 "^\\([ \t]\\)*"
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
805 "\\([A-Za-z0-9_-]+[ \t]+\\)?" ; type specs; there can be
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
806 "\\([A-Za-z0-9_-]+[ \t]+\\)?" ; more than 3 tokens, right?
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
807 "\\([A-Za-z0-9_-]+[ \t]*[[]?[]]?\\)"
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
808 "\\([ \t]\\)"
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
809 "\\([A-Za-z0-9_-]+\\)" ; the string we want to get
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
810 "\\([ \t]*\\)+("
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
811 "\\([a-zA-Z,_1-9\n \t]*[[]?[]]?\\)*" ; arguments
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
812 ")[ \t]*"
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
813 "[^;(]"
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
814 "[,a-zA-Z_1-9\n \t]*{"
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
815 )) 6)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
816 "Imenu generic expression for Java mode. See `imenu-generic-expression'.")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
817
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
818
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 ;; Shut the byte-compiler up. Requires Emacs 19 or JWZ's improved
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 ;; byte-compiler. Otherwise, comment this line out and ignore
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 ;; any warnings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 ;;(byte-compiler-options (warnings nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 ;; figure out what features this Emacs has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 (defconst c-emacs-features
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (let ((major (and (boundp 'emacs-major-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 emacs-major-version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (minor (and (boundp 'emacs-minor-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 emacs-minor-version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 (re-suite 'old-re)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
832 flavor comments infodock-p)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 ;; figure out version numbers if not already discovered
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 (and (or (not major) (not minor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 (string-match "\\([0-9]+\\).\\([0-9]+\\)" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (setq major (string-to-int (substring emacs-version
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 minor (string-to-int (substring emacs-version
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (match-beginning 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (match-end 2)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (if (not (and major minor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 (error "Cannot figure out the major and minor version numbers."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 ;; calculate the major version
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 ((= major 18) (setq major 'v18)) ;Emacs 18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 ((= major 4) (setq major 'v18)) ;Epoch 4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 ((= major 19) (setq major 'v19 ;Emacs 19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 flavor (if (or (string-match "Lucid" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 (string-match "XEmacs" emacs-version))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
851 'XEmacs 'FSF)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
852 infodock-p (boundp 'infodock-version)))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
853 ((= major 20) (setq major 'v20 ;XEmacs 20
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
854 flavor 'XEmacs))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 ;; I don't know
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 (t (error "Cannot recognize major version number: %s" major)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 ;; Regular expression suites...
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
858 (if (or (eq major 'v20)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
859 (and (eq major 'v19)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
860 (or (and (eq flavor 'XEmacs) (>= minor 14))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
861 (and (eq flavor 'FSF) (>= minor 30)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 (setq re-suite 'new-re))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 ;; XEmacs 19 uses 8-bit modify-syntax-entry flags, as do all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 ;; patched Emacs 19, Emacs 18, Epoch 4's. Only Emacs 19 uses a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 ;; 1-bit flag. Let's be as smart as we can about figuring this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 ;; out.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
867 (if (or (eq major 'v20) (eq major 'v19))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 (let ((table (copy-syntax-table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (modify-syntax-entry ?a ". 12345678" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 ;; XEmacs pre 20 and Emacs pre 19.30 use vectors for syntax tables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 ((vectorp table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 (if (= (logand (lsh (aref table ?a) -16) 255) 255)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (setq comments '8-bit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (setq comments '1-bit)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 ;; XEmacs 20 is known to be 8-bit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 ((eq flavor 'XEmacs) (setq comments '8-bit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 ;; Emacs 19.30 and beyond are known to be 1-bit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 ((eq flavor 'FSF) (setq comments '1-bit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 ;; Don't know what this is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 (t (error "Couldn't figure out syntax table format."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 ;; Emacs 18 has no support for dual comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (setq comments 'no-dual-comments))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 ;; lets do some minimal sanity checking.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (if (and (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 ;; Lucid Emacs before 19.6 had bugs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (and (eq major 'v19) (eq flavor 'XEmacs) (< minor 6))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 ;; Emacs 19 before 19.21 has known bugs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (and (eq major 'v19) (eq flavor 'FSF) (< minor 21)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (not c-inhibit-startup-warnings-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (with-output-to-temp-buffer "*cc-mode warnings*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (print (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 "The version of Emacs that you are running, %s,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 has known bugs in its syntax.c parsing routines which will affect the
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
896 performance of CC Mode. You should strongly consider upgrading to the
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
897 latest available version. CC Mode may continue to work, after a
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 fashion, but strange indentation errors could be encountered."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 emacs-version))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 ;; Emacs 18, with no patch is not too good
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 (if (and (eq major 'v18) (eq comments 'no-dual-comments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (not c-inhibit-startup-warnings-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 (with-output-to-temp-buffer "*cc-mode warnings*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 (print (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 "The version of Emacs 18 you are running, %s,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 has known deficiencies in its ability to handle dual C++ comments,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 i.e. C++ line style comments and C block style comments. This will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 not be much of a problem for you if you are only editing C code, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 if you are doing much C++ editing, you should strongly consider
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 upgrading to one of the latest Emacs 19's. In Emacs 18, you may also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 experience performance degradations. Emacs 19 has some new built-in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 routines which will speed things up for you.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
914 Because of these inherent problems, CC Mode is no longer being
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 actively maintained for Emacs 18, however, until you can upgrade to
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
916 Emacs 19, you may want to look at cc-mode-18.el in the CC Mode
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 distribution. THIS FILE IS COMPLETELY UNSUPPORTED! If you use it,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 you are on your own, although patch contributions will be folded into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 the main release."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 emacs-version))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 ;; Emacs 18 with the syntax patches are no longer supported
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 (if (and (eq major 'v18) (not (eq comments 'no-dual-comments))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 (not c-inhibit-startup-warnings-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 (with-output-to-temp-buffer "*cc-mode warnings*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 (print (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 "You are running a syntax patched Emacs 18 variant. While this should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 work for you, you may want to consider upgrading to Emacs 19. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 syntax patches are no longer supported either for syntax.c or
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
929 CC Mode."))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
930 (if infodock-p
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
931 (list major comments re-suite 'infodock)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
932 (list major comments re-suite)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 "A list of features extant in the Emacs you are using.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 There are many flavors of Emacs out there, each with different
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
935 features supporting those needed by CC Mode. Here's the current
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 supported list, along with the values for this variable:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 Emacs 18/Epoch 4: (v18 no-dual-comments RS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 Emacs 18/Epoch 4 (patch2): (v18 8-bit RS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 XEmacs 19: (v19 8-bit RS)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
941 XEmacs 20: (v20 8-bit RS)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 Emacs 19: (v19 1-bit RS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 RS is the regular expression suite to use. XEmacs versions after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 19.13, and Emacs versions after 19.29 use the `new-re' regex suite.
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
946 All other Emacsen use the `old-re' suite.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
947
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
948 Infodock (based on XEmacs) has an additional symbol on this list:
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
949 'infodock")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 (defvar c++-mode-abbrev-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 "Abbrev table in use in c++-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (define-abbrev-table 'c++-mode-abbrev-table ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 (defvar c-mode-abbrev-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 "Abbrev table in use in c-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 (define-abbrev-table 'c-mode-abbrev-table ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 (defvar objc-mode-abbrev-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 "Abbrev table in use in objc-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 (define-abbrev-table 'objc-mode-abbrev-table ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 (defvar java-mode-abbrev-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 "Abbrev table in use in java-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 (define-abbrev-table 'java-mode-abbrev-table ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 (defun c-mode-fsf-menu (name map)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
968 ;; Add menu to a keymap, but don't add them for XEmacs. This
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
969 ;; feature test will fail on other than Emacs 19.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 (define-key map [menu-bar] (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 (define-key map [menu-bar c] (cons name (make-sparse-keymap name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 (define-key map [menu-bar c comment-region]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 '("Comment Out Region" . comment-region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (define-key map [menu-bar c c-macro-expand]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 '("Macro Expand Region" . c-macro-expand))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 (define-key map [menu-bar c c-backslash-region]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 '("Backslashify" . c-backslash-region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 (define-key map [menu-bar c indent-exp]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 '("Indent Expression" . c-indent-exp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 (define-key map [menu-bar c indent-line]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 '("Indent Line" . c-indent-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 (define-key map [menu-bar c fill]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 '("Fill Comment Paragraph" . c-fill-paragraph))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
987 (define-key map [menu-bar c separator2]
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
988 '("----"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 (define-key map [menu-bar c up]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 '("Up Conditional" . c-up-conditional))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 (define-key map [menu-bar c backward]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 '("Backward Conditional" . c-backward-conditional))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 (define-key map [menu-bar c forward]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 '("Forward Conditional" . c-forward-conditional))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 (define-key map [menu-bar c backward-stmt]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 '("Backward Statement" . c-beginning-of-statement))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 (define-key map [menu-bar c forward-stmt]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 '("Forward Statement" . c-end-of-statement))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1000 ;; RMS says: mouse-3 should not select this menu. mouse-3's
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1001 ;; global definition is useful in C mode and we should not
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1002 ;; interfere with that. The menu is mainly for beginners, and
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1003 ;; for them, the menubar requires less memory than a special
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1004 ;; click.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 (error nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 (defvar c-mode-map ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 "Keymap used in c-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 (if c-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 ;; TBD: should we even worry about naming this keymap. My vote: no,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 ;; because Emacs and XEmacs do it differently.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 (setq c-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 ;; put standard keybindings into MAP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 ;; the following mappings correspond more or less directly to BOCM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 (define-key c-mode-map "{" 'c-electric-brace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 (define-key c-mode-map "}" 'c-electric-brace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 (define-key c-mode-map ";" 'c-electric-semi&comma)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 (define-key c-mode-map "#" 'c-electric-pound)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 (define-key c-mode-map ":" 'c-electric-colon)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 ;; Lucid Emacs 19.9 defined these two, the second of which was
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 ;; commented out...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 ;; (define-key c-mode-map "\e{" 'c-insert-braces)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 ;; Commented out electric square brackets because nobody likes them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 ;; (define-key c-mode-map "[" 'c-insert-brackets)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1027 (define-key c-mode-map "\C-c\C-m" 'c-mark-function)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 (define-key c-mode-map "\e\C-q" 'c-indent-exp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 (define-key c-mode-map "\ea" 'c-beginning-of-statement)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 (define-key c-mode-map "\ee" 'c-end-of-statement)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 ;; Emacs 19.30 introduces fill-paragraph-function, but it's not in
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1032 ;; every version of Emacs CC Mode supports.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 (if (not (boundp 'fill-paragraph-function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 ;; I'd rather use an adaptive fill program instead of this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 (define-key c-mode-map "\eq" 'c-fill-paragraph))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 (define-key c-mode-map "\C-c\C-n" 'c-forward-conditional)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 (define-key c-mode-map "\C-c\C-p" 'c-backward-conditional)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 (define-key c-mode-map "\C-c\C-u" 'c-up-conditional)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 (define-key c-mode-map "\t" 'c-indent-command)
157
6b37e6ddd302 Import from CVS: tag r20-3b5
cvs
parents: 155
diff changeset
1040 (define-key c-mode-map 'delete 'c-electric-delete)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 ;; these are new keybindings, with no counterpart to BOCM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 (define-key c-mode-map "," 'c-electric-semi&comma)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 (define-key c-mode-map "*" 'c-electric-star)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 (define-key c-mode-map "\C-c\C-q" 'c-indent-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 (define-key c-mode-map "\C-c\C-\\" 'c-backslash-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 ;; TBD: where if anywhere, to put c-backward|forward-into-nomenclature
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 (define-key c-mode-map "\C-c\C-a" 'c-toggle-auto-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 (define-key c-mode-map "\C-c\C-b" 'c-submit-bug-report)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 (define-key c-mode-map "\C-c\C-c" 'comment-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 (define-key c-mode-map "\C-c\C-d" 'c-toggle-hungry-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 (define-key c-mode-map "\C-c\C-e" 'c-macro-expand)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 (define-key c-mode-map "\C-c\C-o" 'c-set-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 (define-key c-mode-map "\C-c\C-s" 'c-show-syntactic-information)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 (define-key c-mode-map "\C-c\C-t" 'c-toggle-auto-hungry-state)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1055 (define-key c-mode-map "\C-c." 'c-set-style)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 ;; conflicts with OOBR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 ;;(define-key c-mode-map "\C-c\C-v" 'c-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 ;;
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1059 (if (and
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1060 ;; Infodock has it's own menu
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1061 (not (memq 'infodock c-emacs-features))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1062 ;; Emacs 19 defines menus in the mode map. This call will
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1063 ;; return t on Emacs 19, otherwise no-op and return nil.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1064 (not (c-mode-fsf-menu "CC Mode" c-mode-map))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1065 ;; In XEmacs 19, we want the menu to popup when the 3rd button
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1066 ;; is hit. In Lucid Emacs 19.10 and beyond this is done
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1067 ;; automatically if we put the menu on mode-popup-menu
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1068 ;; variable, see c-common-init. Emacs 19 uses C-Mouse-3 for
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1069 ;; this, and it works with no special effort.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1070 (boundp 'current-menubar)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1071 (not (boundp 'mode-popup-menu)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 (define-key c-mode-map 'button3 'c-popup-menu)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 (defvar c++-mode-map ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 "Keymap used in c++-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 (if c++-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 ;; In Emacs 19, it makes more sense to inherit c-mode-map
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1079 (if (or
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1080 (memq 'v19 c-emacs-features)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1081 (memq 'v20 c-emacs-features))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 ;; XEmacs and Emacs 19 do this differently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 ;; XEmacs 19.13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 ((fboundp 'set-keymap-parents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 (setq c++-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 (set-keymap-parents c++-mode-map c-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 ((fboundp 'set-keymap-parent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 (setq c++-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 (set-keymap-parent c++-mode-map c-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 (t (setq c++-mode-map (cons 'keymap c-mode-map))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 ;; Do it the hard way for Emacs 18 -- given by JWZ
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 (setq c++-mode-map (nconc (make-sparse-keymap) c-mode-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 ;; add bindings which are only useful for C++
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 (define-key c++-mode-map "\C-c:" 'c-scope-operator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 (define-key c++-mode-map "/" 'c-electric-slash)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 (define-key c++-mode-map "<" 'c-electric-lt-gt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 (define-key c++-mode-map ">" 'c-electric-lt-gt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 ;; Emacs 19 defines menus in the mode map. This call will return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 ;; t on Emacs 19, otherwise no-op and return nil.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1101 ; (c-mode-fsf-menu "C++" c++-mode-map)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1102 )
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 (defvar objc-mode-map ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 "Keymap used in objc-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 (if objc-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 ;; In Emacs 19, it makes more sense to inherit c-mode-map
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1109 (if (or (memq 'v19 c-emacs-features) (memq 'v20 c-emacs-features))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 ;; XEmacs and Emacs 19 do this differently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 ;; XEmacs 19.13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 ((fboundp 'set-keymap-parents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 (setq objc-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 (set-keymap-parents objc-mode-map c-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 ((fboundp 'set-keymap-parent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 (setq objc-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 (set-keymap-parent objc-mode-map c-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 (t (setq objc-mode-map (cons 'keymap c-mode-map))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 ;; Do it the hard way for Emacs 18 -- given by JWZ
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 (setq objc-mode-map (nconc (make-sparse-keymap) c-mode-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 ;; add bindings which are only useful for Objective-C
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 (define-key objc-mode-map "/" 'c-electric-slash)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 ;; Emacs 19 defines menus in the mode map. This call will return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 ;; t on Emacs 19, otherwise no-op and return nil.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1126 ; (c-mode-fsf-menu "ObjC" objc-mode-map)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1127 )
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 (defvar java-mode-map ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 "Keymap used in java-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 (if java-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 ;; In Emacs 19, it makes more sense to inherit c-mode-map
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1134 (if (or (memq 'v19 c-emacs-features) (memq 'v20 c-emacs-features))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 ;; XEmacs and Emacs 19 do this differently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 ;; XEmacs 19.13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 ((fboundp 'set-keymap-parents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 (setq java-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 (set-keymap-parents java-mode-map c-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 ((fboundp 'set-keymap-parent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 (setq java-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 (set-keymap-parent java-mode-map c-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 (t (setq java-mode-map (cons 'keymap c-mode-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 ;; Do it the hard way for Emacs 18 -- given by JWZ
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 (setq java-mode-map (nconc (make-sparse-keymap) c-mode-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 ;; add bindings which are only useful for Java
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (define-key java-mode-map "/" 'c-electric-slash)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 ;; Emacs 19 defines menus in the mode map. This call will return t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 ;; on Emacs 19, otherwise no-op and return nil.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1152 ; (c-mode-fsf-menu "Java" java-mode-map)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
1153 )
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 (defun c-populate-syntax-table (table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 ;; Populate the syntax TABLE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 ;; DO NOT TRY TO SET _ (UNDERSCORE) TO WORD CLASS!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 (modify-syntax-entry ?_ "_" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 (modify-syntax-entry ?\\ "\\" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 (modify-syntax-entry ?+ "." table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 (modify-syntax-entry ?- "." table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 (modify-syntax-entry ?= "." table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 (modify-syntax-entry ?% "." table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 (modify-syntax-entry ?< "." table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 (modify-syntax-entry ?> "." table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 (modify-syntax-entry ?& "." table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 (modify-syntax-entry ?| "." table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 (modify-syntax-entry ?\' "\"" table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 (defun c-setup-dual-comments (table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 ;; Set up TABLE to handle block and line style comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 ((memq '8-bit c-emacs-features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 ;; XEmacs 19 has the best implementation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 (modify-syntax-entry ?/ ". 1456" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 (modify-syntax-entry ?* ". 23" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 (modify-syntax-entry ?\n "> b" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 ;; Give CR the same syntax as newline, for selective-display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 (modify-syntax-entry ?\^m "> b" table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 ((memq '1-bit c-emacs-features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 ;; Emacs 19 does things differently, but we can work with it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 (modify-syntax-entry ?/ ". 124b" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 (modify-syntax-entry ?* ". 23" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 (modify-syntax-entry ?\n "> b" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 ;; Give CR the same syntax as newline, for selective-display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 (modify-syntax-entry ?\^m "> b" table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 (defvar c-mode-syntax-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 "Syntax table used in c-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 (if c-mode-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 (setq c-mode-syntax-table (make-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 (c-populate-syntax-table c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 ;; add extra comment syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 (modify-syntax-entry ?/ ". 14" c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 (modify-syntax-entry ?* ". 23" c-mode-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 (defvar c++-mode-syntax-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 "Syntax table used in c++-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 (if c++-mode-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 (setq c++-mode-syntax-table (make-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 (c-populate-syntax-table c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 ;; add extra comment syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 (c-setup-dual-comments c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 ;; TBD: does it make sense for colon to be symbol class in C++?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 ;; I'm not so sure, since c-label-key is busted on lines like:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 ;; Foo::bar( i );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 ;; maybe c-label-key should be fixed instead of commenting this out,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 ;; but it also bothers me that this only seems appropriate for C++
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 ;; and not C.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 ;;(modify-syntax-entry ?: "_" c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 (defvar objc-mode-syntax-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 "Syntax table used in objc-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 (if objc-mode-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 (setq objc-mode-syntax-table (make-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 (c-populate-syntax-table objc-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 ;; add extra comment syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 (c-setup-dual-comments objc-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 ;; everyone gets these
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 (modify-syntax-entry ?@ "_" objc-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 (defvar java-mode-syntax-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 "Syntax table used in java-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 (if java-mode-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 (setq java-mode-syntax-table (make-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 (c-populate-syntax-table java-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 ;; add extra comment syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 (c-setup-dual-comments java-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 ;; everyone gets these
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 (modify-syntax-entry ?@ "_" java-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 (defvar c-hungry-delete-key nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 "Internal state of hungry delete key feature.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 (defvar c-auto-newline nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 "Internal state of auto newline feature.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 (defvar c-auto-hungry-string nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 "Internal auto-newline/hungry-delete designation string for mode line.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 (defvar c-syntactic-context nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 "Variable containing syntactic analysis list during indentation.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 (defvar c-comment-start-regexp nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 "Buffer local variable describing how comment are introduced.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 (defvar c-conditional-key nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 "Buffer local language-specific conditional keyword regexp.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 (defvar c-access-key nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 "Buffer local language-specific access key regexp.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 (defvar c-class-key nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 "Buffer local language-specific class key regexp.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 (defvar c-method-key nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 "Buffer local language-specific method regexp.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 (defvar c-double-slash-is-comments-p nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 "Buffer local language-specific comment style flag.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 (defconst c-protection-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 "\\<\\(public\\|protected\\|private\\)\\>"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 "Regexp describing protection keywords.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 (defconst c-symbol-key "\\(\\w\\|\\s_\\)+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 "Regexp describing a C/C++/ObjC symbol.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 We cannot use just `word' syntax class since `_' cannot be in word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 class. Putting underscore in word class breaks forward word movement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 behavior that users are familiar with.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 (defconst c-baseclass-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 ":?[ \t]*\\(virtual[ \t]+\\)?\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 c-protection-key "[ \t]+\\)" c-symbol-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 "Regexp describing C++ base classes in a derived class definition.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1274 ;; defconst'd instead of defvar'd to override any old pre-loaded versions
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1275 (defconst c-recognize-knr-p t
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1276 "Non-nil means K&R style argument declarations are valid.")
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1277 (defvar c-indentation-style c-site-default-style
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1278 "Name of style installed in the current buffer.")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1279
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1280 ;; these variables should always be buffer local. they do not affect
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1281 ;; indentation styles.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1282 ;;
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 ;; minor mode variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 (make-variable-buffer-local 'c-auto-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 (make-variable-buffer-local 'c-hungry-delete-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 (make-variable-buffer-local 'c-auto-hungry-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 ;; language differences
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 (make-variable-buffer-local 'c-comment-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 (make-variable-buffer-local 'c-conditional-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 (make-variable-buffer-local 'c-access-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 (make-variable-buffer-local 'c-class-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 (make-variable-buffer-local 'c-method-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 (make-variable-buffer-local 'c-double-slash-is-comments-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 (make-variable-buffer-local 'c-baseclass-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 (make-variable-buffer-local 'c-recognize-knr-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 ;; style variables are made buffer local at tail end of this file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 ;; cmacexp is lame because it uses no preprocessor symbols.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 ;; It isn't very extensible either -- hardcodes /lib/cpp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 ;; [I add it here only because c-mode has it -- BAW]
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1301 (autoload 'c-macro-expand "cmacexp"
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1302 "Display the result of expanding all C macros occurring in the region.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1303 The expansion is entirely correct because it uses the C preprocessor."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1304 t)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 ;; constant regular expressions for looking at various constructs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 (defconst c-C++-class-key "\\(class\\|struct\\|union\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 "Regexp describing a C++ class declaration, including templates.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 (defconst c-C-class-key "\\(struct\\|union\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 "Regexp describing a C struct declaration.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 (defconst c-inher-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 (concat "\\(\\<static\\>\\s +\\)?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 c-C++-class-key "[ \t]+" c-symbol-key
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
1315 "\\([ \t]*:[ \t]*\\)\\s *[^;]")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 "Regexp describing a class inheritance declaration.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 (defconst c-switch-label-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 "\\(\\(case[( \t]+\\S .*\\)\\|default[ \t]*\\):"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 "Regexp describing a switch's case or default label")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 (defconst c-C++-access-key
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1321 (concat c-protection-key "[ \t]*:")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 "Regexp describing C++ access specification keywords.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 (defconst c-label-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 (concat c-symbol-key ":\\([^:]\\|$\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 "Regexp describing any label.")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1326 (defconst c-C-conditionals '("for" "if" "do" "else" "while" "switch")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1327 "Shared conditional keywords for C-like languages.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 (defconst c-C-conditional-key
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1329 (concat "\\b\\("
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1330 (mapconcat 'identity c-C-conditionals "\\|")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1331 "\\)\\b[^_]")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1332 "Regexp describing a conditional control for C.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 (defconst c-C++-conditional-key
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1334 (concat "\\b\\(" (mapconcat 'identity
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1335 (append '("try" "catch") c-C-conditionals) "\\|")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1336 "\\)\\b[^_]")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 "Regexp describing a conditional control for C++.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 (defconst c-C++-friend-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 "friend[ \t]+\\|template[ \t]*<.+>[ \t]*friend[ \t]+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 "Regexp describing friend declarations in C++ classes.")
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
1341
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
1342 ;; comment starter definitions for various languages. the language
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
1343 ;; modes will set c-comment-start-regexp to this value.
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
1344 (defconst c-C++-comment-start-regexp "/[/*]")
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
1345 (defconst c-C-comment-start-regexp "/[*]")
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
1346 ;; We need to match all 3 Java style comments
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
1347 ;; 1) Traditional C block; 2) javadoc /** ...; 3) C++ style
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
1348 (defconst c-Java-comment-start-regexp "/\\(/\\|[*][*]?\\)")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 (defconst c-ObjC-method-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 "^\\s *[+-]\\s *"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 "\\(([^)]*)\\)?" ; return type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 ;; \\s- in objc syntax table does not include \n
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 ;; since it is considered the end of //-comments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 "[ \t\n]*" c-symbol-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 "Regexp describing an Objective-C method intro.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 (defconst c-ObjC-access-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 (concat "@" c-protection-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 "Regexp describing access specification keywords for Objective-C.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 (defconst c-ObjC-class-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 "@\\(interface\\|implementation\\)\\s +"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 c-symbol-key ;name of the class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 "\\(\\s *:\\s *" c-symbol-key "\\)?" ;maybe followed by the superclass
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 "\\(\\s *<[^>]+>\\)?" ;and maybe the adopted protocols list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 "Regexp describing a class or protocol declaration for Objective-C.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 (defconst c-Java-method-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 "^\\s *[+-]\\s *"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 "\\(([^)]*)\\)?" ; return type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 ;; \\s- in java syntax table does not include \n
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 ;; since it is considered the end of //-comments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 "[ \t\n]*" c-symbol-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 "Regexp describing a Java method intro.")
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1378 (defconst c-Java-access-key nil
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1379 "Regexp describing access labels for Java.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 (defconst c-Java-class-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 (concat
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1382 "\\(" c-protection-key "\\s +\\)?"
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 "\\(interface\\|class\\)\\s +"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 c-symbol-key ;name of the class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 "\\(\\s *extends\\s *" c-symbol-key "\\)?" ;maybe followed by superclass
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 ;;"\\(\\s *implements *[^{]+{\\)?" ;and maybe the adopted protocols list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 "Regexp describing a class or protocol declaration for Java.")
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1389 (defconst c-Java-special-key "\\(implements\\|extends\\|throws\\)[^_]"
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1390 "Regexp describing Java inheritance and throws clauses.")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1391 (defconst c-Java-conditional-key
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1392 (concat "\\b\\("
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1393 (mapconcat 'identity
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1394 (append '("try" "catch" "finally" "synchronized")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1395 c-C-conditionals) "\\|")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1396 "\\)\\b[^_]")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1397 "Regexp describing a conditional control for Java.")
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1398 (defconst c-Java-defun-prompt-regexp
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1399 "^[ \t]*\\(\\(\\(public\\|protected\\|private\\|const\\|abstract\\|synchronized\\|final\\|static\\|threadsafe\\|transient\\|native\\|volatile\\)\\s-+\\)*\\(\\(\\([[a-zA-Z][][_$.a-zA-Z0-9]*[][_$.a-zA-Z0-9]+\\|[[a-zA-Z]\\)\\s-*\\)\\s-+\\)\\)?\\(\\([[a-zA-Z][][_$.a-zA-Z0-9]*\\s-+\\)\\s-*\\)?\\([_a-zA-Z][^][ \t:;.,{}()=]*\\|\\([_$a-zA-Z][_$.a-zA-Z0-9]*\\)\\)\\s-*\\(([^);{}]*)\\)?\\([] \t]*\\)\\(\\s-*\\<throws\\>\\s-*\\(\\([_$a-zA-Z][_$.a-zA-Z0-9]*\\)[, \t\n\r\f]*\\)+\\)?\\s-*"
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1400 "Regexp describing the beginning of a Java top-level definition.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 ;; KLUDGE ALERT. We default these variables to their `C' values so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 ;; that non-cc-mode-ized modes that depend on c-mode will still work
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 ;; out of the box. The most glaring example is awk-mode. There ought
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 ;; to be a better way.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 (setq-default c-conditional-key c-C-conditional-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 c-class-key c-C-class-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 c-comment-start-regexp c-C-comment-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 ;; main entry points for the modes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 (defconst c-list-of-mode-names nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
1414 ;;;###autoload
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 (defun c-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 "Major mode for editing K&R and ANSI C code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 To submit a problem report, enter `\\[c-submit-bug-report]' from a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 c-mode buffer. This automatically sets up a mail buffer with version
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 information already added. You just need to add a description of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 problem, including a reproducible test case and send the message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1422 To see what version of CC Mode you are running, enter `\\[c-version]'.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 The hook variable `c-mode-hook' is run with no args, if that value is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 bound and has a non-nil value. Also the hook `c-mode-common-hook' is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 run first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 Key bindings:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 \\{c-mode-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 (set-syntax-table c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 (setq major-mode 'c-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 mode-name "C"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 local-abbrev-table c-mode-abbrev-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 (use-local-map c-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 (c-common-init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 (setq comment-start "/* "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 comment-end " */"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 comment-multi-line t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 c-conditional-key c-C-conditional-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 c-class-key c-C-class-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 c-baseclass-key nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 c-comment-start-regexp c-C-comment-start-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 imenu-generic-expression cc-imenu-c-generic-expression)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 (run-hooks 'c-mode-common-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 (run-hooks 'c-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 (setq c-list-of-mode-names (cons "C" c-list-of-mode-names))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
1450 ;;;###autoload
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 (defun c++-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 "Major mode for editing C++ code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 To submit a problem report, enter `\\[c-submit-bug-report]' from a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 c++-mode buffer. This automatically sets up a mail buffer with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 version information already added. You just need to add a description
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 of the problem, including a reproducible test case, and send the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1459 To see what version of CC Mode you are running, enter `\\[c-version]'.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 The hook variable `c++-mode-hook' is run with no args, if that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 variable is bound and has a non-nil value. Also the hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 `c-mode-common-hook' is run first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 Key bindings:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 \\{c++-mode-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 (set-syntax-table c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 (setq major-mode 'c++-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 mode-name "C++"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 local-abbrev-table c++-mode-abbrev-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 (use-local-map c++-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 (c-common-init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 (setq comment-start "// "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 comment-end ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 comment-multi-line nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 c-conditional-key c-C++-conditional-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 c-comment-start-regexp c-C++-comment-start-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 c-class-key c-C++-class-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 c-access-key c-C++-access-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 c-double-slash-is-comments-p t
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1483 c-recognize-knr-p nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 imenu-generic-expression cc-imenu-c++-generic-expression)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 (run-hooks 'c-mode-common-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 (run-hooks 'c++-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 (setq c-list-of-mode-names (cons "C++" c-list-of-mode-names))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
1489 ;;;###autoload
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 (defun objc-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 "Major mode for editing Objective C code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 To submit a problem report, enter `\\[c-submit-bug-report]' from an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 objc-mode buffer. This automatically sets up a mail buffer with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 version information already added. You just need to add a description
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 of the problem, including a reproducible test case, and send the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1498 To see what version of CC Mode you are running, enter `\\[c-version]'.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 The hook variable `objc-mode-hook' is run with no args, if that value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 is bound and has a non-nil value. Also the hook `c-mode-common-hook'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 is run first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 Key bindings:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 \\{objc-mode-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 (set-syntax-table objc-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 (setq major-mode 'objc-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 mode-name "ObjC"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 local-abbrev-table objc-mode-abbrev-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 (use-local-map objc-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 (c-common-init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 (setq comment-start "// "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 comment-end ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 comment-multi-line nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 c-conditional-key c-C-conditional-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 c-comment-start-regexp c-C++-comment-start-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 c-class-key c-ObjC-class-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 c-baseclass-key nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 c-access-key c-ObjC-access-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 c-double-slash-is-comments-p t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 c-method-key c-ObjC-method-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 (run-hooks 'c-mode-common-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 (run-hooks 'objc-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 (setq c-list-of-mode-names (cons "ObjC" c-list-of-mode-names))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
1528 ;;;###autoload
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 (defun java-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 "Major mode for editing Java code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 To submit a problem report, enter `\\[c-submit-bug-report]' from an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 java-mode buffer. This automatically sets up a mail buffer with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 version information already added. You just need to add a description
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 of the problem, including a reproducible test case and send the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1537 To see what version of CC Mode you are running, enter `\\[c-version]'.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 The hook variable `java-mode-hook' is run with no args, if that value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540 is bound and has a non-nil value. Also the common hook
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1541 `c-mode-common-hook' is run first. Note that this mode automatically
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1542 sets the \"java\" style before calling any hooks so be careful if you
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1543 set styles in `c-mode-common-hook'.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545 Key bindings:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 \\{java-mode-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 (set-syntax-table java-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 (setq major-mode 'java-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 mode-name "Java"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 local-abbrev-table java-mode-abbrev-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 (use-local-map java-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 (c-common-init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 (setq comment-start "// "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 comment-end ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 comment-multi-line nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 c-conditional-key c-Java-conditional-key
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
1559 c-comment-start-regexp c-Java-comment-start-regexp
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 c-class-key c-Java-class-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 c-method-key c-Java-method-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 c-double-slash-is-comments-p t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 c-baseclass-key nil
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1564 c-recognize-knr-p nil
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1565 c-access-key c-Java-access-key
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1566 ;defun-prompt-regexp c-Java-defun-prompt-regexp
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1567 imenu-generic-expression cc-imenu-java-generic-expression
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1568 )
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1569 (c-set-style "java")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 (run-hooks 'c-mode-common-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 (run-hooks 'java-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 (setq c-list-of-mode-names (cons "Java" c-list-of-mode-names))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1574 (defun c-use-java-style ()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1575 "Institutes `java' indentation style.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1576 For use with the variable `java-mode-hook'."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1577 (c-set-style "java"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1578
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 (defun c-common-init ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 ;; Common initializations for c++-mode and c-mode.
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1581 ;;
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1582 ;; these variables should always be buffer local; they do not affect
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1583 ;; indentation style.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 (make-local-variable 'paragraph-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 (make-local-variable 'paragraph-separate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 (make-local-variable 'paragraph-ignore-fill-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 (make-local-variable 'require-final-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 (make-local-variable 'parse-sexp-ignore-comments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 (make-local-variable 'indent-line-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 (make-local-variable 'indent-region-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 (make-local-variable 'comment-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 (make-local-variable 'comment-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 (make-local-variable 'comment-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 (make-local-variable 'comment-start-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 (make-local-variable 'comment-multi-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 (make-local-variable 'outline-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 (make-local-variable 'outline-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 (make-local-variable 'adaptive-fill-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 (make-local-variable 'imenu-generic-expression) ;set in the mode functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 ;; Emacs 19.30 and beyond only, AFAIK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 (if (boundp 'fill-paragraph-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 (make-local-variable 'fill-paragraph-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 (setq fill-paragraph-function 'c-fill-paragraph)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 ;; now set their values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 (setq paragraph-start (if (memq 'new-re c-emacs-features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 (concat page-delimiter "\\|$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 (concat "^$\\|" page-delimiter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 paragraph-separate paragraph-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 paragraph-ignore-fill-prefix t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 require-final-newline t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 parse-sexp-ignore-comments t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 indent-line-function 'c-indent-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 indent-region-function 'c-indent-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 outline-regexp "[^#\n\^M]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 outline-level 'c-outline-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 comment-column 32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 comment-start-skip "/\\*+ *\\|// *"
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1619 ;; For all but XEmacs 19.13, the default should be nil
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1620 adaptive-fill-regexp (and (memq 'v19 c-emacs-features)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1621 (= emacs-minor-version 13)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1622 "[ \t]*\\([#;>*]+ +\\)?")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1623 )
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 ;; we have to do something special for c-offsets-alist so that the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 ;; buffer local value has its own alist structure.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 (setq c-offsets-alist (copy-alist c-offsets-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 ;; setup the comment indent variable in a Emacs version portable way
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 ;; ignore any byte compiler warnings you might get here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 (if (boundp 'comment-indent-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 (make-local-variable 'comment-indent-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 (setq comment-indent-function 'c-comment-indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 (make-local-variable 'comment-indent-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 (setq comment-indent-hook 'c-comment-indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 ;; Put C menu into menubar and on popup menu for XEmacs 19. I think
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1636 ;; this happens automatically for Emacs 19. Skip it for Infodock.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1637 (if (and (not (memq 'infodock c-emacs-features))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1638 (boundp 'current-menubar)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 current-menubar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 (not (assoc mode-name current-menubar)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 ;; its possible that this buffer has changed modes from one of
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1642 ;; the other CC Mode modes. In that case, only the menubar
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 ;; title of the menu changes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 (let ((modes (copy-sequence c-list-of-mode-names))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 changed-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 (setq modes (delete major-mode modes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 (while modes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 (if (not (assoc (car modes) current-menubar))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 (setq modes (cdr modes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 (relabel-menu-item (list (car modes)) mode-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 (setq modes nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 changed-p t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 (if (not changed-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 (set-buffer-menubar (copy-sequence current-menubar))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1656 (if (fboundp 'add-submenu)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1657 (add-submenu nil (c-mode-menu))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1658 (add-menu nil mode-name c-mode-menu)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1659 )))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 (if (boundp 'mode-popup-menu)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1661 (setq mode-popup-menu (c-mode-menu)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 ;; put auto-hungry designators onto minor-mode-alist, but only once
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 (or (assq 'c-auto-hungry-string minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 (setq minor-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 (cons '(c-auto-hungry-string c-auto-hungry-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 minor-mode-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 (defun c-postprocess-file-styles ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 "Function that post processes relevant file local variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 Currently, this function simply applies any style and offset settings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 found in the file's Local Variable list. It first applies any style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 setting found in `c-file-style', then it applies any offset settings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 it finds in `c-file-offsets'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 ;; apply file styles and offsets
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 (and c-file-style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 (c-set-style c-file-style))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 (and c-file-offsets
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 (lambda (langentry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 (let ((langelem (car langentry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 (offset (cdr langentry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 (c-set-offset langelem offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 c-file-offsets)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687 ;; Add the postprocessing function to hack-local-variables-hook. As
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688 ;; of 28-Aug-1995, XEmacs 19.12 and Emacs 19.29 support this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 (and (fboundp 'add-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 (add-hook 'hack-local-variables-hook 'c-postprocess-file-styles))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 (defun c-enable-//-in-c-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 "Enables // as a comment delimiter in `c-mode'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694 ANSI C currently does *not* allow this, although many C compilers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695 support optional C++ style comments. To use, call this function from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696 your `.emacs' file before you visit any C files. The changes are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697 global and affect all future `c-mode' buffers."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698 (c-setup-dual-comments c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 (setq-default c-C-comment-start-regexp c-C++-comment-start-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1700
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 ;; macros must be defined before first use
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
1703 (defmacro c-add-syntax (symbol &optional relpos)
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
1704 ;; a simple macro to append the syntax in symbol to the syntax list.
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
1705 ;; try to increase performance by using this macro
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
1706 (` (setq syntax (cons (cons (, symbol) (, relpos)) syntax))))
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
1707
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 (defmacro c-point (position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709 ;; Returns the value of point at certain commonly referenced POSITIONs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710 ;; POSITION can be one of the following symbols:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712 ;; bol -- beginning of line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 ;; eol -- end of line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 ;; bod -- beginning of defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715 ;; boi -- back to indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716 ;; ionl -- indentation of next line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 ;; iopl -- indentation of previous line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1718 ;; bonl -- beginning of next line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719 ;; bopl -- beginning of previous line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 ;; This function does not modify point or mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722 (or (and (eq 'quote (car-safe position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 (null (cdr (cdr position))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 (error "bad buffer position requested: %s" position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 (setq position (nth 1 position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 (` (let ((here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727 (,@ (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728 ((eq position 'bol) '((beginning-of-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729 ((eq position 'eol) '((end-of-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 ((eq position 'bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 '((beginning-of-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 ;; if defun-prompt-regexp is non-nil, b-o-d won't leave
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733 ;; us at the open brace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 (and (boundp 'defun-prompt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735 defun-prompt-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736 (looking-at defun-prompt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737 (goto-char (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 ((eq position 'boi) '((back-to-indentation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740 ((eq position 'bonl) '((forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741 ((eq position 'bopl) '((forward-line -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742 ((eq position 'iopl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 '((forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 (back-to-indentation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 ((eq position 'ionl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 '((forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747 (back-to-indentation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 (t (error "unknown buffer position requested: %s" position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752 (goto-char here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 ;; workaround for an Emacs18 bug -- blech! Well, at least it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 ;; doesn't hurt for v19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 (,@ nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758 (defmacro c-auto-newline ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759 ;; if auto-newline feature is turned on, insert a newline character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 ;; and return t, otherwise return nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 (` (and c-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762 (not (c-in-literal))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763 (not (newline)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765 (defmacro c-safe (&rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 ;; safely execute BODY, return nil if an error occurred
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 (` (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768 (progn (,@ body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 (error nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 (defun c-insert-special-chars (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 ;; simply call self-insert-command in Emacs 19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 (self-insert-command (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775 (defun c-intersect-lists (list alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776 ;; return the element of ALIST that matches the first element found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 ;; in LIST. Uses assq.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 (let (match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 (while (and list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780 (not (setq match (assq (car list) alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781 (setq list (cdr list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782 match))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784 (defun c-lookup-lists (list alist1 alist2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 ;; first, find the first entry from LIST that is present in ALIST1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786 ;; then find the entry in ALIST2 for that entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787 (assq (car (c-intersect-lists list alist1)) alist2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 ;; This is used by indent-for-comment to decide how much to indent a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 ;; comment in C code based on its context.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792 (defun c-comment-indent ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 (if (looking-at (concat "^\\(" c-comment-start-regexp "\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 0 ;Existing comment at bol stays there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 (let ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 ;; CASE 1: A comment following a solitary close-brace should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 ;; have only one space.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802 ((looking-at (concat "[ \t]*}[ \t]*\\($\\|"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 c-comment-start-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 "\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 (search-forward "}")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 (1+ (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 ;; CASE 2: 2 spaces after #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 ((or (looking-at "^#[ \t]*endif[ \t]*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 (looking-at "^#[ \t]*else[ \t]*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810 7)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811 ;; CASE 3: when comment-column is nil, calculate the offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 ;; according to c-offsets-alist. E.g. identical to hitting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813 ;; TAB.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 ((and c-indent-comments-syntactically-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817 (or (looking-at comment-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 (eolp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819 (let ((syntax (c-guess-basic-syntax)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 ;; BOGOSITY ALERT: if we're looking at the eol, its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821 ;; because indent-for-comment hasn't put the comment-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 ;; in the buffer yet. this will screw up the syntactic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 ;; analysis so we kludge in the necessary info. Another
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824 ;; kludge is that if we're at the bol, then we really want
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825 ;; to ignore any anchoring as specified by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 ;; c-comment-only-line-offset since it doesn't apply here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 (eolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831 (c-add-syntax 'comment-intro))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 (let ((c-comment-only-line-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833 (if (consp c-comment-only-line-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834 c-comment-only-line-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835 (cons c-comment-only-line-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 c-comment-only-line-offset))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837 (apply '+ (mapcar 'c-get-offset syntax)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838 ;; CASE 4: use comment-column if previous line is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839 ;; comment-only line indented to the left of comment-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842 (and (not (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843 (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846 (looking-at c-comment-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847 (setq placeholder (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848 (goto-char placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 (if (< (current-column) comment-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 comment-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 ;; CASE 5: If comment-column is 0, and nothing but space
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 ;; before the comment, align it at 0 rather than 1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 ((progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 (and (= comment-column 0) (bolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 ;; CASE 6: indent at comment column except leave at least one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860 ;; space.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 (t (max (1+ (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862 comment-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 ;; used by outline-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866 (defun c-outline-level ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 (skip-chars-forward "\t ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 ;; active regions, and auto-newline/hungry delete key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872 (defun c-keep-region-active ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873 ;; Do whatever is necessary to keep the region active in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 ;; XEmacs 19. ignore byte-compiler warnings you might see
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875 (and (boundp 'zmacs-region-stays)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 (setq zmacs-region-stays t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 (defun c-update-modeline ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879 ;; set the c-auto-hungry-string for the correct designation on the modeline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 (setq c-auto-hungry-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881 (if c-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 (if c-hungry-delete-key "/ah" "/a")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 (if c-hungry-delete-key "/h" nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 ;; updates the modeline for all Emacsen
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
1885 (if (or (memq 'v19 c-emacs-features) (memq 'v20 c-emacs-features))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1886 (if (boundp 'redraw-modeline)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1887 (redraw-modeline)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
1888 (force-mode-line-update))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 (set-buffer-modified-p (buffer-modified-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 (defun c-calculate-state (arg prevstate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 ;; Calculate the new state of PREVSTATE, t or nil, based on arg. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893 ;; arg is nil or zero, toggle the state. If arg is negative, turn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 ;; the state off, and if arg is positive, turn the state on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895 (if (or (not arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896 (zerop (setq arg (prefix-numeric-value arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 (not prevstate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 (> arg 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900 (defun c-toggle-auto-state (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901 "Toggle auto-newline feature.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 Optional numeric ARG, if supplied turns on auto-newline when positive,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903 turns it off when negative, and just toggles it when zero.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 When the auto-newline feature is enabled (as evidenced by the `/a' or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906 `/ah' on the modeline after the mode name) newlines are automatically
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907 inserted after special characters such as brace, comma, semi-colon,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908 and colon."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 (setq c-auto-newline (c-calculate-state arg c-auto-newline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911 (c-update-modeline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 (defun c-toggle-hungry-state (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915 "Toggle hungry-delete-key feature.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 Optional numeric ARG, if supplied turns on hungry-delete when positive,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 turns it off when negative, and just toggles it when zero.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919 When the hungry-delete-key feature is enabled (as evidenced by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920 `/h' or `/ah' on the modeline after the mode name) the delete key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921 gobbles all preceding whitespace in one fell swoop."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923 (setq c-hungry-delete-key (c-calculate-state arg c-hungry-delete-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924 (c-update-modeline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927 (defun c-toggle-auto-hungry-state (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 "Toggle auto-newline and hungry-delete-key features.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 Optional numeric ARG, if supplied turns on auto-newline and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 hungry-delete when positive, turns them off when negative, and just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 toggles them when zero.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 See `c-toggle-auto-state' and `c-toggle-hungry-state' for details."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935 (setq c-auto-newline (c-calculate-state arg c-auto-newline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936 (setq c-hungry-delete-key (c-calculate-state arg c-hungry-delete-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 (c-update-modeline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 ;; COMMANDS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 (defun c-electric-delete (arg)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1943 "Deletes preceding or following character or whitespace.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 If `c-hungry-delete-key' is non-nil, as evidenced by the \"/h\" or
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1945 \"/ah\" string on the mode line, then all preceding or following
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1946 whitespace is consumed. If however an ARG is supplied, or
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1947 `c-hungry-delete-key' is nil, or point is inside a literal then the
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1948 function in the variable `c-delete-function' is called."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 (if (or (not c-hungry-delete-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951 arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 (c-in-literal))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953 (funcall c-delete-function (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954 (let ((here (point)))
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1955 (if (and (boundp 'delete-erases-forward)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1956 delete-erases-forward)
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1957 (skip-chars-forward " \t\n")
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1958 (skip-chars-backward " \t\n"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 (if (/= (point) here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 (delete-region (point) here)
155
43dd3413c7c7 Import from CVS: tag r20-3b4
cvs
parents: 153
diff changeset
1961 (funcall c-delete-function 1)))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 (defun c-electric-pound (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964 "Electric pound (`#') insertion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965 Inserts a `#' character specially depending on the variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966 `c-electric-pound-behavior'. If a numeric ARG is supplied, or if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 point is inside a literal, nothing special happens."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 (if (or (c-in-literal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970 arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971 (not (memq 'alignleft c-electric-pound-behavior)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972 ;; do nothing special
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973 (self-insert-command (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 ;; place the pound character at the left edge
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 (let ((pos (- (point-max) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 (bolp (bolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 (insert-char last-command-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 (and (not bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 (goto-char (- (point-max) pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 (defun c-electric-brace (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985 "Insert a brace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987 If the auto-newline feature is turned on, as evidenced by the \"/a\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 or \"/ah\" string on the mode line, newlines are inserted before and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989 after braces based on the value of `c-hanging-braces-alist'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 Also, the line is re-indented unless a numeric ARG is supplied, there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 are non-whitespace characters present on the line after the brace, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993 the brace is inserted inside a literal."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 (let* ((c-state-cache (c-parse-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 (safepos (c-safe-position (point) c-state-cache))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 (literal (c-in-literal safepos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 ;; if we're in a literal, or we're not at the end of the line, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 ;; a numeric arg is provided, or auto-newlining is turned off,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 ;; then just insert the character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 (if (or literal arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 ; (not c-auto-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 (not (looking-at "[ \t]*$")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 (c-insert-special-chars arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005 (let* ((syms '(class-open class-close defun-open defun-close
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006 inline-open inline-close brace-list-open brace-list-close
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007 brace-list-intro brace-list-entry block-open block-close
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2008 substatement-open statement-case-open
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2009 extern-lang-open extern-lang-close))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010 ;; we want to inhibit blinking the paren since this will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2011 ;; be most disruptive. we'll blink it ourselves later on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012 (old-blink-paren (if (boundp 'blink-paren-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013 blink-paren-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 blink-paren-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 blink-paren-function ; emacs19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016 blink-paren-hook ; emacs18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 (insertion-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 delete-temp-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 (preserve-p (= 32 (char-syntax (preceding-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 ;; shut this up too
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021 (c-echo-syntactic-information-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 (syntax (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 ;; only insert a newline if there is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 ;; non-whitespace behind us
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 (not (bolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028 (progn (newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029 (setq delete-temp-newline t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030 (self-insert-command (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031 ;; state cache doesn't change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032 (c-guess-basic-syntax)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033 (newlines (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034 c-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035 (or (c-lookup-lists syms syntax c-hanging-braces-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2036 '(ignore before after)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037 ;; If syntax is a function symbol, then call it using the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038 ;; defined semantics.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039 (if (and (not (consp (cdr newlines)))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2040 (c-functionp (cdr newlines)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041 (let ((c-syntactic-context syntax))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042 (setq newlines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 (funcall (cdr newlines) (car newlines) insertion-point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044 ;; does a newline go before the open brace?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045 (if (memq 'before newlines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 ;; we leave the newline we've put in there before,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047 ;; but we need to re-indent the line above
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 (let ((pos (- (point-max) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 (here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 (c-state-cache c-state-cache))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 ;; we may need to update the cache. this should still be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053 ;; faster than recalculating the state in many cases
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056 (narrow-to-region here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 (if (and (c-safe (progn (backward-up-list -1) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058 (memq (preceding-char) '(?\) ?}))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 (progn (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 (c-safe (progn (forward-sexp -1) t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061 (setq c-state-cache
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 (c-hack-state (point) 'open c-state-cache))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 (if (and (car c-state-cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 (not (consp (car c-state-cache)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065 (<= (point) (car c-state-cache)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2066 (setq c-state-cache (cdr c-state-cache))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068 (let ((here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 (shift (c-indent-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 (setq c-state-cache (c-adjust-state (c-point 'bol) here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 (- shift) c-state-cache)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 (goto-char (- (point-max) pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073 ;; if the buffer has changed due to the indentation, we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 ;; need to recalculate syntax for the current line, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075 ;; we won't need to update the state cache.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 (if (/= (point) here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 (setq syntax (c-guess-basic-syntax))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 ;; must remove the newline we just stuck in (if we really did it)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 (and delete-temp-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 ;; if there is whitespace before point, then preserve
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 ;; at least one space.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 (delete-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084 (just-one-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 (if (not preserve-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 (delete-char -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 ;; since we're hanging the brace, we need to recalculate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088 ;; syntax. Update the state to accurately reflect the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 ;; beginning of the line. We punt if we cross any open or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 ;; closed parens because its just too hard to modify the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 ;; known state. This limitation will be fixed in v5.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 (let ((bol (c-point 'bol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 (if (zerop (car (parse-partial-sexp bol (1- (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 (setq c-state-cache (c-whack-state bol c-state-cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 syntax (c-guess-basic-syntax))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 ;; gotta punt. this requires some horrible kludgery
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 (makunbound 'c-state-cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100 (setq c-state-cache (c-parse-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 syntax nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 ;; now adjust the line's indentation. don't update the state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 ;; cache since c-guess-basic-syntax isn't called when the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105 ;; syntax is passed to c-indent-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106 (let ((here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 (shift (c-indent-line syntax)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 (setq c-state-cache (c-adjust-state (c-point 'bol) here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 (- shift) c-state-cache)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 ;; Do all appropriate clean ups
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111 (let ((here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 (pos (- (point-max) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 mbeg mend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 ;; clean up empty defun braces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 (if (and c-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 (memq 'empty-defun-braces c-cleanup-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117 (= last-command-char ?\})
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 (c-intersect-lists '(defun-close class-close inline-close)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 (skip-chars-backward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 (= (preceding-char) ?\{))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 ;; make sure matching open brace isn't in a comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 (not (c-in-literal)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 (delete-region (point) (1- here)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 ;; clean up brace-else-brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 (if (and c-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129 (memq 'brace-else-brace c-cleanup-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130 (= last-command-char ?\{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131 (re-search-backward "}[ \t\n]*else[ \t\n]*{" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133 (setq mbeg (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134 mend (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135 (= mend here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136 (not (c-in-literal)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138 (delete-region mbeg mend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 (insert "} else {")))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2140 ;; clean up brace-elseif-brace
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2141 (if (and c-auto-newline
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2142 (memq 'brace-elseif-brace c-cleanup-list)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2143 (= last-command-char ?\{)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2144 (re-search-backward "}[ \t\n]*else[ \t\n]+if[ \t\n]*" nil t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2145 (save-excursion
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2146 (goto-char (match-end 0))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2147 (c-safe (forward-sexp 1))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2148 (skip-chars-forward " \t\n")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2149 (setq mbeg (match-beginning 0)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2150 mend (match-end 0))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2151 (= here (1+ (point))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2152 (not (c-in-literal)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2153 (progn
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2154 (delete-region mbeg mend)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2155 (insert "} else if ")))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2156 (goto-char (- (point-max) pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 ;; does a newline go after the brace?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159 (if (memq 'after newlines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 (newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162 ;; update on c-state-cache
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2163 (let* ((bufpos (- (point) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164 (which (if (= (char-after bufpos) ?{) 'open 'close))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165 (c-state-cache (c-hack-state bufpos which c-state-cache)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2166 (c-indent-line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2167 ;; blink the paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168 (and (= last-command-char ?\})
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169 old-blink-paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171 (c-backward-syntactic-ws safepos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172 (if (boundp 'blink-paren-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2173 (funcall old-blink-paren)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2174 (run-hooks old-blink-paren))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2175 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2177 (defun c-electric-slash (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178 "Insert a slash character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179 If slash is second of a double-slash C++ style comment introducing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 construct, and we are on a comment-only-line, indent line as comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 If numeric ARG is supplied or point is inside a literal, indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182 is inhibited."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2184 (let ((indentp (and (not arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2185 (= (preceding-char) ?/)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2186 (= last-command-char ?/)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187 (not (c-in-literal))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2188 ;; shut this up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189 (c-echo-syntactic-information-p nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2190 (self-insert-command (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 (if indentp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2192 (c-indent-line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2194 (defun c-electric-star (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2195 "Insert a star character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196 If the star is the second character of a C style comment introducing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197 construct, and we are on a comment-only-line, indent line as comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198 If numeric ARG is supplied or point is inside a literal, indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2199 is inhibited."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201 (self-insert-command (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202 ;; if we are in a literal, or if arg is given do not re-indent the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203 ;; current line, unless this star introduces a comment-only line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 (if (and (not arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205 (memq (c-in-literal) '(c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206 (= (preceding-char) ?*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 (skip-chars-backward "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 (if (= (preceding-char) ?/)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213 (bolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 ;; shut this up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215 (let (c-echo-syntactic-information-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 (c-indent-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 (defun c-electric-semi&comma (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220 "Insert a comma or semicolon.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 When the auto-newline feature is turned on, as evidenced by the \"/a\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 or \"/ah\" string on the mode line, a newline might be inserted. See
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223 the variable `c-hanging-semi&comma-criteria' for how newline insertion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224 is determined.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226 When semicolon is inserted, the line is re-indented unless a numeric
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227 arg is supplied, point is inside a literal, or there are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 non-whitespace characters on the line following the semicolon."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 (let* ((lim (c-most-enclosing-brace (c-parse-state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231 (literal (c-in-literal lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232 (here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2233 ;; shut this up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234 (c-echo-syntactic-information-p nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2235 (if (or literal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236 arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237 (not (looking-at "[ \t]*$")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238 (c-insert-special-chars arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 ;; do some special stuff with the character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 (self-insert-command (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241 ;; do all cleanups, reindentations, and newline insertions, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242 ;; only if c-auto-newline is turned on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243 (if (not c-auto-newline) nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 ;; clean ups
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 (let ((pos (- (point-max) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 (if (and (or (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 (= last-command-char ?,)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 (memq 'list-close-comma c-cleanup-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250 (= last-command-char ?\;)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251 (memq 'defun-close-semi c-cleanup-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254 (skip-chars-backward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255 (= (preceding-char) ?}))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256 ;; make sure matching open brace isn't in a comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257 (not (c-in-literal lim)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 (delete-region (point) here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 (goto-char (- (point-max) pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 ;; re-indent line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261 (c-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262 ;; check to see if a newline should be added
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263 (let ((criteria c-hanging-semi&comma-criteria)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2264 answer add-newline-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265 (while criteria
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266 (setq answer (funcall (car criteria)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267 ;; only nil value means continue checking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2268 (if (not answer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269 (setq criteria (cdr criteria))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2270 (setq criteria nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 ;; only 'stop specifically says do not add a newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272 (setq add-newline-p (not (eq answer 'stop)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274 (if add-newline-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 (progn (newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276 (c-indent-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279 (defun c-semi&comma-inside-parenlist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280 "Determine if a newline should be added after a semicolon.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2281 If a comma was inserted, no determination is made. If a semicolon was
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2282 inserted inside a parenthesis list, no newline is added otherwise a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2283 newline is added. In either case, checking is stopped. This supports
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284 exactly the old newline insertion behavior."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2285 ;; newline only after semicolon, but only if that semicolon is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2286 ;; inside a parenthesis list (e.g. a for loop statement)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2287 (if (/= last-command-char ?\;)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 nil ; continue checking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 (if (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2290 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2291 (up-list -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 (/= (following-char) ?\())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2293 (error t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294 t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2295 'stop)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297 (defun c-electric-colon (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 "Insert a colon.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 If the auto-newline feature is turned on, as evidenced by the \"/a\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301 or \"/ah\" string on the mode line, newlines are inserted before and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302 after colons based on the value of `c-hanging-colons-alist'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304 Also, the line is re-indented unless a numeric ARG is supplied, there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305 are non-whitespace characters present on the line after the colon, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 the colon is inserted inside a literal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308 This function cleans up double colon scope operators based on the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 value of `c-cleanup-list'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311 (let* ((bod (c-point 'bod))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2312 (literal (c-in-literal bod))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2313 syntax newlines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2314 ;; shut this up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2315 (c-echo-syntactic-information-p nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2316 (if (or literal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2317 arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318 (not (looking-at "[ \t]*$")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319 (c-insert-special-chars arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2320 ;; insert the colon, then do any specified cleanups
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2321 (self-insert-command (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2322 (let ((pos (- (point-max) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2323 (here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324 (if (and c-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 (memq 'scope-operator c-cleanup-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 (= (preceding-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2329 (skip-chars-backward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2330 (= (preceding-char) ?:))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2331 (not (c-in-literal))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2332 (not (= (char-after (- (point) 2)) ?:)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333 (delete-region (point) (1- here)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 (goto-char (- (point-max) pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2335 ;; lets do some special stuff with the colon character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2336 (setq syntax (c-guess-basic-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337 ;; some language elements can only be determined by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338 ;; checking the following line. Lets first look for ones
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2339 ;; that can be found when looking on the line with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340 ;; colon
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2341 newlines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2342 (and c-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343 (or (c-lookup-lists '(case-label label access-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344 syntax c-hanging-colons-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345 (c-lookup-lists '(member-init-intro inher-intro)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346 (prog2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2348 (c-guess-basic-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2349 (delete-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2350 c-hanging-colons-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2351 ;; indent the current line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352 (c-indent-line syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2353 ;; does a newline go before the colon? Watch out for already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354 ;; non-hung colons. However, we don't unhang them because that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355 ;; would be a cleanup (and anti-social).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2356 (if (and (memq 'before newlines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358 (skip-chars-backward ": \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 (not (bolp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 (let ((pos (- (point-max) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362 (newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363 (c-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2364 (goto-char (- (point-max) pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 ;; does a newline go after the colon?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2366 (if (memq 'after (cdr-safe newlines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2367 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2368 (newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2369 (c-indent-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2370 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2371
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2372 (defun c-electric-lt-gt (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2373 "Insert a less-than, or greater-than character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2374 When the auto-newline feature is turned on, as evidenced by the \"/a\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2375 or \"/ah\" string on the mode line, the line will be re-indented if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2376 the character inserted is the second of a C++ style stream operator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377 and the buffer is in C++ mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379 The line will also not be re-indented if a numeric argument is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2380 supplied, or point is inside a literal."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382 (let ((indentp (and (not arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383 (= (preceding-char) last-command-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384 (not (c-in-literal))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2385 ;; shut this up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386 (c-echo-syntactic-information-p nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387 (self-insert-command (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 (if indentp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2389 (c-indent-line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2391 ;; set up electric character functions to work with pending-del,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2392 ;; (a.k.a. delsel) mode. All symbols get the t value except
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 ;; c-electric-delete which gets 'supersede.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2395 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 (lambda (sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397 (put sym 'delete-selection t) ; for delsel (Emacs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398 (put sym 'pending-delete t))) ; for pending-del (XEmacs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399 '(c-electric-pound
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 c-electric-brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401 c-electric-slash
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2402 c-electric-star
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403 c-electric-semi&comma
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404 c-electric-lt-gt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 c-electric-colon))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406 (put 'c-electric-delete 'delete-selection 'supersede) ; delsel
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2407 (put 'c-electric-delete 'pending-delete 'supersede) ; pending-del
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2411 (defvar c-read-offset-history nil)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2412
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413 (defun c-read-offset (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2414 ;; read new offset value for LANGELEM from minibuffer. return a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2415 ;; legal value only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 (let* ((oldoff (cdr-safe (assq langelem c-offsets-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 (defstr (format "(default %s): " oldoff))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418 (errmsg (concat "Offset must be int, func, var, "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419 "or in [+,-,++,--,*,/] "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 defstr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421 (prompt (concat "Offset " defstr))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2422 offset input interned raw)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 (while (not offset)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2424 (setq input (completing-read prompt obarray 'fboundp nil nil
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2425 'c-read-offset-history)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426 offset (cond ((string-equal "" input) oldoff) ; default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427 ((string-equal "+" input) '+)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2428 ((string-equal "-" input) '-)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 ((string-equal "++" input) '++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2430 ((string-equal "--" input) '--)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2431 ((string-equal "*" input) '*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 ((string-equal "/" input) '/)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433 ((string-match "^-?[0-9]+$" input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434 (string-to-int input))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2435 ;; a symbol with a function binding
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436 ((fboundp (setq interned (intern input)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437 interned)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2438 ;; a lambda function
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2439 ((condition-case nil
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2440 (c-functionp (setq raw (read input)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2441 (error nil))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2442 raw)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2443 ;; a symbol with variable binding
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2444 ((boundp interned) interned)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445 ;; error, but don't signal one, keep trying
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2446 ;; to read an input value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2447 (t (ding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448 (setq prompt errmsg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450 offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452 (defun c-set-offset (symbol offset &optional add-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453 "Change the value of a syntactic element symbol in `c-offsets-alist'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 SYMBOL is the syntactic element symbol to change and OFFSET is the new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455 offset for that syntactic element. Optional ADD says to add SYMBOL to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456 `c-offsets-alist' if it doesn't already appear there."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 (let* ((langelem
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459 (intern (completing-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460 (concat "Syntactic symbol to change"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461 (if current-prefix-arg " or add" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462 ": ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465 (lambda (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 (cons (format "%s" (car langelem)) nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467 c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468 nil (not current-prefix-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2469 ;; initial contents tries to be the last element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470 ;; on the syntactic analysis list for the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 ;; line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 (let* ((syntax (c-guess-basic-syntax))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473 (len (length syntax))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474 (ic (format "%s" (car (nth (1- len) syntax)))))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2475 (if (or (memq 'v19 c-emacs-features)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2476 (memq 'v20 c-emacs-features))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477 (cons ic 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2478 ic))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480 (offset (c-read-offset langelem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481 (list langelem offset current-prefix-arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482 ;; sanity check offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2483 (or (eq offset '+)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2484 (eq offset '-)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2485 (eq offset '++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2486 (eq offset '--)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2487 (eq offset '*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2488 (eq offset '/)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2489 (integerp offset)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2490 (c-functionp offset)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2491 (boundp offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2492 (error "Offset must be int, func, var, or in [+,-,++,--,*,/]: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493 offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2494 (let ((entry (assq symbol c-offsets-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495 (if entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2496 (setcdr entry offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2497 (if add-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498 (setq c-offsets-alist (cons (cons symbol offset) c-offsets-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499 (error "%s is not a valid syntactic symbol." symbol))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2500 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2501
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2502 (defun c-set-style-1 (stylevars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2503 ;; given a style's variable alist, institute the style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2504 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2505 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2506 (lambda (conscell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2507 (let ((attr (car conscell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508 (val (cdr conscell)))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2509 (cond
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2510 ((eq attr 'c-offsets-alist)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2511 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2512 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513 (lambda (langentry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2514 (let ((langelem (car langentry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2515 (offset (cdr langentry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2516 (c-set-offset langelem offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2517 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2518 val))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2519 ((eq attr 'c-special-indent-hook)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2520 (if (listp val)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2521 (while val
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2522 (add-hook 'c-special-indent-hook (car val))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2523 (setq val (cdr val)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2524 (add-hook 'c-special-indent-hook val)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2525 (t (set attr val)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2526 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2527 stylevars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2528
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2529 (defvar c-set-style-history nil)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2530
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2531 ;;;###autoload
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2532 (defun c-set-style (stylename)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2533 "Set CC Mode variables to use one of several different indentation styles.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2534 STYLENAME is a string representing the desired style from the list of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2535 styles described in the variable `c-style-alist'. See that variable
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2536 for details of setting up styles.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2537
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2538 The variable `c-indentation-style' always contains the buffer's current
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2539 style name."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2540 (interactive (list (let ((completion-ignore-case t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2541 (prompt (format "Which %s indentation style? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2542 mode-name)))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2543 (completing-read prompt c-style-alist nil t
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2544 (cons c-indentation-style 0)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2545 'c-set-style-history))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2546 (let ((vars (cdr (or (assoc (downcase stylename) c-style-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2547 (assoc (upcase stylename) c-style-alist)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2548 (assoc stylename c-style-alist)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2550 (default (cdr (assoc "cc-mode" c-style-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2551 (or vars (error "Invalid indentation style `%s'" stylename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2552 (or default (error "No `cc-mode' style found!"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2553 ;; first reset the style to `cc-mode' to give every style a common
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2554 ;; base. Then institute the new style.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2555 (c-set-style-1 default)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2556 (setq c-indentation-style stylename)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2557 (if (not (string= stylename "cc-mode"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2558 (c-set-style-1 vars)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2559 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2560
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
2561 ;;;###autoload
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562 (defun c-add-style (style descrip &optional set-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563 "Adds a style to `c-style-alist', or updates an existing one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564 STYLE is a string identifying the style to add or update. DESCRIP is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565 an association list describing the style and must be of the form:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567 ((VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2569 See the variable `c-style-alist' for the semantics of VARIABLE and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2570 VALUE. This function also sets the current style to STYLE using
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2571 `c-set-style' if the optional SET-P flag is non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2572 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573 (let ((stylename (completing-read "Style to add: " c-style-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2574 (description (eval-minibuffer "Style description: ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2575 (list stylename description
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2576 (y-or-n-p "Set the style too? "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2577 (setq style (downcase style))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2578 (let ((s (assoc style c-style-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2579 (if s
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2580 (setcdr s (copy-alist descrip)) ; replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2581 (setq c-style-alist (cons (cons style descrip) c-style-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2582 (and set-p (c-set-style style)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2583
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
2584
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2585 (defun c-fill-paragraph (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2586 "Like \\[fill-paragraph] but handles C and C++ style comments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2587 If any of the current line is a comment or within a comment,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2588 fill the comment or the paragraph of it that point is in,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2589 preserving the comment indentation or line-starting decorations.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2590
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2591 Optional prefix ARG means justify paragraph as well."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2592 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2593 (let* (comment-start-place
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2594 (first-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2595 ;; Check for obvious entry to comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2597 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598 (skip-chars-forward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599 (and (looking-at comment-start-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2600 (setq comment-start-place (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2601 (re1 (if (memq 'new-re c-emacs-features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2602 "\\|[ \t]*/\\*[ \t]*$\\|[ \t]*\\*/[ \t]*$\\|[ \t/*]*$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2603 "\\|^[ \t]*/\\*[ \t]*$\\|^[ \t]*\\*/[ \t]*$\\|^[ \t/*]*$"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2604 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605 (if (and c-double-slash-is-comments-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2606 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2607 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2608 (looking-at ".*//")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2609 (let (fill-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2610 ;; Lines containing just a comment start or just an end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2611 ;; should not be filled into paragraphs they are next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612 ;; to.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2613 (paragraph-start (concat paragraph-start re1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614 (paragraph-separate (concat paragraph-separate re1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2616 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2617 ;; Move up to first line of this comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618 (while (and (not (bobp))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2619 (looking-at "[ \t]*//[ \t]*[^ \t\n]"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2620 (forward-line -1))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2621 (if (not (looking-at ".*//[ \t]*[^ \t\n]"))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2622 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2623 ;; Find the comment start in this line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2624 (re-search-forward "[ \t]*//[ \t]*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2625 ;; Set the fill-prefix to be what all lines except the first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2626 ;; should start with.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2627 (setq fill-prefix (buffer-substring (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2628 (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2629 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2630 ;; Narrow down to just the lines of this comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2631 (narrow-to-region (c-point 'bol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634 (while (looking-at fill-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637 (fill-paragraph arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639 ;; else C style comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2640 (if (or first-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641 ;; t if we enter a comment between start of function and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642 ;; this line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643 (eq (c-in-literal) 'c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644 ;; t if this line contains a comment starter.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645 (setq first-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649 (re-search-forward comment-start-skip
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2650 (save-excursion (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2652 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653 (setq comment-start-place (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654 ;; Inside a comment: fill one comment paragraph.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655 (let ((fill-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656 ;; The prefix for each line of this paragraph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657 ;; is the appropriate part of the start of this line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658 ;; up to the column at which text should be indented.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2659 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 (if (looking-at "[ \t]*/\\*.*\\*/")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662 (progn (re-search-forward comment-start-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663 (make-string (current-column) ?\ ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664 (if first-line (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666 (let ((line-width (progn (end-of-line) (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2667 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 ;; How shall we decide where the end of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673 ;; fill-prefix is?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2675 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676 (skip-chars-forward " \t*" (c-point 'eol))
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
2677 ;; kludge alert, watch out for */, in
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
2678 ;; which case fill-prefix should *not*
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
2679 ;; be "*"!
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
2680 (if (and (= (following-char) ?/)
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
2681 (= (preceding-char) ?*))
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
2682 (forward-char -1))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2683 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2684
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2685 ;; If the comment is only one line followed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2686 ;; by a blank line, calling move-to-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2687 ;; above may have added some spaces and tabs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688 ;; to the end of the line; the fill-paragraph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689 ;; function will then delete it and the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2690 ;; newline following it, so we'll lose a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2691 ;; blank line when we shouldn't. So delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2692 ;; anything move-to-column added to the end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2693 ;; of the line. We record the line width
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2694 ;; instead of the position of the old line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2695 ;; end because move-to-column might break a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2696 ;; tab into spaces, and the new characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2697 ;; introduced there shouldn't be deleted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2698
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2699 ;; If you can see a better way to do this,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2700 ;; please make the change. This seems very
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2701 ;; messy to me.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2702 (delete-region (progn (move-to-column line-width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2703 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2704 (progn (end-of-line) (point))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2705
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2706 ;; Lines containing just a comment start or just an end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2707 ;; should not be filled into paragraphs they are next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708 ;; to.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2709 (paragraph-start (concat paragraph-start re1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2710 (paragraph-separate (concat paragraph-separate re1))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2711 (chars-to-delete 0)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2712 )
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2713 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2714 ;; Don't fill the comment together with the code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2715 ;; following it. So temporarily exclude everything
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2716 ;; before the comment start, and everything after the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2717 ;; line where the comment ends. If comment-start-place
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2718 ;; is non-nil, the comment starter is there. Otherwise,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2719 ;; point is inside the comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2720 (narrow-to-region (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2721 (if comment-start-place
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2722 (goto-char comment-start-place)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2723 (search-backward "/*"))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2724 (if (and (not c-hanging-comment-starter-p)
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
2725 (looking-at
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
2726 (concat c-comment-start-regexp
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
2727 "[ \t]*$")))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2728 (forward-line 1))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2729 ;; Protect text before the comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2730 ;; start by excluding it. Add
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2731 ;; spaces to bring back proper
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2732 ;; indentation of that point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2733 (let ((column (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2734 (prog1 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2735 (setq chars-to-delete column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2736 (insert-char ?\ column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2737 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2738 (if comment-start-place
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2739 (goto-char (+ comment-start-place 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2740 (search-forward "*/" nil 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2741 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2742 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2743 (fill-paragraph arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2744 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2745 ;; Delete the chars we inserted to avoid clobbering
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2746 ;; the stuff before the comment start.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2747 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2748 (if (> chars-to-delete 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2749 (delete-region (point) (+ (point) chars-to-delete)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2750 ;; Find the comment ender (should be on last line of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2751 ;; buffer, given the narrowing) and don't leave it on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2752 ;; its own line, unless that's the style that's desired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2753 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2754 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2755 (search-forward "*/" nil 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2756 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2757 (if (and c-hanging-comment-ender-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2758 (looking-at "[ \t]*\\*/"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2759 ;(delete-indentation)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2760 (let ((fill-column (+ fill-column 9999)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2761 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2762 (fill-region-as-paragraph (point) (point-max))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2763 t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2764
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2765
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2766 ;; better movement routines for ThisStyleOfVariablesCommonInCPlusPlus
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2767 ;; originally contributed by Terry_Glanfield.Southern@rxuk.xerox.com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2768 (defun c-forward-into-nomenclature (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2769 "Move forward to end of a nomenclature section or word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2770 With arg, to it arg times."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2771 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2772 (let ((case-fold-search nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2773 (if (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2774 (re-search-forward "\\W*\\([A-Z]*[a-z0-9]*\\)" (point-max) t arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2775 (while (and (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2776 (re-search-backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2777 "\\(\\(\\W\\|[a-z0-9]\\)[A-Z]+\\|\\W\\w+\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2778 (point-min) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2779 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2780 (setq arg (1+ arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2781 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2782
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2783 (defun c-backward-into-nomenclature (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2784 "Move backward to beginning of a nomenclature section or word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2785 With optional ARG, move that many times. If ARG is negative, move
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2786 forward."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2787 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2788 (c-forward-into-nomenclature (- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2789 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2790
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2791 (defun c-scope-operator ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2792 "Insert a double colon scope operator at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2793 No indentation or other \"electric\" behavior is performed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2794 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2795 (insert "::"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2796
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2797
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2798 (defun c-beginning-of-statement (&optional count lim sentence-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2799 "Go to the beginning of the innermost C statement.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2800 With prefix arg, go back N - 1 statements. If already at the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2801 beginning of a statement then go to the beginning of the preceding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2802 one. If within a string or comment, or next to a comment (only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2803 whitespace between), move by sentences instead of statements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2804
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2805 When called from a program, this function takes 3 optional args: the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2806 repetition count, a buffer position limit which is the farthest back
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2807 to search, and a flag saying whether to do sentence motion when in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2808 comment."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2809 (interactive (list (prefix-numeric-value current-prefix-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2810 nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2811 (let ((here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2812 (count (or count 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2813 (lim (or lim (c-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2814 state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2815 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2816 (goto-char lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2817 (setq state (parse-partial-sexp (point) here nil nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2818 (if (and sentence-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2819 (or (nth 3 state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2820 (nth 4 state)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2821 ; (looking-at (concat "[ \t]*" comment-start-skip))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2822 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2823 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2824 (goto-char (- (point) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2825 (looking-at "\\*/"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2826 (forward-sentence (- count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2827 (while (> count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2828 (c-beginning-of-statement-1 lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2829 (setq count (1- count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2830 (while (< count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2831 (c-end-of-statement-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2832 (setq count (1+ count))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2833 ;; its possible we've been left up-buf of lim
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2834 (goto-char (max (point) lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2835 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2836 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2837
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2838 (defun c-end-of-statement (&optional count lim sentence-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2839 "Go to the end of the innermost C statement.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2840
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2841 With prefix arg, go forward N - 1 statements. Move forward to end of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2842 the next statement if already at end. If within a string or comment,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2843 move by sentences instead of statements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2844
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2845 When called from a program, this function takes 3 optional args: the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2846 repetition count, a buffer position limit which is the farthest back
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2847 to search, and a flag saying whether to do sentence motion when in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2848 comment."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2849 (interactive (list (prefix-numeric-value current-prefix-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2850 nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2851 (c-beginning-of-statement (- (or count 1)) lim sentence-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2852 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2853
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2854 ;; WARNING: Be *exceptionally* careful about modifications to this
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2855 ;; function! Much of CC Mode depends on this Doing The Right Thing.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
2856 ;; If you break it you will be sorry.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2857 (defun c-beginning-of-statement-1 (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2858 ;; move to the start of the current statement, or the previous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2859 ;; statement if already at the beginning of one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2860 (let ((firstp t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2861 (substmt-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2862 donep c-in-literal-cache
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2863 ;; KLUDGE ALERT: maybe-labelp is used to pass information
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2864 ;; between c-crosses-statement-barrier-p and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2865 ;; c-beginning-of-statement-1. A better way should be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2866 ;; implemented.
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2867 maybe-labelp saved
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2868 (last-begin (point)))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2869 ;; first check for bare semicolon
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2870 (if (and (progn (c-backward-syntactic-ws lim)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2871 (= (preceding-char) ?\;))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2872 (c-safe (progn (forward-char -1)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2873 (setq saved (point))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2874 t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2875 (progn (c-backward-syntactic-ws lim)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2876 (memq (preceding-char) '(?\; ?{ ?} ?:)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2877 )
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2878 (setq last-begin saved)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2879 (goto-char last-begin)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2880 (while (not donep)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2881 ;; stop at beginning of buffer
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2882 (if (bobp) (setq donep t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2883 ;; go backwards one balanced expression, but be careful of
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2884 ;; unbalanced paren being reached
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2885 (if (not (c-safe (progn (backward-sexp 1) t)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2886 (progn
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2887 (if firstp
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2888 (backward-up-list 1)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2889 (goto-char last-begin))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2890 ;; skip over any unary operators, or other special
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2891 ;; characters appearing at front of identifier
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2892 (save-excursion
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2893 (c-backward-syntactic-ws lim)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2894 (skip-chars-backward "-+!*&:.~ \t\n")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2895 (if (= (preceding-char) ?\()
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2896 (setq last-begin (point))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2897 (goto-char last-begin)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2898 (setq last-begin (point)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2899 donep t)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2900
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2901 (setq maybe-labelp nil)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2902 ;; see if we're in a literal. if not, then this bufpos may be
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2903 ;; a candidate for stopping
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2904 (cond
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2905 ;; CASE 0: did we hit the error condition above?
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2906 (donep)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2907 ;; CASE 1: are we in a literal?
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2908 ((eq (c-in-literal lim) 'pound)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2909 (beginning-of-line))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2910 ;; CASE 2: some other kind of literal?
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2911 ((c-in-literal lim))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2912 ;; CASE 3: are we looking at a conditional keyword?
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2913 ((or (looking-at c-conditional-key)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2914 (and (= (following-char) ?\()
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2915 (save-excursion
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2916 (forward-sexp 1)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2917 (c-forward-syntactic-ws)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2918 (/= (following-char) ?\;))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2919 (let ((here (point))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2920 (foundp (progn
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2921 (c-backward-syntactic-ws lim)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2922 (forward-word -1)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2923 (and lim
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2924 (<= lim (point))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2925 (not (c-in-literal lim))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2926 (looking-at c-conditional-key)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2927 ))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2928 ;; did we find a conditional?
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2929 (if (not foundp)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2930 (goto-char here))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2931 foundp)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2932 ;; are we in the middle of an else-if clause?
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2933 (if (save-excursion
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2934 (and (not substmt-p)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2935 (c-safe (progn (forward-sexp -1) t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2936 (looking-at "\\<else\\>[ \t\n]+\\<if\\>")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2937 (not (c-in-literal lim))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2938 (progn
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2939 (forward-sexp -1)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2940 (c-backward-to-start-of-if lim)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2941 ;; are we sitting at an else clause, that we are not a
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2942 ;; substatement of?
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2943 (if (and (not substmt-p)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2944 (looking-at "\\<else\\>[^_]"))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2945 (c-backward-to-start-of-if lim))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2946 ;; are we sitting at the while of a do-while?
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2947 (if (and (looking-at "\\<while\\>[^_]")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2948 (c-backward-to-start-of-do lim))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2949 (setq substmt-p nil))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2950 (setq last-begin (point)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2951 donep substmt-p))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2952 ;; CASE 4: are we looking at a label?
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2953 ((looking-at c-label-key))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2954 ;; CASE 5: is this the first time we're checking?
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2955 (firstp (setq firstp nil
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2956 substmt-p (not (c-crosses-statement-barrier-p
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2957 (point) last-begin))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2958 last-begin (point)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2959 ;; CASE 6: have we crossed a statement barrier?
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2960 ((c-crosses-statement-barrier-p (point) last-begin)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2961 (setq donep t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2962 ;; CASE 7: ignore labels
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2963 ((and maybe-labelp
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2964 (or (and c-access-key (looking-at c-access-key))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2965 ;; with switch labels, we have to go back further
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2966 ;; to try to pick up the case or default
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2967 ;; keyword. Potential bogosity alert: we assume
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2968 ;; `case' or `default' is first thing on line
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2969 (let ((here (point)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2970 (beginning-of-line)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2971 (c-forward-syntactic-ws)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2972 (if (looking-at c-switch-label-key)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2973 t
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2974 (goto-char here)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2975 nil))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2976 (looking-at c-label-key))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2977 ;; CASE 8: ObjC or Java method def
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2978 ((and c-method-key
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2979 (setq last-begin (c-in-method-def-p)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2980 (setq donep t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2981 ;; CASE 9: nothing special
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2982 (t (setq last-begin (point)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
2983 ))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2984 (goto-char last-begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2985 ;; we always do want to skip over non-whitespace modifier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2986 ;; characters that didn't get skipped above
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2987 (skip-chars-backward "-+!*&:.~" (c-point 'boi))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2988
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2989 (defun c-end-of-statement-1 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2990 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2991 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2992 (while (and (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2993 (let ((beg (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2994 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2995 (let ((end (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2996 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2997 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2998 (not (re-search-forward "[;{}]" end t)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2999 (re-search-backward "[;}]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3000 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3001 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3002 (let ((beg (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3003 (backward-up-list -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3004 (let ((end (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3005 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3006 (search-forward ";" end 'move))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3007
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3008 (defun c-crosses-statement-barrier-p (from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3009 ;; Does buffer positions FROM to TO cross a C statement boundary?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3010 (let ((here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3011 (lim from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3012 crossedp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3013 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3014 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3015 (goto-char from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3016 (while (and (not crossedp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3017 (< (point) to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3018 (skip-chars-forward "^;{}:" to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3019 (if (not (c-in-literal lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3020 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3021 (if (memq (following-char) '(?\; ?{ ?}))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3022 (setq crossedp t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3023 (if (= (following-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3024 (setq maybe-labelp t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3025 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3026 (setq lim (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3027 (forward-char 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3028 (error (setq crossedp nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3029 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3030 crossedp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3031
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3032
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3033 (defun c-up-conditional (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3034 "Move back to the containing preprocessor conditional, leaving mark behind.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3035 A prefix argument acts as a repeat count. With a negative argument,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3036 move forward to the end of the containing preprocessor conditional.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3037 When going backwards, `#elif' is treated like `#else' followed by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3038 `#if'. When going forwards, `#elif' is ignored."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3039 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3040 (c-forward-conditional (- count) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3041 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3042
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3043 (defun c-backward-conditional (count &optional up-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3044 "Move back across a preprocessor conditional, leaving mark behind.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3045 A prefix argument acts as a repeat count. With a negative argument,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3046 move forward across a preprocessor conditional."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3047 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3048 (c-forward-conditional (- count) up-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3049 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3050
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3051 (defun c-forward-conditional (count &optional up-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3052 "Move forward across a preprocessor conditional, leaving mark behind.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3053 A prefix argument acts as a repeat count. With a negative argument,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3054 move backward across a preprocessor conditional."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3055 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3056 (let* ((forward (> count 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3057 (increment (if forward -1 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3058 (search-function (if forward 're-search-forward 're-search-backward))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3059 (new))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3060 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3061 (while (/= count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3062 (let ((depth (if up-flag 0 -1)) found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3063 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3064 ;; Find the "next" significant line in the proper direction.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3065 (while (and (not found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3066 ;; Rather than searching for a # sign that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3067 ;; comes at the beginning of a line aside from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3068 ;; whitespace, search first for a string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3069 ;; starting with # sign. Then verify what
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3070 ;; precedes it. This is faster on account of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3071 ;; the fastmap feature of the regexp matcher.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3072 (funcall search-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3073 "#[ \t]*\\(if\\|elif\\|endif\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3074 nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3075 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3076 ;; Now verify it is really a preproc line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3077 (if (looking-at "^[ \t]*#[ \t]*\\(if\\|elif\\|endif\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3078 (let ((prev depth))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3079 ;; Update depth according to what we found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3080 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3081 (cond ((looking-at "[ \t]*#[ \t]*endif")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3082 (setq depth (+ depth increment)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3083 ((looking-at "[ \t]*#[ \t]*elif")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3084 (if (and forward (= depth 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3085 (setq found (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3086 (t (setq depth (- depth increment))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3087 ;; If we are trying to move across, and we find an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3088 ;; end before we find a beginning, get an error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3089 (if (and (< prev 0) (< depth prev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3090 (error (if forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3091 "No following conditional at this level"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3092 "No previous conditional at this level")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3093 ;; When searching forward, start from next line so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3094 ;; that we don't find the same line again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3095 (if forward (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3096 ;; If this line exits a level of conditional, exit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3097 ;; inner loop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3098 (if (< depth 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3099 (setq found (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3100 ;; else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3101 (if forward (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3102 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3103 (or found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3104 (error "No containing preprocessor conditional"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3105 (goto-char (setq new found)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3106 (setq count (+ count increment))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3107 (push-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3108 (goto-char new))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3109 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3112 ;; commands to indent lines, regions, defuns, and expressions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3113 (defun c-indent-command (&optional whole-exp)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3114 "Indent current line as C code, and/or insert some whitespace.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3116 If `c-tab-always-indent' is t, always just indent the current line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3117 If nil, indent the current line only if point is at the left margin or
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3118 in the line's indentation; otherwise insert some whitespace[*]. If
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3119 other than nil or t, then some whitespace[*] is inserted only within
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3120 literals (comments and strings) and inside preprocessor directives,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3121 but the line is always reindented.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3123 A numeric argument, regardless of its value, means indent rigidly all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3124 the lines of the expression starting after point so that this line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3125 becomes properly indented. The relative indentation among the lines
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3126 of the expression are preserved.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3127
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3128 [*] The amount and kind of whitespace inserted is controlled by the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3129 variable `c-insert-tab-function', which is called to do the actual
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3130 insertion of whitespace. Normally the function in this variable
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3131 just inserts a tab character, or the equivalent number of spaces,
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3132 depending on the variable `indent-tabs-mode'."
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
3133
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3134 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3135 (let ((bod (c-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3136 (if whole-exp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3137 ;; If arg, always indent this line as C
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3138 ;; and shift remaining lines of expression the same amount.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3139 (let ((shift-amt (c-indent-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3140 beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3141 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3142 (if (eq c-tab-always-indent t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3143 (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3144 (setq beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3145 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3146 (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3147 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3148 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3149 (setq beg (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3150 (if (> end beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3151 (indent-code-rigidly beg end (- shift-amt) "#")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3152 ;; No arg supplied, use c-tab-always-indent to determine
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3153 ;; behavior
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3154 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3155 ;; CASE 1: indent when at column zero or in lines indentation,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3156 ;; otherwise insert a tab
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3157 ((not c-tab-always-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3158 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3159 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3160 (not (bolp)))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3161 (funcall c-insert-tab-function)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3162 (c-indent-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3163 ;; CASE 2: just indent the line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3164 ((eq c-tab-always-indent t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3165 (c-indent-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3166 ;; CASE 3: if in a literal, insert a tab, but always indent the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3167 ;; line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3168 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3169 (if (c-in-literal bod)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3170 (funcall c-insert-tab-function))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3171 (c-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3172 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3174 (defun c-indent-exp (&optional shutup-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3175 "Indent each line in balanced expression following point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3176 Optional SHUTUP-P if non-nil, inhibits message printing and error checking."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3177 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3178 (let ((here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3179 end progress-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3180 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3181 (let ((c-echo-syntactic-information-p nil) ;keep quiet for speed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3182 (start (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3183 ;; try to be smarter about finding the range of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3184 ;; lines to indent. skip all following
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3185 ;; whitespace. failing that, try to find any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3186 ;; opening brace on the current line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3187 (skip-chars-forward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3188 (if (memq (following-char) '(?\( ?\[ ?\{))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3189 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3190 (let ((state (parse-partial-sexp (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3191 (c-point 'eol))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3192 (and (nth 1 state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3193 (goto-char (nth 1 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3194 (memq (following-char) '(?\( ?\[ ?\{))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3195 (point)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3196 ;; find balanced expression end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3197 (setq end (and (c-safe (progn (forward-sexp 1) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3198 (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3199 ;; sanity check
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3200 (and (not start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3201 (not shutup-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3202 (error "Cannot find start of balanced expression to indent."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3203 (and (not end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3204 (not shutup-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3205 (error "Cannot find end of balanced expression to indent."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3206 (c-progress-init start end 'c-indent-exp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3207 (setq progress-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3208 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3209 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3210 (while (< (point) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3211 (if (not (looking-at "[ \t]*$"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3212 (c-indent-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3213 (c-progress-update)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3214 (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3215 ;; make sure marker is deleted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3216 (and end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3217 (set-marker end nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3218 (and progress-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3219 (c-progress-fini 'c-indent-exp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3220 (goto-char here))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3222 (defun c-indent-defun ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3223 "Re-indents the current top-level function def, struct or class declaration."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3224 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3225 (let ((here (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3226 (c-echo-syntactic-information-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3227 (brace (c-least-enclosing-brace (c-parse-state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3228 (if brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3229 (goto-char brace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3230 (beginning-of-defun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3231 ;; if we're sitting at b-o-b, it might be because there was no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3232 ;; least enclosing brace and we were sitting on the defun's open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3233 ;; brace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3234 (if (and (bobp) (not (= (following-char) ?\{)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3235 (goto-char here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3236 ;; if defun-prompt-regexp is non-nil, b-o-d might not leave us at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3237 ;; the open brace. I consider this an Emacs bug.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3238 (and (boundp 'defun-prompt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3239 defun-prompt-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3240 (looking-at defun-prompt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3241 (goto-char (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3242 ;; catch all errors in c-indent-exp so we can 1. give more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3243 ;; meaningful error message, and 2. restore point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3244 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3245 (c-indent-exp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3246 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3247 (set-marker here nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3249 (defun c-indent-region (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3250 ;; Indent every line whose first char is between START and END inclusive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3251 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3252 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3253 ;; Advance to first nonblank line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3254 (skip-chars-forward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3255 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3256 (let (endmark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3257 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3258 (let ((c-tab-always-indent t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3259 ;; shut up any echo msgs on indiv lines
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
3260 (c-echo-syntactic-information-p nil)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
3261 fence)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3262 (c-progress-init start end 'c-indent-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3263 (setq endmark (copy-marker end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3264 (while (and (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3265 (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3266 (< (point) endmark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3267 ;; update progress
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3268 (c-progress-update)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3269 ;; Indent one line as with TAB.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3270 (let (nextline sexpend sexpbeg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3271 ;; skip blank lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3272 (skip-chars-forward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3273 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3274 ;; indent the current line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3275 (c-indent-line)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
3276 (setq fence (point))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3277 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3278 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3279 (looking-at "[ \t]*#"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3280 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3281 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3282 ;; Find beginning of following line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3283 (setq nextline (c-point 'bonl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3284 ;; Find first beginning-of-sexp for sexp extending past
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3285 ;; this line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3286 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3287 (while (< (point) nextline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3288 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3289 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3290 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3291 (setq sexpend (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3292 (error (setq sexpend nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3293 (goto-char nextline)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3294 (c-forward-syntactic-ws))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3295 (if sexpend
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3296 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3297 ;; make sure the sexp we found really starts on the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3298 ;; current line and extends past it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3299 (goto-char sexpend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3300 (setq sexpend (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3301 (c-safe (backward-sexp 1))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
3302 (setq sexpbeg (point))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
3303 (if (and sexpbeg (< sexpbeg fence))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
3304 (setq sexpbeg fence)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3305 ;; check to see if the next line starts a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3306 ;; comment-only line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3307 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3308 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3309 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3310 (if (looking-at c-comment-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3311 (setq sexpbeg (c-point 'bol))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3312 ;; If that sexp ends within the region, indent it all at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3313 ;; once, fast.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3314 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3315 (if (and sexpend
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3316 (> sexpend nextline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3317 (<= sexpend endmark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3318 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3319 (goto-char sexpbeg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3320 (c-indent-exp 'shutup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3321 (c-progress-update)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3322 (goto-char sexpend)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3323 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3324 (goto-char sexpbeg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3325 (c-indent-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3326 ;; Move to following line and try again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3327 (and sexpend
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3328 (markerp sexpend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3329 (set-marker sexpend nil))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
3330 (forward-line 1)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
3331 (setq fence (point))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3332 (set-marker endmark nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3333 (c-progress-fini 'c-indent-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3334 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3336 (defun c-mark-function ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3337 "Put mark at end of a C, C++, or Objective-C defun, point at beginning."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3338 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3339 (let ((here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3340 ;; there should be a c-point position for 'eod
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3341 (eod (save-excursion (end-of-defun) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3342 (state (c-parse-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3343 brace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3344 (while state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3345 (setq brace (car state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3346 (if (consp brace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3347 (goto-char (cdr brace))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3348 (goto-char brace))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3349 (setq state (cdr state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3350 (if (= (following-char) ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3351 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3352 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3353 (while (not (or (bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3354 (looking-at "[ \t]*$")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3355 (forward-line -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3356 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3357 (skip-chars-forward " \t\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3358 (push-mark here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3359 (push-mark eod nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3360
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3361
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3362 ;; for progress reporting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3363 (defvar c-progress-info nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3365 (defun c-progress-init (start end context)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3366 ;; start the progress update messages. if this emacs doesn't have a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3367 ;; built-in timer, just be dumb about it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3368 (if (not (fboundp 'current-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3369 (message "indenting region... (this may take a while)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3370 ;; if progress has already been initialized, do nothing. otherwise
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3371 ;; initialize the counter with a vector of:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3372 ;; [start end lastsec context]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3373 (if c-progress-info
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3374 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3375 (setq c-progress-info (vector start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3376 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3377 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3378 (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3379 (nth 1 (current-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3380 context))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3381 (message "indenting region..."))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3383 (defun c-progress-update ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3384 ;; update progress
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3385 (if (not (and c-progress-info c-progress-interval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3386 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3387 (let ((now (nth 1 (current-time)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3388 (start (aref c-progress-info 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3389 (end (aref c-progress-info 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3390 (lastsecs (aref c-progress-info 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3391 ;; should we update? currently, update happens every 2 seconds,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3392 ;; what's the right value?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3393 (if (< c-progress-interval (- now lastsecs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3394 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3395 (message "indenting region... (%d%% complete)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3396 (/ (* 100 (- (point) start)) (- end start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3397 (aset c-progress-info 2 now)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3398 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3400 (defun c-progress-fini (context)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3401 ;; finished
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3402 (if (or (eq context (aref c-progress-info 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3403 (eq context t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3404 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3405 (set-marker (aref c-progress-info 1) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3406 (setq c-progress-info nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3407 (message "indenting region...done"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3408
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3410 ;; Skipping of "syntactic whitespace" for Emacs 19. Syntactic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3411 ;; whitespace is defined as lexical whitespace, C and C++ style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3412 ;; comments, and preprocessor directives. Search no farther back or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3413 ;; forward than optional LIM. If LIM is omitted, `beginning-of-defun'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3414 ;; is used for backward skipping, point-max is used for forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3415 ;; skipping. Note that Emacs 18 support has been moved to cc-mode-18.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3416
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3417 (defun c-forward-syntactic-ws (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3418 ;; Forward skip of syntactic whitespace for Emacs 19.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3419 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3420 (let* ((lim (or lim (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3421 (here lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3422 (hugenum (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3423 (narrow-to-region lim (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3424 (while (/= here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3425 (setq here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3426 (forward-comment hugenum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3427 ;; skip preprocessor directives
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3428 (if (and (= (following-char) ?#)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3429 (= (c-point 'boi) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3430 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3431 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3433 (defun c-backward-syntactic-ws (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3434 ;; Backward skip over syntactic whitespace for Emacs 19.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3435 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3436 (let* ((lim (or lim (c-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3437 (here lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3438 (hugenum (- (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3439 (if (< lim (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3440 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3441 (narrow-to-region lim (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3442 (while (/= here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3443 (setq here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3444 (forward-comment hugenum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3445 (if (eq (c-in-literal lim) 'pound)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3446 (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3447 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3448 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3451 ;; Return `c' if in a C-style comment, `c++' if in a C++ style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3452 ;; comment, `string' if in a string literal, `pound' if on a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3453 ;; preprocessor line, or nil if not in a comment at all. Optional LIM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3454 ;; is used as the backward limit of the search. If omitted, or nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3455 ;; `beginning-of-defun' is used."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3457 ;; This is for all v19 Emacsen supporting either 1-bit or 8-bit syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3458 (defun c-in-literal (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3459 ;; Determine if point is in a C++ literal. we cache the last point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3460 ;; calculated if the cache is enabled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3461 (if (and (boundp 'c-in-literal-cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3462 c-in-literal-cache
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3463 (= (point) (aref c-in-literal-cache 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3464 (aref c-in-literal-cache 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3465 (let ((rtn (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3466 (let* ((lim (or lim (c-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3467 (here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3468 (state (parse-partial-sexp lim (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3469 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3470 ((nth 3 state) 'string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3471 ((nth 4 state) (if (nth 7 state) 'c++ 'c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3472 ((progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3473 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3474 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3475 (looking-at "[ \t]*#"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3476 'pound)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3477 (t nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3478 ;; cache this result if the cache is enabled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3479 (and (boundp 'c-in-literal-cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3480 (setq c-in-literal-cache (vector (point) rtn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3481 rtn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3483
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3484 ;; utilities for moving and querying around syntactic elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3485 (defun c-parse-state ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3486 ;; Finds and records all open parens between some important point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3487 ;; earlier in the file and point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3488 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3489 ;; if there's a state cache, return it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3490 (if (boundp 'c-state-cache) c-state-cache
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3491 (let* (at-bob
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3492 (pos (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3493 ;; go back 2 bods, but ignore any bogus positions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3494 ;; returned by beginning-of-defun (i.e. open paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3495 ;; in column zero)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3496 (let ((cnt 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3497 (while (not (or at-bob (zerop cnt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3498 (beginning-of-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3499 (if (= (following-char) ?\{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3500 (setq cnt (1- cnt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3501 (if (bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3502 (setq at-bob t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3503 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3504 (here (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3505 ;;(skip-chars-forward " \t}")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3506 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3507 (last-bod pos) (last-pos pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3508 placeholder state sexp-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3509 ;; cache last bod position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3510 (while (catch 'backup-bod
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3511 (setq state nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3512 (while (and pos (< pos here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3513 (setq last-pos pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3514 (if (and (setq pos (c-safe (scan-lists pos 1 -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3515 (<= pos here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3516 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3517 (setq sexp-end (c-safe (scan-sexps (1- pos) 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3518 (if (and sexp-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3519 (<= sexp-end here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3520 ;; we want to record both the start and end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3521 ;; of this sexp, but we only want to record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3522 ;; the last-most of any of them before here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3523 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3524 (if (= (char-after (1- pos)) ?\{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3525 (setq state (cons (cons (1- pos) sexp-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3526 (if (consp (car state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3527 (cdr state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3528 state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3529 (setq pos sexp-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3530 ;; we're contained in this sexp so put pos on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3531 ;; front of list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3532 (setq state (cons (1- pos) state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3533 ;; something bad happened. check to see if we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3534 ;; crossed an unbalanced close brace. if so, we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3535 ;; didn't really find the right `important bufpos'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3536 ;; so lets back up and try again
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3537 (if (and (not pos) (not at-bob)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3538 (setq placeholder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3539 (c-safe (scan-lists last-pos 1 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3540 ;;(char-after (1- placeholder))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3541 (<= placeholder here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3542 (= (char-after (1- placeholder)) ?\}))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3543 (while t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3544 (setq last-bod (c-safe (scan-lists last-bod -1 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3545 (if (not last-bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3546 (error "unbalanced close brace at position %d"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3547 (1- placeholder))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3548 (setq at-bob (= last-bod (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3549 pos last-bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3550 (if (= (char-after last-bod) ?\{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3551 (throw 'backup-bod t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3552 )) ;end-if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3553 )) ;end-while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3554 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3555 state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3556
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3557 (defun c-whack-state (bufpos state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3558 ;; whack off any state information that appears on STATE which lies
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3559 ;; after the bounds of BUFPOS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3560 (let (newstate car)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3561 (while state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3562 (setq car (car state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3563 state (cdr state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3564 (if (consp car)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3565 ;; just check the car, because in a balanced brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3566 ;; expression, it must be impossible for the corresponding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3567 ;; close brace to be before point, but the open brace to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3568 ;; after.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3569 (if (<= bufpos (car car))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3570 nil ; whack it off
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3571 ;; its possible that the open brace is before bufpos, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3572 ;; the close brace is after. In that case, convert this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3573 ;; to a non-cons element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3574 (if (<= bufpos (cdr car))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3575 (setq newstate (append newstate (list (car car))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3576 ;; we know that both the open and close braces are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3577 ;; before bufpos, so we also know that everything else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3578 ;; on state is before bufpos, so we can glom up the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3579 ;; whole thing and exit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3580 (setq newstate (append newstate (list car) state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3581 state nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3582 (if (<= bufpos car)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3583 nil ; whack it off
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3584 ;; it's before bufpos, so everything else should too
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3585 (setq newstate (append newstate (list car) state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3586 state nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3587 newstate))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3588
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3589 (defun c-hack-state (bufpos which state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3590 ;; Using BUFPOS buffer position, and WHICH (must be 'open or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3591 ;; 'close), hack the c-parse-state STATE and return the results.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3592 (if (eq which 'open)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3593 (let ((car (car state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3594 (if (or (null car)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3595 (consp car)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3596 (/= bufpos car))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3597 (cons bufpos state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3598 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3599 (if (not (eq which 'close))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3600 (error "c-hack-state, bad argument: %s" which))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3601 ;; 'close brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3602 (let ((car (car state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3603 (cdr (cdr state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3604 (if (consp car)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3605 (setq car (car cdr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3606 cdr (cdr cdr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3607 ;; TBD: is this test relevant???
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3608 (if (consp car)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3609 state ;on error, don't change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3610 ;; watch out for balanced expr already on cdr of list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3611 (cons (cons car bufpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3612 (if (consp (car cdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3613 (cdr cdr) cdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3614 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3615
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3616 (defun c-adjust-state (from to shift state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3617 ;; Adjust all points in state that lie in the region FROM..TO by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3618 ;; SHIFT amount (as would be returned by c-indent-line).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3619 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3620 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3621 (lambda (e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3622 (if (consp e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3623 (let ((car (car e))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3624 (cdr (cdr e)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3625 (if (and (<= from car) (< car to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3626 (setcar e (+ shift car)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3627 (if (and (<= from cdr) (< cdr to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3628 (setcdr e (+ shift cdr))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3629 (if (and (<= from e) (< e to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3630 (setq e (+ shift e))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3631 e))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3632 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3633
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3634
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3635 (defun c-beginning-of-inheritance-list (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3636 ;; Go to the first non-whitespace after the colon that starts a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3637 ;; multiple inheritance introduction. Optional LIM is the farthest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3638 ;; back we should search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3639 (let ((lim (or lim (c-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3640 (placeholder (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3641 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3642 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3643 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3644 (while (and (> (point) lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3645 (memq (preceding-char) '(?, ?:))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3646 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3647 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3648 (setq placeholder (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3649 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3650 (not (looking-at c-class-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3651 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3652 (c-backward-syntactic-ws lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3653 (goto-char placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3654 (skip-chars-forward "^:" (c-point 'eol))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3655
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3656 (defun c-beginning-of-macro (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3657 ;; Go to the beginning of the macro. Right now we don't support
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3658 ;; multi-line macros too well
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3659 (back-to-indentation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3660
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3661 (defun c-in-method-def-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3662 ;; Return nil if we aren't in a method definition, otherwise the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3663 ;; position of the initial [+-].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3664 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3665 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3666 (and c-method-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3667 (looking-at c-method-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3668 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3669 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3670
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3671 (defun c-just-after-func-arglist-p (&optional containing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3672 ;; Return t if we are between a function's argument list closing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3673 ;; paren and its opening brace. Note that the list close brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3674 ;; could be followed by a "const" specifier or a member init hanging
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3675 ;; colon. Optional CONTAINING is position of containing s-exp open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3676 ;; brace. If not supplied, point is used as search start.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3677 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3678 (c-backward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3679 (let ((checkpoint (or containing (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3680 (goto-char checkpoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3681 ;; could be looking at const specifier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3682 (if (and (= (preceding-char) ?t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3683 (forward-word -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3684 (looking-at "\\<const\\>"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3685 (c-backward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3686 ;; otherwise, we could be looking at a hanging member init
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3687 ;; colon
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3688 (goto-char checkpoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3689 (if (and (= (preceding-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3690 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3691 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3692 (c-backward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3693 (looking-at "[ \t\n]*:\\([^:]+\\|$\\)")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3694 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3695 (goto-char checkpoint))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3696 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3697 (and (= (preceding-char) ?\))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3698 ;; check if we are looking at a method def
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3699 (or (not c-method-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3700 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3701 (forward-sexp -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3702 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3703 (c-backward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3704 (not (or (= (preceding-char) ?-)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3705 (= (preceding-char) ?+)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3706 ;; or a class category
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3707 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3708 (forward-sexp -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3709 (looking-at c-class-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3710 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3711 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3712
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3713 ;; defuns to look backwards for things
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3714 (defun c-backward-to-start-of-do (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3715 ;; Move to the start of the last "unbalanced" do expression.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3716 ;; Optional LIM is the farthest back to search. If none is found,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3717 ;; nil is returned and point is left unchanged, otherwise t is returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3718 (let ((do-level 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3719 (case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3720 (lim (or lim (c-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3721 (here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3722 foundp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3723 (while (not (zerop do-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3724 ;; we protect this call because trying to execute this when the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3725 ;; while is not associated with a do will throw an error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3726 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3727 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3728 (backward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3729 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3730 ((memq (c-in-literal lim) '(c c++)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3731 ((looking-at "while\\b[^_]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3732 (setq do-level (1+ do-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3733 ((looking-at "do\\b[^_]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3734 (if (zerop (setq do-level (1- do-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3735 (setq foundp t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3736 ((<= (point) lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3737 (setq do-level 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3738 (goto-char lim))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3739 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3740 (goto-char lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3741 (setq do-level 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3742 (if (not foundp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3743 (goto-char here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3744 foundp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3745
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3746 (defun c-backward-to-start-of-if (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3747 ;; Move to the start of the last "unbalanced" if and return t. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3748 ;; none is found, and we are looking at an if clause, nil is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3749 ;; returned. If none is found and we are looking at an else clause,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3750 ;; an error is thrown.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3751 (let ((if-level 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3752 (here (c-point 'bol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3753 (case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3754 (lim (or lim (c-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3755 (at-if (looking-at "if\\b[^_]")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3756 (catch 'orphan-if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3757 (while (and (not (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3758 (not (zerop if-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3759 (c-backward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3760 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3761 (backward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3762 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3763 (if at-if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3764 (throw 'orphan-if nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3765 (error "No matching `if' found for `else' on line %d."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3766 (1+ (count-lines 1 here))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3767 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3768 ((looking-at "else\\b[^_]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3769 (setq if-level (1+ if-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3770 ((looking-at "if\\b[^_]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3771 ;; check for else if... skip over
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3772 (let ((here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3773 (c-safe (forward-sexp -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3774 (if (looking-at "\\<else\\>[ \t]+\\<if\\>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3775 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3776 (setq if-level (1- if-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3777 (goto-char here))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3778 ((< (point) lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3779 (setq if-level 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3780 (goto-char lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3781 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3782 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3783
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3784 (defun c-skip-conditional ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3785 ;; skip forward over conditional at point, including any predicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3786 ;; statements in parentheses. No error checking is performed.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3787 (forward-sexp (cond
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3788 ;; else if()
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3789 ((looking-at "\\<else\\>[ \t]+\\<if\\>") 3)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3790 ;; do, else, try, finally
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3791 ((looking-at "\\<\\(do\\|else\\|try\\|finally\\)\\>") 1)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3792 ;; for, if, while, switch, catch, synchronized
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3793 (t 2))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3794
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3795 (defun c-skip-case-statement-forward (state &optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3796 ;; skip forward over case/default bodies, with optional maximal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3797 ;; limit. if no next case body is found, nil is returned and point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3798 ;; is not moved
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3799 (let ((lim (or lim (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3800 (here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3801 donep foundp bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3802 (safepos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3803 (balanced (car state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3804 ;; search until we've passed the limit, or we've found our match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3805 (while (and (< (point) lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3806 (not donep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3807 (setq safepos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3808 ;; see if we can find a case statement, not in a literal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3809 (if (and (re-search-forward c-switch-label-key lim 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3810 (setq bufpos (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3811 (not (c-in-literal safepos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3812 (/= bufpos here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3813 ;; if we crossed into a balanced sexp, we know the case is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3814 ;; not part of our switch statement, so just bound over the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3815 ;; sexp and keep looking.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3816 (if (and (consp balanced)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3817 (> bufpos (car balanced))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3818 (< bufpos (cdr balanced)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3819 (goto-char (cdr balanced))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3820 (goto-char bufpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3821 (setq donep t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3822 foundp t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3823 (if (not foundp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3824 (goto-char here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3825 foundp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3826
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3827 (defun c-search-uplist-for-classkey (brace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3828 ;; search for the containing class, returning a 2 element vector if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3829 ;; found. aref 0 contains the bufpos of the class key, and aref 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3830 ;; contains the bufpos of the open brace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3831 (if (null brace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3832 ;; no brace-state means we cannot be inside a class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3833 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3834 (let ((carcache (car brace-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3835 search-start search-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3836 (if (consp carcache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3837 ;; a cons cell in the first element means that there is some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3838 ;; balanced sexp before the current bufpos. this we can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3839 ;; ignore. the nth 1 and nth 2 elements define for us the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3840 ;; search boundaries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3841 (setq search-start (nth 2 brace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3842 search-end (nth 1 brace-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3843 ;; if the car was not a cons cell then nth 0 and nth 1 define
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3844 ;; for us the search boundaries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3845 (setq search-start (nth 1 brace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3846 search-end (nth 0 brace-state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3847 ;; search-end cannot be a cons cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3848 (and (consp search-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3849 (error "consp search-end: %s" search-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3850 ;; if search-end is nil, or if the search-end character isn't an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3851 ;; open brace, we are definitely not in a class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3852 (if (or (not search-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3853 (< search-end (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3854 (/= (char-after search-end) ?{))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3855 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3856 ;; now, we need to look more closely at search-start. if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3857 ;; search-start is nil, then our start boundary is really
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3858 ;; point-min.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3859 (if (not search-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3860 (setq search-start (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3861 ;; if search-start is a cons cell, then we can start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3862 ;; searching from the end of the balanced sexp just ahead of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3863 ;; us
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3864 (if (consp search-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3865 (setq search-start (cdr search-start))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3866 ;; now we can do a quick regexp search from search-start to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3867 ;; search-end and see if we can find a class key. watch for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3868 ;; class like strings in literals
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3869 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3870 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3871 (goto-char search-start)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3872 (let ((search-key (concat c-class-key "\\|extern[^_]"))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3873 foundp class match-end)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3874 (while (and (not foundp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3875 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3876 (c-forward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3877 (> search-end (point)))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3878 (re-search-forward search-key search-end t))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3879 (setq class (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3880 match-end (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3881 (if (c-in-literal search-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3882 nil ; its in a comment or string, ignore
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3883 (goto-char class)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3884 (skip-chars-forward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3885 (setq foundp (vector (c-point 'boi) search-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3886 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3887 ;; check for embedded keywords
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3888 ((let ((char (char-after (1- class))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3889 (and char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3890 (memq (char-syntax char) '(?w ?_))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3891 (goto-char match-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3892 (setq foundp nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3893 ;; make sure we're really looking at the start of a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3894 ;; class definition, and not a forward decl, return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3895 ;; arg, template arg list, or an ObjC or Java method.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3896 ((and c-method-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3897 (re-search-forward c-method-key search-end t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3898 (setq foundp nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3899 ;; Its impossible to define a regexp for this, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3900 ;; nearly so to do it programmatically.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3901 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3902 ;; ; picks up forward decls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3903 ;; = picks up init lists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3904 ;; ) picks up return types
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3905 ;; > picks up templates, but remember that we can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3906 ;; inherit from templates!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3907 ((let ((skipchars "^;=)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3908 ;; try to see if we found the `class' keyword
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3909 ;; inside a template arg list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3910 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3911 (skip-chars-backward "^<>" search-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3912 (if (= (preceding-char) ?<)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3913 (setq skipchars (concat skipchars ">"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3914 (skip-chars-forward skipchars search-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3915 (/= (point) search-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3916 (setq foundp nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3917 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3918 foundp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3919 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3920
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3921 (defun c-inside-bracelist-p (containing-sexp brace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3922 ;; return the buffer position of the beginning of the brace list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3923 ;; statement if we're inside a brace list, otherwise return nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3924 ;; CONTAINING-SEXP is the buffer pos of the innermost containing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3925 ;; paren. BRACE-STATE is the remainder of the state of enclosing braces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3926 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3927 ;; N.B.: This algorithm can potentially get confused by cpp macros
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3928 ;; places in inconvenient locations. Its a trade-off we make for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3929 ;; speed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3930 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3931 ;; this will pick up enum lists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3932 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3933 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3934 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3935 (forward-sexp -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3936 (if (or (looking-at "enum[\t\n ]+")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3937 (progn (forward-sexp -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3938 (looking-at "enum[\t\n ]+")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3939 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3940 (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3941 ;; this will pick up array/aggregate init lists, even if they are nested.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3942 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3943 (let (bufpos failedp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3944 (while (and (not bufpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3945 containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3946 (if (consp containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3947 (setq containing-sexp (car brace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3948 brace-state (cdr brace-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3949 ;; see if significant character just before brace is an equal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3950 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3951 (setq failedp nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3952 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3953 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3954 (forward-sexp -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3955 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3956 (c-forward-syntactic-ws containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3957 (error (setq failedp t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3958 (if (or failedp (/= (following-char) ?=))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3959 ;; lets see if we're nested. find the most nested
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3960 ;; containing brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3961 (setq containing-sexp (car brace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3962 brace-state (cdr brace-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3963 ;; we've hit the beginning of the aggregate list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3964 (c-beginning-of-statement-1 (c-most-enclosing-brace brace-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3965 (setq bufpos (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3966 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3967 bufpos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3968 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3969
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3970
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3971 ;; defuns for calculating the syntactic state and indenting a single
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3972 ;; line of C/C++/ObjC code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3973 (defun c-most-enclosing-brace (state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3974 ;; return the bufpos of the most enclosing brace that hasn't been
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3975 ;; narrowed out by any enclosing class, or nil if none was found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3976 (let (enclosingp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3977 (while (and state (not enclosingp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3978 (setq enclosingp (car state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3979 state (cdr state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3980 (if (consp enclosingp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3981 (setq enclosingp nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3982 (if (> (point-min) enclosingp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3983 (setq enclosingp nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3984 (setq state nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3985 enclosingp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3986
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3987 (defun c-least-enclosing-brace (state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3988 ;; return the bufpos of the least (highest) enclosing brace that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3989 ;; hasn't been narrowed out by any enclosing class, or nil if none
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3990 ;; was found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3991 (c-most-enclosing-brace (nreverse state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3992
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3993 (defun c-safe-position (bufpos state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3994 ;; return the closest known safe position higher up than point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3995 (let ((safepos nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3996 (while state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3997 (setq safepos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3998 (if (consp (car state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3999 (cdr (car state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4000 (car state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4001 (if (< safepos bufpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4002 (setq state nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4003 (setq state (cdr state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4004 safepos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4005
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4006 (defun c-narrow-out-enclosing-class (state lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4007 ;; narrow the buffer so that the enclosing class is hidden
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4008 (let (inclass-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4009 (and state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4010 (setq inclass-p (c-search-uplist-for-classkey state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4011 (narrow-to-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4012 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4013 (goto-char (1+ (aref inclass-p 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4014 (skip-chars-forward " \t\n" lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4015 ;; if point is now left of the class opening brace, we're
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4016 ;; hosed, so try a different tact
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4017 (if (<= (point) (aref inclass-p 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4018 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4019 (goto-char (1+ (aref inclass-p 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4020 (c-forward-syntactic-ws lim)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4021 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4022 ;; end point is the end of the current line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4023 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4024 (goto-char lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4025 (c-point 'eol))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4026 ;; return the class vector
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4027 inclass-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4028
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4029 (defun c-guess-basic-syntax ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4030 ;; guess the syntactic description of the current line of C++ code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4031 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4032 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4033 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4034 (let* ((indent-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4035 (case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4036 (fullstate (c-parse-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4037 (state fullstate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4038 (in-method-intro-p (and c-method-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4039 (looking-at c-method-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4040 literal containing-sexp char-before-ip char-after-ip lim
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4041 syntax placeholder c-in-literal-cache inswitch-p
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4042 injava-inher
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4043 ;; narrow out any enclosing class or extern "C" block
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4044 (inclass-p (c-narrow-out-enclosing-class state indent-point))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4045 (inextern-p (and inclass-p
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4046 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4047 (save-restriction
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4048 (widen)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4049 (goto-char (aref inclass-p 0))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4050 (looking-at "extern[^_]")))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4051 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4052
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4053 ;; get the buffer position of the most nested opening brace,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4054 ;; if there is one, and it hasn't been narrowed out
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4055 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4056 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4057 (skip-chars-forward " \t}")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4058 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4059 (while (and state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4060 (not in-method-intro-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4061 (not containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4062 (setq containing-sexp (car state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4063 state (cdr state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4064 (if (consp containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4065 ;; if cdr == point, then containing sexp is the brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4066 ;; that opens the sexp we close
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4067 (if (= (cdr containing-sexp) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4068 (setq containing-sexp (car containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4069 ;; otherwise, ignore this element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4070 (setq containing-sexp nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4071 ;; ignore the bufpos if its been narrowed out by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4072 ;; containing class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4073 (if (<= containing-sexp (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4074 (setq containing-sexp nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4075
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4076 ;; set the limit on the farthest back we need to search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4077 (setq lim (or containing-sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4078 (if (consp (car fullstate))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4079 (cdr (car fullstate))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4080 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4081 (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4082
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4083 ;; cache char before and after indent point, and move point to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4084 ;; the most likely position to perform the majority of tests
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4085 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4086 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4087 (setq char-after-ip (following-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4088 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4089 (setq char-before-ip (preceding-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4090 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4091 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4092
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4093 ;; are we in a literal?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4094 (setq literal (c-in-literal lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4095
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4096 ;; now figure out syntactic qualities of the current line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4097 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4098 ;; CASE 1: in a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4099 ((memq literal '(string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4100 (c-add-syntax 'string (c-point 'bopl)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4101 ;; CASE 2: in a C or C++ style comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4102 ((memq literal '(c c++))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4103 ;; we need to catch multi-paragraph C comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4104 (while (and (zerop (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4105 (looking-at "^[ \t]*$")))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4106 (c-add-syntax literal (c-point 'boi)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4107 ;; CASE 3: in a cpp preprocessor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4108 ((eq literal 'pound)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4109 (c-beginning-of-macro lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4110 (c-add-syntax 'cpp-macro (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4111 ;; CASE 4: in an objective-c method intro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4112 (in-method-intro-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4113 (c-add-syntax 'objc-method-intro (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4114 ;; CASE 5: Line is at top level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4115 ((null containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4116 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4117 ;; CASE 5A: we are looking at a defun, class, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4118 ;; inline-inclass method opening brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4119 ((= char-after-ip ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4120 (cond
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4121 ;; CASE 5A.1: extern declaration
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4122 ((save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4123 (goto-char indent-point)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4124 (skip-chars-forward " \t")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4125 (and (c-safe (progn (backward-sexp 2) t))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4126 (looking-at "extern[^_]")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4127 (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4128 (setq placeholder (point))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4129 (forward-sexp 1)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4130 (c-forward-syntactic-ws)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4131 (= (following-char) ?\"))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4132 (goto-char placeholder)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4133 (c-add-syntax 'extern-lang-open (c-point 'boi)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4134 ;; CASE 5A.2: we are looking at a class opening brace
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4135 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4136 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4137 (skip-chars-forward " \t{")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4138 ;; TBD: watch out! there could be a bogus
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4139 ;; c-state-cache in place when we get here. we have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4140 ;; to go through much chicanery to ignore the cache.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4141 ;; But of course, there may not be! BLECH! BOGUS!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4142 (let ((decl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4143 (if (boundp 'c-state-cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4144 (let ((old-cache c-state-cache))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4145 (prog2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4146 (makunbound 'c-state-cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4147 (c-search-uplist-for-classkey (c-parse-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4148 (setq c-state-cache old-cache)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4149 (c-search-uplist-for-classkey (c-parse-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4150 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4151 (and decl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4152 (setq placeholder (aref decl 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4153 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4154 (c-add-syntax 'class-open placeholder))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4155 ;; CASE 5A.3: brace list open
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4156 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4157 (c-beginning-of-statement-1 lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4158 ;; c-b-o-s could have left us at point-min
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4159 (and (bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4160 (c-forward-syntactic-ws indent-point))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4161 (if (looking-at "typedef[^_]")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4162 (progn (forward-sexp 1)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4163 (c-forward-syntactic-ws indent-point)))
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 114
diff changeset
4164 (setq placeholder (c-point 'boi))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4165 (and (or (looking-at "enum[ \t\n]+")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4166 (= char-before-ip ?=))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4167 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4168 (skip-chars-forward "^;(" indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4169 (not (memq (following-char) '(?\; ?\()))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4170 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4171 (c-add-syntax 'brace-list-open placeholder))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4172 ;; CASE 5A.4: inline defun open
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4173 ((and inclass-p (not inextern-p))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4174 (c-add-syntax 'inline-open)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4175 (c-add-syntax 'inclass (aref inclass-p 0)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4176 ;; CASE 5A.5: ordinary defun open
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4177 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4178 (goto-char placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4179 (c-add-syntax 'defun-open (c-point 'bol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4180 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4181 ;; CASE 5B: first K&R arg decl or member init
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4182 ((c-just-after-func-arglist-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4183 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4184 ;; CASE 5B.1: a member init
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4185 ((or (= char-before-ip ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4186 (= char-after-ip ?:))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4187 ;; this line should be indented relative to the beginning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4188 ;; of indentation for the topmost-intro line that contains
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4189 ;; the prototype's open paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4190 ;; TBD: is the following redundant?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4191 (if (= char-before-ip ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4192 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4193 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4194 ;; TBD: is the preceding redundant?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4195 (if (= (preceding-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4196 (progn (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4197 (c-backward-syntactic-ws lim)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4198 (if (= (preceding-char) ?\))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4199 (backward-sexp 1))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4200 (setq placeholder (point))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4201 (save-excursion
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4202 (and (c-safe (backward-sexp 1) t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4203 (looking-at "throw[^_]")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4204 (c-safe (backward-sexp 1) t)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4205 (setq placeholder (point))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4206 (goto-char placeholder)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4207 (c-add-syntax 'member-init-intro (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4208 ;; we don't need to add any class offset since this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4209 ;; should be relative to the ctor's indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4210 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4211 ;; CASE 5B.2: K&R arg decl intro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4212 (c-recognize-knr-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4213 (c-add-syntax 'knr-argdecl-intro (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4214 (and inclass-p (c-add-syntax 'inclass (aref inclass-p 0))))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4215 ;; CASE 5B.3: Nether region after a C++ or Java func
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4216 ;; decl, which could include a `throws' declaration.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4217 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4218 (c-beginning-of-statement-1 lim)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4219 (c-add-syntax 'func-decl-cont (c-point 'boi))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4220 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4221 ;; CASE 5C: inheritance line. could be first inheritance
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4222 ;; line, or continuation of a multiple inheritance
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4223 ((or (and c-baseclass-key (looking-at c-baseclass-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4224 (and (or (= char-before-ip ?:)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4225 ;; watch out for scope operator
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4226 (save-excursion
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4227 (and (= char-after-ip ?:)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4228 (c-safe (progn (forward-char 1) t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4229 (/= (following-char) ?:)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4230 )))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4231 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4232 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4233 (if (= char-before-ip ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4234 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4235 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4236 (c-backward-syntactic-ws lim)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4237 (back-to-indentation)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4238 (looking-at c-class-key)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4239 ;; for Java
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4240 (and (eq major-mode 'java-mode)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4241 (let ((fence (save-excursion
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4242 (c-beginning-of-statement-1 lim)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4243 (point)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4244 cont done)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4245 (save-excursion
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4246 (while (not done)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4247 (cond ((looking-at c-Java-special-key)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4248 (setq injava-inher (cons cont (point))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4249 done t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4250 ((or (not (c-safe (forward-sexp -1) t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4251 (<= (point) fence))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4252 (setq done t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4253 )
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4254 (setq cont t)))
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
4255 injava-inher)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
4256 (not (c-crosses-statement-barrier-p (cdr injava-inher)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
4257 (point)))
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
4258 ))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4259 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4260 ;; CASE 5C.1: non-hanging colon on an inher intro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4261 ((= char-after-ip ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4262 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4263 (c-add-syntax 'inher-intro (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4264 ;; don't add inclass symbol since relative point already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4265 ;; contains any class offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4266 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4267 ;; CASE 5C.2: hanging colon on an inher intro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4268 ((= char-before-ip ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4269 (c-add-syntax 'inher-intro (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4270 (and inclass-p (c-add-syntax 'inclass (aref inclass-p 0))))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4271 ;; CASE 5C.3: in a Java implements/extends
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4272 (injava-inher
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4273 (let ((where (cdr injava-inher))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4274 (cont (car injava-inher))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4275 (here (point)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4276 (goto-char where)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4277 (cond ((looking-at "throws[^_]")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4278 (c-add-syntax 'func-decl-cont
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4279 (progn (c-beginning-of-statement-1 lim)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4280 (c-point 'boi))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4281 (cont (c-add-syntax 'inher-cont where))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4282 (t (c-add-syntax 'inher-intro
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4283 (progn (goto-char (cdr injava-inher))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4284 (c-beginning-of-statement-1 lim)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4285 (point))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4286 )))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4287 ;; CASE 5C.4: a continued inheritance line
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4288 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4289 (c-beginning-of-inheritance-list lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4290 (c-add-syntax 'inher-cont (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4291 ;; don't add inclass symbol since relative point already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4292 ;; contains any class offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4293 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4294 ;; CASE 5D: this could be a top-level compound statement or a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4295 ;; member init list continuation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4296 ((= char-before-ip ?,)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4297 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4298 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4299 (while (and (< lim (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4300 (= (preceding-char) ?,))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4301 ;; this will catch member inits with multiple
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4302 ;; line arglists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4303 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4304 (c-backward-syntactic-ws (c-point 'bol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4305 (if (= (preceding-char) ?\))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4306 (backward-sexp 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4307 ;; now continue checking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4308 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4309 (c-backward-syntactic-ws lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4310 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4311 ;; CASE 5D.1: hanging member init colon, but watch out
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4312 ;; for bogus matches on access specifiers inside classes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4313 ((and (= (preceding-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4314 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4315 (forward-word -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4316 (not (looking-at c-access-key))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4317 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4318 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4319 (c-safe (backward-sexp 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4320 (c-add-syntax 'member-init-cont (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4321 ;; we do not need to add class offset since relative
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4322 ;; point is the member init above us
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4323 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4324 ;; CASE 5D.2: non-hanging member init colon
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4325 ((progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4326 (c-forward-syntactic-ws indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4327 (= (following-char) ?:))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4328 (skip-chars-forward " \t:")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4329 (c-add-syntax 'member-init-cont (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4330 ;; CASE 5D.3: perhaps a multiple inheritance line?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4331 ((looking-at c-inher-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4332 (c-add-syntax 'inher-cont (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4333 ;; CASE 5D.4: perhaps a template list continuation?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4334 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4335 (skip-chars-backward "^<" lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4336 ;; not sure if this is the right test, but it should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4337 ;; be fast and mostly accurate.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4338 (and (= (preceding-char) ?<)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4339 (not (c-in-literal lim))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4340 ;; we can probably indent it just like and arglist-cont
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4341 (c-add-syntax 'arglist-cont (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4342 ;; CASE 5D.5: perhaps a top-level statement-cont
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4343 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4344 (c-beginning-of-statement-1 lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4345 ;; skip over any access-specifiers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4346 (and inclass-p c-access-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4347 (while (looking-at c-access-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4348 (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4349 ;; skip over comments, whitespace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4350 (c-forward-syntactic-ws indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4351 (c-add-syntax 'statement-cont (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4352 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4353 ;; CASE 5E: we are looking at a access specifier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4354 ((and inclass-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4355 c-access-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4356 (looking-at c-access-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4357 (c-add-syntax 'access-label (c-point 'bonl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4358 (c-add-syntax 'inclass (aref inclass-p 0)))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4359 ;; CASE 5F: extern-lang-close?
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4360 ((and inextern-p
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4361 (= char-after-ip ?}))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4362 (c-add-syntax 'extern-lang-close (aref inclass-p 1)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4363 ;; CASE 5G: we are looking at the brace which closes the
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4364 ;; enclosing nested class decl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4365 ((and inclass-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4366 (= char-after-ip ?})
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4367 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4368 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4369 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4370 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4371 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4372 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4373 (progn (backward-sexp 1) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4374 (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4375 (= (point) (aref inclass-p 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4376 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4377 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4378 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4379 (goto-char (aref inclass-p 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4380 (c-add-syntax 'class-close (c-point 'boi))))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4381 ;; CASE 5H: we could be looking at subsequent knr-argdecls
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4382 ((and c-recognize-knr-p
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4383 ;; here we essentially use the hack that is used in
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4384 ;; Emacs' c-mode.el to limit how far back we should
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4385 ;; look. The assumption is made that argdecls are
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4386 ;; indented at least one space and that function
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4387 ;; headers are not indented.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4388 (let ((limit (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4389 (re-search-backward "^[^ \^L\t\n#]" nil 'move)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4390 (point))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4391 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4392 (c-backward-syntactic-ws limit)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4393 (setq placeholder (point))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4394 (while (and (memq (preceding-char) '(?\; ?,))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4395 (> (point) limit))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4396 (beginning-of-line)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4397 (setq placeholder (point))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4398 (c-backward-syntactic-ws limit))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4399 (and (= (preceding-char) ?\))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4400 (or (not c-method-key)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4401 (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4402 (forward-sexp -1)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4403 (forward-char -1)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4404 (c-backward-syntactic-ws)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4405 (not (or (= (preceding-char) ?-)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4406 (= (preceding-char) ?+)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4407 ;; or a class category
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4408 (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4409 (forward-sexp -2)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4410 (looking-at c-class-key))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4411 )))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4412 ))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4413 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4414 (c-beginning-of-statement-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4415 (not (looking-at "typedef[ \t\n]+"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4416 (goto-char placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4417 (c-add-syntax 'knr-argdecl (c-point 'boi)))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4418 ;; CASE 5I: we are at the topmost level, make sure we skip
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4419 ;; back past any access specifiers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4420 ((progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4421 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4422 (while (and inclass-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4423 c-access-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4424 (not (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4425 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4426 (c-safe (progn (backward-sexp 1) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4427 (looking-at c-access-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4428 (backward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4429 (c-backward-syntactic-ws lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4430 (or (bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4431 (memq (preceding-char) '(?\; ?\}))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4432 ;; real beginning-of-line could be narrowed out due to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4433 ;; enclosure in a class block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4434 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4435 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4436 (c-add-syntax 'topmost-intro (c-point 'bol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4437 (if inclass-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4438 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4439 (goto-char (aref inclass-p 1))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4440 (if inextern-p
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4441 (c-add-syntax 'inextern-lang)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4442 (c-add-syntax 'inclass (c-point 'boi)))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4443 ))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4444 ;; CASE 5J: we are at an ObjC or Java method definition
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4445 ;; continuation line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4446 ((and c-method-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4447 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4448 (c-beginning-of-statement-1 lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4449 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4450 (looking-at c-method-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4451 (c-add-syntax 'objc-method-args-cont (point)))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4452 ;; CASE 5K: we are at a topmost continuation line
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4453 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4454 (c-beginning-of-statement-1 lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4455 (c-forward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4456 (c-add-syntax 'topmost-intro-cont (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4457 )) ; end CASE 5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4458 ;; CASE 6: line is an expression, not a statement. Most
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4459 ;; likely we are either in a function prototype or a function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4460 ;; call argument list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4461 ((/= (char-after containing-sexp) ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4462 (c-backward-syntactic-ws containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4463 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4464 ;; CASE 6A: we are looking at the arglist closing paren or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4465 ;; at an Objective-C or Java method call closing bracket.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4466 ((and (/= char-before-ip ?,)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4467 (memq char-after-ip '(?\) ?\])))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4468 (if (and c-method-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4469 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4470 (goto-char (1- containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4471 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4472 (not (looking-at c-symbol-key))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4473 (c-add-syntax 'statement-cont containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4474 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4475 (c-add-syntax 'arglist-close (c-point 'boi))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4476 ;; CASE 6B: we are looking at the first argument in an empty
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4477 ;; argument list. Use arglist-close if we're actually
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4478 ;; looking at a close paren or bracket.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4479 ((memq char-before-ip '(?\( ?\[))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4480 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4481 (c-add-syntax 'arglist-intro (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4482 ;; CASE 6C: we are inside a conditional test clause. treat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4483 ;; these things as statements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4484 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4485 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4486 (and (c-safe (progn (forward-sexp -1) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4487 (looking-at "\\<for\\>")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4488 (goto-char (1+ containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4489 (c-forward-syntactic-ws indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4490 (c-beginning-of-statement-1 containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4491 (if (= char-before-ip ?\;)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4492 (c-add-syntax 'statement (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4493 (c-add-syntax 'statement-cont (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4494 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4495 ;; CASE 6D: maybe a continued method call. This is the case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4496 ;; when we are inside a [] bracketed exp, and what precede
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4497 ;; the opening bracket is not an identifier.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4498 ((and c-method-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4499 (= (char-after containing-sexp) ?\[)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4500 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4501 (goto-char (1- containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4502 (c-backward-syntactic-ws (c-point 'bod))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4503 (if (not (looking-at c-symbol-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4504 (c-add-syntax 'objc-method-call-cont containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4505 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4506 ;; CASE 6E: we are looking at an arglist continuation line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4507 ;; but the preceding argument is on the same line as the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4508 ;; opening paren. This case includes multi-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4509 ;; mathematical paren groupings, but we could be on a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4510 ;; for-list continuation line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4511 ((and (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4512 (goto-char (1+ containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4513 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4514 (not (eolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4515 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4516 (c-beginning-of-statement-1 lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4517 (skip-chars-backward " \t([")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4518 (<= (point) containing-sexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4519 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4520 (c-add-syntax 'arglist-cont-nonempty (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4521 ;; CASE 6F: we are looking at just a normal arglist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4522 ;; continuation line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4523 (t (c-beginning-of-statement-1 containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4524 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4525 (c-forward-syntactic-ws indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4526 (c-add-syntax 'arglist-cont (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4527 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4528 ;; CASE 7: func-local multi-inheritance line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4529 ((and c-baseclass-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4530 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4531 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4532 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4533 (looking-at c-baseclass-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4534 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4535 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4536 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4537 ;; CASE 7A: non-hanging colon on an inher intro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4538 ((= char-after-ip ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4539 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4540 (c-add-syntax 'inher-intro (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4541 ;; CASE 7B: hanging colon on an inher intro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4542 ((= char-before-ip ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4543 (c-add-syntax 'inher-intro (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4544 ;; CASE 7C: a continued inheritance line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4545 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4546 (c-beginning-of-inheritance-list lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4547 (c-add-syntax 'inher-cont (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4548 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4549 ;; CASE 8: we are inside a brace-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4550 ((setq placeholder (c-inside-bracelist-p containing-sexp state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4551 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4552 ;; CASE 8A: brace-list-close brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4553 ((and (= char-after-ip ?})
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4554 (c-safe (progn (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4555 (backward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4556 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4557 (= (point) containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4558 (c-add-syntax 'brace-list-close (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4559 ;; CASE 8B: we're looking at the first line in a brace-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4560 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4561 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4562 (c-backward-syntactic-ws containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4563 (= (point) (1+ containing-sexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4564 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4565 ;;(if (= char-after-ip ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4566 ;;(c-add-syntax 'brace-list-open (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4567 (c-add-syntax 'brace-list-intro (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4568 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4569 ;;)) ; end CASE 8B
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4570 ;; CASE 8C: this is just a later brace-list-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4571 (t (goto-char (1+ containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4572 (c-forward-syntactic-ws indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4573 (if (= char-after-ip ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4574 (c-add-syntax 'brace-list-open (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4575 (c-add-syntax 'brace-list-entry (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4576 )) ; end CASE 8C
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4577 )) ; end CASE 8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4578 ;; CASE 9: A continued statement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4579 ((and (not (memq char-before-ip '(?\; ?} ?:)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4580 (> (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4581 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4582 (c-beginning-of-statement-1 containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4583 (setq placeholder (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4584 (/= placeholder containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4585 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4586 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4587 (let ((after-cond-placeholder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4588 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4589 (goto-char placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4590 (if (looking-at c-conditional-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4591 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4592 (c-safe (c-skip-conditional))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4593 (c-forward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4594 (if (memq (following-char) '(?\;))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4595 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4596 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4597 (c-forward-syntactic-ws)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4598 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4599 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4600 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4601 ;; CASE 9A: substatement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4602 ((and after-cond-placeholder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4603 (>= after-cond-placeholder indent-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4604 (goto-char placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4605 (if (= char-after-ip ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4606 (c-add-syntax 'substatement-open (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4607 (c-add-syntax 'substatement (c-point 'boi))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4608 ;; CASE 9B: open braces for class or brace-lists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4609 ((= char-after-ip ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4610 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4611 ;; CASE 9B.1: class-open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4612 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4613 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4614 (skip-chars-forward " \t{")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4615 (let ((decl (c-search-uplist-for-classkey (c-parse-state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4616 (and decl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4617 (setq placeholder (aref decl 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4618 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4619 (c-add-syntax 'class-open placeholder))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4620 ;; CASE 9B.2: brace-list-open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4621 ((or (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4622 (goto-char placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4623 (looking-at "\\<enum\\>"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4624 (= char-before-ip ?=))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4625 (c-add-syntax 'brace-list-open placeholder))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4626 ;; CASE 9B.3: catch-all for unknown construct.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4627 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4628 ;; Can and should I add an extensibility hook here?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4629 ;; Something like c-recognize-hook so support for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4630 ;; unknown constructs could be added. It's probably a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4631 ;; losing proposition, so I dunno.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4632 (goto-char placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4633 (c-add-syntax 'statement-cont (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4634 (c-add-syntax 'block-open))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4635 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4636 ;; CASE 9C: iostream insertion or extraction operator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4637 ((looking-at "<<\\|>>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4638 (goto-char placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4639 (and after-cond-placeholder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4640 (goto-char after-cond-placeholder))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4641 (while (and (re-search-forward "<<\\|>>" indent-point 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4642 (c-in-literal placeholder)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4643 ;; if we ended up at indent-point, then the first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4644 ;; streamop is on a separate line. Indent the line like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4645 ;; a statement-cont instead
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4646 (if (/= (point) indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4647 (c-add-syntax 'stream-op (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4648 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4649 (c-add-syntax 'statement-cont (c-point 'boi))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4650 ;; CASE 9D: continued statement. find the accurate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4651 ;; beginning of statement or substatement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4652 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4653 (c-beginning-of-statement-1 after-cond-placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4654 ;; KLUDGE ALERT! c-beginning-of-statement-1 can leave
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4655 ;; us before the lim we're passing in. It should be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4656 ;; fixed, but I'm worried about side-effects at this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4657 ;; late date. Fix for v5.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4658 (goto-char (or (and after-cond-placeholder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4659 (max after-cond-placeholder (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4660 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4661 (c-add-syntax 'statement-cont (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4662 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4663 ;; CASE 10: an else clause?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4664 ((looking-at "\\<else\\>[^_]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4665 (c-backward-to-start-of-if containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4666 (c-add-syntax 'else-clause (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4667 ;; CASE 11: Statement. But what kind? Lets see if its a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4668 ;; while closure of a do/while construct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4669 ((progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4670 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4671 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4672 (and (looking-at "while\\b[^_]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4673 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4674 (c-backward-to-start-of-do containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4675 (setq placeholder (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4676 (looking-at "do\\b[^_]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4677 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4678 (c-add-syntax 'do-while-closure placeholder))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4679 ;; CASE 12: A case or default label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4680 ((looking-at c-switch-label-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4681 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4682 ;; check for hanging braces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4683 (if (/= (point) (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4684 (forward-sexp -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4685 (c-add-syntax 'case-label (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4686 ;; CASE 13: any other label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4687 ((looking-at c-label-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4688 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4689 (c-add-syntax 'label (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4690 ;; CASE 14: block close brace, possibly closing the defun or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4691 ;; the class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4692 ((= char-after-ip ?})
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4693 (let* ((lim (c-safe-position containing-sexp fullstate))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4694 (relpos (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4695 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4696 (if (/= (point) (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4697 (c-beginning-of-statement-1 lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4698 (c-point 'boi))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4699 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4700 ;; CASE 14A: does this close an inline?
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4701 ((let ((inclass-p (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4702 (goto-char containing-sexp)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4703 (c-search-uplist-for-classkey state))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4704 ;; inextern-p in higher level let*
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4705 (setq inextern-p (and inclass-p
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4706 (progn
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4707 (goto-char (aref inclass-p 0))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4708 (looking-at "extern[^_]"))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4709 (and inclass-p (not inextern-p)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4710 (c-add-syntax 'inline-close relpos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4711 ;; CASE 14B: if there an enclosing brace that hasn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4712 ;; been narrowed out by a class, then this is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4713 ;; block-close
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4714 ((and (not inextern-p)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4715 (c-most-enclosing-brace state))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4716 (c-add-syntax 'block-close relpos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4717 ;; CASE 14C: find out whether we're closing a top-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4718 ;; class or a defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4719 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4720 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4721 (narrow-to-region (point-min) indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4722 (let ((decl (c-search-uplist-for-classkey (c-parse-state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4723 (if decl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4724 (c-add-syntax 'class-close (aref decl 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4725 (c-add-syntax 'defun-close relpos)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4726 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4727 ;; CASE 15: statement catchall
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4728 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4729 ;; we know its a statement, but we need to find out if it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4730 ;; the first statement in a block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4731 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4732 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4733 (c-forward-syntactic-ws indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4734 ;; now skip forward past any case/default clauses we might find.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4735 (while (or (c-skip-case-statement-forward fullstate indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4736 (and (looking-at c-switch-label-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4737 (not inswitch-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4738 (setq inswitch-p t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4739 ;; we want to ignore non-case labels when skipping forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4740 (while (and (looking-at c-label-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4741 (goto-char (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4742 (c-forward-syntactic-ws indent-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4743 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4744 ;; CASE 15A: we are inside a case/default clause inside a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4745 ;; switch statement. find out if we are at the statement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4746 ;; just after the case/default label.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4747 ((and inswitch-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4748 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4749 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4750 (c-backward-syntactic-ws containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4751 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4752 (setq placeholder (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4753 (looking-at c-switch-label-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4754 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4755 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4756 (if (= (following-char) ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4757 (c-add-syntax 'statement-case-open placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4758 (c-add-syntax 'statement-case-intro placeholder)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4759 ;; CASE 15B: continued statement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4760 ((= char-before-ip ?,)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4761 (c-add-syntax 'statement-cont (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4762 ;; CASE 15C: a question/colon construct? But make sure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4763 ;; what came before was not a label, and what comes after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4764 ;; is not a globally scoped function call!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4765 ((or (and (memq char-before-ip '(?: ??))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4766 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4767 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4768 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4769 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4770 (not (looking-at c-label-key))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4771 (and (memq char-after-ip '(?: ??))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4772 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4773 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4774 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4775 ;; watch out for scope operator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4776 (not (looking-at "::")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4777 (c-add-syntax 'statement-cont (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4778 ;; CASE 15D: any old statement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4779 ((< (point) indent-point)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4780 (let ((safepos (c-most-enclosing-brace fullstate))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4781 relpos done)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4782 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4783 (c-beginning-of-statement-1 safepos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4784 ;; It is possible we're on the brace that opens a nested
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4785 ;; function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4786 (if (and (= (following-char) ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4787 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4788 (c-backward-syntactic-ws safepos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4789 (/= (preceding-char) ?\;)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4790 (c-beginning-of-statement-1 safepos))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4791 (if (and inswitch-p
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4792 (looking-at c-switch-label-key))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4793 (progn
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4794 (goto-char placeholder)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4795 (end-of-line)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4796 (forward-sexp -1)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4797 (setq relpos (c-point 'boi))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4798 (while (and (not done)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4799 (<= safepos (point))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4800 (/= relpos (point)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4801 (c-beginning-of-statement-1 safepos)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4802 (if (= relpos (c-point 'boi))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4803 (setq done t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4804 (setq relpos (c-point 'boi)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
4805 (c-add-syntax 'statement relpos)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4806 (if (= char-after-ip ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4807 (c-add-syntax 'block-open))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4808 ;; CASE 15E: first statement in an inline, or first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4809 ;; statement in a top-level defun. we can tell this is it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4810 ;; if there are no enclosing braces that haven't been
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4811 ;; narrowed out by a class (i.e. don't use bod here!)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4812 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4813 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4814 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4815 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4816 (c-narrow-out-enclosing-class state containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4817 (not (c-most-enclosing-brace state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4818 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4819 ;; if not at boi, then defun-opening braces are hung on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4820 ;; right side, so we need a different relpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4821 (if (/= (point) (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4822 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4823 (c-backward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4824 (c-safe (forward-sexp (if (= (preceding-char) ?\))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4825 -1 -2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4826 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4827 (c-add-syntax 'defun-block-intro (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4828 ;; CASE 15F: first statement in a block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4829 (t (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4830 (if (/= (point) (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4831 (c-beginning-of-statement-1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4832 (if (= (point) lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4833 (c-safe-position (point) state) lim)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4834 (c-add-syntax 'statement-block-intro (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4835 (if (= char-after-ip ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4836 (c-add-syntax 'block-open)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4837 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4838 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4839
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4840 ;; now we need to look at any modifiers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4841 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4842 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4843 ;; are we looking at a comment only line?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4844 (if (looking-at c-comment-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4845 (c-add-syntax 'comment-intro))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4846 ;; we might want to give additional offset to friends (in C++).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4847 (if (and (eq major-mode 'c++-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4848 (looking-at c-C++-friend-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4849 (c-add-syntax 'friend))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4850 ;; return the syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4851 syntax))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4852
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4853
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4854 ;; indent via syntactic language elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4855 (defun c-get-offset (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4856 ;; Get offset from LANGELEM which is a cons cell of the form:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4857 ;; (SYMBOL . RELPOS). The symbol is matched against
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4858 ;; c-offsets-alist and the offset found there is either returned,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4859 ;; or added to the indentation at RELPOS. If RELPOS is nil, then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4860 ;; the offset is simply returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4861 (let* ((symbol (car langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4862 (relpos (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4863 (match (assq symbol c-offsets-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4864 (offset (cdr-safe match)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4865 ;; offset can be a number, a function, a variable, or one of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4866 ;; symbols + or -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4867 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4868 ((not match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4869 (if c-strict-syntax-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4870 (error "don't know how to indent a %s" symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4871 (setq offset 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4872 relpos 0)))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4873 ((eq offset '+) (setq offset c-basic-offset))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4874 ((eq offset '-) (setq offset (- c-basic-offset)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4875 ((eq offset '++) (setq offset (* 2 c-basic-offset)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4876 ((eq offset '--) (setq offset (* 2 (- c-basic-offset))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4877 ((eq offset '*) (setq offset (/ c-basic-offset 2)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4878 ((eq offset '/) (setq offset (/ (- c-basic-offset) 2)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4879 ((c-functionp offset) (setq offset (funcall offset langelem)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4880 ((not (numberp offset)) (setq offset (symbol-value offset)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4881 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4882 (+ (if (and relpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4883 (< relpos (c-point 'bol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4884 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4885 (goto-char relpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4886 (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4887 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4888 offset)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4889
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4890 (defun c-indent-line (&optional syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4891 ;; indent the current line as C/C++/ObjC code. Optional SYNTAX is the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4892 ;; syntactic information for the current line. Returns the amount of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4893 ;; indentation change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4894 (let* ((c-syntactic-context (or syntax (c-guess-basic-syntax)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4895 (pos (- (point-max) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4896 (indent (apply '+ (mapcar 'c-get-offset c-syntactic-context)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4897 (shift-amt (- (current-indentation) indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4898 (and c-echo-syntactic-information-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4899 (message "syntax: %s, indent= %d" c-syntactic-context indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4900 (if (zerop shift-amt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4901 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4902 (delete-region (c-point 'bol) (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4903 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4904 (indent-to indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4905 (if (< (point) (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4906 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4907 ;; If initial point was within line's indentation, position after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4908 ;; the indentation. Else stay at same point in text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4909 (if (> (- (point-max) pos) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4910 (goto-char (- (point-max) pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4911 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4912 (run-hooks 'c-special-indent-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4913 shift-amt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4914
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4915 (defun c-show-syntactic-information (arg)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4916 "Show syntactic information for current line.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4917 With universal argument, inserts the analysis as a comment on that line."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4918 (interactive "P")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4919 (let ((syntax (c-guess-basic-syntax)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4920 (if (not (consp arg))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4921 (message "syntactic analysis: %s" (c-guess-basic-syntax))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4922 (indent-for-comment)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4923 (insert (format "%s" syntax))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4924 ))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4925 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4926
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4927
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4928 ;; Standard indentation line-ups
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4929 (defun c-lineup-arglist (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4930 ;; lineup the current arglist line with the arglist appearing just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4931 ;; after the containing paren which starts the arglist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4932 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4933 (let* ((containing-sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4934 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4935 ;; arglist-cont-nonempty gives relpos ==
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4936 ;; to boi of containing-sexp paren. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4937 ;; is good when offset is +, but bad
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4938 ;; when it is c-lineup-arglist, so we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4939 ;; have to special case a kludge here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4940 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4941 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4942 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4943 (backward-up-list 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4944 (skip-chars-forward " \t" (c-point 'eol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4945 (goto-char (cdr langelem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4946 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4947 (cs-curcol (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4948 (goto-char (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4949 (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4950 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4951 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4952 (looking-at "[ \t]*)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4953 (progn (goto-char (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4954 (forward-sexp -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4955 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4956 (c-forward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4957 (- (current-column) cs-curcol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4958 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4959 (or (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4960 (not (memq (following-char) '(?{ ?\( )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4961 (let ((eol (c-point 'eol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4962 (here (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4963 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4964 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4965 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4966 (c-forward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4967 (if (< (point) eol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4968 (goto-char here))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4969 (- (current-column) cs-curcol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4970 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4971
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4972 (defun c-lineup-arglist-intro-after-paren (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4973 ;; lineup an arglist-intro line to just after the open paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4974 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4975 (let ((cs-curcol (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4976 (goto-char (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4977 (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4978 (ce-curcol (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4979 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4980 (backward-up-list 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4981 (skip-chars-forward " \t" (c-point 'eol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4982 (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4983 (- ce-curcol cs-curcol -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4984
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4985 (defun c-lineup-arglist-close-under-paren (langelem)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4986 ;; lineup an arglist-intro line to just after the open paren
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4987 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4988 (let ((cs-curcol (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4989 (goto-char (cdr langelem))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4990 (current-column)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4991 (ce-curcol (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4992 (beginning-of-line)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4993 (backward-up-list 1)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4994 (current-column))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4995 (- ce-curcol cs-curcol))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
4996
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4997 (defun c-lineup-streamop (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4998 ;; lineup stream operators
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4999 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5000 (let* ((relpos (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5001 (curcol (progn (goto-char relpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5002 (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5003 (re-search-forward "<<\\|>>" (c-point 'eol) 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5004 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5005 (- (current-column) curcol))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5006
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5007 (defun c-lineup-multi-inher (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5008 ;; line up multiple inheritance lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5009 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5010 (let (cs-curcol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5011 (eol (c-point 'eol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5012 (here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5013 (goto-char (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5014 (setq cs-curcol (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5015 (skip-chars-forward "^:" eol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5016 (skip-chars-forward " \t:" eol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5017 (if (or (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5018 (looking-at c-comment-start-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5019 (c-forward-syntactic-ws here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5020 (- (current-column) cs-curcol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5021 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5022
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5023 (defun c-lineup-java-inher (langelem)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5024 ;; line up Java implements and extends continuations
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5025 (save-excursion
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5026 (let ((cs-curcol (progn (goto-char (cdr langelem))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5027 (current-column))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5028 (forward-word 1)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5029 (if (looking-at "[ \t]*$")
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5030 cs-curcol
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5031 (c-forward-syntactic-ws)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5032 (- (current-column) cs-curcol)))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5033
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5034 (defun c-lineup-C-comments (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5035 ;; line up C block comment continuation lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5036 (save-excursion
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5037 (let ((here (point))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5038 (stars (progn (back-to-indentation)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5039 (skip-chars-forward "*")))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5040 (cs-curcol (progn (goto-char (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5041 (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5042 (back-to-indentation)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5043 (if (not (re-search-forward "/[*]+" (c-point 'eol) t))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5044 (progn
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5045 (if (not (looking-at "[*]+"))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5046 (progn
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5047 ;; we now have to figure out where this comment begins.
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5048 (goto-char here)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5049 (back-to-indentation)
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
5050 (if (looking-at "[*]+/")
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
5051 (progn (goto-char (match-end 0))
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
5052 (forward-comment -1))
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5053 (goto-char (cdr langelem))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5054 (back-to-indentation))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5055 (- (current-column) cs-curcol))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5056 (if (zerop stars)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5057 (skip-chars-forward " \t"))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5058 (- (current-column) stars cs-curcol))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5059 )))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5060
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5061 (defun c-lineup-comment (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5062 ;; support old behavior for comment indentation. we look at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5063 ;; c-comment-only-line-offset to decide how to indent comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5064 ;; only-lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5065 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5066 (back-to-indentation)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5067 ;; this highly kludgiforous flag prevents the mapcar over
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5068 ;; c-syntactic-context from entering an infinite loop
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5069 (let ((recurse-prevention-flag (boundp 'recurse-prevention-flag)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5070 (cond
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5071 ;; CASE 1: preserve comment-column
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5072 (recurse-prevention-flag 0)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5073 ((= (current-column) comment-column)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5074 ;; we have to subtract out all other indentation
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5075 (- comment-column (apply '+ (mapcar 'c-get-offset
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5076 c-syntactic-context))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5077 ;; indent as specified by c-comment-only-line-offset
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5078 ((not (bolp))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5079 (or (car-safe c-comment-only-line-offset)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5080 c-comment-only-line-offset))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5081 (t
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5082 (or (cdr-safe c-comment-only-line-offset)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5083 (car-safe c-comment-only-line-offset)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5084 -1000)) ;jam it against the left side
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5085 ))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5086
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5087 (defun c-lineup-runin-statements (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5088 ;; line up statements in coding standards which place the first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5089 ;; statement on the same line as the block opening brace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5090 (if (= (char-after (cdr langelem)) ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5091 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5092 (let ((curcol (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5093 (goto-char (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5094 (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5095 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5096 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5097 (- (current-column) curcol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5098 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5099
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5100 (defun c-lineup-math (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5101 ;; line up math statement-cont after the equals
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5102 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5103 (let* ((relpos (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5104 (equalp (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5105 (goto-char (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5106 (skip-chars-forward "^=" (c-point 'eol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5107 (and (= (following-char) ?=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5108 (- (point) (c-point 'boi)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5109 (curcol (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5110 (goto-char relpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5111 (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5112 donep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5113 (while (and (not donep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5114 (< (point) (c-point 'eol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5115 (skip-chars-forward "^=" (c-point 'eol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5116 (if (c-in-literal (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5117 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5118 (setq donep t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5119 (if (/= (following-char) ?=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5120 ;; there's no equal sign on the line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5121 c-basic-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5122 ;; calculate indentation column after equals and ws, unless
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5123 ;; our line contains an equals sign
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5124 (if (not equalp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5125 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5126 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5127 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5128 (setq equalp 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5129 (- (current-column) equalp curcol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5130 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5132 (defun c-lineup-ObjC-method-call (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5133 ;; Line up methods args as elisp-mode does with function args: go to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5134 ;; the position right after the message receiver, and if you are at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5135 ;; (eolp) indent the current line by a constant offset from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5136 ;; opening bracket; otherwise we are looking at the first character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5137 ;; of the first method call argument, so lineup the current line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5138 ;; with it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5139 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5140 (let* ((extra (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5141 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5142 (c-backward-syntactic-ws (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5143 (if (= (preceding-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5144 (- c-basic-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5145 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5146 (open-bracket-pos (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5147 (open-bracket-col (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5148 (goto-char open-bracket-pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5149 (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5150 (target-col (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5151 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5152 (forward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5153 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5154 (if (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5155 (+ open-bracket-col c-basic-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5156 (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5157 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5158 (- target-col open-bracket-col extra))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5160 (defun c-lineup-ObjC-method-args (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5161 ;; Line up the colons that separate args. This is done trying to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5162 ;; align colons vertically.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5163 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5164 (let* ((here (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5165 (curcol (progn (goto-char here) (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5166 (eol (c-point 'eol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5167 (relpos (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5168 (first-col-column (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5169 (goto-char relpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5170 (skip-chars-forward "^:" eol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5171 (and (= (following-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5172 (current-column)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5173 (if (not first-col-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5174 c-basic-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5175 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5176 (skip-chars-forward "^:" eol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5177 (if (= (following-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5178 (+ curcol (- first-col-column (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5179 c-basic-offset)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5180
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5181 (defun c-lineup-ObjC-method-args-2 (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5182 ;; Line up the colons that separate args. This is done trying to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5183 ;; align the colon on the current line with the previous one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5184 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5185 (let* ((here (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5186 (curcol (progn (goto-char here) (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5187 (eol (c-point 'eol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5188 (relpos (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5189 (prev-col-column (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5190 (skip-chars-backward "^:" relpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5191 (and (= (preceding-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5192 (- (current-column) 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5193 (if (not prev-col-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5194 c-basic-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5195 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5196 (skip-chars-forward "^:" eol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5197 (if (= (following-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5198 (+ curcol (- prev-col-column (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5199 c-basic-offset)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5201 (defun c-snug-do-while (syntax pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5202 "Dynamically calculate brace hanginess for do-while statements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5203 Using this function, `while' clauses that end a `do-while' block will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5204 remain on the same line as the brace that closes that block.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5205
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5206 See `c-hanging-braces-alist' for how to utilize this function as an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5207 ACTION associated with `block-close' syntax."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5208 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5209 (let (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5210 (if (and (eq syntax 'block-close)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5211 (setq langelem (assq 'block-close c-syntactic-context))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5212 (progn (goto-char (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5213 (if (= (following-char) ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5214 (c-safe (forward-sexp -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5215 (looking-at "\\<do\\>[^_]")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5216 '(before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5217 '(before after)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5218
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5219 (defun c-gnu-impose-minimum ()
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5220 "Imposes a minimum indentation for lines inside a top-level construct.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5221 The variable `c-label-minimum-indentation' specifies the minimum
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5222 indentation amount."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5223 (let ((non-top-levels '(defun-block-intro statement statement-cont
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5224 statement-block-intro statement-case-intro
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5225 statement-case-open substatement substatement-open
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5226 case-label label do-while-closure else-clause
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5227 ))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5228 (syntax c-syntactic-context)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5229 langelem)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5230 (while syntax
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5231 (setq langelem (car (car syntax))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5232 syntax (cdr syntax))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5233 ;; don't adjust comment-only lines
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5234 (cond ((eq langelem 'comment-intro)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5235 (setq syntax nil))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5236 ((memq langelem non-top-levels)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5237 (save-excursion
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5238 (setq syntax nil)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5239 (back-to-indentation)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5240 (if (zerop (current-column))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5241 (insert (make-string c-label-minimum-indentation 32)))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5242 ))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5243 ))))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5244
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5246 ;;; This page handles insertion and removal of backslashes for C macros.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5247
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5248 (defun c-backslash-region (from to delete-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5249 "Insert, align, or delete end-of-line backslashes on the lines in the region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5250 With no argument, inserts backslashes and aligns existing backslashes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5251 With an argument, deletes the backslashes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5252
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
5253 This function does not modify blank lines at the start of the region.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
5254 If the region ends at the start of a line, it always deletes the
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
5255 backslash (if any) at the end of the previous line.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
5256
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
5257 You can put the region around an entire macro definition and use this
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
5258 command to conveniently insert and align the necessary backslashes."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5259 (interactive "r\nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5260 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5261 (goto-char from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5262 (let ((column c-backslash-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5263 (endmark (make-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5264 (move-marker endmark to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5265 ;; Compute the smallest column number past the ends of all the lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5266 (if (not delete-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5267 (while (< (point) to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5268 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5269 (if (= (preceding-char) ?\\)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5270 (progn (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5271 (skip-chars-backward " \t")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5272 (setq column (max column (1+ (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5273 (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5274 ;; Adjust upward to a tab column, if that doesn't push past the margin.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5275 (if (> (% column tab-width) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5276 (let ((adjusted (* (/ (+ column tab-width -1) tab-width) tab-width)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5277 (if (< adjusted (window-width))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5278 (setq column adjusted))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5279 ;; Don't modify blank lines at start of region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5280 (goto-char from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5281 (while (and (< (point) endmark) (eolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5282 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5283 ;; Add or remove backslashes on all the lines.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
5284 (while (< (point) endmark)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
5285 (if (and (not delete-flag)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
5286 ;; Un-backslashify the last line
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
5287 ;; if the region ends right at the start of the next line.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
5288 (save-excursion
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
5289 (forward-line 1)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
5290 (< (point) endmark)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5291 (c-append-backslash column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5292 (c-delete-backslash))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5293 (forward-line 1))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
5294 (move-marker endmark nil)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
5295 (c-keep-region-active))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5296
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5297 (defun c-append-backslash (column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5298 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5299 ;; Note that "\\\\" is needed to get one backslash.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5300 (if (= (preceding-char) ?\\)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5301 (progn (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5302 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5303 (indent-to column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5304 (indent-to column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5305 (insert "\\")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5307 (defun c-delete-backslash ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5308 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5309 (or (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5310 (progn
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5311 (forward-char -1)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5312 (if (looking-at "\\\\")
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5313 (delete-region (1+ (point))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5314 (progn (skip-chars-backward " \t") (point)))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5315
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5316
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5317 ;; defuns for submitting bug reports
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5318
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
5319 (defconst c-version "4.390"
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5320 "CC Mode version number.")
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5321 (defconst c-mode-help-address
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5322 "bug-gnu-emacs@prep.ai.mit.edu, cc-mode-help@python.org"
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5323 "Address for CC Mode bug reports.")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5325 (defun c-version ()
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5326 "Echo the current version of CC Mode in the minibuffer."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5327 (interactive)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5328 (message "Using CC Mode version %s" c-version)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5329 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5330
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5331 ;; get reporter-submit-bug-report when byte-compiling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5332 (eval-when-compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5333 (require 'reporter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5334
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5335 (defun c-submit-bug-report ()
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5336 "Submit via mail a bug report on CC Mode."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5337 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5338 ;; load in reporter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5339 (let ((reporter-prompt-for-summary-p t)
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
5340 (reporter-dont-compact-list '(c-offsets-alist))
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
5341 (style c-indentation-style)
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
5342 (hook c-special-indent-hook)
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
5343 (c-features c-emacs-features))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5344 (and
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5345 (if (y-or-n-p "Do you want to submit a report on CC Mode? ")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5346 t (message "") nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5347 (require 'reporter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5348 (reporter-submit-bug-report
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5349 c-mode-help-address
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5350 (concat "CC Mode " c-version " ("
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5351 (cond ((eq major-mode 'c++-mode) "C++")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5352 ((eq major-mode 'c-mode) "C")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5353 ((eq major-mode 'objc-mode) "ObjC")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5354 ((eq major-mode 'java-mode) "Java")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5355 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5356 ")")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5357 (let ((vars (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5358 ;; report only the vars that affect indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5359 'c-basic-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5360 'c-offsets-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5361 'c-cleanup-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5362 'c-comment-only-line-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5363 'c-backslash-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5364 'c-delete-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5365 'c-electric-pound-behavior
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5366 'c-hanging-braces-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5367 'c-hanging-colons-alist
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5368 'c-hanging-comment-starter-p
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5369 'c-hanging-comment-ender-p
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
5370 'c-indent-comments-syntactically-p
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5371 'c-tab-always-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5372 'c-recognize-knr-p
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5373 'c-label-minimum-indentation
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5374 'defun-prompt-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5375 'tab-width
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5376 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5377 (if (not (boundp 'defun-prompt-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5378 (delq 'defun-prompt-regexp vars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5379 vars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5380 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5381 (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5382 (insert
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
5383 "Buffer Style: " style "\n\n"
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
5384 (if hook
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5385 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5386 "c-special-indent-hook is set to '"
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
5387 (format "%s" hook)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5388 ".\nPerhaps this is your problem?\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5389 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5390 "\n")
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
5391 (format "c-emacs-features: %s\n" c-features)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5392 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5393 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5394 "Dear Barry,"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5395 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5396
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5398 ;; menus for XEmacs 19
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5399 (defun c-mode-menu ()
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5400 (cons (concat mode-name " Mode Commands") c-mode-menu))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5401
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5402 (defun c-popup-menu (e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5403 "Pops up the C/C++/ObjC menu."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5404 (interactive "@e")
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5405 (popup-menu (c-mode-menu))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5406 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5408
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5409 ;; Emacs/XEmacs Compatibility
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5410 ;; XEmacs has these, Emacs does not
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5411
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5412 (if (fboundp 'functionp)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5413 (defalias 'c-functionp 'functionp)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5414 ;; Lift XEmacs 19.13's functionp from subr.el
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5415 (defun c-functionp (obj)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5416 "Returns t if OBJ is a function, nil otherwise."
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5417 (cond
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5418 ((symbolp obj) (fboundp obj))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5419 ((subrp obj))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5420 ((compiled-function-p obj))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5421 ((consp obj)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5422 (if (eq (car obj) 'lambda) (listp (car (cdr obj)))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5423 (t nil))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5424
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5425 (if (fboundp 'copy-tree)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5426 (defalias 'c-copy-tree 'copy-tree)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5427 ;; Lift XEmacs 19.12's copy-tree
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5428 (defun c-copy-tree (tree)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5429 (if (consp tree)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5430 (cons (c-copy-tree (car tree))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5431 (c-copy-tree (cdr tree)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5432 (if (vectorp tree)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5433 (let* ((new (copy-sequence tree))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5434 (i (1- (length new))))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5435 (while (>= i 0)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5436 (aset new i (c-copy-tree (aref new i)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5437 (setq i (1- i)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5438 new)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5439 tree))))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5440
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5441
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5442 ;; Dynamically append the default value of most variables. This is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5443 ;; crucial because future c-set-style calls will always reset the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5444 ;; variables first to the `cc-mode' style before instituting the new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5445 ;; style. Only do this once!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5446 (or (assoc "cc-mode" c-style-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5447 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5448 (c-add-style "cc-mode"
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5449 (mapcar
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5450 (function
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5451 (lambda (var)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5452 (let ((val (symbol-value var)))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5453 (cons var (if (atom val) val
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5454 (c-copy-tree val)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5455 ))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5456 )))
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5457 '(c-backslash-column
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5458 c-basic-offset
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5459 c-cleanup-list
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5460 c-comment-only-line-offset
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5461 c-electric-pound-behavior
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5462 c-hanging-braces-alist
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5463 c-hanging-colons-alist
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5464 c-hanging-comment-starter-p
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5465 c-hanging-comment-ender-p
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5466 c-offsets-alist
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5467 )))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5468 ;; the default style is now GNU. This can be overridden in
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5469 ;; c-mode-common-hook or {c,c++,objc,java}-mode-hook.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5470 (c-set-style c-site-default-style)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5471
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5472 (if c-style-variables-are-local-p
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5473 (progn
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5474 ;; style variables
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5475 (make-variable-buffer-local 'c-offsets-alist)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5476 (make-variable-buffer-local 'c-basic-offset)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5477 (make-variable-buffer-local 'c-file-style)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5478 (make-variable-buffer-local 'c-file-offsets)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5479 (make-variable-buffer-local 'c-comment-only-line-offset)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5480 (make-variable-buffer-local 'c-cleanup-list)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5481 (make-variable-buffer-local 'c-hanging-braces-alist)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5482 (make-variable-buffer-local 'c-hanging-colons-alist)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5483 (make-variable-buffer-local 'c-hanging-comment-starter-p)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5484 (make-variable-buffer-local 'c-hanging-comment-ender-p)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5485 (make-variable-buffer-local 'c-backslash-column)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5486 (make-variable-buffer-local 'c-label-minimum-indentation)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5487 (make-variable-buffer-local 'c-special-indent-hook)
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5488 (make-variable-buffer-local 'c-indentation-style)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5491 ;; fsets for compatibility with BOCM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5492 (fset 'electric-c-brace 'c-electric-brace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5493 (fset 'electric-c-semi 'c-electric-semi&comma)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5494 (fset 'electric-c-sharp-sign 'c-electric-pound)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5495 ;; there is no CC Mode equivalent for electric-c-terminator
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5496 (fset 'mark-c-function 'c-mark-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5497 (fset 'indent-c-exp 'c-indent-exp)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 2
diff changeset
5498 ;;;###autoload (fset 'set-c-style 'c-set-style)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5499 ;; Lucid Emacs 19.9 + font-lock + CC Mode - c++-mode lossage
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5500 (fset 'c++-beginning-of-defun 'beginning-of-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5501 (fset 'c++-end-of-defun 'end-of-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5502
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5503 ;; set up bc warnings for obsolete variables, but for now lets not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5504 ;; worry about obsolete functions. maybe later some will be important
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5505 ;; to flag
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
5506 (and (or (memq 'v19 c-emacs-features) (memq 'v20 c-emacs-features))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5507 (let* ((na "Nothing appropriate.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5508 (vars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5509 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5510 (cons 'c++-c-mode-syntax-table 'c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5511 (cons 'c++-tab-always-indent 'c-tab-always-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5512 (cons 'c++-always-arglist-indent-p na)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5513 (cons 'c++-block-close-brace-offset 'c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5514 (cons 'c++-paren-as-block-close-p na)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5515 (cons 'c++-continued-member-init-offset 'c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5516 (cons 'c++-member-init-indent 'c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5517 (cons 'c++-friend-offset na)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5518 (cons 'c++-access-specifier-offset 'c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5519 (cons 'c++-empty-arglist-indent 'c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5520 (cons 'c++-comment-only-line-offset 'c-comment-only-line-offset)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5521 (cons 'c++-C-block-comments-indent-p na)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5522 (cons 'c++-cleanup-list 'c-cleanup-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5523 (cons 'c++-hanging-braces 'c-hanging-braces-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5524 (cons 'c++-hanging-member-init-colon 'c-hanging-colons-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5525 (cons 'c++-auto-hungry-initial-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5526 "Use `c-auto-newline' and `c-hungry-delete-key' instead.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5527 (cons 'c++-auto-hungry-toggle na)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5528 (cons 'c++-relative-offset-p na)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5529 (cons 'c++-special-indent-hook 'c-special-indent-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5530 (cons 'c++-delete-function 'c-delete-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5531 (cons 'c++-electric-pound-behavior 'c-electric-pound-behavior)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5532 (cons 'c++-hungry-delete-key 'c-hungry-delete-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5533 (cons 'c++-auto-newline 'c-auto-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5534 (cons 'c++-match-header-strongly na)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5535 (cons 'c++-defun-header-strong-struct-equivs na)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5536 (cons 'c++-version 'c-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5537 (cons 'c++-mode-help-address 'c-mode-help-address)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5538 (cons 'c-indent-level 'c-basic-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5539 (cons 'c-brace-imaginary-offset na)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5540 (cons 'c-brace-offset 'c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5541 (cons 'c-argdecl-indent 'c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5542 (cons 'c-label-offset 'c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5543 (cons 'c-continued-statement-offset 'c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5544 (cons 'c-continued-brace-offset 'c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5545 (cons 'c-default-macroize-column 'c-backslash-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5546 (cons 'c++-default-macroize-column 'c-backslash-column)
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 78
diff changeset
5547 (cons 'c-block-comments-indent-p na)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5548 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5549 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5550 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5551 (lambda (elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5552 (make-obsolete-variable (car elt) (cdr elt))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5553 vars)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5554
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5555 (provide 'cc-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5556 ;;; cc-mode.el ends here