annotate lisp/progmodes/cc-align.el @ 37861:829203873c2d

Add something for variable aliases.
author Gerd Moellmann <gerd@gnu.org>
date Mon, 21 May 2001 12:47:04 +0000
parents 32a4317c6aa5
children 7a94f1c588c4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; cc-align.el --- custom indentation functions for CC Mode
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
3 ;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
30407
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
5 ;; Authors: 2000- Martin Stjernholm
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
6 ;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
7 ;; 1992-1997 Barry A. Warsaw
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; 1987 Dave Detlefs and Stewart Clamen
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; 1985 Richard M. Stallman
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
10 ;; Maintainer: bug-cc-mode@gnu.org
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; Created: 22-Apr-1997 (split from cc-mode.el)
20141
1a85b213eb6d Remove version number.
Karl Heuer <kwzh@gnu.org>
parents: 20140
diff changeset
12 ;; Version: See cc-mode.el
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; Keywords: c languages oop
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; This file is part of GNU Emacs.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is free software; you can redistribute it and/or modify
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; it under the terms of the GNU General Public License as published by
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; the Free Software Foundation; either version 2, or (at your option)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; any later version.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; GNU Emacs is distributed in the hope that it will be useful,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;; GNU General Public License for more details.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; You should have received a copy of the GNU General Public License
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
28 ;; along with this program; see the file COPYING. If not, write to
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
29 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; Boston, MA 02111-1307, USA.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 (eval-when-compile
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
33 (let ((load-path
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
34 (if (and (boundp 'byte-compile-dest-file)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
35 (stringp byte-compile-dest-file))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
36 (cons (file-name-directory byte-compile-dest-file) load-path)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
37 load-path)))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
38 (require 'cc-bytecomp)))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
39
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
40 (cc-require 'cc-defs)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
41 (cc-require 'cc-vars)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
42 (cc-require 'cc-langs)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
43 (cc-require 'cc-engine)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; Standard indentation line-ups
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
47
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 (defun c-lineup-arglist (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
49 "Line up the current argument line under the first argument.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
50
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
51 Works with: arglist-cont-nonempty."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (let* ((containing-sexp
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;; arglist-cont-nonempty gives relpos ==
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;; to boi of containing-sexp paren. This
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;; is good when offset is +, but bad
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;; when it is c-lineup-arglist, so we
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;; have to special case a kludge here.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 (backward-up-list 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (skip-chars-forward " \t" (c-point 'eol)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (goto-char (cdr langelem)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (langelem-col (c-langelem-col langelem t)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (if (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 (looking-at "[ \t]*)"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (progn (goto-char (match-end 0))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
72 (c-forward-sexp -1)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (forward-char 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (c-forward-syntactic-ws)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (- (current-column) langelem-col))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 (goto-char containing-sexp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 (or (eolp)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
78 (not (memq (char-after) '(?{ ?\( ?\[)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 (let ((eol (c-point 'eol))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 (here (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 (forward-char 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (skip-chars-forward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 (point))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 (c-forward-syntactic-ws)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 (if (< (point) eol)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 (goto-char here))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 (- (current-column) langelem-col)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 (defun c-lineup-arglist-intro-after-paren (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
91 "Line up a line just after the open paren of the surrounding paren or
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
92 brace block.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
93
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
94 Works with: defun-block-intro, brace-list-intro,
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
95 statement-block-intro, statement-case-intro, arglist-intro."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (let ((langelem-col (c-langelem-col langelem t))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (ce-curcol (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 (backward-up-list 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 (skip-chars-forward " \t" (c-point 'eol))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 (current-column))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (- ce-curcol langelem-col -1))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (defun c-lineup-arglist-close-under-paren (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
106 "Line up a closing paren line under the corresponding open paren.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
107
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
108 Works with: defun-close, class-close, inline-close, block-close,
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
109 brace-list-close, arglist-close, extern-lang-close, namespace-close
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
110 \(for most of these, a zero offset will normally produce the same
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
111 result, though)."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (let ((langelem-col (c-langelem-col langelem t))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (ce-curcol (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (backward-up-list 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (current-column))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (- ce-curcol langelem-col))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
120 (defun c-lineup-close-paren (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
121 "Line up the closing paren under its corresponding open paren if the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
122 open paren is followed by code. If the open paren ends its line, no
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
123 indentation is added. E.g:
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
124
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
125 main (int, main (
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
126 char ** int, char **
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
127 ) <-> ) <- c-lineup-close-paren
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
128
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
129 Works with: defun-close, class-close, inline-close, block-close,
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
130 brace-list-close, arglist-close, extern-lang-close, namespace-close."
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
131 (save-excursion
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
132 (condition-case nil
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
133 (let (opencol spec)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
134 (beginning-of-line)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
135 (backward-up-list 1)
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
136 (setq spec (c-looking-at-special-brace-list))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
137 (if spec (goto-char (car (car spec))))
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
138 (setq opencol (current-column))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
139 (forward-char 1)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
140 (if spec (progn
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
141 (c-forward-syntactic-ws)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
142 (forward-char 1)))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
143 (c-forward-syntactic-ws (c-point 'eol))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
144 (if (eolp)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
145 0
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
146 (- opencol (c-langelem-col langelem t))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
147 (error nil))))
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
148
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (defun c-lineup-streamop (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
150 "Line up C++ stream operators under each other.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
151
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
152 Works with: stream-op."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (let ((langelem-col (c-langelem-col langelem)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (re-search-forward "<<\\|>>" (c-point 'eol) 'move)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (goto-char (match-beginning 0))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 (- (current-column) langelem-col))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (defun c-lineup-multi-inher (langelem)
30407
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
160 "Line up the classes in C++ multiple inheritance clauses and member
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
161 initializers under each other. E.g:
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
162
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
163 class Foo: Foo::Foo (int a, int b):
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
164 public Cyphr, Cyphr (a),
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
165 public Bar <-> Bar (b) <- c-lineup-multi-inher
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
166
30407
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
167 class Foo Foo::Foo (int a, int b)
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
168 : public Cyphr, : Cyphr (a),
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
169 public Bar <-> Bar (b) <- c-lineup-multi-inher
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
170
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
171 class Foo Foo::Foo (int a, int b)
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
172 : public Cyphr : Cyphr (a)
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
173 , public Bar <-> , Bar (b) <- c-lineup-multi-inher
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
174
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
175 Works with: inher-cont, member-init-cont."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (save-excursion
30407
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
177 (let* ((eol (c-point 'eol))
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
178 (here (point))
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
179 (char-after-ip (progn
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
180 (skip-chars-forward " \t")
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
181 (char-after)))
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
182 (langelem-col (c-langelem-col langelem)))
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
183
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
184 ;; This kludge is necessary to support both inher-cont and
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
185 ;; member-init-cont, since they have different anchor positions.
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
186 (c-backward-syntactic-ws)
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
187 (when (eq (char-before) ?:)
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
188 (backward-char)
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
189 (c-backward-syntactic-ws))
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
190
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (skip-chars-forward "^:" eol)
30407
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
192 (if (eq char-after-ip ?,)
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
193 (skip-chars-forward " \t" eol)
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
194 (skip-chars-forward " \t:" eol))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (if (or (eolp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (looking-at c-comment-start-regexp))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (c-forward-syntactic-ws here))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (- (current-column) langelem-col)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 )))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (defun c-lineup-java-inher (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
202 "Line up Java implements and extends declarations.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
203 If class names follows on the same line as the implements/extends
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
204 keyword, they are lined up under each other. Otherwise, they are
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
205 indented by adding `c-basic-offset' to the column of the keyword.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
206 E.g:
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
207
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
208 class Foo class Foo
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
209 extends extends Cyphr,
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
210 Bar <-> Bar <- c-lineup-java-inher
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
211 <--> c-basic-offset
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
212
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
213 Works with: inher-cont."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (let ((langelem-col (c-langelem-col langelem)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (forward-word 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (if (looking-at "[ \t]*$")
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
218 c-basic-offset
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (c-forward-syntactic-ws)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (- (current-column) langelem-col)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (defun c-lineup-java-throws (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
223 "Line up Java throws declarations.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
224 If exception names follows on the same line as the throws keyword,
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
225 they are lined up under each other. Otherwise, they are indented by
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
226 adding `c-basic-offset' to the column of the throws keyword. The
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
227 throws keyword itself is also indented by `c-basic-offset' from the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
228 function declaration start if it doesn't hang. E.g:
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
229
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
230 int foo() int foo() throws Cyphr,
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
231 throws <-> Bar, <- c-lineup-java-throws
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
232 Bar <-> Vlod <- c-lineup-java-throws
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
233 <--><--> c-basic-offset
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
234
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
235 Works with: func-decl-cont."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (save-excursion
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
237 (let* ((lim (1- (c-point 'bol)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
238 (throws (catch 'done
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
239 (goto-char (cdr langelem))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
240 (while (zerop (c-forward-token-1 1 t lim))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
241 (if (looking-at "throws\\>[^_]")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
242 (throw 'done t))))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
243 (if throws
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
244 (if (zerop (c-forward-token-1 1 nil (c-point 'eol)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
245 (- (current-column) (c-langelem-col langelem))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
246 (back-to-indentation)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
247 (+ (- (current-column) (c-langelem-col langelem))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
248 c-basic-offset))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
249 c-basic-offset))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
251 (defun c-indent-one-line-block (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
252 "Indent a one line block `c-basic-offset' extra.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
253 E.g:
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
254
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
255 if (n > 0) if (n > 0)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
256 {m+=n; n=0;} <-> { <- c-indent-one-line-block
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
257 <--> c-basic-offset m+=n; n=0;
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
258 }
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
259
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
260 The block may use any kind of parenthesis character. nil is returned
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
261 if the line doesn't start with a one line block, which makes the
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
262 function usable in list expressions.
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
263
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
264 Work with: Almost all syntactic symbols, but most useful on *-open."
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
265 (save-excursion
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
266 (let ((eol (c-point 'eol)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
267 (back-to-indentation)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
268 (if (and (eq (char-syntax (char-after)) ?\()
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
269 (c-safe (progn (c-forward-sexp) t))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
270 (<= (point) eol))
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
271 c-basic-offset
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
272 nil))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
273
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
274 (defun c-indent-multi-line-block (langelem)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
275 "Indent a multi line block `c-basic-offset' extra.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
276 E.g:
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
277
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
278 int *foo[] = { int *foo[] = {
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
279 NULL, NULL,
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
280 {17}, <-> { <- c-indent-multi-line-block
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
281 17
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
282 }
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
283 <--> c-basic-offset
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
284
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
285 The block may use any kind of parenthesis character. nil is returned
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
286 if the line doesn't start with a multi line block, which makes the
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
287 function usable in list expressions.
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
288
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
289 Work with: Almost all syntactic symbols, but most useful on *-open."
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
290 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
291 (let ((eol (c-point 'eol)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
292 (back-to-indentation)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
293 (if (and (eq (char-syntax (char-after)) ?\()
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
294 (or (not (c-safe (progn (c-forward-sexp) t)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
295 (> (point) eol)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
296 c-basic-offset
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
297 nil))))
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
298
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 (defun c-lineup-C-comments (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
300 "Line up C block comment continuation lines.
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
301 Various heuristics are used to handle many of the common comment
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
302 styles. Some examples:
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
303
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
304 /* /** /* /* text /* /**
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
305 * text * text text text ** text ** text
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
306 */ */ */ */ */ */
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
307
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
308 /*********************************************************************
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
309 * text
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
310 ********************************************************************/
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
311
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
312 /*********************************************************************
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
313 Free form text comments:
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
314 In comments with a long delimiter line at the start, the indentation
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
315 is kept unchanged for lines that start with an empty comment line
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
316 prefix. The delimiter line is whatever matches the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
317 `comment-start-skip' regexp.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
318 *********************************************************************/
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
319
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
320 The variable `c-comment-prefix-regexp' is used to recognize the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
321 comment line prefix, e.g. the `*' that usually starts every line
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
322 inside a comment.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
323
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
324 Works with: The `c' syntactic symbol."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (save-excursion
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
326 (let* ((here (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
327 (prefixlen (progn (back-to-indentation)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
328 (if (looking-at c-current-comment-prefix)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
329 (- (match-end 0) (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
330 0)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
331 (starterlen (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
332 (goto-char (cdr langelem))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
333 (looking-at comment-start-skip)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
334 (- (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
335 (goto-char (match-end 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
336 (skip-chars-backward " \t")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
337 (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
338 (or (match-end 1) (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
339 1))) ; Don't count the first '/'.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
340 (langelem-col (save-excursion (c-langelem-col langelem))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
341 (if (and (> starterlen 10) (zerop prefixlen))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
342 ;; The comment has a long starter and the line doesn't have
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
343 ;; a nonempty comment prefix. Treat it as free form text
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
344 ;; and don't change the indentation.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
345 (- (current-column) langelem-col)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
346 (forward-line -1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
347 (back-to-indentation)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
348 (if (>= (cdr langelem) (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
349 ;; On the second line in the comment.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
350 (if (zerop prefixlen)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
351 ;; No nonempty comment prefix. Align after comment
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
352 ;; starter.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (progn
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
354 (goto-char (match-end 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
355 (if (looking-at "\\([ \t]+\\).+$")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
356 ;; Align with the text that hangs after the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
357 ;; comment starter.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
358 (goto-char (match-end 1)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
359 (- (current-column) langelem-col))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
360 ;; How long is the comment starter? if greater than the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
361 ;; length of the comment prefix, align left. if less
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
362 ;; than or equal, align right. this should also pick up
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
363 ;; Javadoc style comments.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
364 (if (> starterlen prefixlen)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
365 (progn
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 (goto-char (cdr langelem))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
367 (- (current-column) -1 langelem-col))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
368 (goto-char (match-end 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
369 (skip-chars-backward " \t")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
370 (- (current-column) prefixlen langelem-col)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
371 ;; Not on the second line in the comment. If the previous
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
372 ;; line has a nonempty comment prefix, align with it.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
373 ;; Otherwise, align with the previous nonempty line, but
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
374 ;; align the comment ender with the starter.
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
375 (when (or (not (looking-at c-current-comment-prefix))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
376 (eq (match-beginning 0) (match-end 0)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
377 (goto-char here)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
378 (back-to-indentation)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
379 (if (looking-at (concat "\\(" c-current-comment-prefix "\\)\\*/"))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
380 (goto-char (cdr langelem))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
381 (while (and (zerop (forward-line -1))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
382 (looking-at "^[ \t]*$")))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
383 (back-to-indentation)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
384 (if (< (point) (cdr langelem))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
385 ;; Align with the comment starter rather than
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
386 ;; with the code before it.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
387 (goto-char (cdr langelem)))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
388 (- (current-column) langelem-col))))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 (defun c-lineup-comment (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
391 "Line up a comment start according to `c-comment-only-line-offset'.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
392 If the comment is lined up with a comment starter on the previous
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
393 line, that alignment is preserved.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
394
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
395 Works with: comment-intro."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 (back-to-indentation)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
398 (let ((col (current-column)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 (cond
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
400 ;; CASE 1: preserve aligned comments
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
401 ((save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
402 (and (c-forward-comment -1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
403 (= col (current-column))))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
404 (vector col)) ; Return an absolute column.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 ;; indent as specified by c-comment-only-line-offset
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 ((not (bolp))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 (or (car-safe c-comment-only-line-offset)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 c-comment-only-line-offset))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 (t
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 (or (cdr-safe c-comment-only-line-offset)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 (car-safe c-comment-only-line-offset)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 -1000)) ;jam it against the left side
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 ))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 (defun c-lineup-runin-statements (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
416 "Line up statements when the first statement is on the same line as
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
417 the block opening brace. E.g:
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
418
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
419 int main()
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
420 { puts (\"Hello world!\");
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
421 return 0; <- c-lineup-runin-statements
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
422 }
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
423
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
424 If there is no statement after the opening brace to align with, nil is
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
425 returned. This makes the function usable in list expressions.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
426
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
427 Works with: The `statement' syntactic symbol."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 (if (eq (char-after (cdr langelem)) ?{)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 (let ((langelem-col (c-langelem-col langelem)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 (forward-char 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 (skip-chars-forward " \t")
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
433 (unless (eolp)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
434 (- (current-column) langelem-col))))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 (defun c-lineup-math (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
437 "Line up the current line after the equal sign on the first line in
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
438 the statement. If there isn't any, indent with `c-basic-offset'. If
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
439 the current line contains an equal sign too, try to align it with the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
440 first one.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
441
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
442 Works with: statement-cont."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (let ((equalp (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (goto-char (c-point 'boi))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
446 (let ((eol (c-point 'eol)))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
447 (c-forward-token-1 0 t eol)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
448 (while (and (not (eq (char-after) ?=))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
449 (= (c-forward-token-1 1 t eol) 0))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 (and (eq (char-after) ?=)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 (- (point) (c-point 'boi)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 (langelem-col (c-langelem-col langelem))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 donep)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 (while (and (not donep)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 (< (point) (c-point 'eol)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 (skip-chars-forward "^=" (c-point 'eol))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 (if (c-in-literal (cdr langelem))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 (forward-char 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 (setq donep t)))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
460 (if (or (not (eq (char-after) ?=))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
461 (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
462 (forward-char 1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
463 (c-forward-syntactic-ws (c-point 'eol))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
464 (eolp)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 ;; there's no equal sign on the line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 c-basic-offset
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 ;; calculate indentation column after equals and ws, unless
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 ;; our line contains an equals sign
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 (if (not equalp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 (forward-char 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 (skip-chars-forward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 (setq equalp 0)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 (- (current-column) equalp langelem-col))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 )))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
477 (defun c-lineup-template-args (langelem)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
478 "Line up template argument lines under the first argument.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
479 To allow this function to be used in a list expression, nil is
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
480 returned if there's no template argument on the first line.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
481
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
482 Works with: template-args-cont."
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
483 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
484 (c-with-syntax-table c++-template-syntax-table
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
485 (beginning-of-line)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
486 (backward-up-list 1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
487 (if (and (eq (char-after) ?<)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
488 (zerop (c-forward-token-1 1 nil (c-point 'eol))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
489 (- (current-column) (c-langelem-col langelem))))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
490
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 (defun c-lineup-ObjC-method-call (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
492 "Line up selector args as elisp-mode does with function args:
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
493 Go to the position right after the message receiver, and if you are at
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
494 the end of the line, indent the current line c-basic-offset columns
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
495 from the opening bracket; otherwise you are looking at the first
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
496 character of the first method call argument, so lineup the current
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
497 line with it.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
498
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
499 Works with: objc-method-call-cont."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 (let* ((extra (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 (back-to-indentation)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 (c-backward-syntactic-ws (cdr langelem))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 (if (eq (char-before) ?:)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 (- c-basic-offset)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 0)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 (open-bracket-pos (cdr langelem))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 (open-bracket-col (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 (goto-char open-bracket-pos)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 (current-column)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 (target-col (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 (forward-char)
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
513 (c-forward-sexp)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 (skip-chars-forward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 (if (eolp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 (+ open-bracket-col c-basic-offset)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 (current-column))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 )
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 (- target-col open-bracket-col extra))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 (defun c-lineup-ObjC-method-args (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
522 "Line up the colons that separate args.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
523 The colon on the current line is aligned with the one on the first
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
524 line.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
525
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
526 Works with: objc-method-args-cont."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 (let* ((here (c-point 'boi))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529 (curcol (progn (goto-char here) (current-column)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 (eol (c-point 'eol))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 (relpos (cdr langelem))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 (first-col-column (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533 (goto-char relpos)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534 (skip-chars-forward "^:" eol)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 (and (eq (char-after) ?:)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 (current-column)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 (if (not first-col-column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 c-basic-offset
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539 (goto-char here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 (skip-chars-forward "^:" eol)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 (if (eq (char-after) ?:)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 (+ curcol (- first-col-column (current-column)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 c-basic-offset)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 (defun c-lineup-ObjC-method-args-2 (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
546 "Line up the colons that separate args.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
547 The colon on the current line is aligned with the one on the previous
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
548 line.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
549
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
550 Works with: objc-method-args-cont."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 (let* ((here (c-point 'boi))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 (curcol (progn (goto-char here) (current-column)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 (eol (c-point 'eol))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 (relpos (cdr langelem))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 (prev-col-column (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 (skip-chars-backward "^:" relpos)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 (and (eq (char-before) ?:)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 (- (current-column) 1)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560 (if (not prev-col-column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561 c-basic-offset
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 (goto-char here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 (skip-chars-forward "^:" eol)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 (if (eq (char-after) ?:)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 (+ curcol (- prev-col-column (current-column)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566 c-basic-offset)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
568 (defun c-lineup-inexpr-block (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
569 "Line up the block for constructs that use a block inside an expression,
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
570 e.g. anonymous classes in Java and lambda functions in Pike. The body
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
571 is aligned with the start of the header, e.g. with the \"new\" or
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
572 \"lambda\" keyword. Returns nil if the block isn't part of such a
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
573 construct.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
574
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
575 Works with: inlambda, inexpr-statement, inexpr-class."
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
576 (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
577 (back-to-indentation)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
578 (let ((res (or (c-looking-at-inexpr-block)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
579 (if (c-safe (backward-up-list 1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
580 (eq (char-after) ?{))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
581 (c-looking-at-inexpr-block)))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
582 (when res
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
583 (goto-char (cdr res))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
584 (- (current-column)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
585 (progn
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
586 (back-to-indentation)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
587 (current-column)))))))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
588
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
589 (defun c-lineup-whitesmith-in-block (langelem)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
590 "Line up lines inside a block in whitesmith style.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
591 It's done in a way that works both when the opening brace hangs and
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
592 when it doesn't. E.g:
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
593
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
594 something
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
595 { something {
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
596 foo; <-> foo; <- c-lineup-whitesmith-in-block
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
597 } }
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
598 <--> c-basic-offset
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
599
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
600 In the first case the indentation is kept unchanged, in the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
601 second `c-basic-offset' is added.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
602
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
603 Works with: defun-close, defun-block-intro, block-close,
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
604 brace-list-close, brace-list-intro, statement-block-intro, inclass,
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
605 inextern-lang, innamespace."
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
606 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
607 (goto-char (cdr langelem))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
608 (back-to-indentation)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
609 (if (eq (char-syntax (char-after)) ?\()
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
610 0
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
611 c-basic-offset)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
612
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
613 (defun c-lineup-dont-change (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
614 "Do not change the indentation of the current line.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
615
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
616 Works with: Any syntactic symbol."
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
617 (save-excursion
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
618 (back-to-indentation)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
619 (vector (current-column))))
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
620
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
621
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
622 (defun c-snug-do-while (syntax pos)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
623 "Dynamically calculate brace hanginess for do-while statements.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
624 Using this function, `while' clauses that end a `do-while' block will
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
625 remain on the same line as the brace that closes that block.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
626
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627 See `c-hanging-braces-alist' for how to utilize this function as an
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
628 ACTION associated with `block-close' syntax."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
629 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
630 (let (langelem)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
631 (if (and (eq syntax 'block-close)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 (setq langelem (assq 'block-close c-syntactic-context))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
633 (progn (goto-char (cdr langelem))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
634 (if (eq (char-after) ?{)
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
635 (c-safe (c-forward-sexp -1)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
636 (looking-at "\\<do\\>[^_]")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
637 '(before)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638 '(before after)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
639
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
640 (defun c-gnu-impose-minimum ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641 "Imposes a minimum indentation for lines inside a top-level construct.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
642 The variable `c-label-minimum-indentation' specifies the minimum
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643 indentation amount."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644 (let ((non-top-levels '(defun-block-intro statement statement-cont
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645 statement-block-intro statement-case-intro
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
646 statement-case-open substatement substatement-open
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647 case-label label do-while-closure else-clause
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
648 ))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
649 (syntax c-syntactic-context)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
650 langelem)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651 (while syntax
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652 (setq langelem (car (car syntax))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653 syntax (cdr syntax))
30407
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
654 ;; don't adjust macro or comment-only lines
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
655 (cond ((memq langelem '(cpp-macro comment-intro))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
656 (setq syntax nil))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657 ((memq langelem non-top-levels)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
658 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
659 (setq syntax nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
660 (back-to-indentation)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
661 (if (zerop (current-column))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
662 (insert (make-string c-label-minimum-indentation 32)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
663 ))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
664 ))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
666
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
667 ;; Useful for c-hanging-semi&comma-criteria
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
668
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669 (defun c-semi&comma-inside-parenlist ()
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
670 "Controls newline insertion after semicolons in parenthesis lists.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 If a comma was inserted, no determination is made. If a semicolon was
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672 inserted inside a parenthesis list, no newline is added otherwise a
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673 newline is added. In either case, checking is stopped. This supports
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674 exactly the old newline insertion behavior."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 ;; newline only after semicolon, but only if that semicolon is not
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676 ;; inside a parenthesis list (e.g. a for loop statement)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
677 (if (not (eq last-command-char ?\;))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
678 nil ; continue checking
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
679 (if (condition-case nil
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
680 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681 (up-list -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
682 (not (eq (char-after) ?\()))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
683 (error t))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
684 t
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
685 'stop)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
687 ;; Suppresses newlines before non-blank lines
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
688 (defun c-semi&comma-no-newlines-before-nonblanks ()
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
689 "Controls newline insertion after semicolons.
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
690 If a comma was inserted, no determination is made. If a semicolon was
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
691 inserted, and the following line is not blank, no newline is inserted.
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
692 Otherwise, no determination is made."
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
693 (save-excursion
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
694 (if (and (= last-command-char ?\;)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
695 ;;(/= (point-max)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
696 ;; (save-excursion (skip-syntax-forward " ") (point))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
697 (zerop (forward-line 1))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
698 (not (looking-at "^[ \t]*$")))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
699 'stop
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
700 nil)))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
701
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
702 ;; Suppresses new lines after semicolons in one-liners methods
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
703 (defun c-semi&comma-no-newlines-for-oneline-inliners ()
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
704 "Controls newline insertion after semicolons for some one-line methods.
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
705 If a comma was inserted, no determination is made. Newlines are
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
706 suppressed in one-liners, if the line is an in-class inline function.
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
707 For other semicolon contexts, no determination is made."
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
708 (let ((syntax (c-guess-basic-syntax))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
709 (bol (save-excursion
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
710 (if (c-safe (up-list -1) t)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
711 (c-point 'bol)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
712 -1))))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
713 (if (and (eq last-command-char ?\;)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
714 (eq (car (car syntax)) 'inclass)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
715 (eq (car (car (cdr syntax))) 'topmost-intro)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
716 (= (c-point 'bol) bol))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
717 'stop
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
718 nil)))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
719
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
720
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
721 (cc-provide 'cc-align)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
722 ;;; cc-align.el ends here