annotate lisp/modes/old-c++-mode.el @ 8:4b173ad71786 r19-15b5

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