annotate lisp/modes/cc-mode.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; cc-mode.el --- major mode for editing C, C++, and Objective-C code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 87, 92, 93, 94, 95, 96 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Authors: 1992-1996 Barry A. Warsaw
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; Version: 4.282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; Last Modified: 1996/02/09 23:15:14
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; This package provides modes in GNU Emacs for editing C, C++,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; Objective-C, and Java code. It is intended to be a replacement for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; c-mode.el (a.k.a. BOCM -- Boring Old C-Mode), and c++-mode.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; (a.k.a cplus-md.el and cplus-md1.el), both of which are ancestors
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; of this file. A number of important improvements have been made,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; briefly: complete K&R C, ANSI C, `ARM' C++, Objective-C, and Java
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; support with consistent indentation across all modes, more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; intuitive indentation controlling variables, compatibility across
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; all known Emacsen, nice new features, and tons of bug fixes. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; package is called "cc-mode" to distinguish it from its ancestors,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; but there really is no top-level cc-mode. Usage and programming
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; details are contained in an accompanying texinfo manual.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; To submit bug reports, type "C-c C-b". These will be sent to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; bug-gnu-emacs@prep.ai.mit.edu and I'll read about them there (this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; is mirrored as the Usenet newsgroup gnu.emacs.bug). Questions can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; sent to help-gnu-emacs@prep.ai.mit.edu (mirrored as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; gnu.emacs.help). Please do not send bugs or questions to my
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; personal account.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; YOU CAN IGNORE ALL BYTE-COMPILER WARNINGS. They are the result of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; the multi-Emacsen support. Emacs 19 (from the FSF), XEmacs 19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; (formerly Lucid Emacs), and GNU Emacs 18 all do things differently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; and there's no way to shut the byte-compiler up at the necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; granularity. Let me say this again: YOU CAN IGNORE ALL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;; BYTE-COMPILER WARNINGS (you'd be surprised at how many people don't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;; follow this advice :-).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; If your Emacs is dumped with c-mode.el and/or c++-mode.el, you will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;; need to add the following to your .emacs file before any other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;; reference to c-mode or c++-mode:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;; (fmakunbound 'c-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;; (makunbound 'c-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;; (fmakunbound 'c++-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;; (makunbound 'c++-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;; (makunbound 'c-style-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;; If your Emacs comes with cc-mode already (and as of 18-Jan-1996,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;; XEmacs 19.13 and Emacs 19.30 both do), you only need to add the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;; following to use the latest version of cc-mode:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;; (load "cc-mode")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;; Make sure the new version is earlier on your load-path.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;; There are four major mode entry points provided by this package,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;; one for editing C++ code, one for editing C code (both K&R and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;; ANSI), one for editing Objective-C code, and one for editing Java
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;; code. The commands are M-x c-mode, M-x c++-mode, M-x objc-mode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; and M-x java-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;; If you are using an old version of Emacs which does not come
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;; with cc-mode.el, you will need to do these things
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;; to use it:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;; (autoload 'c++-mode "cc-mode" "C++ Editing Mode" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;; (autoload 'c-mode "cc-mode" "C Editing Mode" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;; (autoload 'objc-mode "cc-mode" "Objective-C Editing Mode" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;; (autoload 'java-mode "cc-mode" "Java Editing Mode" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;; (setq auto-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;; (append '(("\\.C$" . c++-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;; ("\\.cc$" . c++-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;; ("\\.c$" . c-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;; ("\\.h$" . c-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;; ("\\.m$" . objc-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;; ("\\.java$" . java-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;; ) auto-mode-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;; You do not need these changes in Emacs versions that come with cc-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 ;; 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
107 ;; Without their patience, testing, insight, code contributions, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;; encouragement cc-mode.el would be a far inferior package.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;; Anonymous ftp URL:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;; ftp://ftp.python.org/pub/emacs/cc-mode.tar.gz
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;; user definable variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (defvar c-inhibit-startup-warnings-p nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 "*If non-nil, inhibits start up compatibility warnings.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (defvar c-strict-syntax-p nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 "*If non-nil, all syntactic symbols must be found in `c-offsets-alist'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 If the syntactic symbol for a particular line does not match a symbol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 in the offsets alist, an error is generated, otherwise no error is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 reported and the syntactic symbol is ignored.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (defvar c-echo-syntactic-information-p nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 "*If non-nil, syntactic info is echoed when the line is indented.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (defvar c-basic-offset 4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 "*Amount of basic offset used by + and - symbols in `c-offsets-alist'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (defvar c-offsets-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 '((string . -1000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (c . c-lineup-C-comments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (defun-open . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (defun-close . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (defun-block-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (class-open . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (class-close . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (inline-open . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (inline-close . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (ansi-funcdecl-cont . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (knr-argdecl-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (knr-argdecl . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (topmost-intro . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (topmost-intro-cont . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (member-init-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (member-init-cont . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (inher-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (inher-cont . c-lineup-multi-inher)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (block-open . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (block-close . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (brace-list-open . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (brace-list-close . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (brace-list-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (brace-list-entry . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (statement . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;; some people might prefer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ;;(statement . c-lineup-runin-statements)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (statement-cont . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ;; some people might prefer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ;;(statement-cont . c-lineup-math)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (statement-block-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (statement-case-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (statement-case-open . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (substatement . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (substatement-open . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (case-label . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (access-label . -)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (label . 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (do-while-closure . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (else-clause . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (comment-intro . c-lineup-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (arglist-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (arglist-cont . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (arglist-cont-nonempty . c-lineup-arglist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (arglist-close . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (stream-op . c-lineup-streamop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (inclass . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (cpp-macro . -1000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (friend . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (objc-method-intro . -1000)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (objc-method-args-cont . c-lineup-ObjC-method-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (objc-method-call-cont . c-lineup-ObjC-method-call)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 "*Association list of syntactic element symbols and indentation offsets.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 As described below, each cons cell in this list has the form:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (SYNTACTIC-SYMBOL . OFFSET)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 When a line is indented, cc-mode first determines the syntactic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 context of the line by generating a list of symbols called syntactic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 elements. This list can contain more than one syntactic element and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 the global variable `c-syntactic-context' contains the context list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 for the line being indented. Each element in this list is actually a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 cons cell of the syntactic symbol and a buffer position. This buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 position is called the relative indent point for the line. Some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 syntactic symbols may not have a relative indent point associated with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 After the syntactic context list for a line is generated, cc-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 calculates the absolute indentation for the line by looking at each
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 syntactic element in the list. First, it compares the syntactic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 element against the SYNTACTIC-SYMBOL's in `c-offsets-alist'. When it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 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
206 point. The sum of this calculation for each element in the syntactic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 list is the absolute offset for line being indented.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 If the syntactic element does not match any in the `c-offsets-alist',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 an error is generated if `c-strict-syntax-p' is non-nil, otherwise
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 the element is ignored.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 Actually, OFFSET can be an integer, a function, a variable, or one of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 the following symbols: `+', `-', `++', `--', `*', or `/'. These
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 latter designate positive or negative multiples of `c-basic-offset',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 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
217 function, it is called with a single argument containing the cons of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 the syntactic element symbol and the relative indent point. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 function should return an integer offset.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 Here is the current list of valid syntactic element symbols:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 string -- inside multi-line string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 c -- inside a multi-line C style block comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 defun-open -- brace that opens a function definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 defun-close -- brace that closes a function definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 defun-block-intro -- the first line in a top-level defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 class-open -- brace that opens a class definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 class-close -- brace that closes a class definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 inline-open -- brace that opens an in-class inline method
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 inline-close -- brace that closes an in-class inline method
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 ansi-funcdecl-cont -- the nether region between an ANSI function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 declaration and the defun opening brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 knr-argdecl-intro -- first line of a K&R C argument declaration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 knr-argdecl -- subsequent lines in a K&R C argument declaration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 topmost-intro -- the first line in a topmost construct definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 topmost-intro-cont -- topmost definition continuation lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 member-init-intro -- first line in a member initialization list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 member-init-cont -- subsequent member initialization list lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 inher-intro -- first line of a multiple inheritance list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 inher-cont -- subsequent multiple inheritance lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 block-open -- statement block open brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 block-close -- statement block close brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 brace-list-open -- open brace of an enum or static array list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 brace-list-close -- close brace of an enum or static array list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 brace-list-intro -- first line in an enum or static array list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 brace-list-entry -- subsequent lines in an enum or static array list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 statement -- a C/C++/ObjC statement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 statement-cont -- a continuation of a C/C++/ObjC statement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 statement-block-intro -- the first line in a new statement block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 statement-case-intro -- the first line in a case `block'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 statement-case-open -- the first line in a case block starting with brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 substatement -- the first line after an if/while/for/do/else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 substatement-open -- the brace that opens a substatement block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 case-label -- a case or default label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 access-label -- C++ private/protected/public access label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 label -- any non-special C/C++/ObjC label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 do-while-closure -- the `while' that ends a do/while construct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 else-clause -- the `else' of an if/else construct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 comment-intro -- a line containing only a comment introduction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 arglist-intro -- the first line in an argument list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 arglist-cont -- subsequent argument list lines when no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 arguments follow on the same line as the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 the arglist opening paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 arglist-cont-nonempty -- subsequent argument list lines when at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 least one argument follows on the same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 line as the arglist opening paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 arglist-close -- the solo close paren of an argument list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 stream-op -- lines continuing a stream operator construct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 inclass -- the construct is nested inside a class definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 cpp-macro -- the start of a cpp macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 friend -- a C++ friend declaration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 objc-method-intro -- the first line of an Objective-C method definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 objc-method-args-cont -- lines continuing an Objective-C method definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 objc-method-call-cont -- lines continuing an Objective-C method call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (defvar c-tab-always-indent t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 "*Controls the operation of the TAB key.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 If t, hitting TAB always just indents the current line. If nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 hitting TAB indents the current line if point is at the left margin or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 in the line's indentation, otherwise it insert a real tab character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 If other than nil or t, then tab is inserted only within literals
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 -- defined as comments and strings -- and inside preprocessor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 directives, but line is always reindented.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 Note that indentation of lines containing only comments is also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 controlled by the `c-comment-only-line-offset' variable.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (defvar c-comment-only-line-offset 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 "*Extra offset for line which contains only the start of a comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 Can contain an integer or a cons cell of the form:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (NON-ANCHORED-OFFSET . ANCHORED-OFFSET)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 Where NON-ANCHORED-OFFSET is the amount of offset given to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 non-column-zero anchored comment-only lines, and ANCHORED-OFFSET is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 the amount of offset to give column-zero anchored comment-only lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 Just an integer as value is equivalent to (<val> . -1000).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (defvar c-indent-comments-syntactically-p nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 "*Specifies how comment-only lines should be indented.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 When this variable is non-nil, comment-only lines are indented
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 according to syntactic analysis via `c-offsets-alist', even when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 \\[indent-for-comment] is used.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (defvar c-block-comments-indent-p nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 "*Specifies how to re-indent C style block comments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 Examples of the supported styles of C block comment indentation are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 shown below. When this variable is nil, block comments are indented
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 as shown in styles 1 through 4. If this variable is non-nil, block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 comments are indented as shown in style 5.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 Note that cc-mode does not automatically insert any stars or block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 comment delimiters. You must type these in manually. This variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 only controls how the lines within the block comment are indented when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 you hit ``\\[c-indent-command]''.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 style 1: style 2 (GNU): style 3: style 4: style 5:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 /* /* Blah /* /* /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 blah blah. */ * blah ** blah blah
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 blah * blah ** blah blah
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 */ */ */ */")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (defvar c-cleanup-list '(scope-operator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 "*List of various C/C++/ObjC constructs to \"clean up\".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 These clean ups only take place when the auto-newline feature is turned
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 on, as evidenced by the `/a' or `/ah' appearing next to the mode name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 Valid symbols are:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 brace-else-brace -- cleans up `} else {' constructs by placing entire
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 construct on a single line. This clean up only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 takes place when there is nothing but white
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 space between the braces and the `else'. Clean
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 up occurs when the open-brace after the `else'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 is typed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 empty-defun-braces -- cleans up empty defun braces by placing the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 braces on the same line. Clean up occurs when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 the defun closing brace is typed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 defun-close-semi -- cleans up the terminating semi-colon on defuns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 by placing the semi-colon on the same line as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 the closing brace. Clean up occurs when the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 semi-colon is typed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 list-close-comma -- cleans up commas following braces in array
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 and aggregate initializers. Clean up occurs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 when the comma is typed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 scope-operator -- cleans up double colons which may designate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 a C++ scope operator split across multiple
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 lines. Note that certain C++ constructs can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 generate ambiguous situations. This clean up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 only takes place when there is nothing but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 whitespace between colons. Clean up occurs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 when the second colon is typed.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (defvar c-hanging-braces-alist '((brace-list-open)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (substatement-open after)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (block-close . c-snug-do-while))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 "*Controls the insertion of newlines before and after braces.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 This variable contains an association list with elements of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 following form: (SYNTACTIC-SYMBOL . ACTION).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 When a brace (either opening or closing) is inserted, the syntactic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 context it defines is looked up in this list, and if found, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 associated ACTION is used to determine where newlines are inserted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 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
367 before and after the brace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 SYNTACTIC-SYMBOL can be any of: defun-open, defun-close, class-open,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 class-close, inline-open, inline-close, block-open, block-close,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 substatement-open, statement-case-open, brace-list-open,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 brace-list-close, brace-list-intro, or brace-list-entry. See
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 `c-offsets-alist' for details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 ACTION can be either a function symbol or a list containing any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 combination of the symbols `before' or `after'. If the list is empty,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 no newlines are inserted either before or after the brace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 When ACTION is a function symbol, the function is called with a two
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 arguments: the syntactic symbol for the brace and the buffer position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 at which the brace was inserted. The function must return a list as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 described in the preceding paragraph. Note that during the call to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 the function, the variable `c-syntactic-context' is set to the entire
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 syntactic context for the brace line.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 (defvar c-hanging-colons-alist nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 "*Controls the insertion of newlines before and after certain colons.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 This variable contains an association list with elements of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 following form: (SYNTACTIC-SYMBOL . ACTION).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 See the variable `c-hanging-braces-alist' for the semantics of this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 variable. Note however that making ACTION a function symbol is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 currently not supported for this variable.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (defvar c-hanging-semi&comma-criteria '(c-semi&comma-inside-parenlist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 "*List of functions that decide whether to insert a newline or not.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 The functions in this list are called, in order, whenever the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 auto-newline minor mode is activated (as evidenced by a `/a' or `/ah'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 string in the mode line), and a semicolon or comma is typed (see
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 `c-electric-semi&comma'). Each function in this list is called with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 no arguments, and should return one of the following values:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 nil -- no determination made, continue checking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 'stop -- do not insert a newline, and stop checking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (anything else) -- insert a newline, and stop checking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 If every function in the list is called with no determination made,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 then no newline is inserted.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (defvar c-hanging-comment-ender-p t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 "*If nil, `c-fill-paragraph' leaves C block comment enders on their own line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 Default value is t, which inhibits leaving block comment ending string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 `*/' on a line by itself. This is BOCM's sole behavior.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (defvar c-backslash-column 48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 "*Column to insert backslashes when macroizing a region.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (defvar c-special-indent-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 "*Hook for user defined special indentation adjustments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 This hook gets called after a line is indented by the mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (defvar c-delete-function 'backward-delete-char-untabify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 "*Function called by `c-electric-delete' when deleting characters.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (defvar c-electric-pound-behavior nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 "*List of behaviors for electric pound insertion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 Only currently supported behavior is `alignleft'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (defvar c-recognize-knr-p nil ; Emacs version uses t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 "*If non-nil, `c-mode' and `objc-mode' will recognize K&R constructs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 This variable is needed because of ambiguities in C syntax that make
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 fast recognition of K&R constructs problematic, and slow. If you are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 coding with ANSI prototypes, set this variable to nil to speed up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 recognition of certain constructs. By setting this variable to nil, I
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 have seen an increase of 20 times under some circumstance.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (defvar c-progress-interval 5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 "*Interval used to update progress status during long re-indentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 If a number, percentage complete gets updated after each interval of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 that many seconds. Set to nil to inhibit updating. This is only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 useful for Emacs 19.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (defvar c-style-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 '(("gnu"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (c-basic-offset . 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (c-comment-only-line-offset . (0 . 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (c-offsets-alist . ((statement-block-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (knr-argdecl-intro . 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (substatement-open . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (label . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (statement-case-open . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (statement-cont . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (arglist-intro . c-lineup-arglist-intro-after-paren)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (arglist-close . c-lineup-arglist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 ("k&r"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (c-basic-offset . 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (c-comment-only-line-offset . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (c-offsets-alist . ((statement-block-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (knr-argdecl-intro . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (substatement-open . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (label . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (statement-cont . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 ("bsd"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (c-basic-offset . 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (c-comment-only-line-offset . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (c-offsets-alist . ((statement-block-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (knr-argdecl-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (substatement-open . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (label . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (statement-cont . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 ("stroustrup"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (c-basic-offset . 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (c-comment-only-line-offset . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (c-offsets-alist . ((statement-block-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (substatement-open . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (label . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (statement-cont . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 ("whitesmith"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (c-basic-offset . 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (c-comment-only-line-offset . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (c-offsets-alist . ((statement-block-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 (knr-argdecl-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (substatement-open . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (label . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (statement-cont . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 ("ellemtel"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (c-basic-offset . 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (c-comment-only-line-offset . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (c-hanging-braces-alist . ((substatement-open before after)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (c-offsets-alist . ((topmost-intro . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (topmost-intro-cont . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (substatement . 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (substatement-open . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (statement-case-intro . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (case-label . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (access-label . -3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (inclass . 6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (inline-open . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 ("java"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (c-basic-offset . 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (c-comment-only-line-offset . (0 . 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (c-offsets-alist . ((statement-block-intro . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (knr-argdecl-intro . 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (substatement-open . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (label . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (statement-case-open . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (statement-cont . +)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (arglist-intro . c-lineup-arglist-intro-after-paren)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (arglist-close . c-lineup-arglist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (access-label . 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 "Styles of Indentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 Elements of this alist are of the form:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (STYLE-STRING (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 where STYLE-STRING is a short descriptive string used to select a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 style, VARIABLE is any cc-mode variable, and VALUE is the intended
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 value for that variable when using the selected style.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 There is one special case when VARIABLE is `c-offsets-alist'. In this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 case, the VALUE is a list containing elements of the form:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (SYNTACTIC-SYMBOL . VALUE)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 as described in `c-offsets-alist'. These are passed directly to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 `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
541 your style, only those that are different from the default.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 Note that all styles inherit from the `cc-mode' style, which is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 computed at the time the mode is loaded.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (defvar c-file-style nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 "*Variable interface for setting style via File Local Variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 In a file's Local Variable section, you can set this variable to a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 string suitable for `c-set-style'. When the file is visited, cc-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 will set the style of the file to this value automatically.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 Note that file style settings are applied before file offset settings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 as designated in the variable `c-file-offsets'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (defvar c-file-offsets nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 "*Variable interface for setting offsets via File Local Variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 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
558 association list similar to the values allowed in `c-offsets-alist'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 When the file is visited, cc-mode will institute these offset settings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 automatically.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 Note that file offset settings are applied after file style settings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 as designated in the variable `c-file-style'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (defvar c-site-default-style "gnu"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 "Default style for your site.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 To change the default style at your site, you can set this variable to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 any style defined in `c-style-alist'. However, if cc-mode is usually
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 loaded into your Emacs at compile time, you will need to set this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 variable in the `site-init.el' file before cc-mode is loaded, then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 re-dump Emacs.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (defvar c-mode-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 "*Hook called by `c-mode'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (defvar c++-mode-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 "*Hook called by `c++-mode'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (defvar objc-mode-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 "*Hook called by `objc-mode'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (defvar java-mode-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 "*Hook called by `java-mode'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (defvar c-mode-common-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 "*Hook called by `c-mode', `c++-mode', and 'objc-mode' during common init.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (defvar c-mode-menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 '(["Comment Out Region" comment-region (mark)]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 ["Macro Expand Region" c-macro-expand (mark)]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 ["Backslashify" c-backslash-region (mark)]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 ["Indent Expression" c-indent-exp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (memq (following-char) '(?\( ?\[ ?\{))]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 ["Indent Line" c-indent-command t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 ["Fill Comment Paragraph" c-fill-paragraph t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 ["Up Conditional" c-up-conditional t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 ["Backward Conditional" c-backward-conditional t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 ["Forward Conditional" c-forward-conditional t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 ["Backward Statement" c-beginning-of-statement t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 ["Forward Statement" c-end-of-statement t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 "XEmacs 19 menu for C/C++/ObjC modes.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 ;; Sadly we need this for a macro in Emacs 19.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (eval-when-compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 ;; Imenu isn't used in XEmacs, so just ignore load errors.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (require 'imenu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (error nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (defvar cc-imenu-c++-generic-expression
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (`
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 ((nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 (,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 "^" ; beginning of line is required
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; type specs; there can be no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; more than 3 tokens, right?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 "\\(" ; last type spec including */&
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 "[a-zA-Z0-9_:]+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 "\\([ \t]*[*&]+[ \t]*\\|[ \t]+\\)" ; either pointer/ref sign or whitespace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 "\\)?" ; if there is a last type spec
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 "\\(" ; name; take that into the imenu entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 "[a-zA-Z0-9_:~]+" ; member function, ctor or dtor...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 ; (may not contain * because then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 ; "a::operator char*" would become "char*"!)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 "\\|"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 "\\([a-zA-Z0-9_:~]*::\\)?operator"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 "[^a-zA-Z1-9_][^(]*" ; ...or operator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 " \\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 "[ \t]*([^)]*)[ \t\n]*[^ ;]" ; require something other than a ; after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 ; the (...) to avoid prototypes. Can't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 ; catch cases with () inside the parentheses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 ; surrounding the parameters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 ; (like "int foo(int a=bar()) {...}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 )) 6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 ("Class"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (, (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 "^" ; beginning of line is required
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 "class[ \t]+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 "\\([a-zA-Z0-9_]+\\)" ; this is the string we want to get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 "[ \t]*[:{]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 )) 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 "Imenu generic expression for C++ mode. See `imenu-generic-expression'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (defvar cc-imenu-c-generic-expression
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 cc-imenu-c++-generic-expression
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 "Imenu generic expression for C mode. See `imenu-generic-expression'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 ;; NO USER DEFINABLE VARIABLES BEYOND THIS POINT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 ;; Shut the byte-compiler up. Requires Emacs 19 or JWZ's improved
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 ;; byte-compiler. Otherwise, comment this line out and ignore
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 ;; any warnings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 ;;(byte-compiler-options (warnings nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 ;; figure out what features this Emacs has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (defconst c-emacs-features
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (let ((major (and (boundp 'emacs-major-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 emacs-major-version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 (minor (and (boundp 'emacs-minor-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 emacs-minor-version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (re-suite 'old-re)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 flavor comments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 ;; figure out version numbers if not already discovered
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (and (or (not major) (not minor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (string-match "\\([0-9]+\\).\\([0-9]+\\)" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (setq major (string-to-int (substring emacs-version
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (match-end 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 minor (string-to-int (substring emacs-version
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (match-beginning 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (match-end 2)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (if (not (and major minor))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (error "Cannot figure out the major and minor version numbers."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 ;; calculate the major version
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 ((= major 18) (setq major 'v18)) ;Emacs 18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 ((= major 4) (setq major 'v18)) ;Epoch 4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 ((= major 19) (setq major 'v19 ;Emacs 19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 flavor (if (or (string-match "Lucid" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (string-match "XEmacs" emacs-version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 'XEmacs 'FSF)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 ;; I don't know
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (t (error "Cannot recognize major version number: %s" major)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 ;; Regular expression suites...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (if (and (eq major 'v19)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (or (and (eq flavor 'XEmacs) (>= minor 14))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (and (eq flavor 'FSF) (>= minor 30))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (setq re-suite 'new-re))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 ;; XEmacs 19 uses 8-bit modify-syntax-entry flags, as do all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 ;; patched Emacs 19, Emacs 18, Epoch 4's. Only Emacs 19 uses a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 ;; 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
697 ;; out.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (if (eq major 'v19)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (let ((table (copy-syntax-table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (modify-syntax-entry ?a ". 12345678" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 ;; XEmacs pre 20 and Emacs pre 19.30 use vectors for syntax tables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 ((vectorp table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (if (= (logand (lsh (aref table ?a) -16) 255) 255)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 (setq comments '8-bit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 (setq comments '1-bit)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 ;; XEmacs 20 is known to be 8-bit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 ((eq flavor 'XEmacs) (setq comments '8-bit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 ;; Emacs 19.30 and beyond are known to be 1-bit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 ((eq flavor 'FSF) (setq comments '1-bit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 ;; Don't know what this is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 (t (error "Couldn't figure out syntax table format."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 ;; Emacs 18 has no support for dual comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (setq comments 'no-dual-comments))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 ;; lets do some minimal sanity checking.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (if (and (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 ;; Lucid Emacs before 19.6 had bugs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (and (eq major 'v19) (eq flavor 'XEmacs) (< minor 6))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 ;; Emacs 19 before 19.21 has known bugs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (and (eq major 'v19) (eq flavor 'FSF) (< minor 21)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (not c-inhibit-startup-warnings-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (with-output-to-temp-buffer "*cc-mode warnings*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (print (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 "The version of Emacs that you are running, %s,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 has known bugs in its syntax.c parsing routines which will affect the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 performance of cc-mode. You should strongly consider upgrading to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 latest available version. cc-mode may continue to work, after a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 fashion, but strange indentation errors could be encountered."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 emacs-version))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 ;; Emacs 18, with no patch is not too good
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 (if (and (eq major 'v18) (eq comments 'no-dual-comments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (not c-inhibit-startup-warnings-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (with-output-to-temp-buffer "*cc-mode warnings*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (print (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 "The version of Emacs 18 you are running, %s,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 has known deficiencies in its ability to handle dual C++ comments,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 i.e. C++ line style comments and C block style comments. This will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 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
740 if you are doing much C++ editing, you should strongly consider
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 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
742 experience performance degradations. Emacs 19 has some new built-in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 routines which will speed things up for you.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 Because of these inherent problems, cc-mode is no longer being
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 actively maintained for Emacs 18, however, until you can upgrade to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 Emacs 19, you may want to look at cc-mode-18.el in the cc-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 distribution. THIS FILE IS COMPLETELY UNSUPPORTED! If you use it,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 you are on your own, although patch contributions will be folded into
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 the main release."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 emacs-version))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 ;; Emacs 18 with the syntax patches are no longer supported
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (if (and (eq major 'v18) (not (eq comments 'no-dual-comments))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (not c-inhibit-startup-warnings-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (with-output-to-temp-buffer "*cc-mode warnings*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (print (format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 "You are running a syntax patched Emacs 18 variant. While this should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 work for you, you may want to consider upgrading to Emacs 19. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 syntax patches are no longer supported either for syntax.c or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 cc-mode."))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (list major comments re-suite))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 "A list of features extant in the Emacs you are using.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 There are many flavors of Emacs out there, each with different
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 features supporting those needed by cc-mode. Here's the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 supported list, along with the values for this variable:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 Emacs 18/Epoch 4: (v18 no-dual-comments RS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 Emacs 18/Epoch 4 (patch2): (v18 8-bit RS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 XEmacs 19: (v19 8-bit RS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 Emacs 19: (v19 1-bit RS)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 RS is the regular expression suite to use. XEmacs versions after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 19.13, and Emacs versions after 19.29 use the `new-re' regex suite.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 All other Emacsen use the `old-re' suite.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (defvar c++-mode-abbrev-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 "Abbrev table in use in c++-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (define-abbrev-table 'c++-mode-abbrev-table ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (defvar c-mode-abbrev-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 "Abbrev table in use in c-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (define-abbrev-table 'c-mode-abbrev-table ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (defvar objc-mode-abbrev-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 "Abbrev table in use in objc-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 (define-abbrev-table 'objc-mode-abbrev-table ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 (defvar java-mode-abbrev-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 "Abbrev table in use in java-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 (define-abbrev-table 'java-mode-abbrev-table ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 (defun c-mode-fsf-menu (name map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 ;; Add menu to a keymap. FSF menus suck. Don't add them for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 ;; XEmacs. This feature test will fail on other than Emacs 19.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 (define-key map [menu-bar] (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (define-key map [menu-bar c] (cons name (make-sparse-keymap name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 (define-key map [menu-bar c comment-region]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 '("Comment Out Region" . comment-region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 (define-key map [menu-bar c c-macro-expand]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 '("Macro Expand Region" . c-macro-expand))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 (define-key map [menu-bar c c-backslash-region]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 '("Backslashify" . c-backslash-region))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 (define-key map [menu-bar c indent-exp]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 '("Indent Expression" . c-indent-exp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 (define-key map [menu-bar c indent-line]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 '("Indent Line" . c-indent-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 (define-key map [menu-bar c fill]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 '("Fill Comment Paragraph" . c-fill-paragraph))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 (define-key map [menu-bar c up]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 '("Up Conditional" . c-up-conditional))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 (define-key map [menu-bar c backward]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 '("Backward Conditional" . c-backward-conditional))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 (define-key map [menu-bar c forward]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 '("Forward Conditional" . c-forward-conditional))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 (define-key map [menu-bar c backward-stmt]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 '("Backward Statement" . c-beginning-of-statement))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 (define-key map [menu-bar c forward-stmt]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 '("Forward Statement" . c-end-of-statement))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 ;; RMS: mouse-3 should not select this menu. mouse-3's global
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 ;; definition is useful in C mode and we should not interfere
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 ;; with that. The menu is mainly for beginners, and for them,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 ;; the menubar requires less memory than a special click.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (error nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (defvar c-mode-map ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 "Keymap used in c-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (if c-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 ;; TBD: should we even worry about naming this keymap. My vote: no,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 ;; because Emacs and XEmacs do it differently.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (setq c-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 ;; put standard keybindings into MAP
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 ;; the following mappings correspond more or less directly to BOCM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (define-key c-mode-map "{" 'c-electric-brace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (define-key c-mode-map "}" 'c-electric-brace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (define-key c-mode-map ";" 'c-electric-semi&comma)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (define-key c-mode-map "#" 'c-electric-pound)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 (define-key c-mode-map ":" 'c-electric-colon)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 ;; Lucid Emacs 19.9 defined these two, the second of which was
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 ;; commented out...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 ;; (define-key c-mode-map "\e{" 'c-insert-braces)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 ;; Commented out electric square brackets because nobody likes them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 ;; (define-key c-mode-map "[" 'c-insert-brackets)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (define-key c-mode-map "\e\C-h" 'c-mark-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 (define-key c-mode-map "\e\C-q" 'c-indent-exp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 (define-key c-mode-map "\ea" 'c-beginning-of-statement)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (define-key c-mode-map "\ee" 'c-end-of-statement)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 ;; Emacs 19.30 introduces fill-paragraph-function, but it's not in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 ;; every version of Emacs cc-mode supports.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (if (not (boundp 'fill-paragraph-function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 ;; I'd rather use an adaptive fill program instead of this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 (define-key c-mode-map "\eq" 'c-fill-paragraph))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 (define-key c-mode-map "\C-c\C-n" 'c-forward-conditional)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 (define-key c-mode-map "\C-c\C-p" 'c-backward-conditional)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 (define-key c-mode-map "\C-c\C-u" 'c-up-conditional)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 (define-key c-mode-map "\t" 'c-indent-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 (define-key c-mode-map "\177" 'c-electric-delete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 ;; these are new keybindings, with no counterpart to BOCM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 (define-key c-mode-map "," 'c-electric-semi&comma)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 (define-key c-mode-map "*" 'c-electric-star)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 (define-key c-mode-map "\C-c\C-q" 'c-indent-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 (define-key c-mode-map "\C-c\C-\\" 'c-backslash-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 ;; TBD: where if anywhere, to put c-backward|forward-into-nomenclature
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (define-key c-mode-map "\C-c\C-a" 'c-toggle-auto-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (define-key c-mode-map "\C-c\C-b" 'c-submit-bug-report)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (define-key c-mode-map "\C-c\C-c" 'comment-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (define-key c-mode-map "\C-c\C-d" 'c-toggle-hungry-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 (define-key c-mode-map "\C-c\C-e" 'c-macro-expand)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (define-key c-mode-map "\C-c\C-o" 'c-set-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (define-key c-mode-map "\C-c\C-s" 'c-show-syntactic-information)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 (define-key c-mode-map "\C-c\C-t" 'c-toggle-auto-hungry-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 ;; conflicts with OOBR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 ;;(define-key c-mode-map "\C-c\C-v" 'c-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 ;; Emacs 19 defines menus in the mode map. This call will return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 ;; t on Emacs 19, otherwise no-op and return nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (if (and (not (c-mode-fsf-menu "C" c-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 ;; in XEmacs 19, we want the menu to popup when the 3rd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 ;; button is hit. In Lucid Emacs 19.10 and beyond this is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 ;; done automatically if we put the menu on mode-popup-menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 ;; variable, see c-common-init. Emacs 19 uses C-Mouse-3 for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 ;; this, and it works with no special effort.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (boundp 'current-menubar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (not (boundp 'mode-popup-menu)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (define-key c-mode-map 'button3 'c-popup-menu)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (defvar c++-mode-map ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 "Keymap used in c++-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (if c++-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 ;; In Emacs 19, it makes more sense to inherit c-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (if (memq 'v19 c-emacs-features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 ;; XEmacs and Emacs 19 do this differently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 ;; XEmacs 19.13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 ((fboundp 'set-keymap-parents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (setq c++-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 (set-keymap-parents c++-mode-map c-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 ((fboundp 'set-keymap-parent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (setq c++-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 (set-keymap-parent c++-mode-map c-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (t (setq c++-mode-map (cons 'keymap c-mode-map))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 ;; Do it the hard way for Emacs 18 -- given by JWZ
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (setq c++-mode-map (nconc (make-sparse-keymap) c-mode-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 ;; add bindings which are only useful for C++
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (define-key c++-mode-map "\C-c:" 'c-scope-operator)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 (define-key c++-mode-map "/" 'c-electric-slash)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (define-key c++-mode-map "<" 'c-electric-lt-gt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 (define-key c++-mode-map ">" 'c-electric-lt-gt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 ;; Emacs 19 defines menus in the mode map. This call will return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 ;; t on Emacs 19, otherwise no-op and return nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 (c-mode-fsf-menu "C++" c++-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 (defvar objc-mode-map ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 "Keymap used in objc-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 (if objc-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 ;; In Emacs 19, it makes more sense to inherit c-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 (if (memq 'v19 c-emacs-features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 ;; XEmacs and Emacs 19 do this differently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 ;; XEmacs 19.13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 ((fboundp 'set-keymap-parents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 (setq objc-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 (set-keymap-parents objc-mode-map c-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 ((fboundp 'set-keymap-parent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 (setq objc-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 (set-keymap-parent objc-mode-map c-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 (t (setq objc-mode-map (cons 'keymap c-mode-map))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 ;; Do it the hard way for Emacs 18 -- given by JWZ
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 (setq objc-mode-map (nconc (make-sparse-keymap) c-mode-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 ;; add bindings which are only useful for Objective-C
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 (define-key objc-mode-map "/" 'c-electric-slash)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 ;; Emacs 19 defines menus in the mode map. This call will return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 ;; t on Emacs 19, otherwise no-op and return nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 (c-mode-fsf-menu "ObjC" objc-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 (defvar java-mode-map ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 "Keymap used in java-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 (if java-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 ;; In Emacs 19, it makes more sense to inherit c-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 (if (memq 'v19 c-emacs-features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 ;; XEmacs and Emacs 19 do this differently
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 ;; XEmacs 19.13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 ((fboundp 'set-keymap-parents)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (setq java-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 (set-keymap-parents java-mode-map c-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 ((fboundp 'set-keymap-parent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 (setq java-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 (set-keymap-parent java-mode-map c-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 (t (setq java-mode-map (cons 'keymap c-mode-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 ;; Do it the hard way for Emacs 18 -- given by JWZ
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 (setq java-mode-map (nconc (make-sparse-keymap) c-mode-map)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 ;; add bindings which are only useful for Java
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 (define-key java-mode-map "/" 'c-electric-slash)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 ;; Emacs 19 defines menus in the mode map. This call will return t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 ;; on Emacs 19, otherwise no-op and return nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 (c-mode-fsf-menu "Java" java-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 (defun c-populate-syntax-table (table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 ;; Populate the syntax TABLE
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 ;; DO NOT TRY TO SET _ (UNDERSCORE) TO WORD CLASS!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 (modify-syntax-entry ?_ "_" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 (modify-syntax-entry ?\\ "\\" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 (modify-syntax-entry ?+ "." table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 (modify-syntax-entry ?- "." table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 (modify-syntax-entry ?= "." table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 (modify-syntax-entry ?% "." table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (modify-syntax-entry ?< "." table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 (modify-syntax-entry ?> "." table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 (modify-syntax-entry ?& "." table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 (modify-syntax-entry ?| "." table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 (modify-syntax-entry ?\' "\"" table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 (defun c-setup-dual-comments (table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 ;; Set up TABLE to handle block and line style comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 ((memq '8-bit c-emacs-features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 ;; XEmacs 19 has the best implementation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 (modify-syntax-entry ?/ ". 1456" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 (modify-syntax-entry ?* ". 23" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 (modify-syntax-entry ?\n "> b" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 ;; Give CR the same syntax as newline, for selective-display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 (modify-syntax-entry ?\^m "> b" table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 ((memq '1-bit c-emacs-features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 ;; Emacs 19 does things differently, but we can work with it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 (modify-syntax-entry ?/ ". 124b" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 (modify-syntax-entry ?* ". 23" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 (modify-syntax-entry ?\n "> b" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 ;; Give CR the same syntax as newline, for selective-display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 (modify-syntax-entry ?\^m "> b" table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 (defvar c-mode-syntax-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 "Syntax table used in c-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 (if c-mode-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 (setq c-mode-syntax-table (make-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 (c-populate-syntax-table c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 ;; add extra comment syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 (modify-syntax-entry ?/ ". 14" c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 (modify-syntax-entry ?* ". 23" c-mode-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 (defvar c++-mode-syntax-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 "Syntax table used in c++-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 (if c++-mode-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 (setq c++-mode-syntax-table (make-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 (c-populate-syntax-table c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 ;; add extra comment syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 (c-setup-dual-comments c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 ;; TBD: does it make sense for colon to be symbol class in C++?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 ;; 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
1022 ;; Foo::bar( i );
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 ;; maybe c-label-key should be fixed instead of commenting this out,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 ;; but it also bothers me that this only seems appropriate for C++
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 ;; and not C.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 ;;(modify-syntax-entry ?: "_" c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 (defvar objc-mode-syntax-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 "Syntax table used in objc-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 (if objc-mode-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 (setq objc-mode-syntax-table (make-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 (c-populate-syntax-table objc-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 ;; add extra comment syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 (c-setup-dual-comments objc-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 ;; everyone gets these
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 (modify-syntax-entry ?@ "_" objc-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 (defvar java-mode-syntax-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 "Syntax table used in java-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 (if java-mode-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 (setq java-mode-syntax-table (make-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 (c-populate-syntax-table java-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 ;; add extra comment syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 (c-setup-dual-comments java-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 ;; everyone gets these
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 (modify-syntax-entry ?@ "_" java-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 (defvar c-hungry-delete-key nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 "Internal state of hungry delete key feature.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 (defvar c-auto-newline nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 "Internal state of auto newline feature.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 (defvar c-auto-hungry-string nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 "Internal auto-newline/hungry-delete designation string for mode line.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 (defvar c-syntactic-context nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 "Variable containing syntactic analysis list during indentation.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 (defvar c-comment-start-regexp nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 "Buffer local variable describing how comment are introduced.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 (defvar c-conditional-key nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 "Buffer local language-specific conditional keyword regexp.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 (defvar c-access-key nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 "Buffer local language-specific access key regexp.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 (defvar c-class-key nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 "Buffer local language-specific class key regexp.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 (defvar c-method-key nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 "Buffer local language-specific method regexp.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 (defvar c-double-slash-is-comments-p nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 "Buffer local language-specific comment style flag.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 (defconst c-protection-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 "\\<\\(public\\|protected\\|private\\)\\>"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 "Regexp describing protection keywords.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 (defconst c-symbol-key "\\(\\w\\|\\s_\\)+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 "Regexp describing a C/C++/ObjC symbol.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 We cannot use just `word' syntax class since `_' cannot be in word
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 class. Putting underscore in word class breaks forward word movement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 behavior that users are familiar with.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 (defconst c-baseclass-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 ":?[ \t]*\\(virtual[ \t]+\\)?\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 c-protection-key "[ \t]+\\)" c-symbol-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 "Regexp describing C++ base classes in a derived class definition.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 ;; minor mode variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 (make-variable-buffer-local 'c-auto-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 (make-variable-buffer-local 'c-hungry-delete-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 (make-variable-buffer-local 'c-auto-hungry-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 ;; language differences
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 (make-variable-buffer-local 'c-comment-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 (make-variable-buffer-local 'c-conditional-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 (make-variable-buffer-local 'c-access-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 (make-variable-buffer-local 'c-class-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 (make-variable-buffer-local 'c-method-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 (make-variable-buffer-local 'c-double-slash-is-comments-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 (make-variable-buffer-local 'c-baseclass-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 (make-variable-buffer-local 'c-recognize-knr-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 ;; style variables are made buffer local at tail end of this file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 ;; cmacexp is lame because it uses no preprocessor symbols.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 ;; It isn't very extensible either -- hardcodes /lib/cpp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 ;; [I add it here only because c-mode has it -- BAW]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 ;;(autoload 'c-macro-expand "cmacexp"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 ;; "Display the result of expanding all C macros occurring in the region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 ;;The expansion is entirely correct because it uses the C preprocessor."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 ;; t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 ;; constant regular expressions for looking at various constructs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 (defconst c-C++-class-key "\\(class\\|struct\\|union\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 "Regexp describing a C++ class declaration, including templates.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 (defconst c-C-class-key "\\(struct\\|union\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 "Regexp describing a C struct declaration.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 (defconst c-inher-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 (concat "\\(\\<static\\>\\s +\\)?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 c-C++-class-key "[ \t]+" c-symbol-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 "\\([ \t]*:[ \t]*\\)?\\s *[^;]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 "Regexp describing a class inheritance declaration.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 (defconst c-switch-label-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 "\\(\\(case[( \t]+\\S .*\\)\\|default[ \t]*\\):"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 "Regexp describing a switch's case or default label")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 (defconst c-C++-access-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 (concat c-protection-key ":")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 "Regexp describing C++ access specification keywords.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 (defconst c-label-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 (concat c-symbol-key ":\\([^:]\\|$\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 "Regexp describing any label.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 (defconst c-C-conditional-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 "\\b\\(for\\|if\\|do\\|else\\|while\\|switch\\)\\b[^_]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 "Regexp describing a conditional control.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 (defconst c-C++-conditional-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 "\\b\\(for\\|if\\|do\\|else\\|while\\|switch\\|try\\|catch\\)\\b[^_]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 "Regexp describing a conditional control for C++.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 (defconst c-C++-friend-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 "friend[ \t]+\\|template[ \t]*<.+>[ \t]*friend[ \t]+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 "Regexp describing friend declarations in C++ classes.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 (defconst c-C++-comment-start-regexp "//\\|/\\*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 "Dual comment value for `c-comment-start-regexp'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 (defconst c-C-comment-start-regexp "/\\*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 "Single comment style value for `c-comment-start-regexp'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 (defconst c-ObjC-method-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 "^\\s *[+-]\\s *"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 "\\(([^)]*)\\)?" ; return type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 ;; \\s- in objc syntax table does not include \n
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 ;; since it is considered the end of //-comments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 "[ \t\n]*" c-symbol-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 "Regexp describing an Objective-C method intro.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 (defconst c-ObjC-access-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 (concat "@" c-protection-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 "Regexp describing access specification keywords for Objective-C.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 (defconst c-ObjC-class-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 "@\\(interface\\|implementation\\)\\s +"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 c-symbol-key ;name of the class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 "\\(\\s *:\\s *" c-symbol-key "\\)?" ;maybe followed by the superclass
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 "\\(\\s *<[^>]+>\\)?" ;and maybe the adopted protocols list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 "Regexp describing a class or protocol declaration for Objective-C.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 (defconst c-Java-conditional-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 "\\b\\(for\\|if\\|do\\|else\\|while\\|switch\\|try\\|catch\\|finally\\|synchronized\\)\\b[^_]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 "Regexp describing a conditional control for Java.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 (defconst c-Java-method-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 "^\\s *[+-]\\s *"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 "\\(([^)]*)\\)?" ; return type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 ;; \\s- in java syntax table does not include \n
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 ;; since it is considered the end of //-comments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 "[ \t\n]*" c-symbol-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 "Regexp describing a Java method intro.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 (defconst c-Java-access-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 (concat c-protection-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 "Regexp describing access specification keywords for Java.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 (defconst c-Java-class-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 "\\(interface\\|class\\)\\s +"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 c-symbol-key ;name of the class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 "\\(\\s *extends\\s *" c-symbol-key "\\)?" ;maybe followed by superclass
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 ;;"\\(\\s *implements *[^{]+{\\)?" ;and maybe the adopted protocols list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 "Regexp describing a class or protocol declaration for Java.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 ;; KLUDGE ALERT. We default these variables to their `C' values so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 ;; 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
1190 ;; out of the box. The most glaring example is awk-mode. There ought
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 ;; to be a better way.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 (setq-default c-conditional-key c-C-conditional-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 c-class-key c-C-class-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 c-comment-start-regexp c-C-comment-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 ;; main entry points for the modes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 (defconst c-list-of-mode-names nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 (defun c-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 "Major mode for editing K&R and ANSI C code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 To submit a problem report, enter `\\[c-submit-bug-report]' from a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 c-mode buffer. This automatically sets up a mail buffer with version
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 information already added. You just need to add a description of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 problem, including a reproducible test case and send the message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 To see what version of cc-mode you are running, enter `\\[c-version]'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 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
1210 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
1211 run first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 Key bindings:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 \\{c-mode-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 (set-syntax-table c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 (setq major-mode 'c-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 mode-name "C"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 local-abbrev-table c-mode-abbrev-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 (use-local-map c-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 (c-common-init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 (setq comment-start "/* "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 comment-end " */"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 comment-multi-line t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 c-conditional-key c-C-conditional-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 c-class-key c-C-class-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 c-baseclass-key nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 c-comment-start-regexp c-C-comment-start-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 imenu-generic-expression cc-imenu-c-generic-expression)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 (run-hooks 'c-mode-common-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 (run-hooks 'c-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 (setq c-list-of-mode-names (cons "C" c-list-of-mode-names))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 (defun c++-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 "Major mode for editing C++ code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 To submit a problem report, enter `\\[c-submit-bug-report]' from a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 c++-mode buffer. This automatically sets up a mail buffer with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 version information already added. You just need to add a description
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 of the problem, including a reproducible test case, and send the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 To see what version of cc-mode you are running, enter `\\[c-version]'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 The hook variable `c++-mode-hook' is run with no args, if that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 variable is bound and has a non-nil value. Also the hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 `c-mode-common-hook' is run first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 Key bindings:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 \\{c++-mode-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 (set-syntax-table c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 (setq major-mode 'c++-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 mode-name "C++"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 local-abbrev-table c++-mode-abbrev-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 (use-local-map c++-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 (c-common-init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 (setq comment-start "// "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 comment-end ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 comment-multi-line nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 c-conditional-key c-C++-conditional-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 c-comment-start-regexp c-C++-comment-start-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 c-class-key c-C++-class-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 c-access-key c-C++-access-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 c-double-slash-is-comments-p t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 imenu-generic-expression cc-imenu-c++-generic-expression)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 (run-hooks 'c-mode-common-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 (run-hooks 'c++-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 (setq c-list-of-mode-names (cons "C++" c-list-of-mode-names))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 (defun objc-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 "Major mode for editing Objective C code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 To submit a problem report, enter `\\[c-submit-bug-report]' from an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 objc-mode buffer. This automatically sets up a mail buffer with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 version information already added. You just need to add a description
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 of the problem, including a reproducible test case, and send the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 To see what version of cc-mode you are running, enter `\\[c-version]'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 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
1283 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
1284 is run first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 Key bindings:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 \\{objc-mode-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 (set-syntax-table objc-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 (setq major-mode 'objc-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 mode-name "ObjC"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 local-abbrev-table objc-mode-abbrev-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 (use-local-map objc-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 (c-common-init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 (setq comment-start "// "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 comment-end ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 comment-multi-line nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 c-conditional-key c-C-conditional-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 c-comment-start-regexp c-C++-comment-start-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 c-class-key c-ObjC-class-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 c-baseclass-key nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 c-access-key c-ObjC-access-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 c-double-slash-is-comments-p t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 c-method-key c-ObjC-method-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 (run-hooks 'c-mode-common-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 (run-hooks 'objc-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 (setq c-list-of-mode-names (cons "ObjC" c-list-of-mode-names))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 (defun java-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 "Major mode for editing Java code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 To submit a problem report, enter `\\[c-submit-bug-report]' from an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 java-mode buffer. This automatically sets up a mail buffer with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 version information already added. You just need to add a description
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 of the problem, including a reproducible test case and send the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 To see what version of cc-mode you are running, enter `\\[c-version]'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 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
1321 is bound and has a non-nil value. Also the common hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 `c-mode-common-hook' is run first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 Key bindings:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 \\{java-mode-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 (set-syntax-table java-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 (setq major-mode 'java-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 mode-name "Java"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 local-abbrev-table java-mode-abbrev-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 (use-local-map java-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 (c-common-init)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 (setq comment-start "// "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 comment-end ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 comment-multi-line nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 c-conditional-key c-Java-conditional-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 c-comment-start-regexp c-C++-comment-start-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 c-class-key c-Java-class-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 c-method-key c-Java-method-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 c-double-slash-is-comments-p t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 c-baseclass-key nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 c-access-key c-Java-access-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 (c-set-style "Java")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 (run-hooks 'c-mode-common-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 (run-hooks 'java-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 (setq c-list-of-mode-names (cons "Java" c-list-of-mode-names))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 (defun c-common-init ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 ;; Common initializations for c++-mode and c-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 ;; make local variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 (make-local-variable 'paragraph-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 (make-local-variable 'paragraph-separate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 (make-local-variable 'paragraph-ignore-fill-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 (make-local-variable 'require-final-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 (make-local-variable 'parse-sexp-ignore-comments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 (make-local-variable 'indent-line-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 (make-local-variable 'indent-region-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 (make-local-variable 'comment-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 (make-local-variable 'comment-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 (make-local-variable 'comment-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 (make-local-variable 'comment-start-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 (make-local-variable 'comment-multi-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 (make-local-variable 'outline-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 (make-local-variable 'outline-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 (make-local-variable 'adaptive-fill-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 (make-local-variable 'imenu-generic-expression) ;set in the mode functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 ;; Emacs 19.30 and beyond only, AFAIK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 (if (boundp 'fill-paragraph-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 (make-local-variable 'fill-paragraph-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 (setq fill-paragraph-function 'c-fill-paragraph)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 ;; now set their values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 (setq paragraph-start (if (memq 'new-re c-emacs-features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 (concat page-delimiter "\\|$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 (concat "^$\\|" page-delimiter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 paragraph-separate paragraph-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 paragraph-ignore-fill-prefix t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 require-final-newline t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 parse-sexp-ignore-comments t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 indent-line-function 'c-indent-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 indent-region-function 'c-indent-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 outline-regexp "[^#\n\^M]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 outline-level 'c-outline-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 comment-column 32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 comment-start-skip "/\\*+ *\\|// *"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 adaptive-fill-regexp nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 ;; we have to do something special for c-offsets-alist so that the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 ;; buffer local value has its own alist structure.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 (setq c-offsets-alist (copy-alist c-offsets-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 ;; setup the comment indent variable in a Emacs version portable way
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 ;; ignore any byte compiler warnings you might get here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 (if (boundp 'comment-indent-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 (make-local-variable 'comment-indent-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 (setq comment-indent-function 'c-comment-indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 (make-local-variable 'comment-indent-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 (setq comment-indent-hook 'c-comment-indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 ;; Put C menu into menubar and on popup menu for XEmacs 19. I think
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 ;; this happens automatically for Emacs 19.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 (if (and (boundp 'current-menubar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 current-menubar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 (not (assoc mode-name current-menubar)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 ;; its possible that this buffer has changed modes from one of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 ;; the other cc-mode modes. In that case, only the menubar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 ;; title of the menu changes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 (let ((modes (copy-sequence c-list-of-mode-names))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 changed-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 (setq modes (delete major-mode modes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 (while modes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 (if (not (assoc (car modes) current-menubar))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 (setq modes (cdr modes))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 (relabel-menu-item (list (car modes)) mode-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 (setq modes nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 changed-p t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 (if (not changed-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 (set-buffer-menubar (copy-sequence current-menubar))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 (add-menu nil mode-name c-mode-menu)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 (if (boundp 'mode-popup-menu)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 (setq mode-popup-menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 (cons (concat mode-name " Mode Commands") c-mode-menu)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 ;; put auto-hungry designators onto minor-mode-alist, but only once
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 (or (assq 'c-auto-hungry-string minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 (setq minor-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 (cons '(c-auto-hungry-string c-auto-hungry-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 minor-mode-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 (defun c-postprocess-file-styles ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 "Function that post processes relevant file local variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 Currently, this function simply applies any style and offset settings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 found in the file's Local Variable list. It first applies any style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 setting found in `c-file-style', then it applies any offset settings
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 it finds in `c-file-offsets'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 ;; apply file styles and offsets
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 (and c-file-style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 (c-set-style c-file-style))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 (and c-file-offsets
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 (lambda (langentry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 (let ((langelem (car langentry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 (offset (cdr langentry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 (c-set-offset langelem offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 c-file-offsets)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 ;; Add the postprocessing function to hack-local-variables-hook. As
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 ;; of 28-Aug-1995, XEmacs 19.12 and Emacs 19.29 support this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 (and (fboundp 'add-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 (add-hook 'hack-local-variables-hook 'c-postprocess-file-styles))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 (defun c-enable-//-in-c-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 "Enables // as a comment delimiter in `c-mode'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 ANSI C currently does *not* allow this, although many C compilers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 support optional C++ style comments. To use, call this function from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 your `.emacs' file before you visit any C files. The changes are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 global and affect all future `c-mode' buffers."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 (c-setup-dual-comments c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 (setq-default c-C-comment-start-regexp c-C++-comment-start-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 ;; macros must be defined before first use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 (defmacro c-point (position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 ;; Returns the value of point at certain commonly referenced POSITIONs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 ;; POSITION can be one of the following symbols:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 ;; bol -- beginning of line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 ;; eol -- end of line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 ;; bod -- beginning of defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 ;; boi -- back to indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 ;; ionl -- indentation of next line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 ;; iopl -- indentation of previous line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 ;; bonl -- beginning of next line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 ;; bopl -- beginning of previous line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 ;; This function does not modify point or mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 (or (and (eq 'quote (car-safe position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 (null (cdr (cdr position))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 (error "bad buffer position requested: %s" position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 (setq position (nth 1 position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 (` (let ((here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 (,@ (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 ((eq position 'bol) '((beginning-of-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 ((eq position 'eol) '((end-of-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 ((eq position 'bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 '((beginning-of-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 ;; if defun-prompt-regexp is non-nil, b-o-d won't leave
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 ;; us at the open brace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 (and (boundp 'defun-prompt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 defun-prompt-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 (looking-at defun-prompt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 (goto-char (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 ((eq position 'boi) '((back-to-indentation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 ((eq position 'bonl) '((forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 ((eq position 'bopl) '((forward-line -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 ((eq position 'iopl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 '((forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 (back-to-indentation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 ((eq position 'ionl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 '((forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 (back-to-indentation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 (t (error "unknown buffer position requested: %s" position))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 (goto-char here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 ;; workaround for an Emacs18 bug -- blech! Well, at least it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 ;; doesn't hurt for v19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 (,@ nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 (defmacro c-auto-newline ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 ;; if auto-newline feature is turned on, insert a newline character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 ;; and return t, otherwise return nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 (` (and c-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 (not (c-in-literal))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 (not (newline)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 (defmacro c-safe (&rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 ;; safely execute BODY, return nil if an error occurred
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 (` (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 (progn (,@ body))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 (error nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 (defun c-insert-special-chars (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 ;; simply call self-insert-command in Emacs 19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 (self-insert-command (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 (defun c-intersect-lists (list alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 ;; return the element of ALIST that matches the first element found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 ;; in LIST. Uses assq.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 (let (match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 (while (and list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 (not (setq match (assq (car list) alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 (setq list (cdr list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 match))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540 (defun c-lookup-lists (list alist1 alist2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 ;; first, find the first entry from LIST that is present in ALIST1,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 ;; then find the entry in ALIST2 for that entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 (assq (car (c-intersect-lists list alist1)) alist2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 ;; 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
1547 ;; comment in C code based on its context.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 (defun c-comment-indent ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 (if (looking-at (concat "^\\(" c-comment-start-regexp "\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 0 ;Existing comment at bol stays there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 (let ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 ;; CASE 1: A comment following a solitary close-brace should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 ;; have only one space.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 ((looking-at (concat "[ \t]*}[ \t]*\\($\\|"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 c-comment-start-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 "\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 (search-forward "}")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 (1+ (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 ;; CASE 2: 2 spaces after #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 ((or (looking-at "^#[ \t]*endif[ \t]*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 (looking-at "^#[ \t]*else[ \t]*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 7)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 ;; CASE 3: when comment-column is nil, calculate the offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 ;; according to c-offsets-alist. E.g. identical to hitting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 ;; TAB.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 ((and c-indent-comments-syntactically-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 (or (looking-at comment-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 (eolp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 (let ((syntax (c-guess-basic-syntax)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 ;; BOGOSITY ALERT: if we're looking at the eol, its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 ;; because indent-for-comment hasn't put the comment-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 ;; in the buffer yet. this will screw up the syntactic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 ;; analysis so we kludge in the necessary info. Another
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 ;; kludge is that if we're at the bol, then we really want
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 ;; to ignore any anchoring as specified by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 ;; c-comment-only-line-offset since it doesn't apply here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 (eolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 (c-add-syntax 'comment-intro))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 (let ((c-comment-only-line-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 (if (consp c-comment-only-line-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 c-comment-only-line-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 (cons c-comment-only-line-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 c-comment-only-line-offset))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 (apply '+ (mapcar 'c-get-offset syntax)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 ;; CASE 4: use comment-column if previous line is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 ;; comment-only line indented to the left of comment-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 (and (not (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 (looking-at c-comment-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 (setq placeholder (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 (goto-char placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 (if (< (current-column) comment-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 comment-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 ;; CASE 5: If comment-column is 0, and nothing but space
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 ;; before the comment, align it at 0 rather than 1.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 ((progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 (and (= comment-column 0) (bolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 ;; CASE 6: indent at comment column except leave at least one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 ;; space.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 (t (max (1+ (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 comment-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 ;; used by outline-minor-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 (defun c-outline-level ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 (skip-chars-forward "\t ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 ;; active regions, and auto-newline/hungry delete key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 (defun c-keep-region-active ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 ;; Do whatever is necessary to keep the region active in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 ;; XEmacs 19. ignore byte-compiler warnings you might see
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 (and (boundp 'zmacs-region-stays)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 (setq zmacs-region-stays t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 (defun c-update-modeline ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 ;; set the c-auto-hungry-string for the correct designation on the modeline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 (setq c-auto-hungry-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 (if c-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 (if c-hungry-delete-key "/ah" "/a")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 (if c-hungry-delete-key "/h" nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 ;; updates the modeline for all Emacsen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 (if (memq 'v19 c-emacs-features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 (force-mode-line-update)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 (set-buffer-modified-p (buffer-modified-p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 (defun c-calculate-state (arg prevstate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 ;; Calculate the new state of PREVSTATE, t or nil, based on arg. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 ;; arg is nil or zero, toggle the state. If arg is negative, turn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 ;; the state off, and if arg is positive, turn the state on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 (if (or (not arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 (zerop (setq arg (prefix-numeric-value arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 (not prevstate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 (> arg 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 (defun c-toggle-auto-state (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 "Toggle auto-newline feature.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 Optional numeric ARG, if supplied turns on auto-newline when positive,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 turns it off when negative, and just toggles it when zero.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 When the auto-newline feature is enabled (as evidenced by the `/a' or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 `/ah' on the modeline after the mode name) newlines are automatically
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 inserted after special characters such as brace, comma, semi-colon,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 and colon."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 (setq c-auto-newline (c-calculate-state arg c-auto-newline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 (c-update-modeline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 (c-keep-region-active))
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-toggle-hungry-state (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 "Toggle hungry-delete-key feature.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 Optional numeric ARG, if supplied turns on hungry-delete when positive,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 turns it off when negative, and just toggles it when zero.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 When the hungry-delete-key feature is enabled (as evidenced by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 `/h' or `/ah' on the modeline after the mode name) the delete key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 gobbles all preceding whitespace in one fell swoop."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 (setq c-hungry-delete-key (c-calculate-state arg c-hungry-delete-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 (c-update-modeline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 (defun c-toggle-auto-hungry-state (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 "Toggle auto-newline and hungry-delete-key features.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 Optional numeric ARG, if supplied turns on auto-newline and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 hungry-delete when positive, turns them off when negative, and just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 toggles them when zero.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687 See `c-toggle-auto-state' and `c-toggle-hungry-state' for details."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 (setq c-auto-newline (c-calculate-state arg c-auto-newline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 (setq c-hungry-delete-key (c-calculate-state arg c-hungry-delete-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691 (c-update-modeline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695 ;; COMMANDS
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696 (defun c-electric-delete (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697 "Deletes preceding character or whitespace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698 If `c-hungry-delete-key' is non-nil, as evidenced by the \"/h\" or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 \"/ah\" string on the mode line, then all preceding whitespace is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1700 consumed. If however an ARG is supplied, or `c-hungry-delete-key' is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701 nil, or point is inside a literal then the function in the variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 `c-delete-function' is called."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704 (if (or (not c-hungry-delete-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705 arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1706 (c-in-literal))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707 (funcall c-delete-function (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 (let ((here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709 (skip-chars-backward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710 (if (/= (point) here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711 (delete-region (point) here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712 (funcall c-delete-function 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715 (defun c-electric-pound (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716 "Electric pound (`#') insertion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 Inserts a `#' character specially depending on the variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1718 `c-electric-pound-behavior'. If a numeric ARG is supplied, or if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719 point is inside a literal, nothing special happens."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 (if (or (c-in-literal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722 arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 (not (memq 'alignleft c-electric-pound-behavior)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 ;; do nothing special
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 (self-insert-command (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 ;; place the pound character at the left edge
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727 (let ((pos (- (point-max) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728 (bolp (bolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 (insert-char last-command-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 (and (not bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733 (goto-char (- (point-max) pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736 (defun c-electric-brace (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737 "Insert a brace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 If the auto-newline feature is turned on, as evidenced by the \"/a\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740 or \"/ah\" string on the mode line, newlines are inserted before and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741 after braces based on the value of `c-hanging-braces-alist'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 Also, the line is re-indented unless a numeric ARG is supplied, there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 are non-whitespace characters present on the line after the brace, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 the brace is inserted inside a literal."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747 (let* ((c-state-cache (c-parse-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 (safepos (c-safe-position (point) c-state-cache))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749 (literal (c-in-literal safepos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750 ;; 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
1751 ;; a numeric arg is provided, or auto-newlining is turned off,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752 ;; then just insert the character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 (if (or literal arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 ; (not c-auto-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 (not (looking-at "[ \t]*$")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756 (c-insert-special-chars arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757 (let* ((syms '(class-open class-close defun-open defun-close
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758 inline-open inline-close brace-list-open brace-list-close
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759 brace-list-intro brace-list-entry block-open block-close
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 substatement-open statement-case-open))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 ;; we want to inhibit blinking the paren since this will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762 ;; be most disruptive. we'll blink it ourselves later on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763 (old-blink-paren (if (boundp 'blink-paren-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764 blink-paren-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765 blink-paren-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 blink-paren-function ; emacs19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 blink-paren-hook ; emacs18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768 (insertion-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 delete-temp-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770 (preserve-p (= 32 (char-syntax (preceding-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 ;; shut this up too
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 (c-echo-syntactic-information-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 (syntax (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774 ;; only insert a newline if there is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775 ;; non-whitespace behind us
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 (not (bolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 (progn (newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780 (setq delete-temp-newline t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781 (self-insert-command (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782 ;; state cache doesn't change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 (c-guess-basic-syntax)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784 (newlines (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 c-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786 (or (c-lookup-lists syms syntax c-hanging-braces-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787 '(ignore before after)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788 ;; If syntax is a function symbol, then call it using the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789 ;; defined semantics.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 (if (and (not (consp (cdr newlines)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 (fboundp (cdr newlines)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792 (let ((c-syntactic-context syntax))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 (setq newlines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 (funcall (cdr newlines) (car newlines) insertion-point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 ;; does a newline go before the open brace?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 (if (memq 'before newlines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 ;; we leave the newline we've put in there before,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 ;; but we need to re-indent the line above
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 (let ((pos (- (point-max) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 (here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 (c-state-cache c-state-cache))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 ;; we may need to update the cache. this should still be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 ;; faster than recalculating the state in many cases
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 (narrow-to-region here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 (if (and (c-safe (progn (backward-up-list -1) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 (memq (preceding-char) '(?\) ?}))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810 (progn (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811 (c-safe (progn (forward-sexp -1) t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 (setq c-state-cache
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813 (c-hack-state (point) 'open c-state-cache))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 (if (and (car c-state-cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 (not (consp (car c-state-cache)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 (<= (point) (car c-state-cache)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817 (setq c-state-cache (cdr c-state-cache))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819 (let ((here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 (shift (c-indent-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821 (setq c-state-cache (c-adjust-state (c-point 'bol) here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 (- shift) c-state-cache)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 (goto-char (- (point-max) pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824 ;; if the buffer has changed due to the indentation, we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825 ;; need to recalculate syntax for the current line, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 ;; we won't need to update the state cache.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 (if (/= (point) here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 (setq syntax (c-guess-basic-syntax))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 ;; must remove the newline we just stuck in (if we really did it)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 (and delete-temp-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 ;; if there is whitespace before point, then preserve
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833 ;; at least one space.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834 (delete-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835 (just-one-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 (if (not preserve-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837 (delete-char -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838 ;; since we're hanging the brace, we need to recalculate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839 ;; syntax. Update the state to accurately reflect the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840 ;; beginning of the line. We punt if we cross any open or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841 ;; closed parens because its just too hard to modify the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842 ;; known state. This limitation will be fixed in v5.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844 (let ((bol (c-point 'bol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 (if (zerop (car (parse-partial-sexp bol (1- (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846 (setq c-state-cache (c-whack-state bol c-state-cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847 syntax (c-guess-basic-syntax))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848 ;; gotta punt. this requires some horrible kludgery
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 (makunbound 'c-state-cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 (setq c-state-cache (c-parse-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 syntax nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 ;; now adjust the line's indentation. don't update the state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 ;; cache since c-guess-basic-syntax isn't called when the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 ;; syntax is passed to c-indent-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 (let ((here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 (shift (c-indent-line syntax)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 (setq c-state-cache (c-adjust-state (c-point 'bol) here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860 (- shift) c-state-cache)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 ;; Do all appropriate clean ups
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862 (let ((here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 (pos (- (point-max) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864 mbeg mend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 ;; clean up empty defun braces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866 (if (and c-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 (memq 'empty-defun-braces c-cleanup-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 (= last-command-char ?\})
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 (c-intersect-lists '(defun-close class-close inline-close)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873 (skip-chars-backward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 (= (preceding-char) ?\{))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875 ;; make sure matching open brace isn't in a comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 (not (c-in-literal)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877 (delete-region (point) (1- here)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 ;; clean up brace-else-brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879 (if (and c-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 (memq 'brace-else-brace c-cleanup-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881 (= last-command-char ?\{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 (re-search-backward "}[ \t\n]*else[ \t\n]*{" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 (setq mbeg (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 mend (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 (= mend here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 (not (c-in-literal)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 (delete-region mbeg mend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890 (insert "} else {")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 (goto-char (- (point-max) pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893 ;; does a newline go after the brace?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 (if (memq 'after newlines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896 (newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 ;; update on c-state-cache
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 (let* ((bufpos (- (point) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 (which (if (= (char-after bufpos) ?{) 'open 'close))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900 (c-state-cache (c-hack-state bufpos which c-state-cache)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901 (c-indent-line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 ;; blink the paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903 (and (= last-command-char ?\})
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904 old-blink-paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906 (c-backward-syntactic-ws safepos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907 (if (boundp 'blink-paren-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908 (funcall old-blink-paren)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909 (run-hooks old-blink-paren))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 (defun c-electric-slash (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913 "Insert a slash character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 If slash is second of a double-slash C++ style comment introducing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915 construct, and we are on a comment-only-line, indent line as comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 If numeric ARG is supplied or point is inside a literal, indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 is inhibited."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919 (let ((indentp (and (not arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920 (= (preceding-char) ?/)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921 (= last-command-char ?/)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 (not (c-in-literal))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923 ;; shut this up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924 (c-echo-syntactic-information-p nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925 (self-insert-command (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926 (if indentp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927 (c-indent-line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 (defun c-electric-star (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 "Insert a star character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 If the star is the second character of a C style comment introducing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932 construct, and we are on a comment-only-line, indent line as comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 If numeric ARG is supplied or point is inside a literal, indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 is inhibited."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936 (self-insert-command (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 ;; 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
1938 ;; current line, unless this star introduces a comment-only line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939 (if (and (not arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 (memq (c-in-literal) '(c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 (= (preceding-char) ?*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 (skip-chars-backward "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 (if (= (preceding-char) ?/)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 (bolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 ;; shut this up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 (let (c-echo-syntactic-information-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951 (c-indent-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954 (defun c-electric-semi&comma (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 "Insert a comma or semicolon.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 When the auto-newline feature is turned on, as evidenced by the \"/a\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 or \"/ah\" string on the mode line, a newline might be inserted. See
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 the variable `c-hanging-semi&comma-criteria' for how newline insertion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 is determined.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 When semicolon is inserted, the line is re-indented unless a numeric
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 arg is supplied, point is inside a literal, or there are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 non-whitespace characters on the line following the semicolon."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965 (let* ((lim (c-most-enclosing-brace (c-parse-state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966 (literal (c-in-literal lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 (here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968 ;; shut this up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 (c-echo-syntactic-information-p nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970 (if (or literal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971 arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972 (not (looking-at "[ \t]*$")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973 (c-insert-special-chars arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 ;; do some special stuff with the character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 (self-insert-command (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 ;; do all cleanups, reindentations, and newline insertions, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 ;; only if c-auto-newline is turned on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978 (if (not c-auto-newline) nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 ;; clean ups
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 (let ((pos (- (point-max) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 (if (and (or (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 (= last-command-char ?,)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983 (memq 'list-close-comma c-cleanup-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985 (= last-command-char ?\;)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 (memq 'defun-close-semi c-cleanup-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989 (skip-chars-backward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990 (= (preceding-char) ?}))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 ;; make sure matching open brace isn't in a comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 (not (c-in-literal lim)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993 (delete-region (point) here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994 (goto-char (- (point-max) pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 ;; re-indent line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 (c-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 ;; check to see if a newline should be added
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 (let ((criteria c-hanging-semi&comma-criteria)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 answer add-newline-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 (while criteria
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 (setq answer (funcall (car criteria)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 ;; only nil value means continue checking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 (if (not answer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 (setq criteria (cdr criteria))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005 (setq criteria nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006 ;; only 'stop specifically says do not add a newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007 (setq add-newline-p (not (eq answer 'stop)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2008 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009 (if add-newline-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010 (progn (newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2011 (c-indent-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 (defun c-semi&comma-inside-parenlist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 "Determine if a newline should be added after a semicolon.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016 If a comma was inserted, no determination is made. If a semicolon was
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 inserted inside a parenthesis list, no newline is added otherwise a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 newline is added. In either case, checking is stopped. This supports
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 exactly the old newline insertion behavior."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 ;; newline only after semicolon, but only if that semicolon is not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021 ;; inside a parenthesis list (e.g. a for loop statement)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 (if (/= last-command-char ?\;)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 nil ; continue checking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 (if (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 (up-list -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 (/= (following-char) ?\())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028 (error t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029 t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030 'stop)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032 (defun c-electric-colon (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033 "Insert a colon.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035 If the auto-newline feature is turned on, as evidenced by the \"/a\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2036 or \"/ah\" string on the mode line, newlines are inserted before and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037 after colons based on the value of `c-hanging-colons-alist'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039 Also, the line is re-indented unless a numeric ARG is supplied, there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 are non-whitespace characters present on the line after the colon, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041 the colon is inserted inside a literal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 This function cleans up double colon scope operators based on the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044 value of `c-cleanup-list'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 (let* ((bod (c-point 'bod))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047 (literal (c-in-literal bod))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 syntax newlines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 ;; shut this up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 (c-echo-syntactic-information-p nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051 (if (or literal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053 (not (looking-at "[ \t]*$")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 (c-insert-special-chars arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 ;; insert the colon, then do any specified cleanups
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056 (self-insert-command (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 (let ((pos (- (point-max) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058 (here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 (if (and c-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 (memq 'scope-operator c-cleanup-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061 (= (preceding-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 (skip-chars-backward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065 (= (preceding-char) ?:))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2066 (not (c-in-literal))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 (not (= (char-after (- (point) 2)) ?:)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068 (delete-region (point) (1- here)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 (goto-char (- (point-max) pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 ;; lets do some special stuff with the colon character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 (setq syntax (c-guess-basic-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 ;; some language elements can only be determined by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073 ;; checking the following line. Lets first look for ones
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 ;; that can be found when looking on the line with the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075 ;; colon
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 newlines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 (and c-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 (or (c-lookup-lists '(case-label label access-label)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 syntax c-hanging-colons-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 (c-lookup-lists '(member-init-intro inher-intro)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 (prog2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 (c-guess-basic-syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084 (delete-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 c-hanging-colons-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 ;; indent the current line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 (c-indent-line syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088 ;; does a newline go before the colon? Watch out for already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 ;; non-hung colons. However, we don't unhang them because that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 ;; would be a cleanup (and anti-social).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 (if (and (memq 'before newlines)
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 (skip-chars-backward ": \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 (not (bolp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 (let ((pos (- (point-max) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 (newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 (c-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 (goto-char (- (point-max) pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100 ;; does a newline go after the colon?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 (if (memq 'after (cdr-safe newlines))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 (newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 (c-indent-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 (defun c-electric-lt-gt (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 "Insert a less-than, or greater-than character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 When the auto-newline feature is turned on, as evidenced by the \"/a\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 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
2111 the character inserted is the second of a C++ style stream operator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 and the buffer is in C++ mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 The line will also not be re-indented if a numeric argument is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 supplied, or point is inside a literal."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117 (let ((indentp (and (not arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 (= (preceding-char) last-command-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 (not (c-in-literal))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 ;; shut this up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 (c-echo-syntactic-information-p nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 (self-insert-command (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 (if indentp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 (c-indent-line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 ;; set up electric character functions to work with pending-del,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 ;; (a.k.a. delsel) mode. All symbols get the t value except
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 ;; c-electric-delete which gets 'supersede.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131 (lambda (sym)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132 (put sym 'delete-selection t) ; for delsel (Emacs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133 (put sym 'pending-delete t))) ; for pending-del (XEmacs)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134 '(c-electric-pound
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135 c-electric-brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136 c-electric-slash
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137 c-electric-star
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138 c-electric-semi&comma
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 c-electric-lt-gt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140 c-electric-colon))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 (put 'c-electric-delete 'delete-selection 'supersede) ; delsel
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 (put 'c-electric-delete 'pending-delete 'supersede) ; pending-del
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146 (defun c-read-offset (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147 ;; read new offset value for LANGELEM from minibuffer. return a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148 ;; legal value only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149 (let* ((oldoff (cdr-safe (assq langelem c-offsets-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150 (defstr (format "(default %s): " oldoff))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151 (errmsg (concat "Offset must be int, func, var, "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152 "or in [+,-,++,--,*,/] "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153 defstr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2154 (prompt (concat "Offset " defstr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2155 offset input interned)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2156 (while (not offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157 (setq input (read-string prompt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 offset (cond ((string-equal "" input) oldoff) ; default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159 ((string-equal "+" input) '+)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 ((string-equal "-" input) '-)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 ((string-equal "++" input) '++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162 ((string-equal "--" input) '--)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2163 ((string-equal "*" input) '*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164 ((string-equal "/" input) '/)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165 ((string-match "^-?[0-9]+$" input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2166 (string-to-int input))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2167 ((fboundp (setq interned (intern input)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168 interned)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169 ((boundp interned) interned)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 ;; error, but don't signal one, keep trying
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171 ;; to read an input value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172 (t (ding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2173 (setq prompt errmsg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2174 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2175 offset))
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-set-offset (symbol offset &optional add-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178 "Change the value of a syntactic element symbol in `c-offsets-alist'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179 SYMBOL is the syntactic element symbol to change and OFFSET is the new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 offset for that syntactic element. Optional ADD says to add SYMBOL to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 `c-offsets-alist' if it doesn't already appear there."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183 (let* ((langelem
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2184 (intern (completing-read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2185 (concat "Syntactic symbol to change"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2186 (if current-prefix-arg " or add" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187 ": ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2188 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2190 (lambda (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 (cons (format "%s" (car langelem)) nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2192 c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2193 nil (not current-prefix-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2194 ;; initial contents tries to be the last element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2195 ;; on the syntactic analysis list for the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196 ;; line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197 (let* ((syntax (c-guess-basic-syntax))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198 (len (length syntax))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2199 (ic (format "%s" (car (nth (1- len) syntax)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200 (if (memq 'v19 c-emacs-features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201 (cons ic 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202 ic))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 (offset (c-read-offset langelem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205 (list langelem offset current-prefix-arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206 ;; sanity check offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 (or (eq offset '+)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 (eq offset '-)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 (eq offset '++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 (eq offset '--)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 (eq offset '*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212 (eq offset '/)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213 (integerp offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 (fboundp offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215 (boundp offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 (error "Offset must be int, func, var, or in [+,-,++,--,*,/]: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218 (let ((entry (assq symbol c-offsets-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 (if entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220 (setcdr entry offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 (if add-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 (setq c-offsets-alist (cons (cons symbol offset) c-offsets-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223 (error "%s is not a valid syntactic symbol." symbol))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226 (defun c-set-style-1 (stylevars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227 ;; given a style's variable alist, institute the style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 (lambda (conscell)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231 (let ((attr (car conscell))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232 (val (cdr conscell)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2233 ;; KLUDGE ALERT: special case for c-offsets-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234 (if (not (eq attr 'c-offsets-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2235 (set attr val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238 (lambda (langentry)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 (let ((langelem (car langentry))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 (offset (cdr langentry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241 (c-set-offset langelem offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243 val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 stylevars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 (defun c-set-style (stylename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 "Set cc-mode variables to use one of several different indentation styles.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249 STYLENAME is a string representing the desired style from the list of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250 styles described in the variable `c-style-alist'. See that variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251 for details of setting up styles."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252 (interactive (list (let ((completion-ignore-case t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253 (prompt (format "Which %s indentation style? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254 mode-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255 (completing-read prompt c-style-alist nil t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256 (let ((vars (cdr (or (assoc (downcase stylename) c-style-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257 ;; backwards compatibility
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 (assoc (upcase stylename) c-style-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 (default (cdr (assoc "cc-mode" c-style-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261 (or vars (error "Invalid indentation style `%s'" stylename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262 (or default (error "No `cc-mode' style found!"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263 ;; first reset the style to `cc-mode' to give every style a common
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2264 ;; base. Then institute the new style.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265 (c-set-style-1 default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266 (if (not (string= stylename "cc-mode"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267 (c-set-style-1 vars)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2268 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2270 (defun c-add-style (style descrip &optional set-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 "Adds a style to `c-style-alist', or updates an existing one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272 STYLE is a string identifying the style to add or update. DESCRIP is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273 an association list describing the style and must be of the form:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 ((VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277 See the variable `c-style-alist' for the semantics of VARIABLE and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278 VALUE. This function also sets the current style to STYLE using
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279 `c-set-style' if the optional SET-P flag is non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2281 (let ((stylename (completing-read "Style to add: " c-style-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2282 (description (eval-minibuffer "Style description: ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2283 (list stylename description
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284 (y-or-n-p "Set the style too? "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2285 (setq style (downcase style))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2286 (let ((s (assoc style c-style-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2287 (if s
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 (setcdr s (copy-alist descrip)) ; replace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 (setq c-style-alist (cons (cons style descrip) c-style-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2290 (and set-p (c-set-style style)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2291
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 (defun c-fill-paragraph (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2293 "Like \\[fill-paragraph] but handles C and C++ style comments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294 If any of the current line is a comment or within a comment,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2295 fill the comment or the paragraph of it that point is in,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296 preserving the comment indentation or line-starting decorations.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 Optional prefix ARG means justify paragraph as well."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 (let* (comment-start-place
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301 (first-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302 ;; Check for obvious entry to comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305 (skip-chars-forward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 (and (looking-at comment-start-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307 (setq comment-start-place (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308 (re1 (if (memq 'new-re c-emacs-features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 "\\|[ \t]*/\\*[ \t]*$\\|[ \t]*\\*/[ \t]*$\\|[ \t/*]*$"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 "\\|^[ \t]*/\\*[ \t]*$\\|^[ \t]*\\*/[ \t]*$\\|^[ \t/*]*$"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2312 (if (and c-double-slash-is-comments-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2313 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2314 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2315 (looking-at ".*//")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2316 (let (fill-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2317 ;; Lines containing just a comment start or just an end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318 ;; should not be filled into paragraphs they are next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319 ;; to.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2320 (paragraph-start (concat paragraph-start re1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2321 (paragraph-separate (concat paragraph-separate re1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2322 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2323 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324 ;; Move up to first line of this comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 (while (and (not (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 (looking-at "[ \t]*//"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327 (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328 (if (not (looking-at ".*//"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2329 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2330 ;; Find the comment start in this line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2331 (re-search-forward "[ \t]*//[ \t]*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2332 ;; Set the fill-prefix to be what all lines except the first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333 ;; should start with.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 (setq fill-prefix (buffer-substring (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2335 (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2336 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337 ;; Narrow down to just the lines of this comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338 (narrow-to-region (c-point 'bol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2339 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2341 (while (looking-at fill-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2342 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344 (fill-paragraph arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346 ;; else C style comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347 (if (or first-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2348 ;; t if we enter a comment between start of function and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2349 ;; this line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2350 (eq (c-in-literal) 'c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2351 ;; t if this line contains a comment starter.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352 (setq first-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2353 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2356 (re-search-forward comment-start-skip
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357 (save-excursion (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 (setq comment-start-place (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361 ;; Inside a comment: fill one comment paragraph.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362 (let ((fill-prefix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363 ;; The prefix for each line of this paragraph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2364 ;; is the appropriate part of the start of this line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 ;; up to the column at which text should be indented.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2366 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2367 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2368 (if (looking-at "[ \t]*/\\*.*\\*/")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2369 (progn (re-search-forward comment-start-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2370 (make-string (current-column) ?\ ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2371 (if first-line (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2372
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2373 (let ((line-width (progn (end-of-line) (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2374 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2375 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2376 (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379 ;; How shall we decide where the end of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2380 ;; fill-prefix is?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383 (skip-chars-forward " \t*" (c-point 'eol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2385
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386 ;; If the comment is only one line followed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387 ;; by a blank line, calling move-to-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 ;; above may have added some spaces and tabs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2389 ;; to the end of the line; the fill-paragraph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2390 ;; function will then delete it and the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2391 ;; newline following it, so we'll lose a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2392 ;; blank line when we shouldn't. So delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 ;; anything move-to-column added to the end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394 ;; of the line. We record the line width
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2395 ;; instead of the position of the old line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 ;; end because move-to-column might break a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397 ;; tab into spaces, and the new characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398 ;; introduced there shouldn't be deleted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 ;; If you can see a better way to do this,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401 ;; please make the change. This seems very
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2402 ;; messy to me.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403 (delete-region (progn (move-to-column line-width)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 (progn (end-of-line) (point))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2407 ;; Lines containing just a comment start or just an end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408 ;; should not be filled into paragraphs they are next
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409 ;; to.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410 (paragraph-start (concat paragraph-start re1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2411 (paragraph-separate (concat paragraph-separate re1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412 (chars-to-delete 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2414 ;; Don't fill the comment together with the code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2415 ;; following it. So temporarily exclude everything
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 ;; before the comment start, and everything after the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 ;; line where the comment ends. If comment-start-place
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418 ;; is non-nil, the comment starter is there. Otherwise,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419 ;; point is inside the comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 (narrow-to-region (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421 (if comment-start-place
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2422 (goto-char comment-start-place)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 (search-backward "/*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2424 ;; Protect text before the comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2425 ;; start by excluding it. Add
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426 ;; spaces to bring back proper
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427 ;; indentation of that point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2428 (let ((column (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 (prog1 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2430 (setq chars-to-delete column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2431 (insert-char ?\ column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433 (if comment-start-place
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434 (goto-char (+ comment-start-place 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2435 (search-forward "*/" nil 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2438 (fill-paragraph arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2439 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2440 ;; Delete the chars we inserted to avoid clobbering
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2441 ;; the stuff before the comment start.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2442 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2443 (if (> chars-to-delete 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2444 (delete-region (point) (+ (point) chars-to-delete)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445 ;; Find the comment ender (should be on last line of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2446 ;; buffer, given the narrowing) and don't leave it on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2447 ;; its own line, unless that's the style that's desired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450 (search-forward "*/" nil 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452 (if (and c-hanging-comment-ender-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453 (looking-at "[ \t]*\\*/"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 ;(delete-indentation)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455 (let ((fill-column (+ fill-column 9999)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457 (fill-region-as-paragraph (point) (point-max))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460 ;; better movement routines for ThisStyleOfVariablesCommonInCPlusPlus
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461 ;; originally contributed by Terry_Glanfield.Southern@rxuk.xerox.com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462 (defun c-forward-into-nomenclature (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463 "Move forward to end of a nomenclature section or word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464 With arg, to it arg times."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 (let ((case-fold-search nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467 (if (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468 (re-search-forward "\\W*\\([A-Z]*[a-z0-9]*\\)" (point-max) t arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2469 (while (and (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470 (re-search-backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 "\\(\\(\\W\\|[a-z0-9]\\)[A-Z]+\\|\\W\\w+\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 (point-min) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474 (setq arg (1+ arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2475 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2476
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477 (defun c-backward-into-nomenclature (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2478 "Move backward to beginning of a nomenclature section or word.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479 With optional ARG, move that many times. If ARG is negative, move
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480 forward."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482 (c-forward-into-nomenclature (- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2483 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2484
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2485 (defun c-scope-operator ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2486 "Insert a double colon scope operator at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2487 No indentation or other \"electric\" behavior is performed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2488 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2489 (insert "::"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2491
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2492 (defun c-beginning-of-statement (&optional count lim sentence-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493 "Go to the beginning of the innermost C statement.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2494 With prefix arg, go back N - 1 statements. If already at the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495 beginning of a statement then go to the beginning of the preceding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2496 one. If within a string or comment, or next to a comment (only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2497 whitespace between), move by sentences instead of statements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499 When called from a program, this function takes 3 optional args: the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2500 repetition count, a buffer position limit which is the farthest back
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2501 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
2502 comment."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2503 (interactive (list (prefix-numeric-value current-prefix-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2504 nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2505 (let ((here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2506 (count (or count 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2507 (lim (or lim (c-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508 state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2509 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2510 (goto-char lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2511 (setq state (parse-partial-sexp (point) here nil nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2512 (if (and sentence-flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513 (or (nth 3 state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2514 (nth 4 state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2515 (looking-at (concat "[ \t]*" comment-start-skip))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2516 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2517 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2518 (goto-char (- (point) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2519 (looking-at "\\*/"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2520 (forward-sentence (- count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2521 (while (> count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2522 (c-beginning-of-statement-1 lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2523 (setq count (1- count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2524 (while (< count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2525 (c-end-of-statement-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2526 (setq count (1+ count))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2527 ;; its possible we've been left up-buf of lim
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2528 (goto-char (max (point) lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2529 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2530 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2531
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2532 (defun c-end-of-statement (&optional count lim sentence-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2533 "Go to the end of the innermost C statement.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2534
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2535 With prefix arg, go forward N - 1 statements. Move forward to end of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2536 the next statement if already at end. If within a string or comment,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2537 move by sentences instead of statements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2538
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2539 When called from a program, this function takes 3 optional args: the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2540 repetition count, a buffer position limit which is the farthest back
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2541 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
2542 comment."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2543 (interactive (list (prefix-numeric-value current-prefix-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2544 nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2545 (c-beginning-of-statement (- (or count 1)) lim sentence-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2546 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2547
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2548 (defun c-beginning-of-statement-1 (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549 ;; move to the start of the current statement, or the previous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2550 ;; statement if already at the beginning of one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2551 (let ((firstp t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2552 (substmt-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2553 donep c-in-literal-cache
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2554 ;; KLUDGE ALERT: maybe-labelp is used to pass information
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2555 ;; between c-crosses-statement-barrier-p and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2556 ;; c-beginning-of-statement-1. A better way should be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2557 ;; implemented.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2558 maybe-labelp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2559 (last-begin (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2560 (while (not donep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2561 ;; stop at beginning of buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562 (if (bobp) (setq donep t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563 ;; go backwards one balanced expression, but be careful of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564 ;; unbalanced paren being reached
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565 (if (not (c-safe (progn (backward-sexp 1) t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567 (if firstp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568 (backward-up-list 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2569 (goto-char last-begin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2570 ;; skip over any unary operators, or other special
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2571 ;; characters appearing at front of identifier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2572 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2574 (skip-chars-backward "-+!*&:.~ \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2575 (if (= (preceding-char) ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2576 (setq last-begin (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2577 (goto-char last-begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2578 (setq last-begin (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2579 donep t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2580
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2581 (setq maybe-labelp nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2582 ;; see if we're in a literal. if not, then this bufpos may be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2583 ;; a candidate for stopping
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2584 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2585 ;; CASE 0: did we hit the error condition above?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2586 (donep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2587 ;; CASE 1: are we in a literal?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2588 ((eq (c-in-literal lim) 'pound)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2589 (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2590 ;; CASE 2: some other kind of literal?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2591 ((c-in-literal lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2592 ;; CASE 3: are we looking at a conditional keyword?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2593 ((or (looking-at c-conditional-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2594 (and (= (following-char) ?\()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2595 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2597 (c-forward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598 (/= (following-char) ?\;))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599 (let ((here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2600 (foundp (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2601 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2602 (forward-word -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2603 (and lim
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2604 (<= lim (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605 (not (c-in-literal lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2606 (looking-at c-conditional-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2607 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2608 ;; did we find a conditional?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2609 (if (not foundp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2610 (goto-char here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2611 foundp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612 ;; are we in the middle of an else-if clause?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2613 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614 (and (not substmt-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 (c-safe (progn (forward-sexp -1) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2616 (looking-at "\\<else\\>[ \t\n]+\\<if\\>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2617 (not (c-in-literal lim))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2619 (forward-sexp -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2620 (c-backward-to-start-of-if lim)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2621 ;; are we sitting at an else clause, that we are not a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2622 ;; substatement of?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2623 (if (and (not substmt-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2624 (looking-at "\\<else\\>[^_]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2625 (c-backward-to-start-of-if lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2626 ;; are we sitting at the while of a do-while?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2627 (if (and (looking-at "\\<while\\>[^_]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2628 (c-backward-to-start-of-do lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2629 (setq substmt-p nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2630 (setq last-begin (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2631 donep substmt-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632 ;; CASE 4: are we looking at a label?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633 ((looking-at c-label-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634 ;; CASE 5: is this the first time we're checking?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635 (firstp (setq firstp nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636 substmt-p (not (c-crosses-statement-barrier-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637 (point) last-begin))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638 last-begin (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639 ;; CASE 6: have we crossed a statement barrier?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2640 ((c-crosses-statement-barrier-p (point) last-begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641 (setq donep t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642 ;; CASE 7: ignore labels
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643 ((and maybe-labelp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644 (or (and c-access-key (looking-at c-access-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645 ;; with switch labels, we have to go back further
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646 ;; to try to pick up the case or default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647 ;; keyword. Potential bogosity alert: we assume
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648 ;; `case' or `default' is first thing on line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649 (let ((here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2650 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651 (c-forward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2652 (if (looking-at c-switch-label-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653 t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656 (looking-at c-label-key))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657 ;; CASE 8: ObjC or Java method def
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658 ((and c-method-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2659 (setq last-begin (c-in-method-def-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660 (setq donep t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 ;; CASE 9: nothing special
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662 (t (setq last-begin (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664 (goto-char last-begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665 ;; we always do want to skip over non-whitespace modifier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666 ;; characters that didn't get skipped above
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2667 (skip-chars-backward "-+!*&:.~" (c-point 'boi))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 (defun c-end-of-statement-1 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 (while (and (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673 (let ((beg (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2675 (let ((end (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2677 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2678 (not (re-search-forward "[;{}]" end t)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679 (re-search-backward "[;}]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2680 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2681 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2682 (let ((beg (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2683 (backward-up-list -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2684 (let ((end (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2685 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2686 (search-forward ";" end 'move))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2687
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688 (defun c-crosses-statement-barrier-p (from to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689 ;; Does buffer positions FROM to TO cross a C statement boundary?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2690 (let ((here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2691 (lim from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2692 crossedp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2693 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2694 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2695 (goto-char from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2696 (while (and (not crossedp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2697 (< (point) to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2698 (skip-chars-forward "^;{}:" to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2699 (if (not (c-in-literal lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2700 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2701 (if (memq (following-char) '(?\; ?{ ?}))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2702 (setq crossedp t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2703 (if (= (following-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2704 (setq maybe-labelp t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2705 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2706 (setq lim (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2707 (forward-char 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708 (error (setq crossedp nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2709 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2710 crossedp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2712
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2713 (defun c-up-conditional (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2714 "Move back to the containing preprocessor conditional, leaving mark behind.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2715 A prefix argument acts as a repeat count. With a negative argument,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2716 move forward to the end of the containing preprocessor conditional.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2717 When going backwards, `#elif' is treated like `#else' followed by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2718 `#if'. When going forwards, `#elif' is ignored."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2719 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2720 (c-forward-conditional (- count) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2721 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2723 (defun c-backward-conditional (count &optional up-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2724 "Move back across a preprocessor conditional, leaving mark behind.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2725 A prefix argument acts as a repeat count. With a negative argument,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2726 move forward across a preprocessor conditional."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2727 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2728 (c-forward-conditional (- count) up-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2729 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2730
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2731 (defun c-forward-conditional (count &optional up-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2732 "Move forward across a preprocessor conditional, leaving mark behind.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2733 A prefix argument acts as a repeat count. With a negative argument,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2734 move backward across a preprocessor conditional."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2735 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2736 (let* ((forward (> count 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2737 (increment (if forward -1 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2738 (search-function (if forward 're-search-forward 're-search-backward))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2739 (new))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2740 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2741 (while (/= count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2742 (let ((depth (if up-flag 0 -1)) found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2743 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2744 ;; Find the "next" significant line in the proper direction.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2745 (while (and (not found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2746 ;; Rather than searching for a # sign that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2747 ;; comes at the beginning of a line aside from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2748 ;; whitespace, search first for a string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2749 ;; starting with # sign. Then verify what
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2750 ;; precedes it. This is faster on account of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2751 ;; the fastmap feature of the regexp matcher.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2752 (funcall search-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2753 "#[ \t]*\\(if\\|elif\\|endif\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2754 nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2755 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2756 ;; Now verify it is really a preproc line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2757 (if (looking-at "^[ \t]*#[ \t]*\\(if\\|elif\\|endif\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2758 (let ((prev depth))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2759 ;; Update depth according to what we found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2760 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2761 (cond ((looking-at "[ \t]*#[ \t]*endif")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2762 (setq depth (+ depth increment)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2763 ((looking-at "[ \t]*#[ \t]*elif")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2764 (if (and forward (= depth 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2765 (setq found (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2766 (t (setq depth (- depth increment))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2767 ;; If we are trying to move across, and we find an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2768 ;; end before we find a beginning, get an error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2769 (if (and (< prev 0) (< depth prev))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2770 (error (if forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2771 "No following conditional at this level"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2772 "No previous conditional at this level")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2773 ;; When searching forward, start from next line so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2774 ;; that we don't find the same line again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2775 (if forward (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2776 ;; If this line exits a level of conditional, exit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2777 ;; inner loop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2778 (if (< depth 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2779 (setq found (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2780 ;; else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2781 (if forward (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2782 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2783 (or found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2784 (error "No containing preprocessor conditional"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2785 (goto-char (setq new found)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2786 (setq count (+ count increment))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2787 (push-mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2788 (goto-char new))
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2792 ;; commands to indent lines, regions, defuns, and expressions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2793 (defun c-indent-command (&optional whole-exp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2794 "Indent current line as C++ code, or in some cases insert a tab character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2795
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2796 If `c-tab-always-indent' is t, always just indent the current line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2797 If nil, indent the current line only if point is at the left margin or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2798 in the line's indentation; otherwise insert a tab. If other than nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2799 or t, then tab is inserted only within literals (comments and strings)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2800 and inside preprocessor directives, but line is always reindented.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2801
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2802 A numeric argument, regardless of its value, means indent rigidly all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2803 the lines of the expression starting after point so that this line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2804 becomes properly indented. The relative indentation among the lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2805 of the expression are preserved."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2806 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2807 (let ((bod (c-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2808 (if whole-exp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2809 ;; If arg, always indent this line as C
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2810 ;; and shift remaining lines of expression the same amount.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2811 (let ((shift-amt (c-indent-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2812 beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2813 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2814 (if (eq c-tab-always-indent t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2815 (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2816 (setq beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2817 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2818 (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2819 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2820 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2821 (setq beg (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2822 (if (> end beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2823 (indent-code-rigidly beg end (- shift-amt) "#")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2824 ;; No arg supplied, use c-tab-always-indent to determine
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2825 ;; behavior
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2826 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2827 ;; CASE 1: indent when at column zero or in lines indentation,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2828 ;; otherwise insert a tab
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2829 ((not c-tab-always-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2830 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2831 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2832 (not (bolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2833 (insert-tab)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2834 (c-indent-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2835 ;; CASE 2: just indent the line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2836 ((eq c-tab-always-indent t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2837 (c-indent-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2838 ;; CASE 3: if in a literal, insert a tab, but always indent the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2839 ;; line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2840 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2841 (if (c-in-literal bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2842 (insert-tab))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2843 (c-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2844 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2845
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2846 (defun c-indent-exp (&optional shutup-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2847 "Indent each line in balanced expression following point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2848 Optional SHUTUP-P if non-nil, inhibits message printing and error checking."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2849 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2850 (let ((here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2851 end progress-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2852 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2853 (let ((c-echo-syntactic-information-p nil) ;keep quiet for speed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2854 (start (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2855 ;; try to be smarter about finding the range of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2856 ;; lines to indent. skip all following
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2857 ;; whitespace. failing that, try to find any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2858 ;; opening brace on the current line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2859 (skip-chars-forward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2860 (if (memq (following-char) '(?\( ?\[ ?\{))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2861 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2862 (let ((state (parse-partial-sexp (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2863 (c-point 'eol))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2864 (and (nth 1 state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2865 (goto-char (nth 1 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2866 (memq (following-char) '(?\( ?\[ ?\{))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2867 (point)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2868 ;; find balanced expression end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2869 (setq end (and (c-safe (progn (forward-sexp 1) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2870 (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2871 ;; sanity check
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2872 (and (not start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2873 (not shutup-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2874 (error "Cannot find start of balanced expression to indent."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2875 (and (not end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2876 (not shutup-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2877 (error "Cannot find end of balanced expression to indent."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2878 (c-progress-init start end 'c-indent-exp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2879 (setq progress-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2880 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2881 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2882 (while (< (point) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2883 (if (not (looking-at "[ \t]*$"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2884 (c-indent-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2885 (c-progress-update)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2886 (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2887 ;; make sure marker is deleted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2888 (and end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2889 (set-marker end nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2890 (and progress-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2891 (c-progress-fini 'c-indent-exp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2892 (goto-char here))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2893
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2894 (defun c-indent-defun ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2895 "Re-indents the current top-level function def, struct or class declaration."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2896 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2897 (let ((here (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2898 (c-echo-syntactic-information-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2899 (brace (c-least-enclosing-brace (c-parse-state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2900 (if brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2901 (goto-char brace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2902 (beginning-of-defun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2903 ;; 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
2904 ;; least enclosing brace and we were sitting on the defun's open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2905 ;; brace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2906 (if (and (bobp) (not (= (following-char) ?\{)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2907 (goto-char here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2908 ;; 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
2909 ;; the open brace. I consider this an Emacs bug.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2910 (and (boundp 'defun-prompt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2911 defun-prompt-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2912 (looking-at defun-prompt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2913 (goto-char (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2914 ;; catch all errors in c-indent-exp so we can 1. give more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2915 ;; meaningful error message, and 2. restore point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2916 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2917 (c-indent-exp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2918 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2919 (set-marker here nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2920
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2921 (defun c-indent-region (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2922 ;; Indent every line whose first char is between START and END inclusive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2923 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2924 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2925 ;; Advance to first nonblank line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2926 (skip-chars-forward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2927 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2928 (let (endmark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2929 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2930 (let ((c-tab-always-indent t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2931 ;; shut up any echo msgs on indiv lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2932 (c-echo-syntactic-information-p nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2933 (c-progress-init start end 'c-indent-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2934 (setq endmark (copy-marker end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2935 (while (and (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2936 (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2937 (< (point) endmark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2938 ;; update progress
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2939 (c-progress-update)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2940 ;; Indent one line as with TAB.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2941 (let (nextline sexpend sexpbeg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2942 ;; skip blank lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2943 (skip-chars-forward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2944 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2945 ;; indent the current line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2946 (c-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2947 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2948 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2949 (looking-at "[ \t]*#"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2950 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2951 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2952 ;; Find beginning of following line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2953 (setq nextline (c-point 'bonl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2954 ;; Find first beginning-of-sexp for sexp extending past
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2955 ;; this line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2956 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2957 (while (< (point) nextline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2958 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2959 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2960 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2961 (setq sexpend (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2962 (error (setq sexpend nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2963 (goto-char nextline)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2964 (c-forward-syntactic-ws))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2965 (if sexpend
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2966 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2967 ;; make sure the sexp we found really starts on the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2968 ;; current line and extends past it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2969 (goto-char sexpend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2970 (setq sexpend (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2971 (c-safe (backward-sexp 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2972 (setq sexpbeg (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2973 ;; check to see if the next line starts a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2974 ;; comment-only line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2975 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2976 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2977 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2978 (if (looking-at c-comment-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2979 (setq sexpbeg (c-point 'bol))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2980 ;; If that sexp ends within the region, indent it all at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2981 ;; once, fast.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2982 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2983 (if (and sexpend
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2984 (> sexpend nextline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2985 (<= sexpend endmark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2986 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2987 (goto-char sexpbeg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2988 (c-indent-exp 'shutup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2989 (c-progress-update)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2990 (goto-char sexpend)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2991 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2992 (goto-char sexpbeg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2993 (c-indent-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2994 ;; Move to following line and try again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2995 (and sexpend
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2996 (markerp sexpend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2997 (set-marker sexpend nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2998 (forward-line 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2999 (set-marker endmark nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3000 (c-progress-fini 'c-indent-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3001 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3002
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3003 (defun c-mark-function ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3004 "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
3005 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3006 (let ((here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3007 ;; there should be a c-point position for 'eod
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3008 (eod (save-excursion (end-of-defun) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3009 (state (c-parse-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3010 brace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3011 (while state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3012 (setq brace (car state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3013 (if (consp brace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3014 (goto-char (cdr brace))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3015 (goto-char brace))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3016 (setq state (cdr state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3017 (if (= (following-char) ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3018 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3019 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3020 (while (not (or (bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3021 (looking-at "[ \t]*$")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3022 (forward-line -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3023 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3024 (skip-chars-forward " \t\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3025 (push-mark here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3026 (push-mark eod nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3027
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3028
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3029 ;; for progress reporting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3030 (defvar c-progress-info nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3031
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3032 (defun c-progress-init (start end context)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3033 ;; start the progress update messages. if this emacs doesn't have a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3034 ;; built-in timer, just be dumb about it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3035 (if (not (fboundp 'current-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3036 (message "indenting region... (this may take a while)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3037 ;; if progress has already been initialized, do nothing. otherwise
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3038 ;; initialize the counter with a vector of:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3039 ;; [start end lastsec context]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3040 (if c-progress-info
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3041 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3042 (setq c-progress-info (vector start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3043 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3044 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3045 (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3046 (nth 1 (current-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3047 context))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3048 (message "indenting region..."))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3049
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3050 (defun c-progress-update ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3051 ;; update progress
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3052 (if (not (and c-progress-info c-progress-interval))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3053 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3054 (let ((now (nth 1 (current-time)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3055 (start (aref c-progress-info 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3056 (end (aref c-progress-info 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3057 (lastsecs (aref c-progress-info 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3058 ;; should we update? currently, update happens every 2 seconds,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3059 ;; what's the right value?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3060 (if (< c-progress-interval (- now lastsecs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3061 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3062 (message "indenting region... (%d%% complete)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3063 (/ (* 100 (- (point) start)) (- end start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3064 (aset c-progress-info 2 now)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3065 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3066
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3067 (defun c-progress-fini (context)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3068 ;; finished
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3069 (if (or (eq context (aref c-progress-info 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3070 (eq context t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3071 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3072 (set-marker (aref c-progress-info 1) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3073 (setq c-progress-info nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3074 (message "indenting region...done"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3075
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3076
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3077 ;; Skipping of "syntactic whitespace" for Emacs 19. Syntactic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3078 ;; whitespace is defined as lexical whitespace, C and C++ style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3079 ;; comments, and preprocessor directives. Search no farther back or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3080 ;; forward than optional LIM. If LIM is omitted, `beginning-of-defun'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3081 ;; is used for backward skipping, point-max is used for forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3082 ;; 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
3083
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3084 (defun c-forward-syntactic-ws (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3085 ;; Forward skip of syntactic whitespace for Emacs 19.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3086 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3087 (let* ((lim (or lim (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3088 (here lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3089 (hugenum (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3090 (narrow-to-region lim (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3091 (while (/= here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3092 (setq here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3093 (forward-comment hugenum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3094 ;; skip preprocessor directives
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3095 (if (and (= (following-char) ?#)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3096 (= (c-point 'boi) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3097 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3098 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3099
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3100 (defun c-backward-syntactic-ws (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3101 ;; Backward skip over syntactic whitespace for Emacs 19.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3102 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3103 (let* ((lim (or lim (c-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3104 (here lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3105 (hugenum (- (point-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3106 (if (< lim (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3107 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3108 (narrow-to-region lim (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3109 (while (/= here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3110 (setq here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3111 (forward-comment hugenum)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3112 (if (eq (c-in-literal lim) 'pound)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3113 (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3114 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3115 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3118 ;; 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
3119 ;; comment, `string' if in a string literal, `pound' if on a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3120 ;; preprocessor line, or nil if not in a comment at all. Optional LIM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3121 ;; is used as the backward limit of the search. If omitted, or nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3122 ;; `beginning-of-defun' is used."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3124 ;; 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
3125 (defun c-in-literal (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3126 ;; Determine if point is in a C++ literal. we cache the last point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3127 ;; calculated if the cache is enabled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3128 (if (and (boundp 'c-in-literal-cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3129 c-in-literal-cache
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3130 (= (point) (aref c-in-literal-cache 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3131 (aref c-in-literal-cache 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3132 (let ((rtn (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3133 (let* ((lim (or lim (c-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3134 (here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3135 (state (parse-partial-sexp lim (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3136 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3137 ((nth 3 state) 'string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3138 ((nth 4 state) (if (nth 7 state) 'c++ 'c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3139 ((progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3140 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3141 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3142 (looking-at "[ \t]*#"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3143 'pound)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3144 (t nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3145 ;; cache this result if the cache is enabled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3146 (and (boundp 'c-in-literal-cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3147 (setq c-in-literal-cache (vector (point) rtn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3148 rtn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3151 ;; utilities for moving and querying around syntactic elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3152 (defun c-parse-state ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3153 ;; Finds and records all open parens between some important point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3154 ;; earlier in the file and point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3155 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3156 ;; if there's a state cache, return it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3157 (if (boundp 'c-state-cache) c-state-cache
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3158 (let* (at-bob
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3159 (pos (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3160 ;; go back 2 bods, but ignore any bogus positions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3161 ;; returned by beginning-of-defun (i.e. open paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3162 ;; in column zero)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3163 (let ((cnt 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3164 (while (not (or at-bob (zerop cnt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3165 (beginning-of-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3166 (if (= (following-char) ?\{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3167 (setq cnt (1- cnt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3168 (if (bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3169 (setq at-bob t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3170 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3171 (here (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3172 ;;(skip-chars-forward " \t}")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3173 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3174 (last-bod pos) (last-pos pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3175 placeholder state sexp-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3176 ;; cache last bod position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3177 (while (catch 'backup-bod
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3178 (setq state nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3179 (while (and pos (< pos here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3180 (setq last-pos pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3181 (if (and (setq pos (c-safe (scan-lists pos 1 -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3182 (<= pos here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3183 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3184 (setq sexp-end (c-safe (scan-sexps (1- pos) 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3185 (if (and sexp-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3186 (<= sexp-end here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3187 ;; we want to record both the start and end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3188 ;; of this sexp, but we only want to record
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3189 ;; the last-most of any of them before here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3190 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3191 (if (= (char-after (1- pos)) ?\{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3192 (setq state (cons (cons (1- pos) sexp-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3193 (if (consp (car state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3194 (cdr state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3195 state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3196 (setq pos sexp-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3197 ;; we're contained in this sexp so put pos on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3198 ;; front of list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3199 (setq state (cons (1- pos) state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3200 ;; something bad happened. check to see if we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3201 ;; crossed an unbalanced close brace. if so, we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3202 ;; didn't really find the right `important bufpos'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3203 ;; so lets back up and try again
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3204 (if (and (not pos) (not at-bob)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3205 (setq placeholder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3206 (c-safe (scan-lists last-pos 1 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3207 ;;(char-after (1- placeholder))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3208 (<= placeholder here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3209 (= (char-after (1- placeholder)) ?\}))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3210 (while t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3211 (setq last-bod (c-safe (scan-lists last-bod -1 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3212 (if (not last-bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3213 (error "unbalanced close brace at position %d"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3214 (1- placeholder))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3215 (setq at-bob (= last-bod (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3216 pos last-bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3217 (if (= (char-after last-bod) ?\{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3218 (throw 'backup-bod t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3219 )) ;end-if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3220 )) ;end-while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3221 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3222 state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3224 (defun c-whack-state (bufpos state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3225 ;; whack off any state information that appears on STATE which lies
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3226 ;; after the bounds of BUFPOS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3227 (let (newstate car)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3228 (while state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3229 (setq car (car state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3230 state (cdr state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3231 (if (consp car)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3232 ;; just check the car, because in a balanced brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3233 ;; expression, it must be impossible for the corresponding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3234 ;; close brace to be before point, but the open brace to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3235 ;; after.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3236 (if (<= bufpos (car car))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3237 nil ; whack it off
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3238 ;; its possible that the open brace is before bufpos, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3239 ;; the close brace is after. In that case, convert this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3240 ;; to a non-cons element.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3241 (if (<= bufpos (cdr car))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3242 (setq newstate (append newstate (list (car car))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3243 ;; we know that both the open and close braces are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3244 ;; before bufpos, so we also know that everything else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3245 ;; on state is before bufpos, so we can glom up the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3246 ;; whole thing and exit.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3247 (setq newstate (append newstate (list car) state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3248 state nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3249 (if (<= bufpos car)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3250 nil ; whack it off
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3251 ;; it's before bufpos, so everything else should too
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3252 (setq newstate (append newstate (list car) state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3253 state nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3254 newstate))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3256 (defun c-hack-state (bufpos which state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3257 ;; Using BUFPOS buffer position, and WHICH (must be 'open or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3258 ;; 'close), hack the c-parse-state STATE and return the results.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3259 (if (eq which 'open)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3260 (let ((car (car state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3261 (if (or (null car)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3262 (consp car)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3263 (/= bufpos car))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3264 (cons bufpos state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3265 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3266 (if (not (eq which 'close))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3267 (error "c-hack-state, bad argument: %s" which))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3268 ;; 'close brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3269 (let ((car (car state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3270 (cdr (cdr state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3271 (if (consp car)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3272 (setq car (car cdr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3273 cdr (cdr cdr)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3274 ;; TBD: is this test relevant???
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3275 (if (consp car)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3276 state ;on error, don't change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3277 ;; watch out for balanced expr already on cdr of list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3278 (cons (cons car bufpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3279 (if (consp (car cdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3280 (cdr cdr) cdr))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3281 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3283 (defun c-adjust-state (from to shift state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3284 ;; Adjust all points in state that lie in the region FROM..TO by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3285 ;; SHIFT amount (as would be returned by c-indent-line).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3286 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3287 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3288 (lambda (e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3289 (if (consp e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3290 (let ((car (car e))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3291 (cdr (cdr e)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3292 (if (and (<= from car) (< car to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3293 (setcar e (+ shift car)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3294 (if (and (<= from cdr) (< cdr to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3295 (setcdr e (+ shift cdr))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3296 (if (and (<= from e) (< e to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3297 (setq e (+ shift e))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3298 e))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3299 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3300
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3302 (defun c-beginning-of-inheritance-list (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3303 ;; Go to the first non-whitespace after the colon that starts a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3304 ;; multiple inheritance introduction. Optional LIM is the farthest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3305 ;; back we should search.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3306 (let ((lim (or lim (c-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3307 (placeholder (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3308 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3309 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3310 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3311 (while (and (> (point) lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3312 (memq (preceding-char) '(?, ?:))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3313 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3314 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3315 (setq placeholder (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3316 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3317 (not (looking-at c-class-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3318 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3319 (c-backward-syntactic-ws lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3320 (goto-char placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3321 (skip-chars-forward "^:" (c-point 'eol))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3322
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3323 (defun c-beginning-of-macro (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3324 ;; Go to the beginning of the macro. Right now we don't support
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3325 ;; multi-line macros too well
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3326 (back-to-indentation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3327
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3328 (defun c-in-method-def-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3329 ;; Return nil if we aren't in a method definition, otherwise the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3330 ;; position of the initial [+-].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3331 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3332 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3333 (and c-method-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3334 (looking-at c-method-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3335 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3336 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3338 (defun c-just-after-func-arglist-p (&optional containing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3339 ;; Return t if we are between a function's argument list closing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3340 ;; paren and its opening brace. Note that the list close brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3341 ;; could be followed by a "const" specifier or a member init hanging
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3342 ;; colon. Optional CONTAINING is position of containing s-exp open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3343 ;; brace. If not supplied, point is used as search start.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3344 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3345 (c-backward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3346 (let ((checkpoint (or containing (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3347 (goto-char checkpoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3348 ;; could be looking at const specifier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3349 (if (and (= (preceding-char) ?t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3350 (forward-word -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3351 (looking-at "\\<const\\>"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3352 (c-backward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3353 ;; otherwise, we could be looking at a hanging member init
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3354 ;; colon
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3355 (goto-char checkpoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3356 (if (and (= (preceding-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3357 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3358 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3359 (c-backward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3360 (looking-at "[ \t\n]*:\\([^:]+\\|$\\)")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3361 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3362 (goto-char checkpoint))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3363 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3364 (and (= (preceding-char) ?\))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3365 ;; check if we are looking at a method def
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3366 (or (not c-method-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3367 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3368 (forward-sexp -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3369 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3370 (c-backward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3371 (not (or (= (preceding-char) ?-)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3372 (= (preceding-char) ?+)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3373 ;; or a class category
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3374 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3375 (forward-sexp -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3376 (looking-at c-class-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3377 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3378 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3380 ;; defuns to look backwards for things
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3381 (defun c-backward-to-start-of-do (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3382 ;; Move to the start of the last "unbalanced" do expression.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3383 ;; Optional LIM is the farthest back to search. If none is found,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3384 ;; nil is returned and point is left unchanged, otherwise t is returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3385 (let ((do-level 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3386 (case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3387 (lim (or lim (c-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3388 (here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3389 foundp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3390 (while (not (zerop do-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3391 ;; we protect this call because trying to execute this when the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3392 ;; while is not associated with a do will throw an error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3393 (condition-case nil
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 (backward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3396 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3397 ((memq (c-in-literal lim) '(c c++)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3398 ((looking-at "while\\b[^_]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3399 (setq do-level (1+ do-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3400 ((looking-at "do\\b[^_]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3401 (if (zerop (setq do-level (1- do-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3402 (setq foundp t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3403 ((<= (point) lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3404 (setq do-level 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3405 (goto-char lim))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3406 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3407 (goto-char lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3408 (setq do-level 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3409 (if (not foundp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3410 (goto-char here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3411 foundp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3413 (defun c-backward-to-start-of-if (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3414 ;; Move to the start of the last "unbalanced" if and return t. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3415 ;; none is found, and we are looking at an if clause, nil is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3416 ;; returned. If none is found and we are looking at an else clause,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3417 ;; an error is thrown.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3418 (let ((if-level 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3419 (here (c-point 'bol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3420 (case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3421 (lim (or lim (c-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3422 (at-if (looking-at "if\\b[^_]")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3423 (catch 'orphan-if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3424 (while (and (not (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3425 (not (zerop if-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3426 (c-backward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3427 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3428 (backward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3429 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3430 (if at-if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3431 (throw 'orphan-if nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3432 (error "No matching `if' found for `else' on line %d."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3433 (1+ (count-lines 1 here))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3434 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3435 ((looking-at "else\\b[^_]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3436 (setq if-level (1+ if-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3437 ((looking-at "if\\b[^_]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3438 ;; check for else if... skip over
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3439 (let ((here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3440 (c-safe (forward-sexp -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3441 (if (looking-at "\\<else\\>[ \t]+\\<if\\>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3442 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3443 (setq if-level (1- if-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3444 (goto-char here))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3445 ((< (point) lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3446 (setq if-level 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3447 (goto-char lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3448 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3449 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3450
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3451 (defun c-skip-conditional ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3452 ;; skip forward over conditional at point, including any predicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3453 ;; statements in parentheses. No error checking is performed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3454 (forward-sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3455 ;; else if()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3456 (if (looking-at "\\<else\\>[ \t]+\\<if\\>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3457 3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3458 ;; do and else aren't followed by parens
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3459 (if (looking-at "\\<\\(do\\|else\\)\\>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3460 1 2))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3461
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3462 (defun c-skip-case-statement-forward (state &optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3463 ;; skip forward over case/default bodies, with optional maximal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3464 ;; limit. if no next case body is found, nil is returned and point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3465 ;; is not moved
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3466 (let ((lim (or lim (point-max)))
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 donep foundp bufpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3469 (safepos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3470 (balanced (car state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3471 ;; search until we've passed the limit, or we've found our match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3472 (while (and (< (point) lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3473 (not donep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3474 (setq safepos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3475 ;; see if we can find a case statement, not in a literal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3476 (if (and (re-search-forward c-switch-label-key lim 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3477 (setq bufpos (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3478 (not (c-in-literal safepos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3479 (/= bufpos here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3480 ;; if we crossed into a balanced sexp, we know the case is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3481 ;; not part of our switch statement, so just bound over the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3482 ;; sexp and keep looking.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3483 (if (and (consp balanced)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3484 (> bufpos (car balanced))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3485 (< bufpos (cdr balanced)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3486 (goto-char (cdr balanced))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3487 (goto-char bufpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3488 (setq donep t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3489 foundp t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3490 (if (not foundp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3491 (goto-char here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3492 foundp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3493
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3494 (defun c-search-uplist-for-classkey (brace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3495 ;; search for the containing class, returning a 2 element vector if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3496 ;; found. aref 0 contains the bufpos of the class key, and aref 1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3497 ;; contains the bufpos of the open brace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3498 (if (null brace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3499 ;; no brace-state means we cannot be inside a class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3500 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3501 (let ((carcache (car brace-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3502 search-start search-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3503 (if (consp carcache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3504 ;; a cons cell in the first element means that there is some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3505 ;; balanced sexp before the current bufpos. this we can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3506 ;; ignore. the nth 1 and nth 2 elements define for us the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3507 ;; search boundaries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3508 (setq search-start (nth 2 brace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3509 search-end (nth 1 brace-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3510 ;; 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
3511 ;; for us the search boundaries
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3512 (setq search-start (nth 1 brace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3513 search-end (nth 0 brace-state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3514 ;; search-end cannot be a cons cell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3515 (and (consp search-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3516 (error "consp search-end: %s" search-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3517 ;; 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
3518 ;; open brace, we are definitely not in a class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3519 (if (or (not search-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3520 (< search-end (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3521 (/= (char-after search-end) ?{))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3522 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3523 ;; now, we need to look more closely at search-start. if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3524 ;; search-start is nil, then our start boundary is really
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3525 ;; point-min.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3526 (if (not search-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3527 (setq search-start (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3528 ;; if search-start is a cons cell, then we can start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3529 ;; searching from the end of the balanced sexp just ahead of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3530 ;; us
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3531 (if (consp search-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3532 (setq search-start (cdr search-start))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3533 ;; now we can do a quick regexp search from search-start to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3534 ;; search-end and see if we can find a class key. watch for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3535 ;; class like strings in literals
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3536 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3537 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3538 (goto-char search-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3539 (let (foundp class match-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3540 (while (and (not foundp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3541 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3542 (c-forward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3543 (> search-end (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3544 (re-search-forward c-class-key search-end t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3545 (setq class (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3546 match-end (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3547 (if (c-in-literal search-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3548 nil ; its in a comment or string, ignore
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3549 (goto-char class)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3550 (skip-chars-forward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3551 (setq foundp (vector (c-point 'boi) search-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3552 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3553 ;; check for embedded keywords
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3554 ((let ((char (char-after (1- class))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3555 (and char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3556 (memq (char-syntax char) '(?w ?_))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3557 (goto-char match-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3558 (setq foundp nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3559 ;; make sure we're really looking at the start of a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3560 ;; class definition, and not a forward decl, return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3561 ;; arg, template arg list, or an ObjC or Java method.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3562 ((and c-method-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3563 (re-search-forward c-method-key search-end t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3564 (setq foundp nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3565 ;; Its impossible to define a regexp for this, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3566 ;; nearly so to do it programmatically.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3567 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3568 ;; ; picks up forward decls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3569 ;; = picks up init lists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3570 ;; ) picks up return types
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3571 ;; > picks up templates, but remember that we can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3572 ;; inherit from templates!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3573 ((let ((skipchars "^;=)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3574 ;; try to see if we found the `class' keyword
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3575 ;; inside a template arg list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3576 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3577 (skip-chars-backward "^<>" search-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3578 (if (= (preceding-char) ?<)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3579 (setq skipchars (concat skipchars ">"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3580 (skip-chars-forward skipchars search-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3581 (/= (point) search-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3582 (setq foundp nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3583 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3584 foundp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3585 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3586
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3587 (defun c-inside-bracelist-p (containing-sexp brace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3588 ;; return the buffer position of the beginning of the brace list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3589 ;; statement if we're inside a brace list, otherwise return nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3590 ;; CONTAINING-SEXP is the buffer pos of the innermost containing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3591 ;; paren. BRACE-STATE is the remainder of the state of enclosing braces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3592 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3593 ;; N.B.: This algorithm can potentially get confused by cpp macros
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3594 ;; places in inconvenient locations. Its a trade-off we make for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3595 ;; speed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3596 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3597 ;; this will pick up enum lists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3598 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3599 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3600 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3601 (forward-sexp -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3602 (if (or (looking-at "enum[\t\n ]+")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3603 (progn (forward-sexp -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3604 (looking-at "enum[\t\n ]+")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3605 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3606 (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3607 ;; this will pick up array/aggregate init lists, even if they are nested.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3608 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3609 (let (bufpos failedp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3610 (while (and (not bufpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3611 containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3612 (if (consp containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3613 (setq containing-sexp (car brace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3614 brace-state (cdr brace-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3615 ;; see if significant character just before brace is an equal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3616 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3617 (setq failedp nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3618 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3619 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3620 (forward-sexp -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3621 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3622 (c-forward-syntactic-ws containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3623 (error (setq failedp t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3624 (if (or failedp (/= (following-char) ?=))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3625 ;; lets see if we're nested. find the most nested
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3626 ;; containing brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3627 (setq containing-sexp (car brace-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3628 brace-state (cdr brace-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3629 ;; we've hit the beginning of the aggregate list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3630 (c-beginning-of-statement-1 (c-most-enclosing-brace brace-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3631 (setq bufpos (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3632 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3633 bufpos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3634 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3635
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3636
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3637 ;; defuns for calculating the syntactic state and indenting a single
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3638 ;; line of C/C++/ObjC code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3639 (defmacro c-add-syntax (symbol &optional relpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3640 ;; a simple macro to append the syntax in symbol to the syntax list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3641 ;; try to increase performance by using this macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3642 (` (setq syntax (cons (cons (, symbol) (, relpos)) syntax))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3643
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3644 (defun c-most-enclosing-brace (state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3645 ;; return the bufpos of the most enclosing brace that hasn't been
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3646 ;; narrowed out by any enclosing class, or nil if none was found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3647 (let (enclosingp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3648 (while (and state (not enclosingp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3649 (setq enclosingp (car state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3650 state (cdr state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3651 (if (consp enclosingp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3652 (setq enclosingp nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3653 (if (> (point-min) enclosingp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3654 (setq enclosingp nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3655 (setq state nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3656 enclosingp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3657
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3658 (defun c-least-enclosing-brace (state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3659 ;; return the bufpos of the least (highest) enclosing brace that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3660 ;; hasn't been narrowed out by any enclosing class, or nil if none
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3661 ;; was found.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3662 (c-most-enclosing-brace (nreverse state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3663
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3664 (defun c-safe-position (bufpos state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3665 ;; return the closest known safe position higher up than point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3666 (let ((safepos nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3667 (while state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3668 (setq safepos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3669 (if (consp (car state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3670 (cdr (car state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3671 (car state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3672 (if (< safepos bufpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3673 (setq state nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3674 (setq state (cdr state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3675 safepos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3676
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3677 (defun c-narrow-out-enclosing-class (state lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3678 ;; narrow the buffer so that the enclosing class is hidden
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3679 (let (inclass-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3680 (and state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3681 (setq inclass-p (c-search-uplist-for-classkey state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3682 (narrow-to-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3683 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3684 (goto-char (1+ (aref inclass-p 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3685 (skip-chars-forward " \t\n" lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3686 ;; if point is now left of the class opening brace, we're
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3687 ;; hosed, so try a different tact
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3688 (if (<= (point) (aref inclass-p 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3689 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3690 (goto-char (1+ (aref inclass-p 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3691 (c-forward-syntactic-ws lim)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3692 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3693 ;; end point is the end of the current line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3694 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3695 (goto-char lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3696 (c-point 'eol))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3697 ;; return the class vector
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3698 inclass-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3699
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3700 (defun c-guess-basic-syntax ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3701 ;; guess the syntactic description of the current line of C++ code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3702 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3703 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3704 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3705 (let* ((indent-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3706 (case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3707 (fullstate (c-parse-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3708 (state fullstate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3709 (in-method-intro-p (and c-method-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3710 (looking-at c-method-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3711 literal containing-sexp char-before-ip char-after-ip lim
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3712 syntax placeholder c-in-literal-cache inswitch-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3713 ;; narrow out any enclosing class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3714 (inclass-p (c-narrow-out-enclosing-class state indent-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3715 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3716
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3717 ;; get the buffer position of the most nested opening brace,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3718 ;; if there is one, and it hasn't been narrowed out
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3719 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3720 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3721 (skip-chars-forward " \t}")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3722 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3723 (while (and state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3724 (not in-method-intro-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3725 (not containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3726 (setq containing-sexp (car state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3727 state (cdr state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3728 (if (consp containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3729 ;; if cdr == point, then containing sexp is the brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3730 ;; that opens the sexp we close
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3731 (if (= (cdr containing-sexp) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3732 (setq containing-sexp (car containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3733 ;; otherwise, ignore this element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3734 (setq containing-sexp nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3735 ;; ignore the bufpos if its been narrowed out by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3736 ;; containing class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3737 (if (<= containing-sexp (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3738 (setq containing-sexp nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3739
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3740 ;; set the limit on the farthest back we need to search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3741 (setq lim (or containing-sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3742 (if (consp (car fullstate))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3743 (cdr (car fullstate))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3744 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3745 (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3746
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3747 ;; cache char before and after indent point, and move point to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3748 ;; the most likely position to perform the majority of tests
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3749 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3750 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3751 (setq char-after-ip (following-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3752 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3753 (setq char-before-ip (preceding-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3754 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3755 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3756
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3757 ;; are we in a literal?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3758 (setq literal (c-in-literal lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3759
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3760 ;; now figure out syntactic qualities of the current line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3761 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3762 ;; CASE 1: in a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3763 ((memq literal '(string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3764 (c-add-syntax 'string (c-point 'bopl)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3765 ;; CASE 2: in a C or C++ style comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3766 ((memq literal '(c c++))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3767 ;; we need to catch multi-paragraph C comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3768 (while (and (zerop (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3769 (looking-at "^[ \t]*$")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3770 (c-add-syntax literal (c-point 'bol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3771 ;; CASE 3: in a cpp preprocessor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3772 ((eq literal 'pound)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3773 (c-beginning-of-macro lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3774 (c-add-syntax 'cpp-macro (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3775 ;; CASE 4: in an objective-c method intro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3776 (in-method-intro-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3777 (c-add-syntax 'objc-method-intro (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3778 ;; CASE 5: Line is at top level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3779 ((null containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3780 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3781 ;; CASE 5A: we are looking at a defun, class, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3782 ;; inline-inclass method opening brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3783 ((= char-after-ip ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3784 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3785 ;; CASE 5A.1: we are looking at a class opening brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3786 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3787 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3788 (skip-chars-forward " \t{")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3789 ;; TBD: watch out! there could be a bogus
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3790 ;; c-state-cache in place when we get here. we have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3791 ;; to go through much chicanery to ignore the cache.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3792 ;; But of course, there may not be! BLECH! BOGUS!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3793 (let ((decl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3794 (if (boundp 'c-state-cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3795 (let ((old-cache c-state-cache))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3796 (prog2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3797 (makunbound 'c-state-cache)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3798 (c-search-uplist-for-classkey (c-parse-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3799 (setq c-state-cache old-cache)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3800 (c-search-uplist-for-classkey (c-parse-state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3801 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3802 (and decl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3803 (setq placeholder (aref decl 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3804 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3805 (c-add-syntax 'class-open placeholder))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3806 ;; CASE 5A.2: brace list open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3807 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3808 (c-beginning-of-statement-1 lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3809 ;; c-b-o-s could have left us at point-min
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3810 (and (bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3811 (c-forward-syntactic-ws indent-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3812 (setq placeholder (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3813 (and (or (looking-at "enum[ \t\n]+")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3814 (= char-before-ip ?=))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3815 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3816 (skip-chars-forward "^;(" indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3817 (not (memq (following-char) '(?\; ?\()))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3818 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3819 (c-add-syntax 'brace-list-open placeholder))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3820 ;; CASE 5A.3: inline defun open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3821 (inclass-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3822 (c-add-syntax 'inline-open (aref inclass-p 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3823 ;; CASE 5A.4: ordinary defun open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3824 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3825 (goto-char placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3826 (c-add-syntax 'defun-open (c-point 'bol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3827 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3828 ;; CASE 5B: first K&R arg decl or member init
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3829 ((c-just-after-func-arglist-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3830 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3831 ;; CASE 5B.1: a member init
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3832 ((or (= char-before-ip ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3833 (= char-after-ip ?:))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3834 ;; this line should be indented relative to the beginning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3835 ;; of indentation for the topmost-intro line that contains
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3836 ;; the prototype's open paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3837 ;; TBD: is the following redundant?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3838 (if (= char-before-ip ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3839 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3840 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3841 ;; TBD: is the preceding redundant?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3842 (if (= (preceding-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3843 (progn (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3844 (c-backward-syntactic-ws lim)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3845 (if (= (preceding-char) ?\))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3846 (backward-sexp 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3847 (c-add-syntax 'member-init-intro (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3848 ;; we don't need to add any class offset since this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3849 ;; should be relative to the ctor's indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3850 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3851 ;; CASE 5B.2: K&R arg decl intro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3852 (c-recognize-knr-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3853 (c-add-syntax 'knr-argdecl-intro (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3854 (and inclass-p (c-add-syntax 'inclass (aref inclass-p 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3855 ;; CASE 5B.3: Nether region after a C++ func decl, which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3856 ;; could include a `throw' declaration.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3857 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3858 (c-beginning-of-statement-1 lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3859 (c-add-syntax 'ansi-funcdecl-cont (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3860 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3861 ;; CASE 5C: inheritance line. could be first inheritance
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3862 ;; line, or continuation of a multiple inheritance
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3863 ((or (and c-baseclass-key (looking-at c-baseclass-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3864 (and (or (= char-before-ip ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3865 (= char-after-ip ?:))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3866 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3867 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3868 (if (= char-before-ip ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3869 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3870 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3871 (c-backward-syntactic-ws lim)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3872 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3873 (looking-at c-class-key))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3874 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3875 ;; CASE 5C.1: non-hanging colon on an inher intro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3876 ((= char-after-ip ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3877 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3878 (c-add-syntax 'inher-intro (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3879 ;; don't add inclass symbol since relative point already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3880 ;; contains any class offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3881 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3882 ;; CASE 5C.2: hanging colon on an inher intro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3883 ((= char-before-ip ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3884 (c-add-syntax 'inher-intro (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3885 (and inclass-p (c-add-syntax 'inclass (aref inclass-p 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3886 ;; CASE 5C.3: a continued inheritance line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3887 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3888 (c-beginning-of-inheritance-list lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3889 (c-add-syntax 'inher-cont (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3890 ;; don't add inclass symbol since relative point already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3891 ;; contains any class offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3892 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3893 ;; CASE 5D: this could be a top-level compound statement or a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3894 ;; member init list continuation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3895 ((= char-before-ip ?,)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3896 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3897 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3898 (while (and (< lim (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3899 (= (preceding-char) ?,))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3900 ;; this will catch member inits with multiple
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3901 ;; line arglists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3902 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3903 (c-backward-syntactic-ws (c-point 'bol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3904 (if (= (preceding-char) ?\))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3905 (backward-sexp 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3906 ;; now continue checking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3907 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3908 (c-backward-syntactic-ws lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3909 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3910 ;; CASE 5D.1: hanging member init colon, but watch out
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3911 ;; for bogus matches on access specifiers inside classes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3912 ((and (= (preceding-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3913 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3914 (forward-word -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3915 (not (looking-at c-access-key))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3916 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3917 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3918 (c-safe (backward-sexp 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3919 (c-add-syntax 'member-init-cont (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3920 ;; we do not need to add class offset since relative
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3921 ;; point is the member init above us
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3922 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3923 ;; CASE 5D.2: non-hanging member init colon
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3924 ((progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3925 (c-forward-syntactic-ws indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3926 (= (following-char) ?:))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3927 (skip-chars-forward " \t:")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3928 (c-add-syntax 'member-init-cont (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3929 ;; CASE 5D.3: perhaps a multiple inheritance line?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3930 ((looking-at c-inher-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3931 (c-add-syntax 'inher-cont (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3932 ;; CASE 5D.4: perhaps a template list continuation?
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 (skip-chars-backward "^<" lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3935 ;; not sure if this is the right test, but it should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3936 ;; be fast and mostly accurate.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3937 (and (= (preceding-char) ?<)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3938 (not (c-in-literal lim))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3939 ;; we can probably indent it just like and arglist-cont
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3940 (c-add-syntax 'arglist-cont (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3941 ;; CASE 5D.5: perhaps a top-level statement-cont
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3942 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3943 (c-beginning-of-statement-1 lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3944 ;; skip over any access-specifiers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3945 (and inclass-p c-access-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3946 (while (looking-at c-access-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3947 (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3948 ;; skip over comments, whitespace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3949 (c-forward-syntactic-ws indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3950 (c-add-syntax 'statement-cont (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3951 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3952 ;; CASE 5E: we are looking at a access specifier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3953 ((and inclass-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3954 c-access-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3955 (looking-at c-access-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3956 (c-add-syntax 'access-label (c-point 'bonl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3957 (c-add-syntax 'inclass (aref inclass-p 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3958 ;; CASE 5F: we are looking at the brace which closes the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3959 ;; enclosing nested class decl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3960 ((and inclass-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3961 (= char-after-ip ?})
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3962 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3963 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3964 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3965 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3966 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3967 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3968 (progn (backward-sexp 1) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3969 (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3970 (= (point) (aref inclass-p 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3971 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3972 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3973 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3974 (goto-char (aref inclass-p 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3975 (c-add-syntax 'class-close (c-point 'boi))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3976 ;; CASE 5G: we could be looking at subsequent knr-argdecls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3977 ((and c-recognize-knr-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3978 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3979 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3980 (while (memq (preceding-char) '(?\; ?,))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3981 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3982 (setq placeholder (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3983 (c-backward-syntactic-ws lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3984 (and (= (preceding-char) ?\))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3985 (or (not c-method-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3986 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3987 (forward-sexp -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3988 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3989 (c-backward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3990 (not (or (= (preceding-char) ?-)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3991 (= (preceding-char) ?+)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3992 ;; or a class category
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3993 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3994 (forward-sexp -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3995 (looking-at c-class-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3996 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3997 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3998 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3999 (c-beginning-of-statement-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4000 (not (looking-at "typedef[ \t\n]+"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4001 (goto-char placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4002 (c-add-syntax 'knr-argdecl (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4003 ;; CASE 5H: we are at the topmost level, make sure we skip
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4004 ;; back past any access specifiers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4005 ((progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4006 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4007 (while (and inclass-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4008 c-access-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4009 (not (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4010 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4011 (c-safe (progn (backward-sexp 1) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4012 (looking-at c-access-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4013 (backward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4014 (c-backward-syntactic-ws lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4015 (or (bobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4016 (memq (preceding-char) '(?\; ?\}))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4017 ;; real beginning-of-line could be narrowed out due to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4018 ;; enclosure in a class block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4019 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4020 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4021 (c-add-syntax 'topmost-intro (c-point 'bol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4022 (if inclass-p
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 (aref inclass-p 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4025 (c-add-syntax 'inclass (c-point 'boi))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4026 ;; CASE 5I: we are at an ObjC or Java method definition
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4027 ;; continuation line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4028 ((and c-method-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4029 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4030 (c-beginning-of-statement-1 lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4031 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4032 (looking-at c-method-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4033 (c-add-syntax 'objc-method-args-cont (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4034 ;; CASE 5J: we are at a topmost continuation line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4035 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4036 (c-beginning-of-statement-1 lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4037 (c-forward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4038 (c-add-syntax 'topmost-intro-cont (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4039 )) ; end CASE 5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4040 ;; CASE 6: line is an expression, not a statement. Most
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4041 ;; likely we are either in a function prototype or a function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4042 ;; call argument list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4043 ((/= (char-after containing-sexp) ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4044 (c-backward-syntactic-ws containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4045 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4046 ;; CASE 6A: we are looking at the arglist closing paren or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4047 ;; at an Objective-C or Java method call closing bracket.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4048 ((and (/= char-before-ip ?,)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4049 (memq char-after-ip '(?\) ?\])))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4050 (if (and c-method-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4051 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4052 (goto-char (1- containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4053 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4054 (not (looking-at c-symbol-key))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4055 (c-add-syntax 'statement-cont containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4056 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4057 (c-add-syntax 'arglist-close (c-point 'boi))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4058 ;; CASE 6B: we are looking at the first argument in an empty
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4059 ;; argument list. Use arglist-close if we're actually
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4060 ;; looking at a close paren or bracket.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4061 ((memq char-before-ip '(?\( ?\[))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4062 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4063 (c-add-syntax 'arglist-intro (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4064 ;; CASE 6C: we are inside a conditional test clause. treat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4065 ;; these things as statements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4066 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4067 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4068 (and (c-safe (progn (forward-sexp -1) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4069 (looking-at "\\<for\\>")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4070 (goto-char (1+ containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4071 (c-forward-syntactic-ws indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4072 (c-beginning-of-statement-1 containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4073 (if (= char-before-ip ?\;)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4074 (c-add-syntax 'statement (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4075 (c-add-syntax 'statement-cont (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4076 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4077 ;; CASE 6D: maybe a continued method call. This is the case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4078 ;; when we are inside a [] bracketed exp, and what precede
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4079 ;; the opening bracket is not an identifier.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4080 ((and c-method-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4081 (= (char-after containing-sexp) ?\[)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4082 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4083 (goto-char (1- containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4084 (c-backward-syntactic-ws (c-point 'bod))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4085 (if (not (looking-at c-symbol-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4086 (c-add-syntax 'objc-method-call-cont containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4087 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4088 ;; CASE 6E: we are looking at an arglist continuation line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4089 ;; but the preceding argument is on the same line as the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4090 ;; opening paren. This case includes multi-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4091 ;; mathematical paren groupings, but we could be on a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4092 ;; for-list continuation line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4093 ((and (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4094 (goto-char (1+ containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4095 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4096 (not (eolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4097 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4098 (c-beginning-of-statement-1 lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4099 (skip-chars-backward " \t([")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4100 (<= (point) containing-sexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4101 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4102 (c-add-syntax 'arglist-cont-nonempty (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4103 ;; CASE 6F: we are looking at just a normal arglist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4104 ;; continuation line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4105 (t (c-beginning-of-statement-1 containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4106 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4107 (c-forward-syntactic-ws indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4108 (c-add-syntax 'arglist-cont (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4109 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4110 ;; CASE 7: func-local multi-inheritance line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4111 ((and c-baseclass-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4112 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4113 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4114 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4115 (looking-at c-baseclass-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4116 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4117 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4118 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4119 ;; CASE 7A: non-hanging colon on an inher intro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4120 ((= char-after-ip ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4121 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4122 (c-add-syntax 'inher-intro (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4123 ;; CASE 7B: hanging colon on an inher intro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4124 ((= char-before-ip ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4125 (c-add-syntax 'inher-intro (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4126 ;; CASE 7C: a continued inheritance line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4127 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4128 (c-beginning-of-inheritance-list lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4129 (c-add-syntax 'inher-cont (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4130 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4131 ;; CASE 8: we are inside a brace-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4132 ((setq placeholder (c-inside-bracelist-p containing-sexp state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4133 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4134 ;; CASE 8A: brace-list-close brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4135 ((and (= char-after-ip ?})
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4136 (c-safe (progn (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4137 (backward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4138 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4139 (= (point) containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4140 (c-add-syntax 'brace-list-close (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4141 ;; CASE 8B: we're looking at the first line in a brace-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4142 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4143 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4144 (c-backward-syntactic-ws containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4145 (= (point) (1+ containing-sexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4146 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4147 ;;(if (= char-after-ip ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4148 ;;(c-add-syntax 'brace-list-open (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4149 (c-add-syntax 'brace-list-intro (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4150 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4151 ;;)) ; end CASE 8B
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4152 ;; CASE 8C: this is just a later brace-list-entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4153 (t (goto-char (1+ containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4154 (c-forward-syntactic-ws indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4155 (if (= char-after-ip ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4156 (c-add-syntax 'brace-list-open (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4157 (c-add-syntax 'brace-list-entry (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4158 )) ; end CASE 8C
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4159 )) ; end CASE 8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4160 ;; CASE 9: A continued statement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4161 ((and (not (memq char-before-ip '(?\; ?} ?:)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4162 (> (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4163 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4164 (c-beginning-of-statement-1 containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4165 (setq placeholder (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4166 (/= placeholder containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4167 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4168 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4169 (let ((after-cond-placeholder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4170 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4171 (goto-char placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4172 (if (looking-at c-conditional-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4173 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4174 (c-safe (c-skip-conditional))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4175 (c-forward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4176 (if (memq (following-char) '(?\;))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4177 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4178 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4179 (c-forward-syntactic-ws)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4180 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4181 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4182 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4183 ;; CASE 9A: substatement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4184 ((and after-cond-placeholder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4185 (>= after-cond-placeholder indent-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4186 (goto-char placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4187 (if (= char-after-ip ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4188 (c-add-syntax 'substatement-open (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4189 (c-add-syntax 'substatement (c-point 'boi))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4190 ;; CASE 9B: open braces for class or brace-lists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4191 ((= char-after-ip ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4192 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4193 ;; CASE 9B.1: class-open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4194 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4195 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4196 (skip-chars-forward " \t{")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4197 (let ((decl (c-search-uplist-for-classkey (c-parse-state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4198 (and decl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4199 (setq placeholder (aref decl 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4200 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4201 (c-add-syntax 'class-open placeholder))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4202 ;; CASE 9B.2: brace-list-open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4203 ((or (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4204 (goto-char placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4205 (looking-at "\\<enum\\>"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4206 (= char-before-ip ?=))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4207 (c-add-syntax 'brace-list-open placeholder))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4208 ;; CASE 9B.3: catch-all for unknown construct.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4209 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4210 ;; Can and should I add an extensibility hook here?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4211 ;; Something like c-recognize-hook so support for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4212 ;; unknown constructs could be added. It's probably a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4213 ;; losing proposition, so I dunno.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4214 (goto-char placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4215 (c-add-syntax 'statement-cont (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4216 (c-add-syntax 'block-open))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4217 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4218 ;; CASE 9C: iostream insertion or extraction operator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4219 ((looking-at "<<\\|>>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4220 (goto-char placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4221 (and after-cond-placeholder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4222 (goto-char after-cond-placeholder))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4223 (while (and (re-search-forward "<<\\|>>" indent-point 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4224 (c-in-literal placeholder)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4225 ;; if we ended up at indent-point, then the first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4226 ;; streamop is on a separate line. Indent the line like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4227 ;; a statement-cont instead
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4228 (if (/= (point) indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4229 (c-add-syntax 'stream-op (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4230 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4231 (c-add-syntax 'statement-cont (c-point 'boi))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4232 ;; CASE 9D: continued statement. find the accurate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4233 ;; beginning of statement or substatement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4234 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4235 (c-beginning-of-statement-1 after-cond-placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4236 ;; KLUDGE ALERT! c-beginning-of-statement-1 can leave
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4237 ;; us before the lim we're passing in. It should be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4238 ;; fixed, but I'm worried about side-effects at this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4239 ;; late date. Fix for v5.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4240 (goto-char (or (and after-cond-placeholder
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4241 (max after-cond-placeholder (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4242 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4243 (c-add-syntax 'statement-cont (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4244 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4245 ;; CASE 10: an else clause?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4246 ((looking-at "\\<else\\>[^_]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4247 (c-backward-to-start-of-if containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4248 (c-add-syntax 'else-clause (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4249 ;; CASE 11: Statement. But what kind? Lets see if its a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4250 ;; while closure of a do/while construct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4251 ((progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4252 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4253 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4254 (and (looking-at "while\\b[^_]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4255 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4256 (c-backward-to-start-of-do containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4257 (setq placeholder (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4258 (looking-at "do\\b[^_]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4259 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4260 (c-add-syntax 'do-while-closure placeholder))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4261 ;; CASE 12: A case or default label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4262 ((looking-at c-switch-label-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4263 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4264 ;; check for hanging braces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4265 (if (/= (point) (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4266 (forward-sexp -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4267 (c-add-syntax 'case-label (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4268 ;; CASE 13: any other label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4269 ((looking-at c-label-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4270 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4271 (c-add-syntax 'label (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4272 ;; CASE 14: block close brace, possibly closing the defun or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4273 ;; the class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4274 ((= char-after-ip ?})
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4275 (let* ((lim (c-safe-position containing-sexp fullstate))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4276 (relpos (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4277 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4278 (if (/= (point) (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4279 (c-beginning-of-statement-1 lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4280 (c-point 'boi))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4281 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4282 ;; CASE 14A: does this close an inline?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4283 ((progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4284 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4285 (c-search-uplist-for-classkey state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4286 (c-add-syntax 'inline-close relpos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4287 ;; CASE 14B: if there an enclosing brace that hasn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4288 ;; been narrowed out by a class, then this is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4289 ;; block-close
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4290 ((c-most-enclosing-brace state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4291 (c-add-syntax 'block-close relpos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4292 ;; CASE 14C: find out whether we're closing a top-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4293 ;; class or a defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4294 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4295 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4296 (narrow-to-region (point-min) indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4297 (let ((decl (c-search-uplist-for-classkey (c-parse-state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4298 (if decl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4299 (c-add-syntax 'class-close (aref decl 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4300 (c-add-syntax 'defun-close relpos)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4301 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4302 ;; CASE 15: statement catchall
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4303 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4304 ;; 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
4305 ;; the first statement in a block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4306 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4307 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4308 (c-forward-syntactic-ws indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4309 ;; now skip forward past any case/default clauses we might find.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4310 (while (or (c-skip-case-statement-forward fullstate indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4311 (and (looking-at c-switch-label-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4312 (not inswitch-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4313 (setq inswitch-p t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4314 ;; we want to ignore non-case labels when skipping forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4315 (while (and (looking-at c-label-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4316 (goto-char (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4317 (c-forward-syntactic-ws indent-point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4318 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4319 ;; CASE 15A: we are inside a case/default clause inside a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4320 ;; switch statement. find out if we are at the statement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4321 ;; just after the case/default label.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4322 ((and inswitch-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4323 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4324 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4325 (c-backward-syntactic-ws containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4326 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4327 (setq placeholder (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4328 (looking-at c-switch-label-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4329 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4330 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4331 (if (= (following-char) ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4332 (c-add-syntax 'statement-case-open placeholder)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4333 (c-add-syntax 'statement-case-intro placeholder)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4334 ;; CASE 15B: continued statement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4335 ((= char-before-ip ?,)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4336 (c-add-syntax 'statement-cont (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4337 ;; CASE 15C: a question/colon construct? But make sure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4338 ;; what came before was not a label, and what comes after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4339 ;; is not a globally scoped function call!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4340 ((or (and (memq char-before-ip '(?: ??))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4341 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4342 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4343 (c-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4344 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4345 (not (looking-at c-label-key))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4346 (and (memq char-after-ip '(?: ??))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4347 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4348 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4349 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4350 ;; watch out for scope operator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4351 (not (looking-at "::")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4352 (c-add-syntax 'statement-cont (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4353 ;; CASE 15D: any old statement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4354 ((< (point) indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4355 (let ((safepos (c-most-enclosing-brace fullstate)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4356 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4357 (c-beginning-of-statement-1 safepos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4358 ;; It is possible we're on the brace that opens a nested
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4359 ;; function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4360 (if (and (= (following-char) ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4361 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4362 (c-backward-syntactic-ws safepos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4363 (/= (preceding-char) ?\;)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4364 (c-beginning-of-statement-1 safepos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4365 (c-add-syntax 'statement (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4366 (if (= char-after-ip ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4367 (c-add-syntax 'block-open))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4368 ;; CASE 15E: first statement in an inline, or first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4369 ;; statement in a top-level defun. we can tell this is it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4370 ;; if there are no enclosing braces that haven't been
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4371 ;; narrowed out by a class (i.e. don't use bod here!)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4372 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4373 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4374 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4375 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4376 (c-narrow-out-enclosing-class state containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4377 (not (c-most-enclosing-brace state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4378 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4379 ;; if not at boi, then defun-opening braces are hung on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4380 ;; right side, so we need a different relpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4381 (if (/= (point) (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4382 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4383 (c-backward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4384 (c-safe (forward-sexp (if (= (preceding-char) ?\))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4385 -1 -2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4386 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4387 (c-add-syntax 'defun-block-intro (c-point 'boi)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4388 ;; CASE 15F: first statement in a block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4389 (t (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4390 (if (/= (point) (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4391 (c-beginning-of-statement-1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4392 (if (= (point) lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4393 (c-safe-position (point) state) lim)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4394 (c-add-syntax 'statement-block-intro (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4395 (if (= char-after-ip ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4396 (c-add-syntax 'block-open)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4397 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4398 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4400 ;; now we need to look at any modifiers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4401 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4402 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4403 ;; are we looking at a comment only line?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4404 (if (looking-at c-comment-start-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4405 (c-add-syntax 'comment-intro))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4406 ;; we might want to give additional offset to friends (in C++).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4407 (if (and (eq major-mode 'c++-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4408 (looking-at c-C++-friend-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4409 (c-add-syntax 'friend))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4410 ;; return the syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4411 syntax))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4413
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4414 ;; indent via syntactic language elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4415 (defun c-get-offset (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4416 ;; Get offset from LANGELEM which is a cons cell of the form:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4417 ;; (SYMBOL . RELPOS). The symbol is matched against
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4418 ;; c-offsets-alist and the offset found there is either returned,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4419 ;; or added to the indentation at RELPOS. If RELPOS is nil, then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4420 ;; the offset is simply returned.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4421 (let* ((symbol (car langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4422 (relpos (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4423 (match (assq symbol c-offsets-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4424 (offset (cdr-safe match)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4425 ;; offset can be a number, a function, a variable, or one of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4426 ;; symbols + or -
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4427 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4428 ((not match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4429 (if c-strict-syntax-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4430 (error "don't know how to indent a %s" symbol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4431 (setq offset 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4432 relpos 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4433 ((eq offset '+) (setq offset c-basic-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4434 ((eq offset '-) (setq offset (- c-basic-offset)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4435 ((eq offset '++) (setq offset (* 2 c-basic-offset)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4436 ((eq offset '--) (setq offset (* 2 (- c-basic-offset))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4437 ((eq offset '*) (setq offset (/ c-basic-offset 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4438 ((eq offset '/) (setq offset (/ (- c-basic-offset) 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4439 ((and (not (numberp offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4440 (fboundp offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4441 (setq offset (funcall offset langelem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4442 ((not (numberp offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4443 (setq offset (eval offset)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4444 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4445 (+ (if (and relpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4446 (< relpos (c-point 'bol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4447 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4448 (goto-char relpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4449 (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4450 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4451 offset)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4453 (defun c-indent-line (&optional syntax)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4454 ;; indent the current line as C/C++/ObjC code. Optional SYNTAX is the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4455 ;; syntactic information for the current line. Returns the amount of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4456 ;; indentation change
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4457 (let* ((c-syntactic-context (or syntax (c-guess-basic-syntax)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4458 (pos (- (point-max) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4459 (indent (apply '+ (mapcar 'c-get-offset c-syntactic-context)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4460 (shift-amt (- (current-indentation) indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4461 (and c-echo-syntactic-information-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4462 (message "syntax: %s, indent= %d" c-syntactic-context indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4463 (if (zerop shift-amt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4464 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4465 (delete-region (c-point 'bol) (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4466 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4467 (indent-to indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4468 (if (< (point) (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4469 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4470 ;; If initial point was within line's indentation, position after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4471 ;; the indentation. Else stay at same point in text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4472 (if (> (- (point-max) pos) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4473 (goto-char (- (point-max) pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4474 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4475 (run-hooks 'c-special-indent-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4476 shift-amt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4477
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4478 (defun c-show-syntactic-information ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4479 "Show syntactic information for current line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4480 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4481 (message "syntactic analysis: %s" (c-guess-basic-syntax))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4482 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4483
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4484
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4485 ;; Standard indentation line-ups
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4486 (defun c-lineup-arglist (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4487 ;; lineup the current arglist line with the arglist appearing just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4488 ;; after the containing paren which starts the arglist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4489 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4490 (let* ((containing-sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4491 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4492 ;; arglist-cont-nonempty gives relpos ==
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4493 ;; to boi of containing-sexp paren. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4494 ;; is good when offset is +, but bad
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4495 ;; when it is c-lineup-arglist, so we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4496 ;; have to special case a kludge here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4497 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4498 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4499 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4500 (backward-up-list 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4501 (skip-chars-forward " \t" (c-point 'eol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4502 (goto-char (cdr langelem)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4503 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4504 (cs-curcol (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4505 (goto-char (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4506 (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4507 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4508 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4509 (looking-at "[ \t]*)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4510 (progn (goto-char (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4511 (forward-sexp -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4512 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4513 (c-forward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4514 (- (current-column) cs-curcol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4515 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4516 (or (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4517 (not (memq (following-char) '(?{ ?\( )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4518 (let ((eol (c-point 'eol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4519 (here (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4520 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4521 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4522 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4523 (c-forward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4524 (if (< (point) eol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4525 (goto-char here))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4526 (- (current-column) cs-curcol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4527 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4528
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4529 (defun c-lineup-arglist-intro-after-paren (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4530 ;; lineup an arglist-intro line to just after the open paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4531 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4532 (let ((cs-curcol (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4533 (goto-char (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4534 (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4535 (ce-curcol (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4536 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4537 (backward-up-list 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4538 (skip-chars-forward " \t" (c-point 'eol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4539 (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4540 (- ce-curcol cs-curcol -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4541
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4542 (defun c-lineup-streamop (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4543 ;; lineup stream operators
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4544 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4545 (let* ((relpos (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4546 (curcol (progn (goto-char relpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4547 (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4548 (re-search-forward "<<\\|>>" (c-point 'eol) 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4549 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4550 (- (current-column) curcol))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4551
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4552 (defun c-lineup-multi-inher (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4553 ;; line up multiple inheritance lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4554 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4555 (let (cs-curcol
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4556 (eol (c-point 'eol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4557 (here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4558 (goto-char (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4559 (setq cs-curcol (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4560 (skip-chars-forward "^:" eol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4561 (skip-chars-forward " \t:" eol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4562 (if (or (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4563 (looking-at c-comment-start-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4564 (c-forward-syntactic-ws here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4565 (- (current-column) cs-curcol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4566 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4567
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4568 (defun c-lineup-C-comments (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4569 ;; line up C block comment continuation lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4570 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4571 (let ((stars (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4572 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4573 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4574 (if (looking-at "\\*\\*?")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4575 (- (match-end 0) (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4576 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4577 (cs-curcol (progn (goto-char (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4578 (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4579 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4580 (if (re-search-forward "/\\*[ \t]*" (c-point 'eol) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4581 (goto-char (+ (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4582 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4583 (c-block-comments-indent-p 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4584 ((= stars 1) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4585 ((= stars 2) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4586 (t (- (match-end 0) (match-beginning 0)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4587 (- (current-column) cs-curcol))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4588
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4589 (defun c-lineup-comment (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4590 ;; support old behavior for comment indentation. we look at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4591 ;; c-comment-only-line-offset to decide how to indent comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4592 ;; only-lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4593 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4594 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4595 ;; indent as specified by c-comment-only-line-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4596 (if (not (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4597 (or (car-safe c-comment-only-line-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4598 c-comment-only-line-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4599 (or (cdr-safe c-comment-only-line-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4600 (car-safe c-comment-only-line-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4601 -1000 ;jam it against the left side
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4602 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4603
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4604 (defun c-lineup-runin-statements (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4605 ;; line up statements in coding standards which place the first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4606 ;; statement on the same line as the block opening brace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4607 (if (= (char-after (cdr langelem)) ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4608 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4609 (let ((curcol (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4610 (goto-char (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4611 (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4612 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4613 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4614 (- (current-column) curcol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4615 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4616
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4617 (defun c-lineup-math (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4618 ;; line up math statement-cont after the equals
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4619 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4620 (let* ((relpos (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4621 (equalp (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4622 (goto-char (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4623 (skip-chars-forward "^=" (c-point 'eol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4624 (and (= (following-char) ?=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4625 (- (point) (c-point 'boi)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4626 (curcol (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4627 (goto-char relpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4628 (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4629 donep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4630 (while (and (not donep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4631 (< (point) (c-point 'eol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4632 (skip-chars-forward "^=" (c-point 'eol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4633 (if (c-in-literal (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4634 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4635 (setq donep t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4636 (if (/= (following-char) ?=)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4637 ;; there's no equal sign on the line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4638 c-basic-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4639 ;; calculate indentation column after equals and ws, unless
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4640 ;; our line contains an equals sign
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4641 (if (not equalp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4642 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4643 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4644 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4645 (setq equalp 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4646 (- (current-column) equalp curcol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4647 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4648
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4649 (defun c-lineup-ObjC-method-call (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4650 ;; Line up methods args as elisp-mode does with function args: go to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4651 ;; the position right after the message receiver, and if you are at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4652 ;; (eolp) indent the current line by a constant offset from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4653 ;; opening bracket; otherwise we are looking at the first character
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4654 ;; of the first method call argument, so lineup the current line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4655 ;; with it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4656 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4657 (let* ((extra (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4658 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4659 (c-backward-syntactic-ws (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4660 (if (= (preceding-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4661 (- c-basic-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4662 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4663 (open-bracket-pos (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4664 (open-bracket-col (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4665 (goto-char open-bracket-pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4666 (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4667 (target-col (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4668 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4669 (forward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4670 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4671 (if (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4672 (+ open-bracket-col c-basic-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4673 (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4674 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4675 (- target-col open-bracket-col extra))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4676
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4677 (defun c-lineup-ObjC-method-args (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4678 ;; Line up the colons that separate args. This is done trying to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4679 ;; align colons vertically.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4680 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4681 (let* ((here (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4682 (curcol (progn (goto-char here) (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4683 (eol (c-point 'eol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4684 (relpos (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4685 (first-col-column (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4686 (goto-char relpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4687 (skip-chars-forward "^:" eol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4688 (and (= (following-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4689 (current-column)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4690 (if (not first-col-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4691 c-basic-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4692 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4693 (skip-chars-forward "^:" eol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4694 (if (= (following-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4695 (+ curcol (- first-col-column (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4696 c-basic-offset)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4697
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4698 (defun c-lineup-ObjC-method-args-2 (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4699 ;; Line up the colons that separate args. This is done trying to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4700 ;; align the colon on the current line with the previous one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4701 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4702 (let* ((here (c-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4703 (curcol (progn (goto-char here) (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4704 (eol (c-point 'eol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4705 (relpos (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4706 (prev-col-column (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4707 (skip-chars-backward "^:" relpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4708 (and (= (preceding-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4709 (- (current-column) 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4710 (if (not prev-col-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4711 c-basic-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4712 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4713 (skip-chars-forward "^:" eol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4714 (if (= (following-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4715 (+ curcol (- prev-col-column (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4716 c-basic-offset)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4717
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4718 (defun c-snug-do-while (syntax pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4719 "Dynamically calculate brace hanginess for do-while statements.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4720 Using this function, `while' clauses that end a `do-while' block will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4721 remain on the same line as the brace that closes that block.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4723 See `c-hanging-braces-alist' for how to utilize this function as an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4724 ACTION associated with `block-close' syntax."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4725 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4726 (let (langelem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4727 (if (and (eq syntax 'block-close)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4728 (setq langelem (assq 'block-close c-syntactic-context))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4729 (progn (goto-char (cdr langelem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4730 (if (= (following-char) ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4731 (c-safe (forward-sexp -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4732 (looking-at "\\<do\\>[^_]")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4733 '(before)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4734 '(before after)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4735
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4736
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4737 ;;; This page handles insertion and removal of backslashes for C macros.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4738
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4739 (defun c-backslash-region (from to delete-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4740 "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
4741 With no argument, inserts backslashes and aligns existing backslashes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4742 With an argument, deletes the backslashes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4743
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4744 This function does not modify the last line of the region if the region ends
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4745 right at the start of the following line; it does not modify blank lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4746 at the start of the region. So you can put the region around an entire macro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4747 definition and conveniently use this command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4748 (interactive "r\nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4749 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4750 (goto-char from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4751 (let ((column c-backslash-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4752 (endmark (make-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4753 (move-marker endmark to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4754 ;; Compute the smallest column number past the ends of all the lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4755 (if (not delete-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4756 (while (< (point) to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4757 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4758 (if (= (preceding-char) ?\\)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4759 (progn (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4760 (skip-chars-backward " \t")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4761 (setq column (max column (1+ (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4762 (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4763 ;; 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
4764 (if (> (% column tab-width) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4765 (let ((adjusted (* (/ (+ column tab-width -1) tab-width) tab-width)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4766 (if (< adjusted (window-width))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4767 (setq column adjusted))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4768 ;; Don't modify blank lines at start of region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4769 (goto-char from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4770 (while (and (< (point) endmark) (eolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4771 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4772 ;; Add or remove backslashes on all the lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4773 (while (and (< (point) endmark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4774 ;; Don't backslashify the last line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4775 ;; if the region ends right at the start of the next line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4776 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4777 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4778 (< (point) endmark)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4779 (if (not delete-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4780 (c-append-backslash column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4781 (c-delete-backslash))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4782 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4783 (move-marker endmark nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4784
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4785 (defun c-append-backslash (column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4786 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4787 ;; Note that "\\\\" is needed to get one backslash.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4788 (if (= (preceding-char) ?\\)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4789 (progn (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4790 (delete-horizontal-space)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4791 (indent-to column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4792 (indent-to column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4793 (insert "\\")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4794
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4795 (defun c-delete-backslash ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4796 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4797 (or (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4798 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4799 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4800 (if (looking-at "\\\\")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4801 (delete-region (1+ (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4802 (progn (skip-chars-backward " \t") (point)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4803
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4804
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4805 ;; defuns for submitting bug reports
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4807 (defconst c-version "4.282"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4808 "cc-mode version number.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4809 (defconst c-mode-help-address "bug-gnu-emacs@prep.ai.mit.edu"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4810 "Address for cc-mode bug reports.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4811
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4812 (defun c-version ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4813 "Echo the current version of cc-mode in the minibuffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4814 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4815 (message "Using cc-mode version %s" c-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4816 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4817
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4818 ;; get reporter-submit-bug-report when byte-compiling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4819 (eval-when-compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4820 (require 'reporter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4821
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4822 (defun c-submit-bug-report ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4823 "Submit via mail a bug report on cc-mode."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4824 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4825 ;; load in reporter
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4826 (let ((reporter-prompt-for-summary-p t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4827 (reporter-dont-compact-list '(c-offsets-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4828 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4829 (if (y-or-n-p "Do you want to submit a report on cc-mode? ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4830 t (message "") nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4831 (require 'reporter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4832 (reporter-submit-bug-report
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4833 c-mode-help-address
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4834 (concat "cc-mode " c-version " ("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4835 (cond ((eq major-mode 'c++-mode) "C++")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4836 ((eq major-mode 'c-mode) "C")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4837 ((eq major-mode 'objc-mode) "ObjC")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4838 ((eq major-mode 'java-mode) "Java")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4839 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4840 ")")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4841 (let ((vars (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4842 ;; report only the vars that affect indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4843 'c-basic-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4844 'c-offsets-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4845 'c-block-comments-indent-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4846 'c-cleanup-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4847 'c-comment-only-line-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4848 'c-backslash-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4849 'c-delete-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4850 'c-electric-pound-behavior
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4851 'c-hanging-braces-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4852 'c-hanging-colons-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4853 'c-hanging-comment-ender-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4854 'c-tab-always-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4855 'c-recognize-knr-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4856 'defun-prompt-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4857 'tab-width
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4858 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4859 (if (not (boundp 'defun-prompt-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4860 (delq 'defun-prompt-regexp vars)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4861 vars))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4862 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4863 (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4864 (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4865 (if c-special-indent-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4866 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4867 "c-special-indent-hook is set to '"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4868 (format "%s" c-special-indent-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4869 ".\nPerhaps this is your problem?\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4870 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4871 "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4872 (format "c-emacs-features: %s\n" c-emacs-features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4873 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4874 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4875 "Dear Barry,"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4876 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4877
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4878
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4879 ;; menus for XEmacs 19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4880 (defun c-popup-menu (e)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4881 "Pops up the C/C++/ObjC menu."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4882 (interactive "@e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4883 (popup-menu (cons (concat mode-name " Mode Commands") c-mode-menu))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4884 (c-keep-region-active))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4885
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4886
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4887 (defun c-copy-tree (tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4888 ;; Lift XEmacs 19.12's copy-tree
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4889 (if (consp tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4890 (cons (c-copy-tree (car tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4891 (c-copy-tree (cdr tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4892 (if (vectorp tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4893 (let* ((new (copy-sequence tree))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4894 (i (1- (length new))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4895 (while (>= i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4896 (aset new i (c-copy-tree (aref new i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4897 (setq i (1- i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4898 new)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4899 tree)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4900
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4901 (defun c-mapcar-defun (var)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4902 (let ((val (symbol-value var)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4903 (cons var (if (atom val) val
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4904 ;; XEmacs 19.12 and Emacs 19 + lucid.el have this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4905 (if (fboundp 'copy-tree)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4906 (copy-tree val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4907 ;; Emacs 19 and Emacs 18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4908 (c-copy-tree val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4909 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4910 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4911
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4912 ;; Dynamically append the default value of most variables. This is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4913 ;; crucial because future c-set-style calls will always reset the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4914 ;; variables first to the `cc-mode' style before instituting the new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4915 ;; style. Only do this once!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4916 (or (assoc "cc-mode" c-style-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4917 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4918 (c-add-style "cc-mode"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4919 (mapcar 'c-mapcar-defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4920 '(c-backslash-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4921 c-basic-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4922 c-block-comments-indent-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4923 c-cleanup-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4924 c-comment-only-line-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4925 c-echo-syntactic-information-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4926 c-electric-pound-behavior
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4927 c-hanging-braces-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4928 c-hanging-colons-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4929 c-hanging-comment-ender-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4930 c-offsets-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4931 c-recognize-knr-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4932 c-strict-syntax-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4933 c-tab-always-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4934 c-inhibit-startup-warnings-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4935 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4936 ;; the default style is now GNU. This can be overridden in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4937 ;; c-mode-common-hook or {c,c++,objc}-mode-hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4938 (c-set-style c-site-default-style)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4939
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4940 ;; style variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4941 (make-variable-buffer-local 'c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4942 (make-variable-buffer-local 'c-basic-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4943 (make-variable-buffer-local 'c-file-style)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4944 (make-variable-buffer-local 'c-file-offsets)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4945 (make-variable-buffer-local 'c-comment-only-line-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4946 (make-variable-buffer-local 'c-block-comments-indent-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4947 (make-variable-buffer-local 'c-cleanup-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4948 (make-variable-buffer-local 'c-hanging-braces-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4949 (make-variable-buffer-local 'c-hanging-colons-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4950 (make-variable-buffer-local 'c-hanging-comment-ender-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4951 (make-variable-buffer-local 'c-backslash-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4952
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4953
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4954
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4955 ;; fsets for compatibility with BOCM
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4956 (fset 'electric-c-brace 'c-electric-brace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4957 (fset 'electric-c-semi 'c-electric-semi&comma)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4958 (fset 'electric-c-sharp-sign 'c-electric-pound)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4959 ;; there is no cc-mode equivalent for electric-c-terminator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4960 (fset 'mark-c-function 'c-mark-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4961 (fset 'indent-c-exp 'c-indent-exp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4962 (fset 'set-c-style 'c-set-style)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4963 ;; Lucid Emacs 19.9 + font-lock + cc-mode - c++-mode lossage
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4964 (fset 'c++-beginning-of-defun 'beginning-of-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4965 (fset 'c++-end-of-defun 'end-of-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4966
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4967 ;; set up bc warnings for obsolete variables, but for now lets not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4968 ;; worry about obsolete functions. maybe later some will be important
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4969 ;; to flag
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4970 (and (memq 'v19 c-emacs-features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4971 (let* ((na "Nothing appropriate.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4972 (vars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4973 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4974 (cons 'c++-c-mode-syntax-table 'c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4975 (cons 'c++-tab-always-indent 'c-tab-always-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4976 (cons 'c++-always-arglist-indent-p na)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4977 (cons 'c++-block-close-brace-offset 'c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4978 (cons 'c++-paren-as-block-close-p na)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4979 (cons 'c++-continued-member-init-offset 'c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4980 (cons 'c++-member-init-indent 'c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4981 (cons 'c++-friend-offset na)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4982 (cons 'c++-access-specifier-offset 'c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4983 (cons 'c++-empty-arglist-indent 'c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4984 (cons 'c++-comment-only-line-offset 'c-comment-only-line-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4985 (cons 'c++-C-block-comments-indent-p 'c-block-comments-indent-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4986 (cons 'c++-cleanup-list 'c-cleanup-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4987 (cons 'c++-hanging-braces 'c-hanging-braces-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4988 (cons 'c++-hanging-member-init-colon 'c-hanging-colons-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4989 (cons 'c++-auto-hungry-initial-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4990 "Use `c-auto-newline' and `c-hungry-delete-key' instead.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4991 (cons 'c++-auto-hungry-toggle na)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4992 (cons 'c++-relative-offset-p na)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4993 (cons 'c++-special-indent-hook 'c-special-indent-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4994 (cons 'c++-delete-function 'c-delete-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4995 (cons 'c++-electric-pound-behavior 'c-electric-pound-behavior)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4996 (cons 'c++-hungry-delete-key 'c-hungry-delete-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4997 (cons 'c++-auto-newline 'c-auto-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4998 (cons 'c++-match-header-strongly na)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4999 (cons 'c++-defun-header-strong-struct-equivs na)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5000 (cons 'c++-version 'c-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5001 (cons 'c++-mode-help-address 'c-mode-help-address)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5002 (cons 'c-indent-level 'c-basic-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5003 (cons 'c-brace-imaginary-offset na)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5004 (cons 'c-brace-offset 'c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5005 (cons 'c-argdecl-indent 'c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5006 (cons 'c-label-offset 'c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5007 (cons 'c-continued-statement-offset 'c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5008 (cons 'c-continued-brace-offset 'c-offsets-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5009 (cons 'c-default-macroize-column 'c-backslash-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5010 (cons 'c++-default-macroize-column 'c-backslash-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5011 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5012 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5013 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5014 (lambda (elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5015 (make-obsolete-variable (car elt) (cdr elt))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5016 vars)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5017
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5018 (provide 'cc-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5019 ;;; cc-mode.el ends here