annotate lisp/obsolete/cplus-md.el @ 37945:8f7b126354f0

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