annotate lisp/modes/old-c++-mode.el @ 80:1ce6082ce73f r20-0b90

Import from CVS: tag r20-0b90
author cvs
date Mon, 13 Aug 2007 09:06:37 +0200
parents 0293115a14e9
children
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 ;;; c++-mode.el --- major mode for editing C++ (and 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 ;; Author: 1992 Barry A. Warsaw, Century Computing Inc. <bwarsaw@cen.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; 1987 Dave Detlefs and Stewart Clamen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; 1985 Richard M. Stallman
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Maintainer: c++-mode-help@anthem.nlm.nih.gov
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Created: a long, long, time ago. adapted from the original c-mode.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; Version: 2.353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; Last Modified: 1993/06/23 13:58:52
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; Keywords: c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; Copyright (C) 1992, 1993 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; You should have received a copy of the GNU General Public License
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
27 ;; along with XEmacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 0
diff changeset
29 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; Introduction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; ============
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; Do a "C-h m" in a c++-mode buffer for more information on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; customizing c++-mode. To submit bug reports hit "C-c C-b" in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; c++-mode buffer. This runs the command c++-submit-bug-report and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; automatically sets up the mail buffer with all the necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; information. If you have other questions contact me at the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; following address: c++-mode-help@anthem.nlm.nih.gov. Please don't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; send bug reports to my personal account, I may not get it for a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; long time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; Notes for Novice Users
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; ======================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; c++-mode facilitates editing of C++ code by automatically handling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; the indentation of lines of code in a manner very similar to c-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; as distributed with GNU Emacs. Refer to the GNU Emacs manual,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; chapter 21 for more information on "Editing Programs". In fact,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;; c++-mode (through its companion mode entry point c++-c-mode) can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; also be used to edit both K&R and ANSI C code!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; To use c++-mode, add the following to your .emacs file. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; assumes you will use .cc or .C extensions for your C++ source:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; (autoload 'c++-mode "c++-mode" "C++ Editing Mode" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; (autoload 'c++-c-mode "c++-mode" "C Editing Mode" t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; (setq auto-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; (append '(("\\.C$" . c++-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; ("\\.cc$" . c++-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; ("\\.c$" . c++-c-mode) ; to edit C code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;; ("\\.h$" . c++-c-mode) ; to edit C code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;; ) auto-mode-alist))
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 you want to use the default c-mode for editing C code, then just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;; omit the lines marked "to edit C code".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;; Finally, you may want to customize certain c++-mode variables. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;; best place to do this is in the mode hook variable called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;; c++-mode-hook. Again, see the Emacs manual, chapter 21 for more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;; information.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;; Important Note about Escapes in Comments, and Performance
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;; =========================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;; You may notice that certain characters, when typed in comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;; regions, get escaped with a backslash. This is a workaround for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;; bugs in Emacs' syntax parsing algorithms. In brief, syntax parsing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;; in Emacs 18 and derivatives is broken because syntax tables are not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ;; rich enough to support more than 1 comment style per mode (as C++
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;; requires). The result is that Emacs will sometimes choke on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;; unbalanced parentheses and single quotes in comments. Please do a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;; "C-h v c++-untame-characters" for more information.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;; This problem affect both the accuracy and performance of c++-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;; because some parsing must be performed in Emacs lisp instead of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;; relying on the C primitives. In general, I've chosen accuracy over
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; performance, but have worked hard to give moderately acceptable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;; speed in all but the most uncommon situations. You will most likely
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;; notice c++-mode slowing when you're editing a file of preprocessor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;; commands, or inside long functions or class definitions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;; Optimization is an ongoing concern, but the real solution is to fix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;; Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;; As of release 19.4, Lucid Emacs is distributed with the fixes in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;; place, and c++-mode will automatically take advantage of them so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;; none of the above applies to you. Similar patches will be part of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;; FSF GNU Emacs 19. Some patches for GNU Emacs 18 have been released
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;; on the beta site, but they are unsupported. Email for more
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;; information.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 ;; Beta Testers Mailing List
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ;; =========================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 ;; Want to be a c++-mode victim, er, beta-tester? Send add/drop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 ;; requests to c++-mode-victims-request@anthem.nlm.nih.gov.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 ;; Discussions go to c++-mode-victims@anthem.nlm.nih.gov, but bug
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;; reports and such should still be sent to c++-mode-help only.
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, and code contribution,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;; c++-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 ;; Getting c++-mode.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;; ===================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;; The latest public release version of this file should always be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;; available for anonymous ftp on the Emacs lisp archive machine. The
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 ;; path to the file is:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 ;; archive.cis.ohio-state.edu:pub/gnu/emacs/elisp-archive/modes/c++-mode.el.Z
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 ;; For those of you without anon-ftp access, you can use the DEC's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;; ftpmail'er at the address ftpmail@decwrl.dec.com. Send the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ;; following message in the body of your mail to that address to get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ;; c++-mode:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ;; reply <a valid net address back to you>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ;; connect archive.cis.ohio-state.edu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 ;; binary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 ;; uuencode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ;; chdir pub/gnu/emacs/elisp-archive/modes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 ;; get c++-mode.el.Z
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;; or just send the message "help" for more information on ftpmail.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ;; Response times will vary with the number of requests in the queue.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ;; LCD Archive Entry:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;; c++-mode|Barry A. Warsaw|c++-mode-help@anthem.nlm.nih.gov
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 ;; |Mode for editing C++, and ANSI/K&R C code (was Detlefs' c++-mode.el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 ;; |1993/06/23 13:58:52|2.353|
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 ;; some people may not have c-mode loaded in by default. c++-mode.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 ;; unfortunately still depends on distrib c-mode. c-mode doesn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 ;; provide itself so this hack is best known way to ensure its loaded
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (or (fboundp 'c-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (load "c-mode" nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ;; user definable variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (defconst c++-emacs-features
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (let ((mse-spec 'no-dual-comments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (scanner 'v18))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;; vanilla GNU18/Epoch 4 uses default values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (if (= 8 (length (parse-partial-sexp (point) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ;; we know we're using v19 style dual-comment specifications.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ;; All Lemacsen use 8-bit modify-syntax-entry flags, as do all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;; patched FSF19, GNU18, Epoch4's. Only vanilla FSF19 uses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ;; 1-bit flag. Lets be as smart as we can about figuring this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ;; out.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (let ((table (copy-syntax-table)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (modify-syntax-entry ?a ". 12345678" table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (if (= (logand (lsh (aref table ?a) -16) 255) 255)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (setq mse-spec '8-bit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (setq mse-spec '1-bit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 ;; we also know we're using a quicker, built-in comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 ;; scanner, but we don't know if its old-style or new.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 ;; Fortunately we can ask emacs directly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (if (fboundp 'forward-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (setq scanner 'v19)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (setq scanner 'old-v19))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ;; now cobble up the necessary list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (list mse-spec scanner))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 "A list of needed features extant in the Emacs you are using.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 There are many flavors of Emacs out on the net, each with different
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 features supporting those needed by c++-mode. Here's the current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 known list, along with the values for this variable:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 Vanilla GNU 18/Epoch 4: (no-dual-comments v18)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 GNU 18/Epoch 4 (patch1): (8-bit old-v19)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 GNU 18/Epoch 4 (patch2): (8-bit v19)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 Lemacs 19.4 - 19.7: (8-bit old-v19)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 Lemacs 19.8 and over: (8-bit v19)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 FSF 19: (1-bit v19)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 FSF 19 (patched): (8-bit v19)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (defvar c++-mode-abbrev-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 "Abbrev table in use in c++-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (define-abbrev-table 'c++-mode-abbrev-table ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (defvar c++-mode-map ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 "Keymap used in c++-mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (if c++-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (setq c++-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (define-key c++-mode-map "\C-j" 'reindent-then-newline-and-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (define-key c++-mode-map "\C-m" 'newline-and-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (define-key c++-mode-map "{" 'c++-electric-brace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (define-key c++-mode-map "}" 'c++-electric-brace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (define-key c++-mode-map ";" 'c++-electric-semi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (define-key c++-mode-map "#" 'c++-electric-pound)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (define-key c++-mode-map "\e\C-h" 'mark-c-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (define-key c++-mode-map "\e\C-q" 'c++-indent-exp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (define-key c++-mode-map "\t" 'c++-indent-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (define-key c++-mode-map "\C-c\C-i" 'c++-insert-header)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (define-key c++-mode-map "\C-c\C-\\" 'c++-macroize-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (define-key c++-mode-map "\C-c\C-c" 'c++-comment-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (define-key c++-mode-map "\C-c\C-u" 'c++-uncomment-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (define-key c++-mode-map "\C-c\C-x" 'c++-match-paren)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (define-key c++-mode-map "\e\C-a" 'c++-beginning-of-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (define-key c++-mode-map "\e\C-e" 'c++-end-of-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (define-key c++-mode-map "\e\C-x" 'c++-indent-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (define-key c++-mode-map "/" 'c++-electric-slash)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (define-key c++-mode-map "*" 'c++-electric-star)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (define-key c++-mode-map ":" 'c++-electric-colon)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (define-key c++-mode-map "\177" 'c++-electric-delete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (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
218 (define-key c++-mode-map "\C-c\C-h" 'c++-toggle-hungry-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (define-key c++-mode-map "\C-c\C-a" 'c++-toggle-auto-state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (if (memq 'v18 c++-emacs-features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (define-key c++-mode-map "\C-c'" 'c++-tame-comments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (define-key c++-mode-map "'" 'c++-tame-insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (define-key c++-mode-map "[" 'c++-tame-insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (define-key c++-mode-map "]" 'c++-tame-insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (define-key c++-mode-map "(" 'c++-tame-insert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (define-key c++-mode-map ")" 'c++-tame-insert)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (define-key c++-mode-map "\C-c\C-b" 'c++-submit-bug-report)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (define-key c++-mode-map "\C-c\C-v" 'c++-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ;; these are necessary because default forward-sexp and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 ;; backward-sexp don't automatically let-bind
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 ;; parse-sexp-ignore-comments, which is needed for them to work
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 ;; properly in a C++ buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (define-key c++-mode-map "\e\C-f" 'c++-forward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (define-key c++-mode-map "\e\C-b" 'c++-backward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (defvar c++-mode-syntax-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 "Syntax table used in c++-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (defvar c++-c-mode-syntax-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 "Syntax table used in c++-c-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (if c++-mode-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (setq c++-mode-syntax-table (make-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (modify-syntax-entry ?\\ "\\" c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (modify-syntax-entry ?+ "." c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (modify-syntax-entry ?- "." c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (modify-syntax-entry ?= "." c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (modify-syntax-entry ?% "." c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (modify-syntax-entry ?< "." c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (modify-syntax-entry ?> "." c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (modify-syntax-entry ?& "." c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (modify-syntax-entry ?| "." c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (modify-syntax-entry ?\' "\"" c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 ;; comment syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 ((memq '8-bit c++-emacs-features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 ;; Lucid emacs has the best implementation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (modify-syntax-entry ?/ ". 1456" c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (modify-syntax-entry ?* ". 23" c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (modify-syntax-entry ?\n "> b" c++-mode-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ((memq '1-bit c++-emacs-features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 ;; FSF19 has sub-optimal, but workable implementation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 ;; Some strange behavior may be encountered. LOBBY FSF!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (modify-syntax-entry ?/ ". 124" c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (modify-syntax-entry ?* ". 23b" c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (modify-syntax-entry ?\n ">" c++-mode-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ;; Vanilla GNU18 is just plain busted. We'll do the best we can,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 ;; but some strange behavior may be encountered. PATCH or UPGRADE!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (modify-syntax-entry ?/ ". 124" c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (modify-syntax-entry ?* ". 23" c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (modify-syntax-entry ?\n ">" c++-mode-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (if c++-c-mode-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (setq c++-c-mode-syntax-table (make-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (modify-syntax-entry ?\\ "\\" c++-c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (modify-syntax-entry ?+ "." c++-c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (modify-syntax-entry ?- "." c++-c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (modify-syntax-entry ?= "." c++-c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (modify-syntax-entry ?% "." c++-c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (modify-syntax-entry ?< "." c++-c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (modify-syntax-entry ?> "." c++-c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (modify-syntax-entry ?& "." c++-c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (modify-syntax-entry ?| "." c++-c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (modify-syntax-entry ?\' "\"" c++-c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (modify-syntax-entry ?/ ". 14" c++-c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (modify-syntax-entry ?* ". 23" c++-c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (defvar c++-tab-always-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (if (boundp 'c-tab-always-indent) c-tab-always-indent t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 "*Controls the operation of the TAB key.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 If t (the default), always just indent the current line. If nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 indent the current line only if point is at the left margin or in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 line's indentation; otherwise insert a tab. If not-nil-or-t, then tab
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 is inserted only within literals (comments and strings) and inside
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 preprocessor directives, but line is always reindented.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (defvar c++-always-arglist-indent-p nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 "*Control indentation of continued arglists.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 When non-nil, arglists continued on subsequent lines will always
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 indent `c++-empty-arglist-indent' spaces, otherwise, they will indent to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 just under previous line's argument indentation.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (defvar c++-block-close-brace-offset 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 "*Extra indentation given to close braces which close a block.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 This variable can be either an integer or a list. If an integer, it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 describes the extra offset given a block closing brace (and a closing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 paren if `c++-paren-as-block-close-p' is non-nil), treating all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 closing parens the same. If a list of the form (OTHERS . TOPLEVEL),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 OTHERS is an integer describing the offset given to all but top-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (e.g. function) closing braces, while TOPLEVEL is an integer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 describing offset given only to braces which close top-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 constructs.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (defvar c++-paren-as-block-close-p nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 "*Treat a parenthesis which is the first non-whitespace on a line as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 a paren which closes a block. When non-nil, `c-indent-level' is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 subtracted, and `c++-block-close-brace-offset' is added to the line's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 offset.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (defvar c++-continued-member-init-offset nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 "*Extra indent for continuation lines of member inits; nil means to align
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 with previous initializations rather than with the colon on the first line.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (defvar c++-member-init-indent 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 "*Indentation level of member initializations in function declarations.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (defvar c++-friend-offset -4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 "*Offset of C++ friend class declarations relative to member declarations.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (defvar c++-access-specifier-offset c-label-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 "*Extra indentation given to public, protected, and private labels.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (defvar c++-empty-arglist-indent nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 "*Indicates how far to indent a line following an empty argument list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 Nil means indent to just after the paren.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (defvar c++-comment-only-line-offset 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 "*Indentation offset for line which contains only C or C++ style comments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 This variable can take either a single integer or a list of integers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 If a single integer this is the extra indentation offset to apply to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 all comment-only lines, except those which start in column zero. If a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 list is used, the first integer is for all non-column-zero
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 comment-only lines and the second integer is for all column-zero
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 lines. You can also use a list containing only 1 integer, in which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 case, this value is used for all comment-only lines. For example:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 value meaning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 ===== =======
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 0 comment-only lines do not indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 4 non-col0 lines indent 4 spaces, col0 lines don't indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 '(4) all comment-only lines indent 4 spaces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 '(4 1) non-col0 lines indent 4 spaces, col0 lines indent 1 space")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (defvar c++-C-block-comments-indent-p nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 "*4 styles of C block comments are supported. If this variable is nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 then styles 1-3 are supported. If this variable is non-nil, style 4 is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 supported.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 style 1: style 2: style 3: style 4:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 /* /* /* /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 blah * blah ** blah blah
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 blah * blah ** blah blah
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 */ */ */ */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 (defvar c++-cleanup-list nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 "*List of various C++ constructs to ``clean up''.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 These cleanups only take place when the auto-newline feature is turned
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 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
365
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 Current legal values are:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 `brace-else-brace' -- clean up ``} else {'' constructs by placing entire
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 construct on a single line. This cleanup only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 takes place when there is nothing but white
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 space between the braces and the else.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 `empty-defun-braces' -- cleans up empty C++ function braces by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 placing them on the same line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 `defun-close-semi' -- cleans up the terminating semi-colon on class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 definitions and functions by placing the semi
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 on the same line as the closing brace.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (defvar c++-hanging-braces t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 "*Controls the insertion of newlines before open (left) braces.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 This variable only has effect when auto-newline is on, as evidenced by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 the `/a' or `/ah' appearing next to the mode name. If nil, open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 braces do not hang (i.e. a newline is inserted before all open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 braces). If t, all open braces hang -- no newline is inserted before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 open braces. If not nil or t, newlines are only inserted before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 top-level open braces; all other braces hang.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 (defvar c++-hanging-member-init-colon 'before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 "*Defines how colons which introduce member initializations are formatted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 Legal values are:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 t -- no newlines inserted before or after colon
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 nil -- newlines inserted before and after colon
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 `after' -- newlines inserted only after colon
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 `before` -- newlines inserted only before colon")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (defvar c++-auto-hungry-initial-state 'none
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 "*Initial state of auto/hungry features when buffer is first visited.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 Legal values are:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 `none' -- no auto-newline and no hungry-delete-key.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 `auto-only' -- auto-newline, but no hungry-delete-key.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 `hungry-only' -- no auto-newline, but hungry-delete-key.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 `auto-hungry' -- both auto-newline and hungry-delete-key enabled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 Nil is synonymous for `none' and t is synonymous for `auto-hungry'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (defvar c++-auto-hungry-toggle t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 "*Enable/disable toggling of auto/hungry features.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 Legal values are:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 `none' -- auto-newline and hungry-delete-key cannot be enabled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 `auto-only' -- only auto-newline feature can be toggled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 `hungry-only' -- only hungry-delete-key feature can be toggled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 `auto-hungry' -- both auto-newline and hungry-delete-key can be toggled.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 Nil is synonymous for `none' and t is synonymous for `auto-hungry'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (defvar c++-relative-offset-p t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 "*Control the calculation for indentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 When non-nil (the default), indentation is calculated relative to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 first statement in the block. When nil, the indentation is calculated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 without regard to how the first statement is indented.")
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++-untame-characters (and (memq 'v18 c++-emacs-features) '(?\'))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 "*Utilize a backslashing workaround of an Emacs syntax parsing bug.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 If non-nil, this variable should contain a list of characters which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 will be prepended by a backslash in comment regions. By default, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 list contains only the most troublesome character, the single quote.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 To be completely safe, set this variable to:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 '(?\( ?\) ?\' ?\{ ?\} ?\[ ?\])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 This is the full list of characters which can potentially cause
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 problems if they exist unbalanced within comments. Setting this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 variable to nil will defeat this feature, but be forewarned! Such
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 un-escaped characters in comment regions can potentially break many
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 things such as some indenting and blinking of parenthesis.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 Note further that only the default set of characters will be escaped
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 automatically as they are typed. But, executing `c++-tame-comments'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (\\[c++-tame-comments]) will escape all characters which are members
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 of this set, and which are found in comments throughout the file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 Finally, c++-mode can tell if you're running a patched Emacs. If so,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 taming characters isn't necessary and this variable is automatically
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 set to nil.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (defvar c++-default-macroize-column 78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 "*Column to insert backslashes.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (defvar c++-special-indent-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 "*Hook for user defined special indentation adjustments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 This hook gets called after a line is indented by the mode. By
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 supplying a hook, you can make adjustments to the line's standard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 indentation. If you do use this hook, you will likely need to also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 set `c++-relative-offset-p' to nil. The call to this hook is wrapped in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 a `save-excursion' so you don't need to worry about restoring point and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 mark inside the hook function.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (defvar c++-delete-function 'backward-delete-char-untabify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 "*Function called by `c++-electric-delete' when deleting a single char.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (defvar c++-electric-pound-behavior nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 "*List of behaviors for electric pound insertion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 Only currently supported behavior is `alignleft'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (defvar c++-backscan-limit 2000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 "*Limit in characters for looking back while skipping syntactic ws.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 If you typically write really big methods, and start noticing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 incorrect indentations, try cranking this value up. The larger this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 value is, though, the slower parts of c++-mode can become. Setting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 this variable to nil defeats backscan limits.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 ;; NO USER DEFINABLE VARIABLES BEYOND THIS POINT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (defvar c++-hungry-delete-key nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 "Internal state of hungry delete key feature.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (defvar c++-auto-newline nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 "Internal state of auto newline feature.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (make-variable-buffer-local 'c++-auto-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (make-variable-buffer-local 'c++-hungry-delete-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (defconst c++-access-key "\\<\\(public\\|protected\\|private\\)\\>:"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 "Regexp which describes access specification keywords.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (defconst c++-class-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 "\\(\\(extern\\|typedef\\)\\s +\\)?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 "\\(template\\s *<[^>]*>\\s *\\)?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 "\\<\\(class\\|struct\\|union\\)\\>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 "Regexp which describes a class declaration, including templates.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (defconst c++-inher-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (concat "\\(\\<static\\>\\s +\\)?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 c++-class-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 "[ \t]+\\(\\(\\w\\|_\\)+[ \t]*:[ \t]*\\)?")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 "Regexp which describes a class inheritance declaration.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 ;; c++-mode main entry point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 ;;##autoload ;; don't autoload an obsolete package
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (defun c++-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 "Major mode for editing C++ code. 2.353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 To submit a problem report, enter `\\[c++-submit-bug-report]' from a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 c++-mode buffer. This automatically sets up a mail buffer with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 version information already added. You just need to add a description
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 of the problem and send the message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 1. Very much like editing C code,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 2. Expression and list commands understand all C++ brackets,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 3. Tab at left margin indents for C++ code,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 4. Both C++ and C style block comments are recognized,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 5. Paragraphs are separated by blank lines only,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 6. Hungry delete key and auto newline features are optional.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 IMPORTANT NOTE: You may notice that some characters (by default, only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 single quote) will get escaped with a backslash when typed in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 comment region. This is a necessary workaround of a bug present in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 GNU Emacs 18 and derivatives. Enter `\\[describe-variable] c++-untame-characters RET'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 for more information. If you are running a patched Emacs, no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 characters will be escaped in comment regions, and many functions will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 run much faster.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 Key bindings:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 \\{c++-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 These variables control indentation style. Those with names like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 c-<thing> are inherited from c-mode. Those with names like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 c++-<thing> are unique for this mode, or have extended functionality
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 from their c-mode cousins.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 c-argdecl-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 Indentation level of declarations of C function arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 c-brace-imaginary-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 An open brace following other text is treated as if it were
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 this far to the right of the start of its line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 c-brace-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 Extra indentation for line if it starts with an open brace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 c-continued-brace-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 Extra indentation given to a brace that starts a substatement.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 This is in addition to `c-continued-statement-offset'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 c-continued-statement-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 Extra indentation given to a substatement, such as the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 then-clause of an if or body of a while.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 c-indent-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 Indentation of C statements within surrounding block.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 The surrounding block's indentation is the indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 of the line on which the open-brace appears.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 c-label-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 Extra indentation for line that is a label, or case or ``default:''
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 c++-C-block-comments-indent-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 Style of C block comments to support.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 c++-access-specifier-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 Extra indentation given to public, protected, and private keyword lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 c++-always-arglist-indent-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 Control indentation of continued arglists. When non-nil, arglists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 continued on subsequent lines will always indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 `c++-empty-arglist-indent' spaces, otherwise, they will indent to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 just under previous line's argument indentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 c++-auto-hungry-initial-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 Initial state of auto/hungry feature when a C++ buffer is first visited.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 c++-auto-hungry-toggle
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 Enable/disable toggling of auto/hungry features.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 c++-backscan-limit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 Limit in characters for looking back while skipping syntactic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 whitespace. This variable is only used in an un-patched Emacs to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 help improve performance at the expense of some accuracy. Patched
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 Emacses are both fast and accurate.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 c++-block-close-brace-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 Extra indentation give to braces which close a block.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 c++-cleanup-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 A list of construct ``clean ups'' which c++-mode will perform when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 auto-newline feature is on. Current legal values are:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 `brace-else-brace', `empty-defun-braces', `defun-close-semi'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 c++-comment-only-line-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 Extra indentation for a line containing only a C or C++ style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 comment. Can be an integer or list, specifying the various styles
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 of comment-only line special indentations.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 c++-continued-member-init-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 Extra indentation for continuation lines of member initializations; nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 means to align with previous initializations rather than with the colon.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 c++-default-macroize-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 Column to insert backslashes when macroizing a region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 c++-delete-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 Function called by `c++-electric-delete' when deleting a single char.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 c++-electric-pound-behavior
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 List of behaviors for electric pound insertion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 c++-empty-arglist-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 Extra indentation to apply to a line following an empty argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 list. nil means to line it up with the left paren.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 c++-friend-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 Offset of C++ friend class declarations relative to member declarations.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 c++-hanging-braces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 Controls open brace hanging behavior when using auto-newline feature.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 nil says no braces hang, t says all open braces hang. non-nil-or-t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 means top-level open braces don't hang, all others do.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 c++-hanging-member-init-colon
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 Defines how colons which introduce member initialization lists are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 formatted. t means no newlines are inserted either before or after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 the colon. nil means newlines are inserted both before and after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 the colon. `before' inserts newlines only before the colon, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 `after' inserts newlines only after colon.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 c++-member-init-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 Indentation level of member initializations in function declarations,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 if they are on a separate line beginning with a colon.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 c++-paren-as-block-close-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 If non-nil, treat a parenthesis which is the first non-whitespace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 on a line as a paren which closes a block (i.e. treat it similar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 to right curly brace).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 c++-relative-offset-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 Control the calculation for indentation. When non-nil (the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 default), indentation is calculated relative to the first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 statement in the block. When nil, the indentation is calculated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 without regard to how the first statement is indented. Useful when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 using a `c++-special-indent-hook'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 c++-special-indent-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 Hook for user defined special indentation adjustments. You can use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 this hook, which gets called after a line is indented by the mode,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 to customize indentations of the line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 c++-tab-always-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 Controls the operation of the TAB key. t means always just indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 the current line. nil means indent the current line only if point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 is at the left margin or in the line's indentation; otherwise
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 insert a tab. If not-nil-or-t, then tab is inserted only within
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 literals (comments and strings) and inside preprocessor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 directives, but the line is always reindented. Default is value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 for `c-tab-always-indent'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 c++-untame-characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 When non-nil, inserts backslash escapes before certain untamed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 characters in comment regions. It is recommended that you keep the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 default setting to workaround a nasty Emacs bug, unless you are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 running a patched Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 Auto-newlining is no longer an all or nothing proposition. In my
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 opinion, I don't believe it is possible to implement a perfect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 auto-newline algorithm. Sometimes you want it and sometimes you don't.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 So now auto-newline (and its companion feature, hungry-delete-key) can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 be toggled on and off on the fly. Hungry-delete-key is the optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 behavior of the delete key so that, when enabled, hitting the delete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 key once consumes all preceding whitespace, unless point is within a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 literal (defined as a C or C++ comment, or string). Inside literals,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 and with hungry-delete-key disabled, the delete key just calls the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 function in variable `c++-delete-function'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 Selection and toggling of these features is controlled by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 variables `c++-auto-hungry-initial-state' and `c++-auto-hungry-toggle'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 Legal values for both variables are:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 `none' (or nil) -- no auto-newline or hungry-delete-key.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 `auto-only' -- function affects only auto-newline feature.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 `hungry-only' -- function affects only hungry-delete-key feature.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 `auto-hungry' (or t) -- function affects both features.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 Thus if `c++-auto-hungry-initial-state' is `hungry-only', then only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 hungry-delete-key feature is turned on when the buffer is first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 visited. If `c++-auto-hungry-toggle' is `auto-hungry', and both
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 auto-newline and hungry-delete-key features are on, then hitting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 `\\[c++-toggle-auto-hungry-state]' will toggle both features. Hitting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 `\\[c++-toggle-hungry-state]' will always toggle hungry-delete-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 feature and hitting `\\[c++-toggle-auto-state]' will always toggle
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 auto-newline feature, regardless of the value of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 `c++-auto-hungry-toggle'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 Settings for K&R, BSD, and Stroustrup indentation styles are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 c-indent-level 5 8 4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 c-continued-statement-offset 5 8 4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 c-continued-brace-offset 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 c-brace-offset -5 -8 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 c-brace-imaginary-offset 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 c-argdecl-indent 0 8 4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 c-label-offset -5 -8 -4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 c++-access-specifier-offset -5 -8 -4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 c++-empty-arglist-indent 4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 c++-friend-offset 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 Turning on C++ mode calls the value of the variable `c++-mode-hook' with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 no args, if that value is non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (use-local-map c++-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (set-syntax-table c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (setq major-mode 'c++-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 mode-name "C++"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 local-abbrev-table c++-mode-abbrev-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (set (make-local-variable 'paragraph-start) (concat "^$\\|" page-delimiter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (set (make-local-variable 'paragraph-separate) paragraph-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (set (make-local-variable 'require-final-newline) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (set (make-local-variable 'parse-sexp-ignore-comments) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (set (make-local-variable 'indent-line-function) 'c++-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (set (make-local-variable 'comment-start) "// ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (set (make-local-variable 'comment-end) "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (set (make-local-variable 'comment-column) 32)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|// *")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (set (make-local-variable 'comment-indent-hook) 'c++-comment-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 ;; hack auto-hungry designators into modeline-format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (if (listp modeline-format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (setq modeline-format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (let ((modeline nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (lambda (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (setq modeline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (append modeline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (if (eq element 'mode-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 '(mode-name (c++-hungry-delete-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (c++-auto-newline "/ah" "/h")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (c++-auto-newline "/a")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (list element))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 modeline-format)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 modeline)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (run-hooks 'c++-mode-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (c++-set-auto-hungry-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 (memq c++-auto-hungry-initial-state '(auto-only auto-hungry t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 (memq c++-auto-hungry-initial-state '(hungry-only auto-hungry t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 ;;##autoload ;; don't autoload an obsolete package
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (defun c++-c-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 "Major mode for editing K&R and ANSI C code. 2.353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 This mode is based on c++-mode. Documentation for this mode is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 available by doing a `\\[describe-function] c++-mode'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (c++-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (setq major-mode 'c++-c-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 mode-name "C"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 local-abbrev-table c-mode-abbrev-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (setq comment-start "/* "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 comment-end " */")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 ;; some syntax differences are necessary for C vs. C++
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (set-syntax-table c++-c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (run-hooks 'c++-c-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (defun c++-comment-indent ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 "Used by `indent-for-comment' to decide how much to indent a comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 in C++ code based on its context."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (if (looking-at "^\\(/\\*\\|//\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 0 ; Existing comment at bol stays there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 (max
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 ;; leave at least one space on non-empty lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (if (zerop (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (1+ (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 ;; use comment-column if previous line is comment only line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 ;; indented to the left of comment-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (if (not (bobp)) (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (if (looking-at "/\\*\\|//")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 (if (< (current-column) comment-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 comment-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (let ((cur-pt (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (beginning-of-line 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 ;; If previous line had a comment, use it's indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (if (re-search-forward comment-start-skip cur-pt t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 comment-column)))))) ; otherwise indent at comment column.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 ;; most command level (interactive) and related
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (defun c++-set-auto-hungry-state (auto-p hungry-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 "Set auto/hungry to state indicated by AUTO-P and HUNGRY-P.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 Update modeline to indicate state to user."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (setq c++-auto-newline auto-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 c++-hungry-delete-key hungry-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (set-buffer-modified-p (buffer-modified-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 (defun c++-toggle-auto-state (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 "Toggle auto-newline feature.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 This function ignores `c++-auto-hungry-toggle' variable. Optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 numeric ARG, if supplied turns on auto-newline when positive, turns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 off auto-newline when negative and toggles when zero."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (let ((auto (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 ((not arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (not c++-auto-newline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 ((zerop (setq arg (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (not c++-auto-newline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 ((< arg 0) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (t t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (c++-set-auto-hungry-state auto c++-hungry-delete-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (defun c++-toggle-hungry-state (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 "Toggle hungry-delete-key feature.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 This function ignores `c++-auto-hungry-toggle' variable. Optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 numeric ARG, if supplied turns on hungry-delete-key when positive,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 turns off hungry-delete-key when negative and toggles when zero."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 (let ((hungry (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 ((not arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 (not c++-hungry-delete-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 ((zerop (setq arg (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 (not c++-hungry-delete-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 ((< arg 0) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 (t t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 (c++-set-auto-hungry-state c++-auto-newline hungry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 (defun c++-toggle-auto-hungry-state (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 "Toggle auto-newline and hungry-delete-key features.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 Actual toggling of these features is controlled by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 `c++-auto-hungry-toggle' variable.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 Optional argument has the following meanings when supplied:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 Universal argument \\[universal-argument]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 resets features to c++-auto-hungry-initial-state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 negative number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 turn off both auto-newline and hungry-delete-key features.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 positive number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 turn on both auto-newline and hungry-delete-key features.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 zero
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 toggle both features regardless of `c++-auto-hungry-toggle-p'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 (let* ((numarg (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 (apl (list 'auto-only 'auto-hungry t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 (hpl (list 'hungry-only 'auto-hungry t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 (auto (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 ((not arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (if (memq c++-auto-hungry-toggle apl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 (not c++-auto-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 c++-auto-newline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 ((listp arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 (memq c++-auto-hungry-initial-state apl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 ((zerop numarg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 (not c++-auto-newline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 ((< arg 0) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (t t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 (hungry (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 ((not arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (if (memq c++-auto-hungry-toggle hpl)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (not c++-hungry-delete-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 c++-hungry-delete-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 ((listp arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (memq c++-auto-hungry-initial-state hpl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 ((zerop numarg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 (not c++-hungry-delete-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 ((< arg 0) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 (t t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (c++-set-auto-hungry-state auto hungry)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (defun c++-tame-insert (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 "Safely inserts certain troublesome characters in comment regions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 Because of syntax bugs in Emacs, characters with string or parenthesis
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 syntax must be escaped with a backslash or lots of things get messed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 up. Unfortunately, setting `parse-sexp-ignore-comments' to non-nil does
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 not fix the problem, but this function is unnecessary if you are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 running a patched Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 See also the variable `c++-untame-characters'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (if (and (memq last-command-char c++-untame-characters)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 (memq (c++-in-literal) '(c c++)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 (insert "\\"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (self-insert-command arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 (defun c++-electric-delete (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 "If `c++-hungry-delete-key' is non-nil, consumes all preceding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 whitespace unless ARG is supplied, or point is inside a C or C++ style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 comment or string. If ARG is supplied, this just calls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 `backward-delete-char-untabify' passing along ARG.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 If `c++-hungry-delete-key' is nil, just call `backward-delete-char-untabify'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 ((or (not c++-hungry-delete-key) arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 (funcall c++-delete-function (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 ((let ((bod (c++-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 (not (or (memq (c++-in-literal bod) '(c c++ string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (= (preceding-char) ?#)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (let ((here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (skip-chars-backward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (if (/= (point) here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 (delete-region (point) here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (funcall c++-delete-function 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (t (funcall c++-delete-function 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (defun c++-electric-pound (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 "Electric pound command."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 (if (memq (c++-in-literal) '(c c++ string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 (self-insert-command arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (let ((here (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 (bobp (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884 (bolp (bolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (if (memq 'alignleft c++-electric-pound-behavior)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (progn (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 (delete-horizontal-space)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 (if bobp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 (insert (make-string arg last-command-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (insert-before-markers (make-string arg last-command-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (if (not bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (goto-char here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (set-marker here nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (defun c++-electric-brace (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 "Insert character and correct line's indentation."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (let (insertpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 (last-command-char last-command-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 (bod (c++-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 (if (and (not arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 (eolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (or (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 (let ((c++-auto-newline c++-auto-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (open-brace-p (= last-command-char ?{)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (if (and open-brace-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (or (eq c++-hanging-braces t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 (and c++-hanging-braces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (not (c++-at-top-level-p t bod)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 (setq c++-auto-newline nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (if (c++-auto-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 ;; this may have auto-filled so we need to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 ;; indent the previous line. we also need to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 ;; indent the currently line, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 ;; c++-beginning-of-defun will not be able to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 ;; correctly find the bod when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 ;; c++-match-headers-strongly is nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 (progn (c++-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 (c++-indent-line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (if (and (memq last-command-char c++-untame-characters)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 (memq (c++-in-literal bod) '(c c++)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 (insert "\\"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 ;; we need to work around a bogus feature of Emacs where an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 ;; open brace at bolp means a beginning-of-defun. but it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 ;; really might not.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 (and (= last-command-char ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 (c++-indent-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 (insert last-command-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 ;; try to clean up empty defun braces if conditions apply
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 (let ((here (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 (and (memq 'empty-defun-braces c++-cleanup-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 (c++-at-top-level-p t bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 c++-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 (= last-command-char ?\})
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 (progn (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 (skip-chars-backward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 (= (preceding-char) ?\{))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 (not (memq (c++-in-literal) '(c c++ string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 (delete-region (point) (1- here)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (set-marker here nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 (let ((here (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 mbeg mend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (if (and (memq 'brace-else-brace c++-cleanup-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 (= last-command-char ?\{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 (let ((status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 (re-search-backward "}[ \t\n]*else[ \t\n]*{"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 (setq mbeg (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 mend (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 (= mend here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 (not (memq (c++-in-literal bod) '(c c++ string))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 ;; we should clean up brace-else-brace syntax
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 (delete-region mbeg mend)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 (insert-before-markers "} else {")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 (set-marker here nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 (set-marker here nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 (c++-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 (if (c++-auto-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 ;; c++-auto-newline may have done an auto-fill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 (let ((here (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 (goto-char (- (point) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 (c++-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 (setq insertpos (- (goto-char here) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 (set-marker here nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 (c++-indent-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 (if insertpos (goto-char (1+ insertpos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 (delete-char -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 (if insertpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 (goto-char insertpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 (self-insert-command (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 (self-insert-command (prefix-numeric-value arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 (defun c++-electric-slash (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 "Insert slash, and if slash is second of a double-slash comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 introducing construct, indent line as comment. This only indents if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 we're on a comment-only line, otherwise use `indent-for-comment' (\\[indent-for-comment])."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 (let ((here (point)) char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 (self-insert-command (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 (and (setq char (char-after (1- here)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 (= char ?/)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 (c++-indent-line)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 (defun c++-electric-star (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 "Works with `c++-electric-slash' to auto indent C style comment lines."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 (let ((here (point)) char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 (self-insert-command (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 (if (and (setq char (char-after (1- here)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 (memq (c++-in-literal) '(c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 (memq char '(?/ ?* ?\t 32 ?\n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 (skip-chars-backward "* \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 (if (= (preceding-char) ?/)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 (skip-chars-backward " \t")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 (bolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 (c++-indent-line)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 (defun c++-electric-semi (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 "Insert character and correct line's indentation."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 (if (c++-in-literal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 (self-insert-command (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 (let ((here (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 (if (and (memq 'defun-close-semi c++-cleanup-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 c++-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 (skip-chars-backward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 (= (preceding-char) ?})))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 (delete-region here (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 (set-marker here nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 (c++-electric-terminator arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 (defun c++-electric-colon (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 "Electrify colon.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 De-auto-newline double colons. No auto-new-lines for member
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 initialization list."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 (if (c++-in-literal)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 (self-insert-command (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 (let ((c++-auto-newline c++-auto-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 (insertion-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 (bod (c++-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 ;; check for double-colon where the first colon is not in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 ;; comment or literal region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 ((progn (skip-chars-backward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 (and (= (preceding-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 (not (memq (c++-in-literal bod) '(c c++ string)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 (progn (delete-region insertion-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 (setq c++-auto-newline nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 insertion-point (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 ;; check for ?: construct which may be at any level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 ((progn (goto-char insertion-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 (condition-case premature-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 (backward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 ;; is possible that the sexp we just skipped was a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 ;; negative number. in that case the minus won't be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 ;; gobbled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 (skip-chars-backward "-")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 (c++-backward-syntactic-ws bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 (= (preceding-char) ?\?))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 (setq c++-auto-newline nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 ;; check for being at top level or top with respect to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 ;; class. if not, process as normal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 ((progn (goto-char insertion-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 (not (c++-at-top-level-p t bod))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 ;; if at top level, check to see if we are introducing a member
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 ;; init list. if not, continue
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 ((progn (c++-backward-syntactic-ws bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 (= (preceding-char) ?\)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 (goto-char insertion-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 ;; at a member init list, figure out about auto newlining. if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 ;; nil or before then put a newline before the colon and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 ;; adjust the insertion point, but *only* if there is no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 ;; newline already before the insertion point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 (if (and (memq c++-hanging-member-init-colon '(nil before))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 c++-auto-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 (if (not (save-excursion (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 (bolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 (let ((c++-auto-newline t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 (c++-auto-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 (setq insertion-point (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 ;; if hanging colon is after or nil, then newline is inserted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 ;; after colon. set up variable so c++-electric-terminator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 ;; places the newline correctly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 (setq c++-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 (and c++-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 (memq c++-hanging-member-init-colon '(nil after)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 ;; last condition is always put newline after colon
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 (t (setq c++-auto-newline nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 )) ; end-cond, end-save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 (goto-char insertion-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 (c++-electric-terminator arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 (defun c++-electric-terminator (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 "Insert character and correct line's indentation."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 (let (insertpos (end (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 (if (and (not arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 (eolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 (not (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 (or (= (following-char) ?#)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 ;; Colon is special only after a label, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 ;; case, or another colon.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 ;; So quickly rule out most other uses of colon
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 ;; and do no indentation for them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 (and (eq last-command-char ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 (not (looking-at "case[ \t]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 (forward-word 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 (< (point) end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 ;; Do re-indent double colons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 (end-of-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 (looking-at ":")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 (c++-beginning-of-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 (let* ((parse-sexp-ignore-comments t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 (pps (parse-partial-sexp (point) end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 (or (nth 3 pps) (nth 4 pps) (nth 5 pps))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135 (insert last-command-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 (c++-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 (and c++-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 (not (c++-in-parens-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 ;; the new marker object, used to be just an integer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 (setq insertpos (make-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 ;; changed setq to set-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 (set-marker insertpos (1- (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 ;; do this before the newline, since in auto fill can break
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 (newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 (c++-indent-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 (if insertpos (goto-char (1+ insertpos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (delete-char -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 (if insertpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 (goto-char insertpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 (self-insert-command (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 (self-insert-command (prefix-numeric-value arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 (defun c++-indent-command (&optional whole-exp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 "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
1158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 If `c++-tab-always-indent' is t, always just indent the current line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 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
1161 in the line's indentation; otherwise insert a tab. If not-nil-or-t,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 then tab is inserted only within literals (comments and strings) and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 inside preprocessor directives, but line is always reindented.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 A numeric argument, regardless of its value, means indent rigidly all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 the lines of the expression starting after point so that this line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 becomes properly indented. The relative indentation among the lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 of the expression are preserved."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 (let ((bod (c++-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 (if whole-exp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 ;; If arg, always indent this line as C
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 ;; and shift remaining lines of expression the same amount.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 (let ((shift-amt (c++-indent-line bod))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 (if (eq c++-tab-always-indent t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 (setq beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 (setq beg (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 (if (> end beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 (indent-code-rigidly beg end shift-amt "#")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 ;; CASE 1: indent when at column zero or in lines indentation,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 ;; otherwise insert a tab
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 ((not c++-tab-always-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 (if (and (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 (or (looking-at "[ \t]*$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 (/= (point) (c++-point 'boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 (bolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 (c++-indent-line bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 (insert-tab)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 ;; CASE 2: just indent the line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 ((eq c++-tab-always-indent t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 (c++-indent-line bod))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 ;; CASE 3: if in a literal, insert a tab, but always indent the line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 ((or (memq (c++-in-literal bod) '(c c++ string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 (= (preceding-char) ?#)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 (let ((here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 (boi (save-excursion (back-to-indentation) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 (indent-p nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 (c++-indent-line bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 (setq indent-p (and (> here boi) (= (point) boi))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 (if indent-p (insert-tab))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 ;; CASE 4: bogus, just indent the line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 (t (c++-indent-line bod))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 (defun c++-indent-exp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 "Indent each line of the C++ grouping following point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 (let ((indent-stack (list nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222 (contain-stack (list (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 (case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 restart outer-loop-done inner-loop-done state ostate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 this-indent last-sexp last-depth
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 at-else at-brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 (parse-sexp-ignore-comments t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 (opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 (next-depth 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 (forward-sexp 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 (setq outer-loop-done nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 (while (and (not (eobp)) (not outer-loop-done))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 (setq last-depth next-depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 ;; Compute how depth changes over this line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 ;; plus enough other lines to get to one that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 ;; does not end inside a comment or string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 ;; Meanwhile, do appropriate indentation on comment lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 (setq inner-loop-done nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 (while (and (not inner-loop-done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 (not (and (eobp) (setq outer-loop-done t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 (setq ostate state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 ;; fix by reed@adapt.net.com
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 ;; must pass in the return past the end of line, so that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 ;; parse-partial-sexp finds it, and recognizes that a "//"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 ;; comment is over. otherwise, state is set that we're in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 ;; comment, and never gets unset, causing outer-loop to only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 ;; terminate in (eobp). old:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 ;;(setq state (parse-partial-sexp (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 ;;(progn (end-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 ;;nil nil state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 (let ((start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 (line-end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 (progn (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 (while (eq (c++-in-literal) 'c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 (c++-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 (end-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 (end (progn (if (not (eobp)) (forward-char)) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 (setq state (parse-partial-sexp start end nil nil state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 (goto-char line-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 (setq next-depth (car state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 (if (and (car (cdr (cdr state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 (>= (car (cdr (cdr state))) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 (setq last-sexp (car (cdr (cdr state)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 (if (or (nth 4 ostate))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 (c++-indent-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 (if (or (nth 3 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 (setq inner-loop-done t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 (if (<= next-depth 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 (setq outer-loop-done t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 (if outer-loop-done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 ;; If this line had ..))) (((.. in it, pop out of the levels
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 ;; that ended anywhere in this line, even if the final depth
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 ;; doesn't indicate that they ended.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 (while (> last-depth (nth 6 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 (setq indent-stack (cdr indent-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 contain-stack (cdr contain-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 last-depth (1- last-depth)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 (if (/= last-depth next-depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 (setq last-sexp nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 ;; Add levels for any parens that were started in this line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 (while (< last-depth next-depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 (setq indent-stack (cons nil indent-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 contain-stack (cons nil contain-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 last-depth (1+ last-depth)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 (if (null (car contain-stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 (setcar contain-stack (or (car (cdr state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 (save-excursion (forward-sexp -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 ;; check for C comment block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 (if (memq (c++-in-literal) '(c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 (let ((eoc (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 (re-search-forward "\\*/" (point-max) 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 (while (< (point) eoc)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 (c++-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 (forward-line 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 (if (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 (if (and (car indent-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 (>= (car indent-stack) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 ;; Line is on an existing nesting level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 ;; Lines inside parens are handled specially.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 (if (or (/= (char-after (car contain-stack)) ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 ;;(c++-at-top-level-p t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 ;; baw hack for continued statement offsets
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 ;; repercussions???
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 (setq this-indent (car indent-stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 ;; Line is at statement level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 ;; Is it a new statement? Is it an else?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 ;; Find last non-comment character before this line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 (setq at-else (looking-at "else\\W"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 (setq at-brace (= (following-char) ?{))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 (c++-backward-syntactic-ws opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 (if (not (memq (preceding-char) '(nil ?\, ?\; ?} ?: ?{)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 ;; Preceding line did not end in comma or semi;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 ;; indent this line c-continued-statement-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 ;; more than previous.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 (c-backward-to-start-of-continued-exp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 (car contain-stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 (setq this-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 (+ c-continued-statement-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 (current-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 (if at-brace c-continued-brace-offset 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 ;; Preceding line ended in comma or semi;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 ;; use the standard indent for this level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 (if at-else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 (progn (c++-backward-to-start-of-if opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 (skip-chars-forward "{ \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 (setq this-indent (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 (setq this-indent (car indent-stack))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 ;; Just started a new nesting level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 ;; Compute the standard indent for this level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 (let ((val (c++-calculate-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 (if (car indent-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 (- (car indent-stack))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 (setcar indent-stack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 (setq this-indent val))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 ;; Adjust line indentation according to its contents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 ;; looking at public, protected, private line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 ((looking-at c++-access-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 (setq this-indent (+ this-indent c++-access-specifier-offset)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 ;; looking at a case, default, or other label
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 ((or (looking-at "\\(case[ \t]+.*\\|default[ \t]*\\):")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 (and (looking-at "[A-Za-z]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362 (looking-at ":[^:]"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 (setq this-indent (max 0 (+ this-indent c-label-offset))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 ;; looking at a comment only line?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 ((looking-at comment-start-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 ;; different indentation base on whether this is a col0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 ;; comment only line or not. also, if comment is in, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 ;; to the right of comment-column, the comment doesn't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 ;; move
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 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 (setq this-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 (if (>= (current-column) comment-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 (current-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 (c++-comment-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 (+ this-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 (c++-backward-syntactic-ws
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 (car contain-stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 (memq (preceding-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 '(nil ?\, ?\; ?} ?: ?{)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 0 c-continued-statement-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 ;; looking at a friend declaration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 ((looking-at "friend[ \t]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 (setq this-indent (+ this-indent c++-friend-offset)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 ;; looking at a close brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 ((= (following-char) ?})
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 (setq this-indent (- this-indent c-indent-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 ;; looking at an open brace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 ((= (following-char) ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 (setq this-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 (+ this-indent c-brace-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 (if (c++-at-top-level-p t (car contain-stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 0 c-indent-level))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 ;; check for continued statements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 (c++-backward-syntactic-ws (car contain-stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 (and (not (c++-in-parens-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 (not (memq (preceding-char) '(nil ?\000 ?\; ?\} ?\: ?\{)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 (not (looking-at c++-class-key)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 (setq this-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 (+ this-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 c-continued-statement-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 ;; are we in a member init list?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 (if (not (looking-at "[ \t]*:"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 (let ((lim (car contain-stack)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 (c++-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 (while (and (< lim (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 (= (preceding-char) ?,))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 (c++-backward-syntactic-ws))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 (if (looking-at "[ \t]*:")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 (- (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 ;; check for stream operator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 ((looking-at "\\(<<\\|>>\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 (setq this-indent (c++-calculate-indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 ) ;; end-cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 ;; Put chosen indentation into effect.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 (or (= (current-column) this-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 (= (following-char) ?\#)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 (delete-region (point) (progn (beginning-of-line) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 (indent-to this-indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 ;; Indent any comment following the text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 (or (looking-at comment-start-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 (if (re-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 comment-start-skip
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 (c++-point 'eol) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 (progn (indent-for-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 (beginning-of-line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 ))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 (defun c++-insert-header ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 "Insert header denoting C++ code at top of buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 (insert "// "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 "This may look like C code, but it is really "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 "-*- C++ -*-"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 "\n\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 (defun c++-tame-comments ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 "Backslashifies all untamed in comment regions found in the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 This is a workaround for Emacs syntax bugs. This function is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 unnecessary (and un-used automatically) if you are running a patched
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 Emacs. Untamed characters to escape are defined in the variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 `c++-untame-characters'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 ;; make the list into a valid charset, escaping where necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 (let ((charset (concat "^" (mapconcat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 (lambda (char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 (if (memq char '(?\\ ?^ ?-))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 (concat "\\" (char-to-string char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 (char-to-string char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 c++-untame-characters ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 (beginning-of-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 (skip-chars-forward charset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 (if (and (not (zerop (following-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 (memq (c++-in-literal) '(c c++))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 (/= (preceding-char) ?\\ ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 (insert "\\"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 (if (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 (forward-char 1))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 ;; taken from match-paren.el. Author: unknown
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 (defun c++-match-paren ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 "Jumps to the paren matching the one under point, if there is one."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 (let ((parse-sexp-ignore-comments (memq 'v19 c++-emacs-features)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 ((looking-at "[\(\[{]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 (backward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 ((looking-at "[])}]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 (backward-sexp 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 (t (message "Could not find matching paren.")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 (defun c++-forward-sexp (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 "Safe forward-sexp call."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 (interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 (let ((parse-sexp-ignore-comments (memq 'v19 c++-emacs-features)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 (forward-sexp arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 (defun c++-backward-sexp (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 "Safe backward-sexp call."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 (interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 (let ((parse-sexp-ignore-comments (memq 'v19 c++-emacs-features)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 (backward-sexp arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 ;; compatibility between emacsen
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 ;; This is the best we can do in vanilla GNU 18 emacsen. Note that the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 ;; following problems exist:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 ;; 1. We only look back to LIM, and that could place us inside a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 ;; literal if we are scanning backwards over lots of comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 ;; 2. This can potentially get slower the larger LIM is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 ;; If anybody has a better solution, I'll all ears
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 (defun c++-backward-syntactic-ws-v18 (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 "Skip backwards over syntactic whitespace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 Syntactic whitespace is defined as lexical whitespace, C and C++ style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 comments, and preprocessor directives. Search no farther back than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 optional LIM. If LIM is omitted, `beginning-of-defun' is used."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 (let ((lim (or lim (c++-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 literal stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 (if (and c++-backscan-limit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 (> (- (point) lim) c++-backscan-limit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 (setq lim (- (point) c++-backscan-limit)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 (while (not stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 (skip-chars-backward " \t\n\r\f" lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 ;; c++ comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 (if (eq (setq literal (c++-in-literal lim)) 'c++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 (skip-chars-backward "^/" lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 (skip-chars-backward "/" lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 (while (not (or (and (= (following-char) ?/)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 (= (char-after (1+ (point))) ?/))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 (<= (point) lim)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540 (skip-chars-backward "^/" lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 (skip-chars-backward "/" lim)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 ;; c comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 (if (eq literal 'c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545 (skip-chars-backward "^*" lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 (skip-chars-backward "*" lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 (while (not (or (and (= (following-char) ?*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 (= (preceding-char) ?/))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 (<= (point) lim)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 (skip-chars-backward "^*" lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 (skip-chars-backward "*" lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 (or (bobp) (forward-char -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 ;; preprocessor directive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 (if (eq literal 'pound)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 (setq stop (<= (point) lim)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 ;; just outside of c block
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 (if (and (= (preceding-char) ?/)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 (= (char-after (- (point) 2)) ?*))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 (skip-chars-backward "^*" lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 (skip-chars-backward "*" lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 (while (not (or (and (= (following-char) ?*)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 (= (preceding-char) ?/))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 (<= (point) lim)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 (skip-chars-backward "^*" lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 (skip-chars-backward "*" lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 (or (bobp) (forward-char -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 ;; none of the above
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 (setq stop t))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 ;; This defun works well for Lemacs 19.4-7, which implemented a first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 ;; shot at doing this via a C built-in backward-syntactic-ws. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 ;; has been obsoleted in future Lemacsen and in FSF19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 (defun c++-fast-backward-syntactic-ws-1 (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 "Skip backwards over syntactic whitespace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 Syntactic whitespace is defined as lexical whitespace, C and C++ style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 comments, and preprocessor directives. Search no farther back than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 optional LIM. If LIM is omitted, `beginning-of-defun' is used."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 (let ((parse-sexp-ignore-comments t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 donep boi char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 (lim (or lim (c++-point 'bod))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 (if (< lim (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 (narrow-to-region lim (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 ;; cpp statements are comments for our purposes here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 (if (eq major-mode 'c++-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 (modify-syntax-entry ?# "< b" c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 (modify-syntax-entry ?\n "> b" c++-c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 (modify-syntax-entry ?# "< b" c++-c-mode-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 (while (not donep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 ;; if you're not running a patched XEmacs, the new byte
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 ;; compiler will complain about this function. ignore that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 (backward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 (if (not (looking-at "#\\|/\\*\\|//\\|\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 (setq boi (c++-point 'boi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 char (char-after boi))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 (if (and char (= char ?#))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 (progn (goto-char boi)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 (setq donep (<= (point) lim)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 (setq donep t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 ;; cpp statements are not comments anywhere else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608 (if (eq major-mode 'c++-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 (modify-syntax-entry ?# "." c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 (modify-syntax-entry ?\n " " c++-c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 (modify-syntax-entry ?# "." c++-c-mode-syntax-table))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 ;; This is the way it should be done for all post 19.7 Lemacsen and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 ;; for all FSF19 implementations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 (defun c++-fast-backward-syntactic-ws-2 (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 "Skip backwards over syntactic whitespace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 Syntactic whitespace is defined as lexical whitespace, C and C++ style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 comments, and preprocessor directives. Search no farther back than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 optional LIM. If LIM is omitted, `beginning-of-defun' is used."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 (let* ((lim (or lim (c++-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 (here lim))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 (if (< lim (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 (narrow-to-region lim (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 ;; cpp statements are comments for our purposes here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 (if (eq major-mode 'c++-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 (modify-syntax-entry ?# "< b" c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 (modify-syntax-entry ?\n "> b" c++-c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 (modify-syntax-entry ?# "< b" c++-c-mode-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 (while (/= here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 (setq here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 (forward-comment -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 ;; cpp statements are not comments everywhere else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 (if (eq major-mode 'c++-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 (modify-syntax-entry ?# "." c++-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 (modify-syntax-entry ?\n " " c++-c-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 (modify-syntax-entry ?# "." c++-c-mode-syntax-table))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 ;; This is the slow and ugly way, but its the best we can do in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 ;; vanilla GNU18 emacsen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 (defun c++-in-literal-v18 (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 "Determine if point is in a C++ ``literal''.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 Return `c' if in a C-style comment, `c++' if in a C++ style comment,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 `string' if in a string literal, `pound' if on a preprocessor line, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 nil if not in a comment at all. Optional LIM is used as the backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 limit of the search. If omitted, or nil, `c++-beginning-of-defun' is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 used."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 (let* ((here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 (state nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 (match nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 (backlim (or lim (c++-point 'bod))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 (goto-char backlim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 (while (< (point) here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 (setq match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 (and (re-search-forward "\\(/[/*]\\)\\|[\"']\\|\\(^[ \t]*#\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 here 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 (buffer-substring (match-beginning 0) (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 (setq state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 ;; no match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 ((null match) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 ;; looking at the opening of a C++ style comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 ((string= "//" match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 (if (<= here (progn (end-of-line) (point))) 'c++))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 ;; looking at the opening of a C block comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 ((string= "/*" match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 (if (not (re-search-forward "*/" here 'move)) 'c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 ;; looking at the opening of a double quote string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 ((string= "\"" match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 (if (not (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 ;; this seems to be necessary since the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 ;; re-search-forward will not work without it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 (narrow-to-region (point) here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 (re-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 ;; this regexp matches a double quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 ;; which is preceded by an even number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 ;; of backslashes, including zero
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)*\"" here 'move)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 'string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 ;; looking at the opening of a single quote string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 ((string= "'" match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687 (if (not (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688 ;; see comments from above
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 (narrow-to-region (point) here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 (re-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691 ;; this matches a single quote which is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 ;; preceded by zero or two backslashes.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 "\\([^\\]\\|^\\)\\(\\\\\\\\\\)?'"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694 here 'move)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695 'string))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696 ((string-match "[ \t]*#" match)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697 (if (<= here (progn (end-of-line) (point))) 'pound))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698 (t nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 ) ; end-while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1700 state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 ;; This is for all 8-bit emacsen (Lucid 19, patched GNU18)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 (defun c++-in-literal-8-bit (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704 "Determine if point is in a C++ ``literal''.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705 Return `c' if in a C-style comment, `c++' if in a C++ style comment,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1706 `string' if in a string literal, `pound' if on a preprocessor line, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707 nil if not in a comment at all. Optional LIM is used as the backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 limit of the search. If omitted, or nil, `c++-beginning-of-defun' is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709 used."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711 (let* ((backlim (or lim (c++-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712 (here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 (parse-sexp-ignore-comments t) ; may not be necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 (state (parse-partial-sexp backlim (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716 ((nth 3 state) 'string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 ((nth 4 state) (if (nth 7 state) 'c++ 'c))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1718 ((progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 (looking-at "[ \t]*#"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722 'pound)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 (t nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 ;; This is for all 1-bit emacsen (FSF19)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 (defun c++-in-literal-1-bit (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727 "Determine if point is in a C++ ``literal''.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728 Return `c' if in a C-style comment, `c++' if in a C++ style comment,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729 `string' if in a string literal, `pound' if on a preprocessor line, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 nil if not in a comment at all. Optional LIM is used as the backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 limit of the search. If omitted, or nil, `c++-beginning-of-defun' is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 used."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 (let* ((backlim (or lim (c++-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735 (here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736 (parse-sexp-ignore-comments t) ; may not be necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737 (state (parse-partial-sexp backlim (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 ((nth 3 state) 'string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740 ((nth 4 state) (if (nth 7 state) 'c 'c++))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741 ((progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 (looking-at "[ \t]*#"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 'pound)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 (t nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749 ((memq 'old-v19 c++-emacs-features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750 (fset 'c++-backward-syntactic-ws 'c++-fast-backward-syntactic-ws-1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751 ((memq 'v19 c++-emacs-features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752 (fset 'c++-backward-syntactic-ws 'c++-fast-backward-syntactic-ws-2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 (fset 'c++-backward-syntactic-ws 'c++-backward-syntactic-ws-v18))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757 ((memq '8-bit c++-emacs-features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758 (fset 'c++-in-literal 'c++-in-literal-8-bit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759 ((memq '1-bit c++-emacs-features)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 (fset 'c++-in-literal 'c++-in-literal-1-bit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762 (fset 'c++-in-literal 'c++-in-literal-v18))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 ;; defuns for parsing syntactic elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 (defun c++-parse-state (&optional limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770 "Determinate the syntactic state of the code at point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 Iteratively uses `parse-partial-sexp' from point to LIMIT and returns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 the result of `parse-partial-sexp' at point. LIMIT is optional and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 defaults to `point-max'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774 (let ((limit (or limit (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775 (parse-sexp-ignore-comments t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776 state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 (while (< (point) limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 (setq state (parse-partial-sexp (point) limit 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781 (defun c++-at-top-level-p (wrt &optional bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782 "Return t if point is not inside a containing C++ expression, nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 if it is embedded in an expression. When WRT is non-nil, returns nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784 if not at the top level with respect to an enclosing class, or the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 depth of class nesting at point. With WRT nil, returns nil if not at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786 the ``real'' top level. Optional BOD is the beginning of defun."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788 (let ((indent-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789 (case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 state containing-sexp paren-depth
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 (bod (or bod (c++-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792 foundp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 (goto-char bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 (setq state (c++-parse-state indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 containing-sexp (nth 1 state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 paren-depth (nth 0 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 ((eq major-mode 'c++-c-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 (and (null containing-sexp) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 ((not wrt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 (null containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802 ((null containing-sexp) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 ((c++-in-parens-p) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 ;; calculate depth wrt containing (possibly nested) classes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 (while (and (setq foundp (re-search-backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 (concat "[;}]\\|" c++-class-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 (point-min) t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810 (let ((bod (c++-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811 (or (c++-in-literal bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 (c++-in-parens-p bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813 ;; see if class key is inside a template spec
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 (and (looking-at c++-class-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 (progn (skip-chars-backward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 (memq (preceding-char) '(?, ?<))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817 (if (memq (following-char) '(?} ?\;))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819 (setq state (c++-parse-state containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820 (and foundp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821 (not (nth 1 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 (nth 2 state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 paren-depth))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 (defun c++-in-parens-p (&optional lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 "Return t if inside a paren expression.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 Optional LIM is used as the backward limit of the search."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 (let ((lim (or lim (c++-point 'bod))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 (condition-case var
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 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833 (narrow-to-region (point) lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835 (= (char-after (or (scan-lists (point) -1 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 (point-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837 ?\()))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838 (error nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841 (defun c++-in-function-p (&optional containing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842 "Return t if inside a C++ function definition.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843 Optional CONTAINING is position of containing s-exp open brace. If not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844 supplied, point is used as search start."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846 (let ((here (if (not containing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847 (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848 (goto-char containing)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 (c++-backward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 (if (and (= (preceding-char) ?t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 (forward-word -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 (looking-at "\\<const\\>"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 (c++-backward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 (goto-char here))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 (= (preceding-char) ?\)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860 ;; defuns for calculating indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862 (defun c++-indent-line (&optional bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 "Indent current line as C++ code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864 Return the amount the indentation changed by. Optional BOD is the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 point of the beginning of the C++ definition."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866 (let* ((bod (or bod (c++-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 (indent (c++-calculate-indent nil bod))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 beg shift-amt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 close-paren top-close-paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 (case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 (pos (- (point-max) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872 ;; calculate block close paren offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873 (if (listp c++-block-close-brace-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 (setq close-paren (car c++-block-close-brace-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875 top-close-paren (cdr c++-block-close-brace-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 (setq close-paren c++-block-close-brace-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877 top-close-paren c++-block-close-brace-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 ;; now start cleanup
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 (setq beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 ((eq indent nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 (setq indent (current-indentation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 ((eq indent t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 (setq indent (c++-calculate-c-indent-within-comment)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 ((looking-at "[ \t]*#")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 (setq indent 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890 (looking-at "//\\|/\\*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 ;; we've found a comment-only line. we now must try to determine
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 ;; if the line is a continuation from a comment on the previous
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893 ;; line. we check to see if the comment starts in or to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 ;; right of comment-column and if so, we don't change its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895 ;; indentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 (if (>= (current-column) comment-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 (setq indent (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 (setq indent (c++-comment-offset (bolp) indent))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 (if (listp indent) (setq indent (car indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904 ((looking-at c++-access-key)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 (setq indent (+ indent c++-access-specifier-offset)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906 ((looking-at "default[ \t]*:")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907 (setq indent (+ indent c-label-offset)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908 ((or (looking-at "case[ \t]+.*:")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909 (and (looking-at "[A-Za-z]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 (looking-at ":[^:]"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913 (setq indent (max 1 (+ indent c-label-offset))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 ((and (looking-at "else\\b")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915 (not (looking-at "else\\s_")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 (setq indent (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 (c++-backward-to-start-of-if)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919 (skip-chars-forward "{ \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920 (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921 ((looking-at "\\<friend\\>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 (setq indent (+ indent c++-friend-offset)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923 ((and (= (following-char) ?\))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924 c++-paren-as-block-close-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925 (setq indent (+ (- indent c-indent-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 (c++-at-top-level-p nil bod))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 top-close-paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 close-paren))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 ((= (following-char) ?})
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932 (setq indent (+ (- indent c-indent-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935 (c++-at-top-level-p nil bod))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936 top-close-paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 close-paren))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938 ((= (following-char) ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939 (setq indent (+ indent c-brace-offset))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 (setq shift-amt (- indent (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 (if (zerop shift-amt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 (if (> (- (point-max) pos) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 (goto-char (- (point-max) pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 (delete-region beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 (indent-to indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 ;; If initial point was within line's indentation,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 ;; position after the indentation. Else stay at same point in text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 (if (> (- (point-max) pos) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 (goto-char (- (point-max) pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951 ;; save-excursion is necessary because things break if the hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 ;; changes point or mark
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954 (run-hooks 'c++-special-indent-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 shift-amt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 (defun c++-cont-indent (ipnt char lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 "Calculate the indentation for a continued statement.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 IPNT is the indentation point; CHAR is the character before the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 indentation point, excluding any intervening whitespace; LIM is the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 minimum point to search backwards to."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 (let ((charlist '(nil ?\000 ?\, ?\; ?\} ?\: ?\{))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 streamop-pos here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964 (goto-char ipnt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965 (c++-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966 (if (not (memq char charlist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 ;; This line is continuation of preceding line's statement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 (c-backward-to-start-of-continued-exp lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970 ;; take care of << and >> while in streams
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971 (setq here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973 (and (progn (goto-char ipnt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 (looking-at "[ \t]*\\(<<\\|>>\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 (progn (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 (skip-chars-forward "^><\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 (setq streamop-pos (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978 (looking-at "\\(<<\\|>>\\)"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 streamop-pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 (+ (current-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 ;; prevent repeated continued indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983 (beginning-of-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 (c++-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985 (memq (preceding-char) charlist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 c-continued-statement-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987 ;; the following statements *do* indent even
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 ;; for single statements (are there others?)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989 (if (looking-at "\\(do\\|else\\|for\\|if\\|while\\)\\b")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990 c-continued-statement-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 ;; else may be a continued statement inside
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 ;; a simple for/else/while/if/do loop
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993 (beginning-of-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 (c++-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 (c-backward-to-start-of-continued-exp lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 (if (looking-at "\\(do\\|else\\|for\\|if\\|while\\)\\b")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 c-continued-statement-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 (goto-char ipnt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 ((= (following-char) ?\{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005 c-continued-brace-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006 ((and (= (following-char) ?\})
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007 (progn (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2008 (c++-at-top-level-p nil lim)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009 (- c-continued-statement-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010 (t 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2011 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013 (defun c++-calculate-indent (&optional parse-start bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 "Return appropriate indentation for current line as C++ code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 In usual case returns an integer: the column to indent to.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016 Returns nil if line starts inside a string, t if in a comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 Optional PARSE-START is the location to start parsing, and optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 BOD is the beginning of the C++ definition."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021 (let ((indent-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 (case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 state do-indentation literal in-meminit-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 containing-sexp streamop-pos char-before-ip
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 (inclass-shift 0) inclass-depth inclass-unshift
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 (bod (or bod (c++-point 'bod))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 (if parse-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028 (goto-char parse-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029 (goto-char bod))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030 (setq parse-start (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031 state (c++-parse-state indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032 containing-sexp (nth 1 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033 ;; it is possible that c++-defun-header-weak could not find the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034 ;; beginning of the C++ definition. The following code attempts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035 ;; to work around this. It is probably better to just use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2036 ;; c++-match-header-strongly, but there are performance questions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037 (if (null state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038 (let* ((c++-match-header-strongly t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039 (bod (c++-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 (goto-char bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041 (setq state (c++-parse-state indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042 containing-sexp (nth 1 state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 parse-start (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044 (setq literal (c++-in-literal bod))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045 ;; cache char before indent point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 (c++-backward-syntactic-ws bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 (setq char-before-ip (preceding-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051 ;; CASE 1: in a string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 ((memq literal '(string)) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053 ;; CASE 2: in a C or C++ style comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 ((memq literal '(c c++)) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 ;; CASE 3: Line is at top level. May be comment-only line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056 ;; data or function definition, or may be function argument
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 ;; declaration or member initialization. Indent like the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058 ;; previous top level line unless:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 ;; 1. the previous line ends in a closeparen without
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061 ;; semicolon, in which case this line is the first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 ;; argument declaration or member initialization, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 ;; 2. the previous line ends with a closeparen
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065 ;; (closebrace), optional spaces, and a semicolon, in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2066 ;; which case this line follows a multiline function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 ;; declaration (class definition), or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 ;; 3. the previous line begins with a colon, in which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 ;; case this is the second line of member inits. It is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 ;; assumed that arg decls and member inits are not mixed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073 ((setq inclass-depth (c++-at-top-level-p t bod))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 (+
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075 ;; add an offset if we are inside a class defun body, i.e. we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 ;; are at the top level, but only wrt a containing class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 (let ((shift/level (+ c-indent-level c-brace-imaginary-offset)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 (setq inclass-shift (* shift/level inclass-depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 inclass-unshift (* shift/level (max 0 (1- inclass-depth))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 inclass-shift)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 ((or (= (following-char) ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088 (c++-backward-syntactic-ws parse-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 (bobp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 ;; first arg decl or member init
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 ((c++-in-function-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 (if (= (following-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 c++-member-init-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 c-argdecl-indent))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 ((progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100 (if (= (preceding-char) ?\;)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 (backward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 (skip-chars-backward " \t")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 ;; may be first line after a hanging member init colon.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105 ;; check to be sure its not a scope operator meaning we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106 ;; are inside a member def
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 (or (= (preceding-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111 (or (eobp) (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 (and (= (preceding-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 (/= (following-char) ?:)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 (and (= (preceding-char) ?,)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 (let ((bol (c++-point 'bol)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117 (skip-chars-backward "^:" bol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 (= (preceding-char) ?:))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 (not (c++-in-parens-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 (not (bolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 ;; make sure its not a multiple inheritance
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 ;; continuation line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 (not (looking-at c++-inher-key)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130 ;; check to see if we're looking at a member init, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131 ;; access specifier
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132 (if (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135 (looking-at c++-access-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136 ;; access specifier. class defun opening brace may
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137 ;; not be in col zero, and derived classes could be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138 ;; on a separate line than class intro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140 (goto-char (or containing-sexp bod))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143 (if (looking-at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144 ":[ \t]*\\<\\(public\\|protected\\|private\\)\\>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145 (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146 (- (current-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147 ;; remove some nested inclass indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148 inclass-unshift))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149 ;; member init, so add offset. add additional offset if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150 ;; looking at line with just a member init colon
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151 (+ c++-member-init-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152 (if (looking-at ":[ \t]*$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153 (or c++-continued-member-init-offset 0) 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2154 ((or (= (preceding-char) ?})
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2155 (= (preceding-char) ?\))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2156 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 (looking-at "[ \t]*\\<friend\\>")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159 ;; indentation of class defun opening brace may not be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 ;; zero
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 (goto-char (or containing-sexp bod))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162 (- (current-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2163 ;; remove some nested inclass indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164 inclass-unshift))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165 ;; cont arg decls or member inits. we might be inside a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2166 ;; K&R C arg decl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2167 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168 (while (and (< bod (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169 (memq (preceding-char) '(?\, ?\;)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171 (c++-backward-syntactic-ws bod))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172 (and (eq major-mode 'c++-c-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2173 (= (preceding-char) ?\))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2174 (+ c-argdecl-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2175 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2176 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2177 (c++-backward-syntactic-ws bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178 (if (= (preceding-char) ?,)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179 c-continued-statement-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 ((progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2184 (or (memq (c++-in-literal bod) '(c c++))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2185 (looking-at "/[/*]")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2186 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187 ;; are we looking at the first member init?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2188 ((and (= (following-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2190 (c++-backward-syntactic-ws bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 (= (preceding-char) ?\))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2192 (if c++-continued-member-init-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2193 (+ (current-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2194 c++-continued-member-init-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2195 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198 (- (current-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2199 inclass-shift))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200 ;; else first check to see if its a multiple inheritance
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201 ;; continuation line, but not a K&R C arg decl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202 ((and (not (eq major-mode 'c++-c-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203 (looking-at c++-inher-key))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 (if (= char-before-ip ?,)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205 (progn (goto-char (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206 (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 ;; nope, its probably a nested class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 ;; we might be looking at the opening brace of a class
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 ;; defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 ((= (following-char) ?\{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212 ;; indentation of opening brace may not be zero
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213 (- (current-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 ;; remove some nested inclass indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215 inclass-unshift))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 ((eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 ;; looking at a blank line, indent next line to zero
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 ;; at beginning of buffer, if nothing else, indent to zero
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223 (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225 ;; this could be a compound statement, but make sure its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226 ;; not a member init list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227 ((save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229 (c++-backward-syntactic-ws bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 (and (= (preceding-char) ?,)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232 (while (and (< bod (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2233 (= (preceding-char) ?,))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2235 (c++-backward-syntactic-ws bod))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237 (not (setq in-meminit-p (looking-at "[ \t]*:"))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238 c-continued-statement-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 (if (c++-in-parens-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241 ;; we are perhaps inside a member init call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242 (while (and (c++-in-parens-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243 (< bod (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 (skip-chars-forward " \t")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 ;; check to be sure that we're not on the first line of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 ;; the member init list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 (if (and (= (following-char) ?:)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250 (c++-backward-syntactic-ws bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251 (= (preceding-char) ?\))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254 (skip-chars-forward " \t")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255 ;; skip to start of compound statement, but only if we're
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256 ;; not in a member initialization list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257 (if (not in-meminit-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 (let ((ipnt (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 (c++-backward-syntactic-ws bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 (while (and (= (preceding-char) ?,)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261 (< bod (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2264 (setq ipnt (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265 (c++-backward-syntactic-ws bod))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266 (goto-char ipnt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267 ;; subtract inclass-shift since its already incorporated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2268 ;; by default in current-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269 (- (current-column) inclass-shift)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2270 )))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 ;; CASE 4: line is expression, not statement. indent to just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272 ;; after the surrounding open -- unless empty arg list, in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273 ;; which case we do what c++-empty-arglist-indent says to do.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274 ((/= (char-after containing-sexp) ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 (if (and c++-empty-arglist-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276 (or c++-always-arglist-indent-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277 (null (nth 2 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278 ;; indicates empty arg list. Use a heuristic: if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279 ;; the first non-whitespace following left paren
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280 ;; on same line is not a comment, is not an empty
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2281 ;; arglist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2282 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2283 (goto-char (1+ containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284 (looking-at "[ \t]*[/\n]"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2285 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2286 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2287 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 (goto-char (min (+ (point) c++-empty-arglist-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2290 (1+ containing-sexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2291 (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 ;; In C-mode, we would always indent to one after the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2293 ;; left paren. Here, though, we may have an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294 ;; empty-arglist, so we'll indent to the min of that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2295 ;; and the beginning of the first argument.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296 (goto-char (1+ containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297 ;; we want to skip any whitespace b/w open paren and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 ;; first argument. this handles while (thing) style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 ;; and while( thing ) style
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301 (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302 ;; CASE 5: Statement. Find previous non-comment character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304 (or (c++-cont-indent indent-point char-before-ip containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305 ;; This line may start a new statement, or it could
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 ;; represent the while closure of a do/while construct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308 (and (progn (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 (skip-chars-forward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 (looking-at "while\\b"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2312 (c++-backward-to-start-of-do containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2313 (looking-at "do\\b"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2314 (setq do-indentation (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2315 do-indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2316 ;; this could be a case statement. if so we want to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2317 ;; indent it like the first case statement after a switch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2320 (skip-chars-forward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2321 (looking-at "\\(case[ \t]+.*\\|default[ \t]*\\):"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2322 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2323 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 (+ (current-column) c-indent-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 ;; else, this is the start of a new statement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327 ;; Position following last unclosed open.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2329 ;; Is line first statement after an open-brace?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2330 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2331 (and c++-relative-offset-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2332 ;; If no, find that first statement and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333 ;; indent like it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2335 (forward-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2336 (while
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338 (skip-chars-forward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2339 (looking-at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2341 "#\\|/\\*\\|//"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2342 "\\|\\(case[ \t]+.*\\|default[ \t]*\\):"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343 "\\|[a-zA-Z0-9_$]*:[^:]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344 "\\|friend[ \t]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345 c++-class-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346 "[ \t]")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347 ;; Skip over comments and labels
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2348 ;; following openbrace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2349 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2350 ((= (following-char) ?\#)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2351 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352 ((looking-at "/\\*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2353 (search-forward "*/" nil 'move))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354 ((looking-at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355 (concat "//\\|friend[ \t]" c++-class-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2356 "[ \t]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358 ((looking-at "\\(case[ \t]+.*\\|default[ \t]*\\):")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361 (re-search-forward ":[^:]" nil 'move))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362 ;; The first following code counts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363 ;; if it is before the line we want to indent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2364 (and (< (point) indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 (+ (current-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2366 (c++-compound-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2367 char-before-ip containing-sexp bod)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2368 ;; If no previous statement, indent it relative to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2369 ;; line brace is on. For open brace in column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2370 ;; zero, don't let statement start there too. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2371 ;; c-indent-offset is zero, use c-brace-offset +
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2372 ;; c-continued-statement-offset instead. For
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2373 ;; open-braces not the first thing in a line, add
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2374 ;; in c-brace-imaginary-offset.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2375 (+ (if (and (bolp) (zerop c-indent-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2376 (+ c-brace-offset c-continued-statement-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377 c-indent-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378 ;; Move back over whitespace before the openbrace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379 ;; If openbrace is not first nonwhite thing on the line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2380 ;; add the c-brace-imaginary-offset.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381 (progn (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382 (if (bolp) 0 c-brace-imaginary-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383 ;; If the openbrace is preceded by a parenthesized exp,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384 ;; move to the beginning of that;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2385 ;; possibly a different line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387 (if (eq (preceding-char) ?\))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 (forward-sexp -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2389 ;; Get initial indentation of the line we are on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2390 (current-indentation)))))))) ; end t outer cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2391 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 (defun c++-calculate-c-indent-within-comment ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394 "Return the indentation amount for line, assuming that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2395 the current line is to be regarded as part of a block comment."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 (let (end stars indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 (setq stars (if (looking-at "\\*\\*?")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401 (- (match-end 0) (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2402 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403 (skip-chars-backward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404 (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2407 (if (re-search-forward "/\\*[ \t]*" end t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408 (goto-char (+ (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410 (c++-C-block-comments-indent-p 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2411 ((= stars 1) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412 ((= stars 2) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413 (t (- (match-end 0) (match-beginning 0)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2414 (current-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2415
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 (defun c++-comment-offset (col0-line-p indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 "Calculates and returns the comment-only line offset.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418 Offset is based on the value of `c++-comment-only-line-offset', the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419 argument COL0-LINE-P, and the current indentation INDENT."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 (let ((offset 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421 (if col0-line-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2422 ;; col0 means we need to look at the second member of the var's
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 ;; list value. if value is not a list, then zero is used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2424 (if (listp c++-comment-only-line-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2425 ;; it is a list, so second element must be nil or a number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426 (setq offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427 (+ indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2428 (or (car (cdr c++-comment-only-line-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 (car c++-comment-only-line-offset)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2430 ;; not in column zero so indentation is car or value of variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2431 (setq offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 (+ indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433 (if (listp c++-comment-only-line-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434 (car c++-comment-only-line-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2435 c++-comment-only-line-offset))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436 offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2438 (defun c++-compound-offset (char-before-ip containing-sexp bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2439 "Calculates any addition offset due a comma separated compound statement.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2440 CHAR-BEFORE-IP is the character before the indentation point and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2441 CONTAINING-SEXP is the buffer position of the open brace or paren.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2442 BOD is the `beginning-of-defun' point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2443 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2444 ;; not a compound statement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445 ((/= char-before-ip ?,) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2446 ;; open brace could be at column zero == bod
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2447 ((and (= containing-sexp bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448 (or (let ((lim (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453 (c++-backward-syntactic-ws lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 (= (preceding-char) ?=))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457 (looking-at "\\(^\\|[ \t]*\\)enum[ \t]"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460 ;; check for inside an enum
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461 ((let ((parse-sexp-ignore-comments t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462 in-enum-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464 (while (< bod (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465 (c++-backward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 (if (memq (preceding-char) '(?\) ?\" ?\; ?\}))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467 (goto-char bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468 (forward-sexp -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2469 (if (looking-at "\\(enum[ \t\n]\\|\\[.*\\]\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470 (progn (goto-char bod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 (setq in-enum-p t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 in-enum-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474 ;; assume we're not in a list of enums or static array elems
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2475 (t c-continued-statement-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2476 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481 ;; defuns to look backwards for things
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2483
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2484 (defun c++-backward-to-start-of-do (&optional limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2485 "Move to the start of the last ``unbalanced'' do."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2486 (let ((do-level 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2487 (case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2488 (limit (or limit (c++-point 'bod))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2489 (while (not (zerop do-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490 ;; we protect this call because trying to execute this when the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2491 ;; while is not associated with a do will throw an error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2492 (condition-case err
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2494 (backward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2496 ((memq (c++-in-literal limit) '(c c++)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2497 ((looking-at "while\\b")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498 (setq do-level (1+ do-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499 ((looking-at "do\\b")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2500 (setq do-level (1- do-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2501 ((< (point) limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2502 (setq do-level 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2503 (goto-char limit))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2504 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2505 (goto-char limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2506 (setq do-level 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2507
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508 (defun c++-backward-to-start-of-if (&optional limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2509 "Move to the start of the last ``unbalanced'' if."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2510 (let ((if-level 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2511 (case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2512 (limit (or limit (c++-point 'bod))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513 (while (and (not (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2514 (not (zerop if-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2515 (c++-backward-syntactic-ws)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2516 (c++-backward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2517 (cond ((looking-at "else\\b")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2518 (setq if-level (1+ if-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2519 ((looking-at "if\\b")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2520 (setq if-level (1- if-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2521 ((< (point) limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2522 (setq if-level 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2523 (goto-char limit))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2524
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2525 (defun c++-auto-newline ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2526 "Insert a newline iff we're not in a literal.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2527 Literals are defined as being inside a C or C++ style comment or open
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2528 string according to mode's syntax."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2529 (let ((bod (c++-point 'bod)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2530 (and c++-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2531 (not (c++-in-literal bod))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2532 (not (newline)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2533
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2534 (defun c++-point (position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2535 "Returns the value of point at certain commonly referenced POSITIONs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2536 POSITION can be one of the following symbols:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2537 `bol' -- beginning of line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2538 `eol' -- end of line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2539 `bod' -- beginning of defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2540 `boi' -- back to indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2541 This function does not modify point or mark."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2542 (let ((here (point)) bufpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2543 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2544 ((eq position 'bol) (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2545 ((eq position 'eol) (end-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2546 ((eq position 'bod) (c++-beginning-of-defun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2547 ((eq position 'boi) (back-to-indentation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2548 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549 (setq bufpos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2550 (goto-char here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2551 bufpos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2552
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2553
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2554 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2555 ;; defuns for "macroizations" -- making C++ parameterized types via macros
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2556 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2557 (defun c++-macroize-region (from to arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2558 "Insert backslashes at end of every line in region.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2559 Useful for defining cpp macros. If called with a prefix argument,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2560 it will remove trailing backslashes."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2561 (interactive "r\nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563 (goto-char from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564 (beginning-of-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565 (let ((line (count-lines (point-min) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566 (to-line (save-excursion (goto-char to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567 (count-lines (point-min) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568 (while (< line to-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2569 (c++-backslashify-current-line (null arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2570 (forward-line 1) (setq line (1+ line))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2571
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2572 (defun c++-backslashify-current-line (doit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573 "Backslashifies current line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2574 (end-of-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2575 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2576 (doit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2577 ;; Note that "\\\\" is needed to get one backslash.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2578 (if (not (save-excursion (forward-char -1) (looking-at "\\\\")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2579 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2580 (if (>= (current-column) c++-default-macroize-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2581 (insert " \\")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2582 (while (<= (current-column) c++-default-macroize-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2583 (insert "\t") (end-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2584 (delete-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2585 (while (< (current-column) c++-default-macroize-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2586 (insert " ") (end-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2587 (insert "\\")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2588 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2589 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2590 (if (looking-at "\\\\")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2591 (progn (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2592 (kill-line))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2593
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2594
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2595 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596 ;; defuns for commenting out multiple lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2597 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598 (defun c++-comment-region (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599 "Comment out all lines in a region between mark and current point by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2600 inserting `comment-start' in front of each line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2601 (interactive "*r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2602 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2603 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2604 (narrow-to-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605 (progn (goto-char beg) (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2606 (progn (goto-char end) (or (bolp) (forward-line 1)) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2607 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2608 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2609 (insert comment-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2610 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2611 (if (eq major-mode 'c++-c-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612 (insert comment-end)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2613
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614 (defun c++-uncomment-region (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 "Uncomment all lines in region between mark and current point by deleting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2616 the leading ``// '' from each line, if any."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2617 (interactive "*r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2619 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2620 (narrow-to-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2621 (progn (goto-char beg) (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2622 (progn (goto-char end) (forward-line 1) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2623 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2624 (let ((comment-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2625 (if (eq major-mode 'c++-c-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2626 (concat "\\s *\\(" (regexp-quote comment-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2627 "\\|" (regexp-quote comment-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2628 "\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2629 (concat "\\s *" (regexp-quote comment-start)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2630 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2631 (if (looking-at comment-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632 (delete-region (match-beginning 0) (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633 (forward-line 1))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637 ;; grammar parsing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2640 ;;; Below are two regular expressions that attempt to match defuns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641 ;;; "strongly" and "weakly." The strong one almost reconstructs the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642 ;;; grammar of C++; the weak one just figures anything id or curly on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643 ;;; the left begins a defun. The constant "c++-match-header-strongly"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644 ;;; determines which to use; the default is the weak one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646 (defvar c++-match-header-strongly nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647 "*If nil, use `c++-defun-header-weak' to identify beginning of definitions,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648 if non-nil, use `c++-defun-header-strong'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2650 (defvar c++-defun-header-strong-struct-equivs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651 "\\(class\\|struct\\|union\\|enum\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2652 "Regexp to match names of structure declaration blocks in C++")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654 (defconst c++-defun-header-strong
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655 (let*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656 (; valid identifiers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657 ;; There's a real weirdness here -- if I switch the below
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658 (id "\\(\\w\\|_\\)+")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2659 ;; to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660 ;; (id "\\(_\\|\\w\\)+")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 ;; things no longer work right. Try it and see!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663 ; overloadable operators
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664 (op-sym1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665 "[---+*/%^&|~!=<>]\\|[---+*/%^&|<>=!]=\\|<<=?\\|>>=?")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666 (op-sym2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2667 "&&\\|||\\|\\+\\+\\|--\\|()\\|\\[\\]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668 (op-sym (concat "\\(" op-sym1 "\\|" op-sym2 "\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 ; whitespace
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670 (middle "[^\\*]*\\(\\*+[^/\\*][^\\*]*\\)*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 (c-comment (concat "/\\*" middle "\\*+/"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 (wh (concat "\\(\\s \\|\n\\|//.*$\\|" c-comment "\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673 (wh-opt (concat wh "*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674 (wh-nec (concat wh "+"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2675 (oper (concat "\\(" "operator" "\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676 wh-opt op-sym "\\|" wh-nec id "\\)" "\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2677 (dcl-list "([^():]*)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2678 (func-name (concat "\\(" oper "\\|" id "::" id "\\|" id "\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679 (inits
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2680 (concat "\\(:"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2681 "\\(" wh-opt id "(.*\\()" wh-opt "," "\\)\\)*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2682 wh-opt id "(.*)" wh-opt "{"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2683 "\\|" wh-opt "{\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2684 (type-name (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2685 "\\(" c++-defun-header-strong-struct-equivs wh-nec "\\)?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2686 id))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2687 (type (concat "\\(const" wh-nec "\\)?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688 "\\(" type-name "\\|" type-name wh-opt "\\*+" "\\|"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689 type-name wh-opt "&" "\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2690 (modifier "\\(inline\\|virtual\\|overload\\|auto\\|static\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2691 (modifiers (concat "\\(" modifier wh-nec "\\)*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2692 (func-header
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2693 ;; type arg-dcl
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2694 (concat modifiers type wh-nec func-name wh-opt dcl-list wh-opt inits))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2695 (inherit (concat "\\(:" wh-opt "\\(public\\|protected\\|private\\)?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2696 wh-nec id "\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2697 (cs-header (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2698 c++-defun-header-strong-struct-equivs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2699 wh-nec id wh-opt inherit "?" wh-opt "{")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2700 (concat "^\\(" func-header "\\|" cs-header "\\)"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2701 "Strongly-defined regexp to match beginning of structure or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2702 function definition.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2703
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2704
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2705 ;; This part has to do with recognizing defuns.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2706
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2707 ;; The weak convention we will use is that a defun begins any time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708 ;; there is a left curly brace, or some identifier on the left margin,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2709 ;; followed by a left curly somewhere on the line. (This will also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2710 ;; incorrectly match some continued strings, but this is after all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2711 ;; just a weak heuristic.) Suggestions for improvement (short of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2712 ;; strong scheme shown above) are welcomed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2713
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2714 (defconst c++-defun-header-weak "^{\\|^[_a-zA-Z].*{"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2715 "Weakly-defined regexp to match beginning of structure or function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2716 definition.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2717
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2718
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2719 (defun c++-beginning-of-defun (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2720 "Find the beginning of the C++ function or class."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2721 (interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2722 (if (not arg) (setq arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2723 (let ((c++-defun-header (if c++-match-header-strongly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2724 c++-defun-header-strong
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2725 c++-defun-header-weak)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2726 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2727 ((or (= arg 0) (and (> arg 0) (bobp))) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2728 ((and (not (looking-at c++-defun-header))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2729 (let ((curr-pos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2730 (open-pos (if (search-forward "{" nil 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2731 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2732 (beg-pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2733 (if (re-search-backward c++-defun-header nil 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2734 (match-beginning 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2735 (if (and open-pos beg-pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2736 (< beg-pos curr-pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2737 (> open-pos curr-pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2738 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2739 (goto-char beg-pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2740 (if (= arg 1) t nil));; Are we done?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2741 (goto-char curr-pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2742 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2743 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2744 (if (and (looking-at c++-defun-header) (not (bobp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2745 (forward-char (if (< arg 0) 1 -1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2746 (and (re-search-backward c++-defun-header nil 'move (or arg 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2747 (goto-char (match-beginning 0)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2748
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2749
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2750 (defun c++-end-of-defun (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2751 "Find the end of the C++ function or class."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2752 (interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2753 (let ((c++-defun-header (if c++-match-header-strongly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2754 c++-defun-header-strong
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2755 c++-defun-header-weak))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2756 (parse-sexp-ignore-comments t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2757 (if (and (eobp) (> arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2758 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2759 (if (and (> arg 0) (looking-at c++-defun-header)) (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2760 (let ((pos (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2761 (c++-beginning-of-defun
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2762 (if (< arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2763 (- (- arg (if (eobp) 0 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2764 arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2765 (if (and (< arg 0) (bobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2766 t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2767 (if (re-search-forward c++-defun-header nil 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2768 (progn (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2769 (forward-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2770 (beginning-of-line 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2771 (if (and (= pos (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2772 (re-search-forward c++-defun-header nil 'move))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2773 (c++-end-of-defun 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2774 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2775
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2776 (defun c++-indent-defun ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2777 "Indents the current function def, struct or class declaration."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2778 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2779 (let ((restore (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2780 (c++-end-of-defun 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2781 (beginning-of-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2782 (let ((end (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2783 (c++-beginning-of-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2784 (while (and (< (point) end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2785 (c++-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2786 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2787 (beginning-of-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2788 (set-marker end nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2789 (goto-char restore)))
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 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2793 ;; defuns for submitting bug reports
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2794 ;; ======================================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2795 (defconst c++-version "2.353"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2796 "c++-mode version number.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2797 (defconst c++-mode-help-address "c++-mode-help@anthem.nlm.nih.gov"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2798 "Address accepting submission of bug reports.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2799
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2800 (defun c++-version ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2801 "Echo the current version of c++-mode."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2802 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2803 (message "Using c++-mode.el %s" c++-version))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2804
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2805 (defun c++-submit-bug-report ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2806 "Submit via mail a bug report on c++-mode."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2807 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2808 (require 'reporter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2809 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2810 (y-or-n-p "Do you want to submit a report on c++-mode? ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2811 (reporter-submit-bug-report
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2812 c++-mode-help-address
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2813 (concat "c++-mode.el " c++-version " (editing "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2814 (if (eq major-mode 'c++-mode) "C++" "C")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2815 " code)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2816 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2817 'c++-emacs-features
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2818 'c++-C-block-comments-indent-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2819 'c++-access-specifier-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2820 'c++-always-arglist-indent-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2821 'c++-auto-hungry-initial-state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2822 'c++-auto-hungry-toggle
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2823 'c++-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2824 'c++-backscan-limit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2825 'c++-block-close-brace-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2826 'c++-cleanup-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2827 'c++-comment-only-line-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2828 'c++-continued-member-init-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2829 'c++-default-macroize-column
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2830 'c++-defun-header-strong-struct-equivs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2831 'c++-delete-function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2832 'c++-electric-pound-behavior
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2833 'c++-empty-arglist-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2834 'c++-friend-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2835 'c++-hanging-braces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2836 'c++-hanging-member-init-colon
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2837 'c++-hungry-delete-key
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2838 'c++-match-header-strongly
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2839 'c++-member-init-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2840 'c++-paren-as-block-close-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2841 'c++-relative-offset-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2842 'c++-tab-always-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2843 'c++-untame-characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2844 'c-argdecl-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2845 'c-brace-imaginary-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2846 'c-brace-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2847 'c-continued-brace-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2848 'c-continued-statement-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2849 'c-indent-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2850 'c-label-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2851 'tab-width
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2852 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2853 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2854 (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2855 (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2856 (if c++-special-indent-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2857 (concat "\n@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2858 "c++-special-indent-hook is set to '"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2859 (format "%s" c++-special-indent-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2860 ".\nPerhaps this is your problem?\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2861 "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\n\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2862 "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2863 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2864 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2865
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2866
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2867 ;; this is sometimes useful
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2868 (provide 'c++-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2869
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2870 ;;; c++-mode.el ends here