annotate lisp/progmodes/cplus-md.el @ 17977:727cf56647a4

Comment change.
author Richard M. Stallman <rms@gnu.org>
date Tue, 27 May 1997 19:51:23 +0000
parents 720d1f98ae42
children 11218164bc54
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17970
720d1f98ae42 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 16427
diff changeset
1 ;;; cplus-md.el --- old C++ code editing mode for Emacs
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13973
diff changeset
2
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13973
diff changeset
3 ;; Copyright (C) 1985, 1992, 1994, 1995 Free Software Foundation, Inc.
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13973
diff changeset
4
17970
720d1f98ae42 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 16427
diff changeset
5 ;; Maintainer: FSF
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13973
diff changeset
6 ;; Keywords: c
896
7e4999005da1 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 861
diff changeset
7
7e4999005da1 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 861
diff changeset
8 ;; This file is part of GNU Emacs.
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 257
diff changeset
9
896
7e4999005da1 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 861
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
7e4999005da1 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 861
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
7e4999005da1 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 861
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
7e4999005da1 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 861
diff changeset
13 ;; any later version.
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
14
896
7e4999005da1 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 861
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
7e4999005da1 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 861
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
7e4999005da1 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 861
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7e4999005da1 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 861
diff changeset
18 ;; GNU General Public License for more details.
7e4999005da1 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 861
diff changeset
19
7e4999005da1 entered into RCS
Richard M. Stallman <rms@gnu.org>
parents: 861
diff changeset
20 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13973
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13973
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13973
diff changeset
23 ;; Boston, MA 02111-1307, USA.
798
b7932f859d4e *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
24
b7932f859d4e *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
25 ;;; Commentary:
b7932f859d4e *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
26
2307
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 896
diff changeset
27 ;; 1987 Dave Detlefs <dld@cs.cmu.edu>
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 896
diff changeset
28 ;; and Stewart Clamen <clamen@cs.cmu.edu>.
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 ;; Done by fairly faithful modification of:
2307
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 896
diff changeset
30
798
b7932f859d4e *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
31 ;;; Change Log:
b7932f859d4e *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
32
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 ;; Feb, 1990 (Dave Detlefs, dld@cs.cmu.edu)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
34 ;; Fixed electric-c++-terminator to handle double colons, at the
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 ;; request of John Hagerman.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 ;;
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 ;; Jan, 1990 (Doug Lea, dl@oswego.edu)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 ;; Replaced c++-comment-region and c++-uncomment-region with
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
39 ;; versions from Igor Metz that avoid potential infinite loops.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 ;;
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 ;; Oct, 1989 (Dave Detlefs, dld@cs.cmu.edu)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42 ;; Added contribution from Igor Metz <metz@iam.unibe.ch>:
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
43 ;; functions c++-comment-region and c++-uncomment-region and
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
44 ;; corresponding key-binding.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 ;; Also fixed bug in indentation of second line after an empty
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 ;; arglist with empty-arglist non-null.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 ;;
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 ;; Sept, 1989 (Glen Ditchfield, gjditchfield@violet.uwaterloo.ca):
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 ;; Textual changes to more closely imitate Emacs 18.55's c-mode.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 ;; Fixed handling of "default:", where ":" was the last character in the
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 ;; buffer. Fixed indentation of comments starting in column 0, and when
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 ;; previous line contained more than one comment start string. Fixed
5300
954744cd720f (c++-indent-line, calculate-c++-indent):
Richard M. Stallman <rms@gnu.org>
parents: 4308
diff changeset
53 ;; handling of "friend".
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 ;;
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 ;; Aug 7, 1989; John Hagerman (hagerman@ece.cmu.edu):
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56 ;; Changed calculate-c++-indent to handle member initializations
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 ;; more flexibly. Two new variables are used to control behavior:
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 ;; c++-member-init-indent and c++-continued-member-init-offset.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 ;; Note the assumption that member initializations and argument
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 ;; declarations are not mixed in one function definition.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61 ;;
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 ;; June 1989 (Dave Detlefs, dld@cs.cmu.edu)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 ;; Fixed calculate-c++-indent to handle continued lines ending in
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 ;; {'s. (I wasn't following C-mode closely enough, or C-mode
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65 ;; changed.) Made ' a quote character, at the behest of someone
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 ;; whose mail I apparently deleted (if they send me mail I'll credit
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 ;; them here in a future revision.)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 ;; Dan Weinreb (dlw@odi.com) pointed out that 'c++-mode successively
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69 ;; bound c++-indent-exp and c++-indent-defun to ESC-^q. ESC-^q is
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 ;; now bound to c++-indent-exp, while, c++-indent-defun is invoked
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 ;; with ESC-^x.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73 ;; February 1989 (Dave Detlefs, dld@cs.cmu.edu)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 ;; Fixed some errors in c++-indent-defun, as pointed out by Sam
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 ;; Haradhvala (odi!sam@talcott.harvard.edu).
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 ;; October 1988 (Dave Detlefs, dld@cs.cmu.edu)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77 ;; It turns out I had only *thought* I had made
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 ;; beginning(end)-of-defun work. It should work better now -- you
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 ;; can either attempt to match defun headers "strongly," using a
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 ;; very complicated regexp, or "weakly," using a simple one. This
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81 ;; is settable by a variable; the default is the cheaper weak
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 ;; method. (Stewart Clamen was intimately involved in this, too.)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 ;;
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 ;; I made "'" *not* be a string delimiter, because that was causing
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 ;; comments containing contractions to ("// don't") to mess up paren
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 ;; balancing.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87 ;;
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 ;; I also incorporated another slight indentation fix from Glen
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 ;; Ditchfield.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 ;;
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 ;; We hope this is will make into version 19 of gnu-emacs.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 ;;
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93 ;; September 1988: incorporated changes from Fred Calm at Schlumberger.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 ;; Also, made beginning(end)-of-defun, indent-defun work.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 ;;
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 ;; August 1987: incorporated changes done by Glen Ditchfield of Waterloo.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97
798
b7932f859d4e *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
98 ;;; Code:
b7932f859d4e *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
99
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 (defvar c++-mode-abbrev-table nil
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 "Abbrev table used in C++ mode.")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 (define-abbrev-table 'c++-mode-abbrev-table ())
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 (defvar c++-mode-map ()
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 "Keymap used in C++ mode.")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 (if c++-mode-map
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 ()
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 (setq c++-mode-map (make-sparse-keymap))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 (define-key c++-mode-map "\C-j" 'reindent-then-newline-and-indent)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 (define-key c++-mode-map "{" 'electric-c++-brace)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 (define-key c++-mode-map "}" 'electric-c++-brace)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 (define-key c++-mode-map ";" 'electric-c++-semi)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 (define-key c++-mode-map "\e\C-h" 'mark-c-function)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 (define-key c++-mode-map "\e\C-q" 'indent-c++-exp)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 (define-key c++-mode-map "\177" 'backward-delete-char-untabify)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 (define-key c++-mode-map "\t" 'c++-indent-command)
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
117 ;; (define-key c++-mode-map "\C-c\C-i" 'c++-insert-header)
861
345296f94a1e *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
118 (define-key c++-mode-map "\C-c\C-\\" 'c-backslash-region))
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
119 ;; (define-key c++-mode-map "\e\C-a" 'c++-beginning-of-defun)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
120 ;; (define-key c++-mode-map "\e\C-e" 'c++-end-of-defun)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
121 ;; (define-key c++-mode-map "\e\C-x" 'c++-indent-defun))
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 (defvar c++-mode-syntax-table nil
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 "Syntax table used in C++ mode.")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 (if c++-mode-syntax-table
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 ()
14631
25ecb6e5fffc (c++-mode-syntax-table): Don't use c-mode-syntax-table.
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
128 (setq c++-mode-syntax-table (make-syntax-table))
25ecb6e5fffc (c++-mode-syntax-table): Don't use c-mode-syntax-table.
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
129 (modify-syntax-entry ?\\ "\\" c++-mode-syntax-table)
25ecb6e5fffc (c++-mode-syntax-table): Don't use c-mode-syntax-table.
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
130 (modify-syntax-entry ?/ ". 14" c++-mode-syntax-table)
25ecb6e5fffc (c++-mode-syntax-table): Don't use c-mode-syntax-table.
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
131 (modify-syntax-entry ?* ". 23" c++-mode-syntax-table)
25ecb6e5fffc (c++-mode-syntax-table): Don't use c-mode-syntax-table.
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
132 (modify-syntax-entry ?+ "." c++-mode-syntax-table)
25ecb6e5fffc (c++-mode-syntax-table): Don't use c-mode-syntax-table.
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
133 (modify-syntax-entry ?- "." c++-mode-syntax-table)
25ecb6e5fffc (c++-mode-syntax-table): Don't use c-mode-syntax-table.
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
134 (modify-syntax-entry ?= "." c++-mode-syntax-table)
25ecb6e5fffc (c++-mode-syntax-table): Don't use c-mode-syntax-table.
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
135 (modify-syntax-entry ?% "." c++-mode-syntax-table)
25ecb6e5fffc (c++-mode-syntax-table): Don't use c-mode-syntax-table.
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
136 (modify-syntax-entry ?< "." c++-mode-syntax-table)
25ecb6e5fffc (c++-mode-syntax-table): Don't use c-mode-syntax-table.
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
137 (modify-syntax-entry ?> "." c++-mode-syntax-table)
25ecb6e5fffc (c++-mode-syntax-table): Don't use c-mode-syntax-table.
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
138 (modify-syntax-entry ?& "." c++-mode-syntax-table)
25ecb6e5fffc (c++-mode-syntax-table): Don't use c-mode-syntax-table.
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
139 (modify-syntax-entry ?| "." c++-mode-syntax-table)
25ecb6e5fffc (c++-mode-syntax-table): Don't use c-mode-syntax-table.
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
140 (modify-syntax-entry ?\' "\"" c++-mode-syntax-table)
4285
37dded875497 (c++-mode-syntax-table): Handle C-style comments.
Richard M. Stallman <rms@gnu.org>
parents: 3806
diff changeset
141 (modify-syntax-entry ?* ". 23b" c++-mode-syntax-table)
37dded875497 (c++-mode-syntax-table): Handle C-style comments.
Richard M. Stallman <rms@gnu.org>
parents: 3806
diff changeset
142 (modify-syntax-entry ?/ ". 124" c++-mode-syntax-table)
8326
57533025d628 (c++-mode-syntax-table): Give RET the same syntax as newline.
Richard M. Stallman <rms@gnu.org>
parents: 7300
diff changeset
143 (modify-syntax-entry ?\n ">" c++-mode-syntax-table)
57533025d628 (c++-mode-syntax-table): Give RET the same syntax as newline.
Richard M. Stallman <rms@gnu.org>
parents: 7300
diff changeset
144 (modify-syntax-entry ?\^m ">" c++-mode-syntax-table))
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146 (defvar c++-continued-member-init-offset nil
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 "*Extra indent for continuation lines of member inits;
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
148 nil means to align with previous initializations rather than
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 with the colon on the first line.")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 (defvar c++-member-init-indent 0
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 "*Indentation level of member initializations in function declarations.")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 (defvar c++-friend-offset -4
5300
954744cd720f (c++-indent-line, calculate-c++-indent):
Richard M. Stallman <rms@gnu.org>
parents: 4308
diff changeset
153 "*Offset of C++ friend declarations relative to member declarations.")
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 (defvar c++-electric-colon t
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 "*If t, colon is an electric terminator.")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 (defvar c++-empty-arglist-indent nil
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 "*Indicates how far to indent an line following an empty argument
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158 list. Nil indicates to just after the paren.")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159
12706
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
160 (defvar c++-imenu-generic-expression
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
161 (`
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
162 ((nil
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
163 (,
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
164 (concat
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
165 "^" ; beginning of line is required
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
166 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
167 "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; type specs; there can be no
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
168 "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; more than 3 tokens, right?
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
169
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
170 "\\(" ; last type spec including */&
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
171 "[a-zA-Z0-9_:]+"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
172 "\\([ \t]*[*&]+[ \t]*\\|[ \t]+\\)" ; either pointer/ref sign or whitespace
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
173 "\\)?" ; if there is a last type spec
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
174 "\\(" ; name; take that into the imenu entry
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
175 "[a-zA-Z0-9_:~]+" ; member function, ctor or dtor...
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
176 ; (may not contain * because then
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
177 ; "a::operator char*" would become "char*"!)
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
178 "\\|"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
179 "\\([a-zA-Z0-9_:~]*::\\)?operator"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
180 "[^a-zA-Z1-9_][^(]*" ; ...or operator
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
181 " \\)"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
182 "[ \t]*([^)]*)[ \t\n]*[^ ;]" ; require something other than a ; after
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
183 ; the (...) to avoid prototypes. Can't
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
184 ; catch cases with () inside the parentheses
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
185 ; surrounding the parameters
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
186 ; (like "int foo(int a=bar()) {...}"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
187
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
188 )) 6)
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
189 ("Class"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
190 (, (concat
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
191 "^" ; beginning of line is required
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
192 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
193 "class[ \t]+"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
194 "\\([a-zA-Z0-9_]+\\)" ; this is the string we want to get
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
195 "[ \t]*[:{]"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
196 )) 2)
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
197 ;; Example of generic expression for finding prototypes, structs, unions, enums.
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
198 ;; Uncomment if you want to find these too. It will be a bit slower gathering
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
199 ;; the indexes.
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
200 ; ("Prototypes"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
201 ; (,
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
202 ; (concat
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
203 ; "^" ; beginning of line is required
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
204 ; "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
205 ; "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; type specs; there can be no
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
206 ; "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; more than 3 tokens, right?
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
207
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
208 ; "\\(" ; last type spec including */&
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
209 ; "[a-zA-Z0-9_:]+"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
210 ; "\\([ \t]*[*&]+[ \t]*\\|[ \t]+\\)" ; either pointer/ref sign or whitespace
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
211 ; "\\)?" ; if there is a last type spec
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
212 ; "\\(" ; name; take that into the imenu entry
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
213 ; "[a-zA-Z0-9_:~]+" ; member function, ctor or dtor...
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
214 ; ; (may not contain * because then
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
215 ; ; "a::operator char*" would become "char*"!)
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
216 ; "\\|"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
217 ; "\\([a-zA-Z0-9_:~]*::\\)?operator"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
218 ; "[^a-zA-Z1-9_][^(]*" ; ...or operator
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
219 ; " \\)"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
220 ; "[ \t]*([^)]*)[ \t\n]*;" ; require ';' after
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
221 ; ; the (...) Can't
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
222 ; ; catch cases with () inside the parentheses
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
223 ; ; surrounding the parameters
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
224 ; ; (like "int foo(int a=bar());"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
225 ; )) 6)
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
226 ; ("Struct"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
227 ; (, (concat
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
228 ; "^" ; beginning of line is required
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
229 ; "\\(static[ \t]+\\)?" ; there may be static or const.
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
230 ; "\\(const[ \t]+\\)?"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
231 ; "struct[ \t]+"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
232 ; "\\([a-zA-Z0-9_]+\\)" ; this is the string we want to get
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
233 ; "[ \t]*[{]"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
234 ; )) 3)
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
235 ; ("Enum"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
236 ; (, (concat
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
237 ; "^" ; beginning of line is required
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
238 ; "\\(static[ \t]+\\)?" ; there may be static or const.
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
239 ; "\\(const[ \t]+\\)?"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
240 ; "enum[ \t]+"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
241 ; "\\([a-zA-Z0-9_]+\\)" ; this is the string we want to get
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
242 ; "[ \t]*[{]"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
243 ; )) 3)
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
244 ; ("Union"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
245 ; (, (concat
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
246 ; "^" ; beginning of line is required
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
247 ; "\\(static[ \t]+\\)?" ; there may be static or const.
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
248 ; "\\(const[ \t]+\\)?"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
249 ; "union[ \t]+"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
250 ; "\\([a-zA-Z0-9_]+\\)" ; this is the string we want to get
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
251 ; "[ \t]*[{]"
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
252 ; )) 3)
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
253 ))
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
254 "Imenu generic expression for C++ mode. See `imenu-generic-expression'.")
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 (defun c++-mode ()
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 "Major mode for editing C++ code. Very much like editing C code.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 Expression and list commands understand all C++ brackets.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 Tab at left margin indents for C++ code
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 Comments are delimited with /* ... */ {or with // ... <newline>}
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 Paragraphs are separated by blank lines only.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 Delete converts tabs to spaces as it moves back.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 \\{c++-mode-map}
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 Variables controlling indentation style:
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 c-tab-always-indent
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
266 Non-nil means TAB in C mode should always reindent the current line,
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
267 regardless of where in the line point is when the TAB command is used.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
268 Default is t.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
269 c-auto-newline
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
270 Non-nil means automatically newline before and after braces,
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
271 and after colons and semicolons, inserted in C code.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
272 c-indent-level
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
273 Indentation of C statements within surrounding block.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
274 The surrounding block's indentation is the indentation
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
275 of the line on which the open-brace appears.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
276 c-continued-statement-offset
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
277 Extra indentation given to a substatement, such as the
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
278 then-clause of an if or body of a while.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
279 c-continued-brace-offset
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
280 Extra indentation given to a brace that starts a substatement.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
281 This is in addition to c-continued-statement-offset.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
282 c-brace-offset
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
283 Extra indentation for line if it starts with an open brace.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
284 c-brace-imaginary-offset
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
285 An open brace following other text is treated as if it were
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
286 this far to the right of the start of its line.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
287 c-argdecl-indent
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
288 Indentation level of declarations of C function arguments.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
289 c-label-offset
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
290 Extra indentation for line that is a label, or case or ``default:'', or
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
291 ``public:'' or ``private:'', or ``protected:''.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
292 c++-electric-colon
13973
4c199361d7ff (c++-mode): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 13558
diff changeset
293 If non-nil at invocation of c++-mode (t is the default) colon electrically
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
294 indents.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
295 c++-empty-arglist-indent
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
296 If non-nil, a function declaration or invocation which ends a line with a
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
297 left paren is indented this many extra spaces, instead of flush with the
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
298 left paren.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
299 c++-friend-offset
5300
954744cd720f (c++-indent-line, calculate-c++-indent):
Richard M. Stallman <rms@gnu.org>
parents: 4308
diff changeset
300 Offset of C++ friend declarations relative to member declarations.
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
301 c++-member-init-indent
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
302 Indentation level of member initializations in function declarations,
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
303 if they are on a separate line beginning with a colon.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
304 c++-continued-member-init-offset
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
305 Extra indentation for continuation lines of member initializations; NIL
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
306 means to align with previous initializations rather than with the colon.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
307
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
308 Settings for K&R, BSD, and Stroustrup indentation styles are
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
309 c-indent-level 5 8 4
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
310 c-continued-statement-offset 5 8 4
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
311 c-continued-brace-offset 0
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
312 c-brace-offset -5 -8 0
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
313 c-brace-imaginary-offset 0
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
314 c-argdecl-indent 0 8 4
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
315 c-label-offset -5 -8 -4
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
316 c++-empty-arglist-indent 4
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
317 c++-friend-offset 0
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
318
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
319 Turning on C++ mode calls the value of the variable `c++-mode-hook' with
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
320 no args if that value is non-nil."
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
321 (interactive)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
322 (kill-all-local-variables)
14853
e263cca8d928 (indent-c++-exp): Use calculate-c-indent-after-brace.
Richard M. Stallman <rms@gnu.org>
parents: 14631
diff changeset
323 ;; This code depends on the old C mode.
e263cca8d928 (indent-c++-exp): Use calculate-c-indent-after-brace.
Richard M. Stallman <rms@gnu.org>
parents: 14631
diff changeset
324 (require 'c-mode)
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
325 (use-local-map c++-mode-map)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
326 (set-syntax-table c++-mode-syntax-table)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
327 (setq major-mode 'c++-mode
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
328 mode-name "C++"
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
329 comment-column 32
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
330 local-abbrev-table c++-mode-abbrev-table)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
331 (set (make-local-variable 'indent-line-function) 'c++-indent-line)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
332 (set (make-local-variable 'comment-start) "// ")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
333 (set (make-local-variable 'comment-end) "")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
334 (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|// *")
2307
10e417efb12a Added or corrected Commentary sections
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 896
diff changeset
335 (set (make-local-variable 'comment-indent-function) 'c++-comment-indent)
10871
77c4e66af25a (c++-mode): Remove ^ from paragraph-start & paragraph-separate.
Boris Goldowsky <boris@gnu.org>
parents: 10829
diff changeset
336 (set (make-local-variable 'paragraph-start) (concat "$\\|" page-delimiter))
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
337 (set (make-local-variable 'paragraph-separate) paragraph-start)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
338 (set (make-local-variable 'paragraph-ignore-fill-prefix) t)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
339 (set (make-local-variable 'require-final-newline) t)
5957
334f7ce7c8db (c++-mode): Set parse-sexp-ignore-comments to t.
Richard M. Stallman <rms@gnu.org>
parents: 5300
diff changeset
340 (set (make-local-variable 'parse-sexp-ignore-comments) t)
12706
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
341 (make-local-variable 'imenu-generic-expression)
bbd37ab04957 (c++-imenu-generic-expression): Var defined.
Karl Heuer <kwzh@gnu.org>
parents: 12416
diff changeset
342 (setq imenu-generic-expression c++-imenu-generic-expression)
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
343 (run-hooks 'c++-mode-hook)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
344 (if c++-electric-colon
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
345 (define-key c++-mode-map ":" 'electric-c++-terminator)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
346
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
347 ;; This is used by indent-for-comment
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
348 ;; to decide how much to indent a comment in C++ code
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
349 ;; based on its context.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
350 (defun c++-comment-indent ()
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
351 (if (looking-at "^\\(/\\*\\|//\\)")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
352 0 ; Existing comment at bol stays there.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
353 (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
354 (skip-chars-backward " \t")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
355 (max
16427
3b9f64eb097b Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 14853
diff changeset
356 ;; Leave at least one space on non-empty lines.
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
357 (if (zerop (current-column)) 0 (1+ (current-column)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
358 (let ((cur-pt (point)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
359 (beginning-of-line 0)
16427
3b9f64eb097b Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 14853
diff changeset
360 ;; If previous line had a comment, use its indentation.
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
361 (if (re-search-forward comment-start-skip cur-pt t)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
362 (progn
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
363 (goto-char (match-beginning 0))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
364 (current-column))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
365 comment-column)))))) ; otherwise indent at comment column.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
366
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
367 (defun electric-c++-brace (arg)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
368 "Insert character and correct line's indentation."
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
369 (interactive "P")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
370 (let (insertpos)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
371 (if (and (not arg)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
372 (eolp)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
373 (or (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
374 (skip-chars-backward " \t")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
375 (bolp))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
376 (if c-auto-newline (progn (c++-indent-line) (newline) t))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
377 (progn
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
378 (insert last-command-char)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
379 (c++-indent-line)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
380 (if c-auto-newline
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
381 (progn
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
382 (newline)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
383 ;; (newline) may have done auto-fill
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
384 (setq insertpos (- (point) 2))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
385 (c++-indent-line)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
386 (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
387 (if insertpos (goto-char (1+ insertpos)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
388 (delete-char -1))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
389 (if insertpos
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
390 (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
391 (goto-char insertpos)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
392 (self-insert-command (prefix-numeric-value arg)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
393 (self-insert-command (prefix-numeric-value arg)))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
394
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
395 (defun electric-c++-semi (arg)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
396 "Insert character and correct line's indentation."
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
397 (interactive "P")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
398 (if c-auto-newline
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
399 (electric-c++-terminator arg)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
400 (self-insert-command (prefix-numeric-value arg))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
401
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
402 (defun electric-c++-terminator (arg)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
403 "Insert character and correct line's indentation."
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
404 (interactive "P")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
405 (let (insertpos (end (point)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
406 (if (and (not arg) (eolp)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
407 (not (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
408 (beginning-of-line)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
409 (skip-chars-forward " \t")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
410 (or (= (following-char) ?#)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
411 ;; Colon is special only after a label, or
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
412 ;; case, or another colon.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
413 ;; So quickly rule out most other uses of colon
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
414 ;; and do no indentation for them.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
415 (and (eq last-command-char ?:)
12416
8c1c47eb351a (electric-c++-terminator): Fix logic for handling colon.
Richard M. Stallman <rms@gnu.org>
parents: 11455
diff changeset
416 (or (not (or (looking-at "case[ \t]")
8c1c47eb351a (electric-c++-terminator): Fix logic for handling colon.
Richard M. Stallman <rms@gnu.org>
parents: 11455
diff changeset
417 (save-excursion
8c1c47eb351a (electric-c++-terminator): Fix logic for handling colon.
Richard M. Stallman <rms@gnu.org>
parents: 11455
diff changeset
418 (forward-word 1)
8c1c47eb351a (electric-c++-terminator): Fix logic for handling colon.
Richard M. Stallman <rms@gnu.org>
parents: 11455
diff changeset
419 (skip-chars-forward " \t")
8c1c47eb351a (electric-c++-terminator): Fix logic for handling colon.
Richard M. Stallman <rms@gnu.org>
parents: 11455
diff changeset
420 (>= (point) end))))
8c1c47eb351a (electric-c++-terminator): Fix logic for handling colon.
Richard M. Stallman <rms@gnu.org>
parents: 11455
diff changeset
421 ;; Do re-indent double colons
8c1c47eb351a (electric-c++-terminator): Fix logic for handling colon.
Richard M. Stallman <rms@gnu.org>
parents: 11455
diff changeset
422 (save-excursion
8c1c47eb351a (electric-c++-terminator): Fix logic for handling colon.
Richard M. Stallman <rms@gnu.org>
parents: 11455
diff changeset
423 (end-of-line 1)
8c1c47eb351a (electric-c++-terminator): Fix logic for handling colon.
Richard M. Stallman <rms@gnu.org>
parents: 11455
diff changeset
424 (looking-at ":"))))
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
425 (progn
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
426 (beginning-of-defun)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
427 (let ((pps (parse-partial-sexp (point) end)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
428 (or (nth 3 pps) (nth 4 pps) (nth 5 pps))))))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
429 (progn
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
430 (insert last-command-char)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
431 (c++-indent-line)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
432 (and c-auto-newline
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
433 (not (c-inside-parens-p))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
434 (progn
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
435 ;; the new marker object, used to be just an integer
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
436 (setq insertpos (make-marker))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
437 ;; changed setq to set-marker
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
438 (set-marker insertpos (1- (point)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
439 ;; do this before the newline, since in auto fill can break
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
440 (newline)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
441 (c-indent-line)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
442 (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
443 (if insertpos (goto-char (1+ insertpos)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
444 (delete-char -1))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
445 (if insertpos
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
446 (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
447 (goto-char insertpos)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
448 (self-insert-command (prefix-numeric-value arg)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
449 (self-insert-command (prefix-numeric-value arg)))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
450
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
451 (defun c++-indent-command (&optional whole-exp)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
452 "Indent current line as C++ code, or in some cases insert a tab character.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
453 If `c-tab-always-indent' is non-nil (the default), always indent current
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
454 line. Otherwise, indent the current line only if point is at the left
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
455 margin or in the line's indentation; otherwise insert a tab.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
456
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
457 A numeric argument, regardless of its value, means indent rigidly all means
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
458 indent rigidly all the lines of the expression starting after point so that
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
459 this line becomes properly indented. The relative indentation among the
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
460 lines of the expression are preserved."
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
461 (interactive "P")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
462 (if whole-exp
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
463 ;; If arg, always indent this line as C
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
464 ;; and shift remaining lines of expression the same amount.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
465 (let ((shift-amt (c++-indent-line))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
466 beg end)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
467 (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
468 (if c-tab-always-indent
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
469 (beginning-of-line))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
470 (setq beg (point))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
471 (forward-sexp 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
472 (setq end (point))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
473 (goto-char beg)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
474 (forward-line 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
475 (setq beg (point)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
476 (if (> end beg)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
477 (indent-code-rigidly beg end shift-amt "#")))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
478 (if (and (not c-tab-always-indent)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
479 (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
480 (skip-chars-backward " \t")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
481 (not (bolp))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
482 (insert-tab)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
483 (c++-indent-line))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
484
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
485 (defun c++-indent-line ()
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
486 "Indent current line as C++ code.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
487 Return the amount the indentation changed by."
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
488 (let ((indent (calculate-c++-indent nil))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
489 beg shift-amt
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
490 (case-fold-search nil)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
491 (pos (- (point-max) (point))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
492 (beginning-of-line)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
493 (setq beg (point))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
494 (cond ((eq indent nil)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
495 (setq indent (current-indentation)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
496 ((eq indent t)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
497 (setq indent (calculate-c-indent-within-comment)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
498 ((looking-at "[ \t]*#")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
499 (setq indent 0))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
500 (t
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
501 (skip-chars-forward " \t")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
502 (if (listp indent) (setq indent (car indent)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
503 (cond ((looking-at "\\(default\\|public\\|private\\|protected\\):")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
504 (setq indent (+ indent c-label-offset)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
505 ((or (looking-at "case\\b")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
506 (and (looking-at "[A-Za-z]")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
507 (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
508 (forward-sexp 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
509 (looking-at ":[^:]"))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
510 (setq indent (max 1 (+ indent c-label-offset))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
511 ((and (looking-at "else\\b")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
512 (not (looking-at "else\\s_")))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
513 (setq indent (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
514 (c-backward-to-start-of-if)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
515 (current-indentation))))
5300
954744cd720f (c++-indent-line, calculate-c++-indent):
Richard M. Stallman <rms@gnu.org>
parents: 4308
diff changeset
516 ((looking-at "friend\[ \t]")
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
517 (setq indent (+ indent c++-friend-offset)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
518 ((= (following-char) ?})
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
519 (setq indent (- indent c-indent-level)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
520 ((= (following-char) ?{)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
521 (setq indent (+ indent c-brace-offset))))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
522 (skip-chars-forward " \t")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
523 (setq shift-amt (- indent (current-column)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
524 (if (zerop shift-amt)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
525 (if (> (- (point-max) pos) (point))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
526 (goto-char (- (point-max) pos)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
527 (delete-region beg (point))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
528 (indent-to indent)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
529 ;; If initial point was within line's indentation,
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
530 ;; position after the indentation. Else stay at same point in text.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
531 (if (> (- (point-max) pos) (point))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
532 (goto-char (- (point-max) pos))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
533 shift-amt))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
534
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
535 (defun calculate-c++-indent (&optional parse-start)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
536 "Return appropriate indentation for current line as C++ code.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
537 In usual case returns an integer: the column to indent to.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
538 Returns nil if line starts inside a string, t if in a comment."
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
539 (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
540 (beginning-of-line)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
541 (let ((indent-point (point))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
542 (case-fold-search nil)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
543 state
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
544 containing-sexp)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
545 (if parse-start
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
546 (goto-char parse-start)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
547 (beginning-of-defun))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
548 (while (< (point) indent-point)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
549 (setq parse-start (point))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
550 (setq state (parse-partial-sexp (point) indent-point 0))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
551 (setq containing-sexp (car (cdr state))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
552 (cond ((or (nth 3 state) (nth 4 state))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
553 ;; return nil or t if should not change this line
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
554 (nth 4 state))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
555 ((null containing-sexp)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
556 ;; Line is at top level. May be data or function definition, or
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
557 ;; may be function argument declaration or member initialization.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
558 ;; Indent like the previous top level line unless
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
559 ;; (1) the previous line ends in a closeparen without semicolon,
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
560 ;; in which case this line is the first argument declaration or
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
561 ;; member initialization, or
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
562 ;; (2) the previous line begins with a colon,
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
563 ;; in which case this is the second line of member inits.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
564 ;; It is assumed that arg decls and member inits are not mixed.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
565 (goto-char indent-point)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
566 (skip-chars-forward " \t")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
567 (if (= (following-char) ?{)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
568 0 ; Unless it starts a function body
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
569 (c++-backward-to-noncomment (or parse-start (point-min)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
570 (if (= (preceding-char) ?\))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
571 (progn ; first arg decl or member init
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
572 (goto-char indent-point)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
573 (skip-chars-forward " \t")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
574 (if (= (following-char) ?:)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
575 c++-member-init-indent
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
576 c-argdecl-indent))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
577 (if (= (preceding-char) ?\;)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
578 (backward-char 1))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
579 (if (= (preceding-char) ?})
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
580 0
13253
a8126303dc0f (calculate-c++-indent): Skip over paren-group
Richard M. Stallman <rms@gnu.org>
parents: 12706
diff changeset
581 (if (= (preceding-char) ?\))
a8126303dc0f (calculate-c++-indent): Skip over paren-group
Richard M. Stallman <rms@gnu.org>
parents: 12706
diff changeset
582 (forward-list -1))
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
583 (beginning-of-line) ; continued arg decls or member inits
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
584 (skip-chars-forward " \t")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
585 (if (= (following-char) ?:)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
586 (if c++-continued-member-init-offset
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
587 (+ (current-indentation)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
588 c++-continued-member-init-offset)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
589 (progn
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
590 (forward-char 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
591 (skip-chars-forward " \t")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
592 (current-column)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
593 (current-indentation)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
594 )))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
595 ((/= (char-after containing-sexp) ?{)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
596 ;; line is expression, not statement:
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
597 ;; indent to just after the surrounding open -- unless
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
598 ;; empty arg list, in which case we do what
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
599 ;; c++-empty-arglist-indent says to do.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
600 (if (and c++-empty-arglist-indent
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
601 (or (null (nth 2 state)) ;; indicates empty arg
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
602 ;; list.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
603 ;; Use a heuristic: if the first
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
604 ;; non-whitespace following left paren on
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
605 ;; same line is not a comment,
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
606 ;; is not an empty arglist.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
607 (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
608 (goto-char (1+ containing-sexp))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
609 (not
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
610 (looking-at "\\( \\|\t\\)*[^/\n]")))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
611 (progn
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
612 (goto-char containing-sexp)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
613 (beginning-of-line)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
614 (skip-chars-forward " \t")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
615 (goto-char (min (+ (point) c++-empty-arglist-indent)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
616 (1+ containing-sexp)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
617 (current-column))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
618 ;; In C-mode, we would always indent to one after the
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
619 ;; left paren. Here, though, we may have an
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
620 ;; empty-arglist, so we'll indent to the min of that
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
621 ;; and the beginning of the first argument.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
622 (goto-char (1+ containing-sexp))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
623 (current-column)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
624 (t
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
625 ;; Statement. Find previous non-comment character.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
626 (goto-char indent-point)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
627 (c++-backward-to-noncomment containing-sexp)
13253
a8126303dc0f (calculate-c++-indent): Skip over paren-group
Richard M. Stallman <rms@gnu.org>
parents: 12706
diff changeset
628 (if (and (not (memq (preceding-char) '(0 ?\, ?\; ?\} ?\{)))
a8126303dc0f (calculate-c++-indent): Skip over paren-group
Richard M. Stallman <rms@gnu.org>
parents: 12706
diff changeset
629 ;; But don't treat a line with a close-brace
a8126303dc0f (calculate-c++-indent): Skip over paren-group
Richard M. Stallman <rms@gnu.org>
parents: 12706
diff changeset
630 ;; as a continuation. It is probably the
a8126303dc0f (calculate-c++-indent): Skip over paren-group
Richard M. Stallman <rms@gnu.org>
parents: 12706
diff changeset
631 ;; end of an enum type declaration.
a8126303dc0f (calculate-c++-indent): Skip over paren-group
Richard M. Stallman <rms@gnu.org>
parents: 12706
diff changeset
632 (save-excursion
a8126303dc0f (calculate-c++-indent): Skip over paren-group
Richard M. Stallman <rms@gnu.org>
parents: 12706
diff changeset
633 (goto-char indent-point)
a8126303dc0f (calculate-c++-indent): Skip over paren-group
Richard M. Stallman <rms@gnu.org>
parents: 12706
diff changeset
634 (skip-chars-forward " \t")
a8126303dc0f (calculate-c++-indent): Skip over paren-group
Richard M. Stallman <rms@gnu.org>
parents: 12706
diff changeset
635 (not (= (following-char) ?}))))
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
636 ;; This line is continuation of preceding line's statement;
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
637 ;; indent c-continued-statement-offset more than the
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
638 ;; previous line of the statement.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
639 (progn
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
640 (c-backward-to-start-of-continued-exp containing-sexp)
3627
6895c2df25a6 (calculate-c++-indent): Respect
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
641 (+ c-continued-statement-offset (current-column)
6895c2df25a6 (calculate-c++-indent): Respect
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
642 (if (save-excursion (goto-char indent-point)
6895c2df25a6 (calculate-c++-indent): Respect
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
643 (skip-chars-forward " \t")
6895c2df25a6 (calculate-c++-indent): Respect
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
644 (eq (following-char) ?{))
6895c2df25a6 (calculate-c++-indent): Respect
Richard M. Stallman <rms@gnu.org>
parents: 3591
diff changeset
645 c-continued-brace-offset 0)))
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
646 ;; This line starts a new statement.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
647 ;; Position following last unclosed open.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
648 (goto-char containing-sexp)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
649 ;; Is line first statement after an open-brace?
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
650 (or
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
651 ;; If no, find that first statement and indent like it.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
652 (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
653 (forward-char 1)
11128
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
654 (let ((colon-line-end 0))
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
655 (while (progn (skip-chars-forward " \t\n")
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
656 (looking-at
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
657 (concat
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
658 "#\\|/\\*\\|//"
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
659 "\\|case[ \t]"
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
660 "\\|[a-zA-Z0-9_$]*:[^:]"
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
661 "\\|friend[ \t]")))
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
662 ;; Skip over comments and labels following openbrace.
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
663 (cond ((= (following-char) ?\#)
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
664 (forward-line 1))
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
665 ((looking-at "/\\*")
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
666 (search-forward "*/" nil 'move))
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
667 ((looking-at "//\\|friend[ \t]")
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
668 (forward-line 1))
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
669 (t
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
670 (save-excursion (end-of-line)
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
671 (setq colon-line-end (point)))
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
672 (search-forward ":"))))
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
673 ;; The first following code counts
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
674 ;; if it is before the line we want to indent.
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
675 (and (< (point) indent-point)
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
676 (-
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
677 (if (> colon-line-end (point))
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
678 (- (current-indentation) c-label-offset)
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
679 (current-column))
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
680 ;; If prev stmt starts with open-brace, that
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
681 ;; open brace was offset by c-brace-offset.
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
682 ;; Compensate to get the column where
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
683 ;; an ordinary statement would start.
291aaa280603 (calculate-c++-indent): Copy colon-line-end code from calculate-c-indent.
Richard M. Stallman <rms@gnu.org>
parents: 10871
diff changeset
684 (if (= (following-char) ?\{) c-brace-offset 0)))))
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
685 ;; If no previous statement,
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
686 ;; indent it relative to line brace is on.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
687 ;; For open brace in column zero, don't let statement
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
688 ;; start there too. If c-indent-offset is zero,
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
689 ;; use c-brace-offset + c-continued-statement-offset instead.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
690 ;; For open-braces not the first thing in a line,
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
691 ;; add in c-brace-imaginary-offset.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
692 (+ (if (and (bolp) (zerop c-indent-level))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
693 (+ c-brace-offset c-continued-statement-offset)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
694 c-indent-level)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
695 ;; Move back over whitespace before the openbrace.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
696 ;; If openbrace is not first nonwhite thing on the line,
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
697 ;; add the c-brace-imaginary-offset.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
698 (progn (skip-chars-backward " \t")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
699 (if (bolp) 0 c-brace-imaginary-offset))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
700 ;; If the openbrace is preceded by a parenthesized exp,
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
701 ;; move to the beginning of that;
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
702 ;; possibly a different line
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
703 (progn
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
704 (if (eq (preceding-char) ?\))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
705 (forward-sexp -1))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
706 ;; Get initial indentation of the line we are on.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
707 (current-indentation))))))))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
708
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
709 (defun c++-backward-to-noncomment (lim)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
710 (let (opoint stop)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
711 (while (not stop)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
712 (skip-chars-backward " \t\n\r\f" lim)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
713 (setq opoint (point))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
714 (cond ((and (>= (point) (+ 2 lim))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
715 (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
716 (forward-char -2)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
717 (looking-at "\\*/")))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
718 (search-backward "/*" lim 'move))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
719 ((and
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
720 (search-backward "//" (max (c++-point-bol) lim) 'move)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
721 (not (c++-within-string-p (point) opoint))))
10829
135ef978d711 (c++-backward-to-noncomment): Don't loop forever
Richard M. Stallman <rms@gnu.org>
parents: 10409
diff changeset
722 ;; No comment to be found.
135ef978d711 (c++-backward-to-noncomment): Don't loop forever
Richard M. Stallman <rms@gnu.org>
parents: 10409
diff changeset
723 ;; If there's a # command on this line,
135ef978d711 (c++-backward-to-noncomment): Don't loop forever
Richard M. Stallman <rms@gnu.org>
parents: 10409
diff changeset
724 ;; move back to it.
135ef978d711 (c++-backward-to-noncomment): Don't loop forever
Richard M. Stallman <rms@gnu.org>
parents: 10409
diff changeset
725 (t (beginning-of-line)
135ef978d711 (c++-backward-to-noncomment): Don't loop forever
Richard M. Stallman <rms@gnu.org>
parents: 10409
diff changeset
726 (skip-chars-forward " \t")
135ef978d711 (c++-backward-to-noncomment): Don't loop forever
Richard M. Stallman <rms@gnu.org>
parents: 10409
diff changeset
727 ;; But don't get fooled if we are already before the #.
135ef978d711 (c++-backward-to-noncomment): Don't loop forever
Richard M. Stallman <rms@gnu.org>
parents: 10409
diff changeset
728 (if (and (looking-at "#") (< (point) opoint))
135ef978d711 (c++-backward-to-noncomment): Don't loop forever
Richard M. Stallman <rms@gnu.org>
parents: 10409
diff changeset
729 (setq stop (<= (point) lim))
135ef978d711 (c++-backward-to-noncomment): Don't loop forever
Richard M. Stallman <rms@gnu.org>
parents: 10409
diff changeset
730 (setq stop t)
135ef978d711 (c++-backward-to-noncomment): Don't loop forever
Richard M. Stallman <rms@gnu.org>
parents: 10409
diff changeset
731 (goto-char opoint)))))))
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
732
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
733 (defun indent-c++-exp ()
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
734 "Indent each line of the C++ grouping following point."
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
735 (interactive)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
736 (let ((indent-stack (list nil))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
737 (contain-stack (list (point)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
738 (case-fold-search nil)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
739 restart outer-loop-done inner-loop-done state ostate
861
345296f94a1e *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
740 this-indent last-sexp last-depth
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
741 at-else at-brace
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
742 (opoint (point))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
743 (next-depth 0))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
744 (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
745 (forward-sexp 1))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
746 (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
747 (setq outer-loop-done nil)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
748 (while (and (not (eobp)) (not outer-loop-done))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
749 (setq last-depth next-depth)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
750 ;; Compute how depth changes over this line
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
751 ;; plus enough other lines to get to one that
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
752 ;; does not end inside a comment or string.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
753 ;; Meanwhile, do appropriate indentation on comment lines.
861
345296f94a1e *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
754 (setq inner-loop-done nil)
345296f94a1e *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
755 (while (and (not inner-loop-done)
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
756 (not (and (eobp) (setq outer-loop-done t))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
757 (setq ostate state)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
758 (setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
759 nil nil state))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
760 (setq next-depth (car state))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
761 (if (and (car (cdr (cdr state)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
762 (>= (car (cdr (cdr state))) 0))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
763 (setq last-sexp (car (cdr (cdr state)))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
764 (if (or (nth 4 ostate))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
765 (c++-indent-line))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
766 (if (or (nth 3 state))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
767 (forward-line 1)
861
345296f94a1e *** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents: 846
diff changeset
768 (setq inner-loop-done t)))
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
769 (if (<= next-depth 0)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
770 (setq outer-loop-done t))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
771 (if outer-loop-done
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
772 nil
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
773 ;; If this line had ..))) (((.. in it, pop out of the levels
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
774 ;; that ended anywhere in this line, even if the final depth
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
775 ;; doesn't indicate that they ended.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
776 (while (> last-depth (nth 6 state))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
777 (setq indent-stack (cdr indent-stack)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
778 contain-stack (cdr contain-stack)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
779 last-depth (1- last-depth)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
780 (if (/= last-depth next-depth)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
781 (setq last-sexp nil))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
782 ;; Add levels for any parens that were started in this line.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
783 (while (< last-depth next-depth)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
784 (setq indent-stack (cons nil indent-stack)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
785 contain-stack (cons nil contain-stack)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
786 last-depth (1+ last-depth)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
787 (if (null (car contain-stack))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
788 (setcar contain-stack (or (car (cdr state))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
789 (save-excursion (forward-sexp -1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
790 (point)))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
791 (forward-line 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
792 (skip-chars-forward " \t")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
793 (if (eolp)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
794 nil
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
795 (if (and (car indent-stack)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
796 (>= (car indent-stack) 0))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
797 ;; Line is on an existing nesting level.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
798 ;; Lines inside parens are handled specially.
10409
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
799 nil
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
800 ;; Just started a new nesting level.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
801 ;; Compute the standard indent for this level.
10409
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
802 (let (val)
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
803 (if (= (char-after (car contain-stack)) ?{)
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
804 (save-excursion
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
805 (goto-char (car contain-stack))
14853
e263cca8d928 (indent-c++-exp): Use calculate-c-indent-after-brace.
Richard M. Stallman <rms@gnu.org>
parents: 14631
diff changeset
806 (setq val (calculate-c-indent-after-brace)))
10409
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
807 (setq val (calculate-c++-indent
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
808 (if (car indent-stack)
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
809 (- (car indent-stack))))))
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
810 (setcar indent-stack val)))
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
811 ;; Adjust line indentation according to its predecessor.
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
812 (if (/= (char-after (car contain-stack)) ?\{)
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
813 (setq this-indent (car indent-stack))
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
814 ;; Line is at statement level.
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
815 ;; Is it a new statement? Is it an else?
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
816 ;; Find last non-comment character before this line
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
817 (save-excursion
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
818 (setq at-else (looking-at "else\\W"))
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
819 (setq at-brace (= (following-char) ?\{))
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
820 (c++-backward-to-noncomment opoint)
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
821 (if (not (memq (preceding-char) '(nil ?\, ?\; ?\} ?: ?\{)))
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
822 ;; Preceding line did not end in comma or semi;
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
823 ;; indent this line c-continued-statement-offset
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
824 ;; more than previous.
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
825 (progn
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
826 (c-backward-to-start-of-continued-exp
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
827 (car contain-stack))
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
828 (setq this-indent
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
829 (+ c-continued-statement-offset
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
830 (current-column)
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
831 (if at-brace c-continued-brace-offset 0))))
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
832 ;; Preceding line ended in comma or semi;
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
833 ;; use the standard indent for this level.
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
834 (if at-else
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
835 (progn (c-backward-to-start-of-if opoint)
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
836 (setq this-indent (current-indentation)))
0e814787d3be (indent-c++-exp): Handle `{ if (x)\n foo;\n bar;' case.
Richard M. Stallman <rms@gnu.org>
parents: 9219
diff changeset
837 (setq this-indent (car indent-stack))))))
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
838 ;; Adjust line indentation according to its contents
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
839 (if (looking-at "\\(public\\|private\\|protected\\):")
9219
c57babb0ebd5 (indent-c++-exp): For public/private/protected,
Richard M. Stallman <rms@gnu.org>
parents: 8326
diff changeset
840 (setq this-indent (- this-indent c-indent-level))
c57babb0ebd5 (indent-c++-exp): For public/private/protected,
Richard M. Stallman <rms@gnu.org>
parents: 8326
diff changeset
841 (if (or (looking-at "case[ \t]")
c57babb0ebd5 (indent-c++-exp): For public/private/protected,
Richard M. Stallman <rms@gnu.org>
parents: 8326
diff changeset
842 (and (looking-at "[A-Za-z]")
c57babb0ebd5 (indent-c++-exp): For public/private/protected,
Richard M. Stallman <rms@gnu.org>
parents: 8326
diff changeset
843 (save-excursion
c57babb0ebd5 (indent-c++-exp): For public/private/protected,
Richard M. Stallman <rms@gnu.org>
parents: 8326
diff changeset
844 (forward-sexp 1)
c57babb0ebd5 (indent-c++-exp): For public/private/protected,
Richard M. Stallman <rms@gnu.org>
parents: 8326
diff changeset
845 (looking-at ":[^:]"))))
c57babb0ebd5 (indent-c++-exp): For public/private/protected,
Richard M. Stallman <rms@gnu.org>
parents: 8326
diff changeset
846 (setq this-indent (max 1 (+ this-indent c-label-offset)))))
5300
954744cd720f (c++-indent-line, calculate-c++-indent):
Richard M. Stallman <rms@gnu.org>
parents: 4308
diff changeset
847 (if (looking-at "friend[ \t]")
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
848 (setq this-indent (+ this-indent c++-friend-offset)))
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
849 (if (= (following-char) ?\})
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
850 (setq this-indent (- this-indent c-indent-level)))
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
851 (if (= (following-char) ?\{)
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
852 (setq this-indent (+ this-indent c-brace-offset)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
853 ;; Put chosen indentation into effect.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
854 (or (= (current-column) this-indent)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
855 (= (following-char) ?\#)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
856 (progn
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
857 (delete-region (point) (progn (beginning-of-line) (point)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
858 (indent-to this-indent)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
859 ;; Indent any comment following the text.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
860 (or (looking-at comment-start-skip)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
861 (if (re-search-forward comment-start-skip
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
862 (save-excursion (end-of-line)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
863 (point)) t)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
864 (progn
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
865 (indent-for-comment)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
866 (beginning-of-line))))))))))
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
867
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
868 (defun fill-c++-comment ()
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
869 "Fill a comment contained in consecutive lines containing point.
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
870 The fill lines remain a comment."
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
871 (interactive)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
872 (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
873 (let ((save fill-prefix))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
874 (beginning-of-line 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
875 (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
876 (re-search-forward comment-start-skip
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
877 (save-excursion (end-of-line) (point))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
878 t)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
879 (goto-char (match-end 0))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
880 (set-fill-prefix))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
881 (while (looking-at fill-prefix)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
882 (previous-line 1))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
883 (next-line 1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
884 (insert-string "\n")
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
885 (fill-paragraph nil)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
886 (delete-char -1)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
887 (setq fill-prefix save))))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
888
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
889 (defun c++-point-bol ()
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
890 "Returns the value of the point at the beginning of the current line."
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
891 (save-excursion
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
892 (beginning-of-line)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
893 (point)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
894
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
895 ;; (defun c++-insert-header ()
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
896 ;; "Insert header denoting C++ code at top of buffer."
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
897 ;; (interactive)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
898 ;; (save-excursion
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
899 ;; (goto-char (point-min))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
900 ;; (insert "// "
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
901 ;; "This may look like C code, but it is really "
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
902 ;; "-*- C++ -*-"
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
903 ;; "\n\n")))
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
904
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
905 (defun c++-within-string-p (point1 point2)
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
906 "Returns true if number of double quotes between two points is odd."
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
907 (let ((s (buffer-substring point1 point2)))
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
908 (not (zerop (% (c++-count-char-in-string ?\" s) 2)))))
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
909
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
910 (defun c++-count-char-in-string (c s)
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
911 (let ((count 0)
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
912 (pos 0))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
913 (while (< pos (length s))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
914 (setq count (+ count (if (\= (aref s pos) c) 1 0)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
915 (setq pos (1+ pos)))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
916 count))
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
917
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
918 ;; rms: This page is creeping featurism, and not worth having.
257
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
919
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
920 ;;; Below are two regular expressions that attempt to match defuns
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
921 ;;; "strongly" and "weakly." The strong one almost reconstructs the
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
922 ;;; grammar of C++; the weak one just figures anything id or curly on
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
923 ;;; the left begins a defun. The constant "c++-match-header-strongly"
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
924 ;;; determines which to use; the default is the weak one.
e5ba2ba35226 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
925
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
926 ;; (defvar c++-match-header-strongly nil
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
927 ;; "*If nil, use `c++-defun-header-weak' to identify beginning of definitions.
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
928 ;; If non-nil, use `c++-defun-header-strong'.")
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
929 ;;
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
930 ;; (defvar c++-defun-header-strong-struct-equivs "\\(class\\|struct\\|enum\\)"
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
931 ;; "Regexp to match names of structure declaration blocks in C++.")
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
932 ;;
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
933 ;; (defconst c++-defun-header-strong
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
934 ;; (let*
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
935 ;; (; valid identifiers
3591
507f64624555 Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents: 2307
diff changeset
936 ;; ;; There's a real weirdness here -- if I switch the below
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
937 ;; (id "\\(\\w\\|_\\)+")
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
938 ;; ;; to be
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
939 ;; ;; (id "\\(_\\|\\w\\)+")
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
940 ;; ;; things no longer work right. Try it and see!
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
941 ;;
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
942 ;; ; overloadable operators
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
943 ;; (op-sym1
6309
9217f29851c2 Don't use triple-hyphen in a character class.
Karl Heuer <kwzh@gnu.org>
parents: 5957
diff changeset
944 ;; "[-+*/%^&|~!=<>]\\|[-+*/%^&|<>=!]=\\|<<=?\\|>>=?")
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
945 ;; (op-sym2
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
946 ;; "&&\\|||\\|\\+\\+\\|--\\|()\\|\\[\\]")
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
947 ;; (op-sym (concat "\\(" op-sym1 "\\|" op-sym2 "\\)"))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
948 ;; ; whitespace
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
949 ;; (middle "[^\\*]*\\(\\*+[^/\\*][^\\*]*\\)*")
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
950 ;; (c-comment (concat "/\\*" middle "\\*+/"))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
951 ;; (wh (concat "\\(\\s \\|\n\\|//.*$\\|" c-comment "\\)"))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
952 ;; (wh-opt (concat wh "*"))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
953 ;; (wh-nec (concat wh "+"))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
954 ;; (oper (concat "\\(" "operator" "\\("
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
955 ;; wh-opt op-sym "\\|" wh-nec id "\\)" "\\)"))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
956 ;; (dcl-list "([^():]*)")
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
957 ;; (func-name (concat "\\(" oper "\\|" id "::" id "\\|" id "\\)"))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
958 ;; (inits
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
959 ;; (concat "\\(:"
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
960 ;; "\\(" wh-opt id "(.*\\()" wh-opt "," "\\)\\)*"
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
961 ;; wh-opt id "(.*)" wh-opt "{"
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
962 ;; "\\|" wh-opt "{\\)"))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
963 ;; (type-name (concat
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
964 ;; "\\(" c++-defun-header-strong-struct-equivs wh-nec "\\)?"
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
965 ;; id))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
966 ;; (type (concat "\\(const" wh-nec "\\)?"
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
967 ;; "\\(" type-name "\\|" type-name wh-opt "\\*+" "\\|"
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
968 ;; type-name wh-opt "&" "\\)"))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
969 ;; (modifier "\\(inline\\|virtual\\|overload\\|auto\\|static\\)")
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
970 ;; (modifiers (concat "\\(" modifier wh-nec "\\)*"))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
971 ;; (func-header
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
972 ;; ;; type arg-dcl
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
973 ;; (concat modifiers type wh-nec func-name wh-opt dcl-list wh-opt inits))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
974 ;; (inherit (concat "\\(:" wh-opt "\\(public\\|private\\)?"
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
975 ;; wh-nec id "\\)"))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
976 ;; (cs-header (concat
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
977 ;; c++-defun-header-strong-struct-equivs
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
978 ;; wh-nec id wh-opt inherit "?" wh-opt "{")))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
979 ;; (concat "^\\(" func-header "\\|" cs-header "\\)"))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
980 ;; "Strongly-defined regexp to match beginning of structure or function def.")
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
981 ;;
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
982 ;;
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
983 ;; ;; This part has to do with recognizing defuns.
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
984 ;;
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
985 ;; ;; The weak convention we will use is that a defun begins any time
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
986 ;; ;; there is a left curly brace, or some identifier on the left margin,
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
987 ;; ;; followed by a left curly somewhere on the line. (This will also
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
988 ;; ;; incorrectly match some continued strings, but this is after all
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
989 ;; ;; just a weak heuristic.) Suggestions for improvement (short of the
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
990 ;; ;; strong scheme shown above) are welcomed.
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
991 ;;
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
992 ;; (defconst c++-defun-header-weak "^{\\|^[_a-zA-Z].*{"
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
993 ;; "Weakly-defined regexp to match beginning of structure or function def.")
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
994 ;;
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
995 ;; (defun c++-beginning-of-defun (arg)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
996 ;; (interactive "p")
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
997 ;; (let ((c++-defun-header (if c++-match-header-strongly
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
998 ;; c++-defun-header-strong
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
999 ;; c++-defun-header-weak)))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1000 ;; (cond ((or (= arg 0) (and (> arg 0) (bobp))) nil)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1001 ;; ((and (not (looking-at c++-defun-header))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1002 ;; (let ((curr-pos (point))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1003 ;; (open-pos (if (search-forward "{" nil 'move)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1004 ;; (point)))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1005 ;; (beg-pos
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1006 ;; (if (re-search-backward c++-defun-header nil 'move)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1007 ;; (match-beginning 0))))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1008 ;; (if (and open-pos beg-pos
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1009 ;; (< beg-pos curr-pos)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1010 ;; (> open-pos curr-pos))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1011 ;; (progn
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1012 ;; (goto-char beg-pos)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1013 ;; (if (= arg 1) t nil));; Are we done?
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1014 ;; (goto-char curr-pos)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1015 ;; nil))))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1016 ;; (t
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1017 ;; (if (and (looking-at c++-defun-header) (not (bobp)))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1018 ;; (forward-char (if (< arg 0) 1 -1)))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1019 ;; (and (re-search-backward c++-defun-header nil 'move (or arg 1))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1020 ;; (goto-char (match-beginning 0)))))))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1021 ;;
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1022 ;;
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1023 ;; (defun c++-end-of-defun (arg)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1024 ;; (interactive "p")
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1025 ;; (let ((c++-defun-header (if c++-match-header-strongly
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1026 ;; c++-defun-header-strong
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1027 ;; c++-defun-header-weak)))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1028 ;; (if (and (eobp) (> arg 0))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1029 ;; nil
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1030 ;; (if (and (> arg 0) (looking-at c++-defun-header)) (forward-char 1))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1031 ;; (let ((pos (point)))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1032 ;; (c++-beginning-of-defun
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1033 ;; (if (< arg 0)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1034 ;; (- (- arg (if (eobp) 0 1)))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1035 ;; arg))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1036 ;; (if (and (< arg 0) (bobp))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1037 ;; t
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1038 ;; (if (re-search-forward c++-defun-header nil 'move)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1039 ;; (progn (forward-char -1)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1040 ;; (forward-sexp)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1041 ;; (beginning-of-line 2)))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1042 ;; (if (and (= pos (point))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1043 ;; (re-search-forward c++-defun-header nil 'move))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1044 ;; (c++-end-of-defun 1))))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1045 ;; t)))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1046 ;;
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1047 ;; (defun c++-indent-defun ()
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1048 ;; "Indents the current function definition, struct or class declaration."
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1049 ;; (interactive)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1050 ;; (let ((restore (point)))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1051 ;; (c++-end-of-defun 1)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1052 ;; (beginning-of-line 1)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1053 ;; (let ((end (point)))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1054 ;; (c++-beginning-of-defun 1)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1055 ;; (while (<= (point) end)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1056 ;; (c++-indent-line)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1057 ;; (next-line 1)
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1058 ;; (beginning-of-line 1)))
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 798
diff changeset
1059 ;; (goto-char restore)))
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 257
diff changeset
1060
3806
d43666cf0dbb Comment changes for renaming from c++-mode.el to cplus-md.el.
Richard M. Stallman <rms@gnu.org>
parents: 3627
diff changeset
1061 ;;; cplus-md.el ends here