annotate lisp/progmodes/cc-align.el @ 70142:aaccd198c2be

*** empty log message ***
author Nick Roberts <nickrob@snap.net.nz>
date Thu, 20 Apr 2006 23:00:16 +0000
parents 3d8b060d10fb
children 6086ff65590f 8a1ee48a8386
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
69140
3d8b060d10fb cc-align.el, cc-awk.el, cc-bytecomp.el, cc-cmds.el, cc-compat.el,
Alan Mackenzie <acm@muc.de>
parents: 68773
diff changeset
3 ;; Copyright (C) 1985,1987,1992-2003, 2004, 2005, 2006 Free Software
3d8b060d10fb cc-align.el, cc-awk.el, cc-bytecomp.el, cc-cmds.el, cc-compat.el,
Alan Mackenzie <acm@muc.de>
parents: 68773
diff changeset
4 ;; Foundation, Inc.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
6 ;; Authors: 1998- Martin Stjernholm
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
7 ;; 1992-1999 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
62641
27b53b1903b6 2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents: 56646
diff changeset
28 ;; along with this program; see the file COPYING. If not, write to
27b53b1903b6 2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents: 56646
diff changeset
29 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
27b53b1903b6 2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents: 56646
diff changeset
30 ;; Boston, MA 02110-1301, USA.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
38422
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 36920
diff changeset
32 ;;; Commentary:
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 36920
diff changeset
33
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 36920
diff changeset
34 ;;; Code:
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 36920
diff changeset
35
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 (eval-when-compile
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
37 (let ((load-path
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
38 (if (and (boundp 'byte-compile-dest-file)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
39 (stringp byte-compile-dest-file))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
40 (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
41 load-path)))
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
42 (load "cc-bytecomp" nil t)))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
43
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
44 (cc-require 'cc-defs)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
45 (cc-require 'cc-vars)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
46 (cc-require 'cc-engine)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
49 ;; Standard line-up functions
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
50 ;;
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
51 ;; See the section "Custom Indentation Functions" in the manual for
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
52 ;; details on the calling convention.
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
53
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
54 (defun c-lineup-topmost-intro-cont (langelem)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
55 "Line up declaration continuation lines zero or one indentation step.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
56 For lines in the \"header\" of a definition, zero is used. For other
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
57 lines, `c-basic-offset' is added to the indentation. E.g:
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
58
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
59 int
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
60 neg (int i) <- c-lineup-topmost-intro-cont
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
61 {
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
62 return -i;
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
63 }
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
64
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
65 struct
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
66 larch <- c-lineup-topmost-intro-cont
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
67 {
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
68 double height;
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
69 }
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
70 the_larch, <- c-lineup-topmost-intro-cont
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
71 another_larch; <- c-lineup-topmost-intro-cont
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
72 <--> c-basic-offset
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
73
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
74 struct larch
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
75 the_larch, <- c-lineup-topmost-intro-cont
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
76 another_larch; <- c-lineup-topmost-intro-cont
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
77
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
78 \(This function is mainly provided to mimic the behavior of CC Mode
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
79 5.28 and earlier where this case wasn't handled consistently so that
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
80 these lines could be analyzed as either topmost-intro-cont or
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
81 statement-cont.)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
82
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
83 Works with: topmost-intro-cont."
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
84 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
85 (beginning-of-line)
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
86 (c-backward-syntactic-ws (c-langelem-pos langelem))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
87 (if (and (memq (char-before) '(?} ?,))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
88 (not (and c-overloadable-operators-regexp
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
89 (c-after-special-operator-id))))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
90 c-basic-offset)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
91
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
92 (defun c-block-in-arglist-dwim (arglist-start)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
93 ;; This function implements the DWIM to avoid far indentation of
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
94 ;; brace block constructs in arguments in `c-lineup-arglist' etc.
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
95 ;; Return non-nil if a brace block construct is detected within the
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
96 ;; arglist starting at ARGLIST-START.
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
97
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
98 (or
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
99 ;; Check if the syntactic context contains any of the symbols for
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
100 ;; in-expression constructs. This can both save the work that we
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
101 ;; have to do below, and it also detect the brace list constructs
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
102 ;; that `c-looking-at-inexpr-block' currently misses (they are
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
103 ;; recognized by `c-inside-bracelist-p' instead).
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
104 (assq 'inexpr-class c-syntactic-context)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
105 (assq 'inexpr-statement c-syntactic-context)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
106 (assq 'inlambda c-syntactic-context)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
107
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
108 (save-restriction
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
109 ;; Search for open braces from the arglist start to the end of the
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
110 ;; line.
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
111 (narrow-to-region arglist-start (c-point 'eol arglist-start))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
112
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
113 (goto-char arglist-start)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
114 (while (and (c-syntactic-re-search-forward "{" nil t)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
115 (progn
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
116 (backward-char)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
117 (or
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
118 ;; Ignore starts of special brace lists.
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
119 (and c-special-brace-lists
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
120 (save-restriction
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
121 (widen)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
122 (c-looking-at-special-brace-list)))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
123 ;; Ignore complete blocks.
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
124 (c-safe (c-forward-sexp) t))))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
125 (forward-char))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
126
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
127 (looking-at "{"))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
128
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
129 (let (containing-sexp)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
130 (goto-char arglist-start)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
131 ;; `c-syntactic-eol' always matches somewhere on the line.
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
132 (re-search-forward c-syntactic-eol)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
133 (goto-char (match-beginning 0))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
134 (c-forward-syntactic-ws)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
135 (setq containing-sexp (c-most-enclosing-brace (c-parse-state)))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
136 (c-looking-at-inexpr-block
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
137 (c-safe-position (or containing-sexp (point)) c-state-cache)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
138 containing-sexp))))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
139
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (defun c-lineup-arglist (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
141 "Line up the current argument line under the first argument.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
142
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
143 As a special case, if the indented line is inside a brace block
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
144 construct, the indentation is `c-basic-offset' only. This is intended
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
145 as a \"DWIM\" measure in cases like macros that contains statement
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
146 blocks, e.g:
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
147
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
148 A_VERY_LONG_MACRO_NAME ({
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
149 some (code, with + long, lines * in[it]);
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
150 });
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
151 <--> c-basic-offset
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
152
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
153 This is motivated partly because it's more in line with how code
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
154 blocks are handled, and partly since it approximates the behavior of
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
155 earlier CC Mode versions, which due to inaccurate analysis tended to
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
156 indent such cases this way.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
157
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
158 Works with: arglist-cont-nonempty, arglist-close."
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
159 (save-excursion
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
160 (let ((indent-pos (point)))
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
161
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
162 (if (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
163 c-basic-offset ; DWIM case.
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
164
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
165 ;; Normal case. Indent to the token after the arglist open paren.
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
166 (goto-char (c-langelem-2nd-pos c-syntactic-element))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
167 (if (and c-special-brace-lists
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
168 (c-looking-at-special-brace-list))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
169 ;; Skip a special brace list opener like "({".
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
170 (progn (c-forward-token-2)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
171 (forward-char))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
172 (forward-char))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
173 (let ((arglist-content-start (point)))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
174 (c-forward-syntactic-ws)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
175 (when (< (point) indent-pos)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
176 (goto-char arglist-content-start)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
177 (skip-chars-forward " \t"))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
178 (vector (current-column)))))))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
179
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
180 ;; Contributed by Kevin Ryde <user42@zip.com.au>.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
181 (defun c-lineup-argcont (elem)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
182 "Line up a continued argument.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
183
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
184 foo (xyz, aaa + bbb + ccc
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
185 + ddd + eee + fff); <- c-lineup-argcont
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
186
50860
4fd35ed09e9b (c-lineup-argcont, c-lineup-gcc-asm-reg): Don't quote nil and t in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents: 44728
diff changeset
187 Only continuation lines like this are touched, nil is returned on lines
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
188 which are the start of an argument.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
189
63516
1975a7b1ec5f (c-lineup-argcont): Fix spelling in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents: 62641
diff changeset
190 Within a gcc asm block, \":\" is recognized as an argument separator,
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
191 but of course only between operand specifications, not in the expressions
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
192 for the operands.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
193
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
194 Works with: arglist-cont, arglist-cont-nonempty."
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
195
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (save-excursion
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
197 (beginning-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
198
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
199 (when (eq (car elem) 'arglist-cont-nonempty)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
200 ;; Our argument list might not be the innermost one. If it
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
201 ;; isn't, go back to the last position in it. We do this by
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
202 ;; stepping back over open parens until we get to the open paren
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
203 ;; of our argument list.
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
204 (let ((open-paren (c-langelem-2nd-pos c-syntactic-element))
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
205 (paren-state (c-parse-state)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
206 (while (not (eq (car paren-state) open-paren))
62641
27b53b1903b6 2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents: 56646
diff changeset
207 (unless (consp (car paren-state)) ;; ignore matched braces
27b53b1903b6 2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents: 56646
diff changeset
208 (goto-char (car paren-state)))
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
209 (setq paren-state (cdr paren-state)))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
210
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
211 (let ((start (point)) c)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
212
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
213 (when (bolp)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
214 ;; Previous line ending in a comma means we're the start of an
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
215 ;; argument. This should quickly catch most cases not for us.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
216 ;; This case is only applicable if we're the innermost arglist.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
217 (c-backward-syntactic-ws)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
218 (setq c (char-before)))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
219
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
220 (unless (eq c ?,)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
221 ;; In a gcc asm, ":" on the previous line means the start of an
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
222 ;; argument. And lines starting with ":" are not for us, don't
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
223 ;; want them to indent to the preceding operand.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
224 (let ((gcc-asm (save-excursion
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
225 (goto-char start)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
226 (c-in-gcc-asm-p))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
227 (unless (and gcc-asm
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
228 (or (eq c ?:)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
229 (save-excursion
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
230 (goto-char start)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
231 (looking-at "[ \t]*:"))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
232
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
233 (c-lineup-argcont-scan (if gcc-asm ?:))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
234 (vector (current-column))))))))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
235
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
236 (defun c-lineup-argcont-scan (&optional other-match)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
237 ;; Find the start of an argument, for `c-lineup-argcont'.
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
238 (when (zerop (c-backward-token-2 1 t))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
239 (let ((c (char-after)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
240 (if (or (eq c ?,) (eq c other-match))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
241 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
242 (forward-char)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
243 (c-forward-syntactic-ws))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
244 (c-lineup-argcont-scan other-match)))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (defun c-lineup-arglist-intro-after-paren (langelem)
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
247 "Line up a line to just after the open paren of the surrounding paren
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
248 or brace block.
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
249
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
250 Works with: defun-block-intro, brace-list-intro,
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
251 statement-block-intro, statement-case-intro, arglist-intro."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (save-excursion
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
253 (beginning-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
254 (backward-up-list 1)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
255 (skip-chars-forward " \t" (c-point 'eol))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
256 (vector (1+ (current-column)))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (defun c-lineup-arglist-close-under-paren (langelem)
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
259 "Line up a line under the enclosing open paren.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
260 Normally used to line up a closing paren in the same column as its
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
261 corresponding open paren, but can also be used with arglist-cont and
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
262 arglist-cont-nonempty to line up all lines inside a parenthesis under
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
263 the open paren.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
264
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
265 As a special case, if a brace block construct starts at the same line
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
266 as the open parenthesis of the argument list, the indentation is
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
267 `c-basic-offset' only. See `c-lineup-arglist' for further discussion
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
268 of this \"DWIM\" measure.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
269
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
270 Works with: Almost all symbols, but are typically most useful on
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
271 arglist-close, brace-list-close, arglist-cont and arglist-cont-nonempty."
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
272 (save-excursion
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
273 (if (memq (c-langelem-sym langelem)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
274 '(arglist-cont-nonempty arglist-close))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
275 (goto-char (c-langelem-2nd-pos c-syntactic-element))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
276 (beginning-of-line)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
277 (c-go-up-list-backward))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
278
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
279 (if (save-excursion (c-block-in-arglist-dwim (point)))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
280 c-basic-offset ; DWIM case.
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
281
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
282 ;; Normal case. Indent to the arglist open paren.
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
283 (let (special-list)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
284 (if (and c-special-brace-lists
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
285 (setq special-list (c-looking-at-special-brace-list)))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
286 ;; Cope if we're in the middle of a special brace list
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
287 ;; opener like "({".
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
288 (goto-char (car (car special-list))))
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
289 (vector (current-column))))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
290
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
291 (defun c-lineup-arglist-operators (langelem)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
292 "Line up lines starting with an infix operator under the open paren.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
293 Return nil on lines that don't start with an operator, to leave those
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
294 cases to other line-up functions. Example:
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
295
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
296 if ( x < 10
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
297 || at_limit (x, <- c-lineup-arglist-operators
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
298 list) <- c-lineup-arglist-operators returns nil
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
299 )
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
300
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
301 Since this function doesn't do anything for lines without an infix
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
302 operator you typically want to use it together with some other line-up
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
303 settings, e.g. as follows \(the arglist-close setting is just a
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
304 suggestion to get a consistent style):
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
305
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
306 \(c-set-offset 'arglist-cont '(c-lineup-arglist-operators 0))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
307 \(c-set-offset 'arglist-cont-nonempty '(c-lineup-arglist-operators
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
308 c-lineup-arglist))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
309 \(c-set-offset 'arglist-close '(c-lineup-arglist-close-under-paren))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
310
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
311 Works with: arglist-cont, arglist-cont-nonempty."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 (save-excursion
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
313 (back-to-indentation)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
314 (when (looking-at "[-+|&*%<>=]\\|\\(/[^/*]\\)")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
315 ;; '-' can be both an infix and a prefix operator, but I'm lazy now..
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
316 (c-lineup-arglist-close-under-paren langelem))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
318 (defun c-lineup-close-paren (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
319 "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
320 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
321 indentation is added. E.g:
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
322
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
323 main (int, main (
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
324 char ** int, char **
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
325 ) <-> ) <- c-lineup-close-paren
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
326
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
327 As a special case, if a brace block construct starts at the same line
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
328 as the open parenthesis of the argument list, the indentation is
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
329 `c-basic-offset' instead of the open paren column. See
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
330 `c-lineup-arglist' for further discussion of this \"DWIM\" measure.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
331
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
332 Works with: All *-close symbols."
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
333 (save-excursion
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
334 (if (memq (c-langelem-sym langelem)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
335 '(arglist-cont-nonempty arglist-close))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
336 (goto-char (c-langelem-2nd-pos c-syntactic-element))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
337 (beginning-of-line)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
338 (c-go-up-list-backward))
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
339
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
340 (let (special-list arglist-start)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
341 (if (and c-special-brace-lists
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
342 (setq special-list (c-looking-at-special-brace-list)))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
343 ;; Cope if we're in the middle of a special brace list
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
344 ;; opener like "({".
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
345 (progn
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
346 (goto-char (setq arglist-start (car (car special-list))))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
347 (c-forward-token-2)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
348 (forward-char))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
349 (setq arglist-start (point))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
350 (forward-char))
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
351
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
352 (cond ((looking-at c-syntactic-eol)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
353 0) ; The arglist is "empty".
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
354
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
355 ((c-block-in-arglist-dwim (point))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
356 c-basic-offset) ; DWIM case.
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
357
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
358 (t
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
359 ;; Normal case. Indent to the arglist open paren.
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
360 (goto-char arglist-start)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
361 (vector (current-column)))))))
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
362
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 (defun c-lineup-streamop (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
364 "Line up C++ stream operators under each other.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
365
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
366 Works with: stream-op."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 (save-excursion
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
368 (goto-char (c-langelem-pos langelem))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
369 (re-search-forward "<<\\|>>" (c-point 'eol) 'move)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
370 (goto-char (match-beginning 0))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
371 (vector (current-column))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 (defun c-lineup-multi-inher (langelem)
30407
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
374 "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
375 initializers under each other. E.g:
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
376
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
377 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
378 public Cyphr, Cyphr (a),
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
379 public Bar <-> Bar (b) <- c-lineup-multi-inher
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
380
30407
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
381 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
382 : public Cyphr, : Cyphr (a),
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
383 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
384
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
385 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
386 : public Cyphr : Cyphr (a)
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
387 , 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
388
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
389 Works with: inher-cont, member-init-cont."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 (save-excursion
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
391 (back-to-indentation)
30407
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
392 (let* ((eol (c-point 'eol))
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
393 (here (point))
56646
b7446b6f097d Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents: 53073
diff changeset
394 (char-after-ip (char-after)))
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
395 (if (c-langelem-pos langelem)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
396 (goto-char (c-langelem-pos langelem)))
30407
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
397
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
398 ;; 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
399 ;; 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
400 (c-backward-syntactic-ws)
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
401 (when (eq (char-before) ?:)
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
402 (backward-char)
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
403 (c-backward-syntactic-ws))
b88ff2eabd4e (c-lineup-multi-inher): Handle lines with
Gerd Moellmann <gerd@gnu.org>
parents: 26817
diff changeset
404
56646
b7446b6f097d Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents: 53073
diff changeset
405 (c-syntactic-re-search-forward ":" eol 'move)
b7446b6f097d Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents: 53073
diff changeset
406 (if (looking-at c-syntactic-eol)
b7446b6f097d Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents: 53073
diff changeset
407 (c-forward-syntactic-ws here)
b7446b6f097d Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents: 53073
diff changeset
408 (if (eq char-after-ip ?,)
b7446b6f097d Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents: 53073
diff changeset
409 (backward-char)
b7446b6f097d Updated CC Mode to 5.30.9.
Martin Stjernholm <mast@lysator.liu.se>
parents: 53073
diff changeset
410 (skip-chars-forward " \t" eol)))
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
411 (if (< (point) here)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
412 (vector (current-column)))
18720
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-java-inher (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
416 "Line up Java implements and extends declarations.
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
417 If class names follow on the same line as the implements/extends
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
418 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
419 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
420 E.g:
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
421
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
422 class Foo class Foo
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
423 extends extends Cyphr,
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
424 Bar <-> Bar <- c-lineup-java-inher
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
425 <--> c-basic-offset
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: inher-cont."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 (save-excursion
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
429 (goto-char (c-langelem-pos langelem))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
430 (forward-word 1)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
431 (if (looking-at "[ \t]*$")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
432 c-basic-offset
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
433 (c-forward-syntactic-ws)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
434 (vector (current-column)))))
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-java-throws (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
437 "Line up Java throws declarations.
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
438 If exception names follow on the same line as the throws keyword,
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
439 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
440 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
441 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
442 function declaration start if it doesn't hang. E.g:
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
443
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
444 int foo() int foo() throws Cyphr,
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
445 throws <-> Bar, <- c-lineup-java-throws
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
446 Bar <-> Vlod <- c-lineup-java-throws
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
447 <--><--> c-basic-offset
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
448
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
449 Works with: func-decl-cont."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 (save-excursion
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
451 (let* ((lim (1- (c-point 'bol)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
452 (throws (catch 'done
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
453 (goto-char (c-langelem-pos langelem))
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
454 (while (zerop (c-forward-token-2 1 t lim))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
455 (if (looking-at "throws\\>[^_]")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
456 (throw 'done t))))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
457 (if throws
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
458 (if (zerop (c-forward-token-2 1 nil (c-point 'eol)))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
459 (vector (current-column))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
460 (back-to-indentation)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
461 (vector (+ (current-column) c-basic-offset)))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
462 c-basic-offset))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
464 (defun c-indent-one-line-block (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
465 "Indent a one line block `c-basic-offset' extra.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
466 E.g:
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
467
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
468 if (n > 0) if (n > 0)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
469 {m+=n; n=0;} <-> { <- c-indent-one-line-block
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
470 <--> c-basic-offset m+=n; n=0;
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
471 }
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
472
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
473 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
474 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
475 function usable in list expressions.
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
476
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
477 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
478 (save-excursion
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
479 (let ((eol (c-point 'eol)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
480 (back-to-indentation)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
481 (if (and (eq (char-syntax (char-after)) ?\()
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
482 (c-safe (progn (c-forward-sexp) t))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
483 (<= (point) eol))
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
484 c-basic-offset
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
485 nil))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
486
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
487 (defun c-indent-multi-line-block (langelem)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
488 "Indent a multi line block `c-basic-offset' extra.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
489 E.g:
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
490
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
491 int *foo[] = { int *foo[] = {
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
492 NULL, NULL,
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
493 {17}, <-> { <- c-indent-multi-line-block
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
494 17
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
495 }
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
496 <--> c-basic-offset
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
497
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
498 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
499 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
500 function usable in list expressions.
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
501
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
502 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
503 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
504 (let ((eol (c-point 'eol)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
505 (back-to-indentation)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
506 (if (and (eq (char-syntax (char-after)) ?\()
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
507 (or (not (c-safe (progn (c-forward-sexp) t)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
508 (> (point) eol)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
509 c-basic-offset
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
510 nil))))
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
511
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 (defun c-lineup-C-comments (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
513 "Line up C block comment continuation lines.
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
514 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
515 styles. Some examples:
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
516
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
517 /* /** /* /* text /* /**
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
518 * text * text text text ** text ** text
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
519 */ */ */ */ */ */
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
520
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
521 /*********************************************************************
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
522 * text
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
523 ********************************************************************/
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
524
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 Free form text comments:
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
527 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
528 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
529 prefix. The delimiter line is whatever matches the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
530 `comment-start-skip' regexp.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
531 *********************************************************************/
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
532
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
533 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
534 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
535 inside a comment.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
536
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
537 Works with: The `c' syntactic symbol."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 (save-excursion
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
539 (let* ((here (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
540 (prefixlen (progn (back-to-indentation)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
541 (if (looking-at c-current-comment-prefix)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
542 (- (match-end 0) (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
543 0)))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
544 (starterlen
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
545 ;; Get the length of the comment starter, not including
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
546 ;; the first '/'. We check if the comment prefix matched
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
547 ;; on the current line matches the starter or if it
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
548 ;; matches comment-start-skip, and choose whichever is
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
549 ;; longest.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
550 (max (save-excursion
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
551 (goto-char (1+ (c-langelem-pos langelem)))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
552 (if (and (match-string 0)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
553 (looking-at (regexp-quote (match-string 0))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
554 (- (match-end 0) (match-beginning 0))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
555 0))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
556 (save-excursion
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
557 (goto-char (c-langelem-pos langelem))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
558 (looking-at comment-start-skip)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
559 (- (or (match-end 1)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
560 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
561 (goto-char (match-end 0))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
562 (skip-chars-backward " \t")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
563 (point)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
564 (point)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
565 1)))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
566 (if (and (> starterlen 10) (zerop prefixlen))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
567 ;; 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
568 ;; a nonempty comment prefix. Treat it as free form text
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
569 ;; and don't change the indentation.
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
570 (vector (current-column))
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
571 ;; Go back to the previous non-blank line, if any.
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
572 (while
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
573 (progn
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
574 (forward-line -1)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
575 (back-to-indentation)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
576 (and (> (point) (c-langelem-pos langelem))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
577 (looking-at "[ \t]*$"))))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
578 ;; Is the starting line the first continuation line with content?
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
579 (if (>= (c-langelem-pos langelem) (point))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
580 (if (zerop prefixlen)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
581 ;; No nonempty comment prefix. Align after comment
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
582 ;; starter.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
583 (progn
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
584 (looking-at comment-start-skip)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
585 (goto-char (match-end 0))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
586 ;; The following should not be necessary, since
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
587 ;; comment-start-skip should match everything (i.e.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
588 ;; typically whitespace) that leads up to the text.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
589 ;;(if (looking-at "\\([ \t]+\\).+$")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
590 ;; ;; Align with the text that hangs after the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
591 ;; ;; comment starter.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
592 ;; (goto-char (match-end 1)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
593 (vector (current-column)))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
594 ;; How long is the comment starter? if greater than the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
595 ;; length of the comment prefix, align left. if less
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
596 ;; than or equal, align right. this should also pick up
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
597 ;; Javadoc style comments.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
598 (if (> starterlen prefixlen)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
599 (progn
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
600 (goto-char (c-langelem-pos langelem))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
601 (vector (1+ (current-column))))
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
602 (goto-char (+ (c-langelem-pos langelem) starterlen 1))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
603 (vector (- (current-column) prefixlen))))
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
604 ;; We didn't start on the first non-blank continuation line. If the
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
605 ;; previous line has a nonempty comment prefix, align with it.
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
606 ;; Otherwise, align with the previous nonempty line, but align the
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
607 ;; comment ender with the starter.
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
608 (when (or (not (looking-at c-current-comment-prefix))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
609 (eq (match-beginning 0) (match-end 0)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
610 (goto-char here)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
611 (back-to-indentation)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
612 (if (looking-at (concat "\\(" c-current-comment-prefix "\\)\\*/"))
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
613 (goto-char (c-langelem-pos langelem))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
614 (while (and (zerop (forward-line -1))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
615 (looking-at "^[ \t]*$")))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
616 (back-to-indentation)
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
617 (if (< (point) (c-langelem-pos langelem))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
618 ;; Align with the comment starter rather than
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
619 ;; with the code before it.
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
620 (goto-char (c-langelem-pos langelem)))))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
621 (vector (current-column)))))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
622
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
623 (defun c-lineup-comment (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
624 "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
625 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
626 line, that alignment is preserved.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
627
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
628 Works with: comment-intro."
18720
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 (back-to-indentation)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
631 (let ((col (current-column)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 (cond
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
633 ;; CASE 1: preserve aligned comments
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
634 ((save-excursion
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
635 (and (c-backward-single-comment)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
636 (= col (current-column))))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
637 (vector col)) ; Return an absolute column.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638 ;; indent as specified by c-comment-only-line-offset
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
639 ((not (bolp))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
640 (or (car-safe c-comment-only-line-offset)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641 c-comment-only-line-offset))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
642 (t
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643 (or (cdr-safe c-comment-only-line-offset)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
644 (car-safe c-comment-only-line-offset)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
645 -1000)) ;jam it against the left side
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
646 ))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
648 (defun c-lineup-knr-region-comment (langelem)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
649 "Line up a comment in the \"K&R region\" with the declaration.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
650 That is the region between the function or class header and the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
651 beginning of the block. E.g:
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
652
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
653 int main()
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
654 /* This is the main function. */ <- c-lineup-knr-region-comment
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
655 {
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
656 return 0;
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
657 }
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
658
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
659 Return nil if called in any other situation, to be useful in list
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
660 expressions.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
661
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
662 Works with: comment-intro."
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
663 (when (or (assq 'topmost-intro-cont c-syntactic-context)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
664 (assq 'func-decl-cont c-syntactic-context)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
665 (assq 'knr-argdecl-intro c-syntactic-context)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
666 (assq 'lambda-intro-cont c-syntactic-context))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
667 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
668 (beginning-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
669 (c-beginning-of-statement-1)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
670 (vector (current-column)))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
671
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672 (defun c-lineup-runin-statements (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
673 "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
674 the block opening brace. E.g:
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
675
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
676 int main()
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
677 { puts (\"Hello world!\");
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
678 return 0; <- c-lineup-runin-statements
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
679 }
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
680
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
681 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
682 returned. This makes the function usable in list expressions.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
683
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
684 Works with: The `statement' syntactic symbol."
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
685 (if (eq (char-after (c-langelem-pos langelem)) ?{)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686 (save-excursion
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
687 (if (c-langelem-pos langelem)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
688 (goto-char (c-langelem-pos langelem)))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
689 (forward-char 1)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
690 (skip-chars-forward " \t")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
691 (unless (eolp)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
692 (vector (current-column))))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
693
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
694 (defun c-lineup-assignments (langelem)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
695 "Line up the current line after the assignment operator on the first
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
696 line in the statement. If there isn't any, return nil to allow
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
697 stacking with other line-up functions. If the current line contains
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
698 an assignment operator too, try to align it with the first one.
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
699
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
700 Works with: topmost-intro-cont, statement-cont, arglist-cont,
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
701 arglist-cont-nonempty."
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
702 (let (startpos endpos equalp)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
703
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
704 (if (eq (c-langelem-sym langelem) 'arglist-cont-nonempty)
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
705 ;; If it's an arglist-cont-nonempty then we're only interested
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
706 ;; in equal signs outside it. We don't search for a "=" on
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
707 ;; the current line since that'd have a different nesting
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
708 ;; compared to the one we should align with.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
709 (save-excursion
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
710 (save-restriction
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
711 (setq endpos (c-langelem-2nd-pos c-syntactic-element))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
712 (narrow-to-region (c-langelem-pos langelem) endpos)
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
713 (if (setq startpos (c-up-list-backward endpos))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
714 (setq startpos (1+ startpos))
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
715 (setq startpos (c-langelem-pos langelem)))))
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
716
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
717 (setq startpos (c-langelem-pos langelem)
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
718 endpos (point))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
719
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
720 ;; Find a syntactically relevant and unnested "=" token on the
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
721 ;; current line. equalp is in that case set to the number of
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
722 ;; columns to left shift the current line to align it with the
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
723 ;; goal column.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
724 (save-excursion
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
725 (beginning-of-line)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
726 (when (c-syntactic-re-search-forward
52341
6a060e586596 (c-lineup-math): Don't align the operators "!=", "<=" and ">=" as assignment
Martin Stjernholm <mast@lysator.liu.se>
parents: 51714
diff changeset
727 c-assignment-op-regexp
6a060e586596 (c-lineup-math): Don't align the operators "!=", "<=" and ">=" as assignment
Martin Stjernholm <mast@lysator.liu.se>
parents: 51714
diff changeset
728 (c-point 'eol) t t t)
6a060e586596 (c-lineup-math): Don't align the operators "!=", "<=" and ">=" as assignment
Martin Stjernholm <mast@lysator.liu.se>
parents: 51714
diff changeset
729 (setq equalp (- (or (match-beginning 1)
6a060e586596 (c-lineup-math): Don't align the operators "!=", "<=" and ">=" as assignment
Martin Stjernholm <mast@lysator.liu.se>
parents: 51714
diff changeset
730 (match-end 0))
6a060e586596 (c-lineup-math): Don't align the operators "!=", "<=" and ">=" as assignment
Martin Stjernholm <mast@lysator.liu.se>
parents: 51714
diff changeset
731 (c-point 'boi))))))
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
732
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
733 (save-excursion
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
734 (goto-char startpos)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
735 (if (or (if (c-syntactic-re-search-forward
52341
6a060e586596 (c-lineup-math): Don't align the operators "!=", "<=" and ">=" as assignment
Martin Stjernholm <mast@lysator.liu.se>
parents: 51714
diff changeset
736 c-assignment-op-regexp
6a060e586596 (c-lineup-math): Don't align the operators "!=", "<=" and ">=" as assignment
Martin Stjernholm <mast@lysator.liu.se>
parents: 51714
diff changeset
737 (min endpos (c-point 'eol)) t t t)
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
738 (progn
52341
6a060e586596 (c-lineup-math): Don't align the operators "!=", "<=" and ">=" as assignment
Martin Stjernholm <mast@lysator.liu.se>
parents: 51714
diff changeset
739 (goto-char (or (match-beginning 1)
6a060e586596 (c-lineup-math): Don't align the operators "!=", "<=" and ">=" as assignment
Martin Stjernholm <mast@lysator.liu.se>
parents: 51714
diff changeset
740 (match-end 0)))
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
741 nil)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
742 t)
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
743 (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
744 (c-forward-syntactic-ws (c-point 'eol))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
745 (eolp)))
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
746 ;; There's no equal sign on the line, or there is one but
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
747 ;; nothing follows it.
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
748 nil
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
749
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
750 ;; calculate indentation column after equals and ws, unless
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
751 ;; our line contains an equals sign
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
752 (if (not equalp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
753 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
754 (skip-chars-forward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
755 (setq equalp 0)))
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
756
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
757 (vector (- (current-column) equalp)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
758 )))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
759
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
760 (defun c-lineup-math (langelem)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
761 "Like `c-lineup-assignments' but indent with `c-basic-offset' if no
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
762 assignment operator was found on the first line. I.e. this function
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
763 is the same as specifying a list (c-lineup-assignments +). It's
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
764 provided for compatibility with old configurations.
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
765
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
766 Works with: topmost-intro-cont, statement-cont, arglist-cont,
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
767 arglist-cont-nonempty."
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
768 (or (c-lineup-assignments langelem)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
769 c-basic-offset))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
770
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
771 (defun c-lineup-cascaded-calls (langelem)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
772 "Line up \"cascaded calls\" under each other.
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
773 If the line begins with \"->\" or \".\" and the preceding line ends
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
774 with one or more function calls preceded by the same token, then the
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
775 arrow is lined up with the first of those tokens. E.g:
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
776
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
777 result = proc->add(17)->add(18)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
778 ->add(19) + <- c-lineup-cascaded-calls
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
779 offset; <- c-lineup-cascaded-calls (inactive)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
780
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
781 In any other situation nil is returned to allow use in list
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
782 expressions.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
783
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
784 Works with: topmost-intro-cont, statement-cont, arglist-cont,
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
785 arglist-cont-nonempty."
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
786
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
787 (if (and (eq (c-langelem-sym langelem) 'arglist-cont-nonempty)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
788 (not (eq (c-langelem-2nd-pos c-syntactic-element)
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
789 (c-most-enclosing-brace (c-parse-state)))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
790 ;; The innermost open paren is not our one, so don't do
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
791 ;; anything. This can occur for arglist-cont-nonempty with
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
792 ;; nested arglist starts on the same line.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
793 nil
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
794
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
795 (save-excursion
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
796 (back-to-indentation)
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
797 (let ((operator (and (looking-at "->\\|\\.")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
798 (regexp-quote (match-string 0))))
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
799 (stmt-start (c-langelem-pos langelem)) col)
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
800
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
801 (when (and operator
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
802 (looking-at operator)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
803 (zerop (c-backward-token-2 1 t stmt-start))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
804 (eq (char-after) ?\()
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
805 (zerop (c-backward-token-2 2 t stmt-start))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
806 (looking-at operator))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
807 (setq col (current-column))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
808
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
809 (while (and (zerop (c-backward-token-2 1 t stmt-start))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
810 (eq (char-after) ?\()
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
811 (zerop (c-backward-token-2 2 t stmt-start))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
812 (looking-at operator))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
813 (setq col (current-column)))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
814
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
815 (vector col))))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
816
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
817 (defun c-lineup-string-cont (langelem)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
818 "Line up a continued string under the one it continues.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
819 A continued string in this sense is where a string literal follows
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
820 directly after another one. E.g:
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
821
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
822 result = prefix + \"A message \"
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
823 \"string.\"; <- c-lineup-string-cont
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
824
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
825 Nil is returned in other situations, to allow stacking with other
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
826 line-up functions.
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
827
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
828 Works with: topmost-intro-cont, statement-cont, arglist-cont,
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
829 arglist-cont-nonempty."
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
830 (save-excursion
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
831 (back-to-indentation)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
832 (and (looking-at "\\s\"")
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
833 (let ((quote (char-after)) pos)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
834 (while (and (progn (c-backward-syntactic-ws)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
835 (eq (char-before) quote))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
836 (c-safe (c-backward-sexp) t)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
837 (/= (setq pos (point)) (c-point 'boi))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
838 (when pos
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
839 (goto-char pos)
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
840 (vector (current-column)))))))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
841
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
842 (defun c-lineup-template-args (langelem)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
843 "Line up template argument lines under the first argument.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
844 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
845 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
846
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
847 Works with: template-args-cont."
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
848 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
849 (c-with-syntax-table c++-template-syntax-table
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
850 (beginning-of-line)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
851 (backward-up-list 1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
852 (if (and (eq (char-after) ?<)
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
853 (zerop (c-forward-token-2 1 nil (c-point 'eol))))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
854 (vector (current-column))))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
855
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
856 (defun c-lineup-ObjC-method-call (langelem)
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
857 "Line up selector args as Emacs Lisp mode does with function args:
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
858 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
859 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
860 from the opening bracket; otherwise you are looking at the first
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
861 character of the first method call argument, so line up the current
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
862 line with it.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
863
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
864 Works with: objc-method-call-cont."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
865 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
866 (let* ((extra (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
867 (back-to-indentation)
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
868 (c-backward-syntactic-ws (c-langelem-pos langelem))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
869 (if (eq (char-before) ?:)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
870 (- c-basic-offset)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
871 0)))
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
872 (open-bracket-pos (c-langelem-pos langelem))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
873 (open-bracket-col (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
874 (goto-char open-bracket-pos)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
875 (current-column)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
876 (target-col (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
877 (forward-char)
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
878 (c-forward-sexp)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
879 (skip-chars-forward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
880 (if (eolp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
881 (+ open-bracket-col c-basic-offset)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
882 (current-column))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
883 )
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
884 (- target-col open-bracket-col extra))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
885
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
886 (defun c-lineup-ObjC-method-args (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
887 "Line up the colons that separate args.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
888 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
889 line.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
890
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
891 Works with: objc-method-args-cont."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
892 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
893 (let* ((here (c-point 'boi))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
894 (curcol (progn (goto-char here) (current-column)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
895 (eol (c-point 'eol))
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
896 (relpos (c-langelem-pos langelem))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
897 (first-col-column (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
898 (goto-char relpos)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
899 (skip-chars-forward "^:" eol)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
900 (and (eq (char-after) ?:)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
901 (current-column)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
902 (if (not first-col-column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
903 c-basic-offset
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
904 (goto-char here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
905 (skip-chars-forward "^:" eol)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
906 (if (eq (char-after) ?:)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
907 (+ curcol (- first-col-column (current-column)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
908 c-basic-offset)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
909
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
910 (defun c-lineup-ObjC-method-args-2 (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
911 "Line up the colons that separate args.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
912 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
913 line.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
914
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
915 Works with: objc-method-args-cont."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
916 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
917 (let* ((here (c-point 'boi))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
918 (curcol (progn (goto-char here) (current-column)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
919 (eol (c-point 'eol))
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
920 (relpos (c-langelem-pos langelem))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
921 (prev-col-column (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
922 (skip-chars-backward "^:" relpos)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
923 (and (eq (char-before) ?:)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
924 (- (current-column) 1)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
925 (if (not prev-col-column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
926 c-basic-offset
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
927 (goto-char here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
928 (skip-chars-forward "^:" eol)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
929 (if (eq (char-after) ?:)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
930 (+ curcol (- prev-col-column (current-column)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
931 c-basic-offset)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
932
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
933 (defun c-lineup-inexpr-block (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
934 "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
935 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
936 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
937 \"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
938 construct.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
939
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
940 Works with: inlambda, inexpr-statement, inexpr-class."
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
941 (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
942 (back-to-indentation)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
943 (let* ((paren-state (c-parse-state))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
944 (containing-sexp (c-most-enclosing-brace paren-state))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
945 (res (or (c-looking-at-inexpr-block
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
946 (c-safe-position containing-sexp paren-state)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
947 containing-sexp)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
948 (and containing-sexp
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
949 (progn (goto-char containing-sexp)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
950 (eq (char-after) ?{))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
951 (progn (setq containing-sexp
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
952 (c-most-enclosing-brace paren-state
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
953 (point)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
954 (c-looking-at-inexpr-block
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
955 (c-safe-position containing-sexp paren-state)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
956 containing-sexp))))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
957 (when res
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
958 (goto-char (cdr res))
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
959 (vector (current-column))))))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
960
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
961 (defun c-lineup-whitesmith-in-block (langelem)
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
962 "Line up lines inside a block in Whitesmith style.
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
963 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
964 when it doesn't. E.g:
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
965
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
966 something
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
967 { something {
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
968 foo; <-> foo; <- c-lineup-whitesmith-in-block
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
969 } }
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
970 <--> c-basic-offset
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
971
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
972 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
973 second `c-basic-offset' is added.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
974
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
975 Works with: defun-close, defun-block-intro, inline-close, block-close,
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
976 brace-list-close, brace-list-intro, statement-block-intro,
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
977 arglist-intro, arglist-cont-nonempty, arglist-close, and all in*
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
978 symbols, e.g. inclass and inextern-lang."
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
979 (save-excursion
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
980 (if (and (c-go-up-list-backward)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
981 (= (point) (c-point 'boi)))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
982 nil
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
983 c-basic-offset)))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
984
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
985 (defun c-lineup-after-whitesmith-blocks (langelem)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
986 "Compensate for Whitesmith style indentation of blocks.
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
987 Due to the way CC Mode calculates anchor positions for normal lines
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
988 inside blocks, this function is necessary for those lines to get
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
989 correct Whitesmith style indentation. Consider the following
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
990 examples:
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
991
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
992 int foo()
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
993 {
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
994 int foo() {
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
995 { a;
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
996 a; }
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
997 x; <-> x; <- c-lineup-after-whitesmith-blocks
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
998
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
999 The fact that the line with \"x\" is preceded by a Whitesmith style
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1000 indented block in one case and not the other should not affect its
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1001 indentation. But since CC Mode in cases like this uses the
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1002 indentation of the preceding statement as anchor position, the \"x\"
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1003 would in the rightmost case be indented too much if the offset for
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1004 `statement' was set simply to zero.
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1005
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1006 This lineup function corrects for this situation by detecting if the
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1007 anchor position is at an open paren character. In that case, it
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1008 instead indents relative to the surrounding block just like
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1009 `c-lineup-whitesmith-in-block'.
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1010
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1011 Works with: brace-list-entry, brace-entry-open, statement,
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1012 arglist-cont."
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1013 (save-excursion
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1014 (goto-char (c-langelem-pos langelem))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1015 (when (looking-at "\\s\(")
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1016 (if (c-go-up-list-backward)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1017 (let ((pos (point)))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1018 (back-to-indentation)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1019 (if (= pos (point))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1020 (vector (current-column))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1021 (vector (+ (current-column) c-basic-offset))))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1022 (vector 0)))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
1023
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1024 (defun c-lineup-cpp-define (langelem)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1025 "Line up macro continuation lines according to the indentation of
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1026 the construct preceding the macro. E.g:
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1027
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1028 v beg of preceding constr v beg of preceding constr
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1029 int dribble() {
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1030 const char msg[] = if (!running)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1031 \"Some text.\"; error(\"Not running!\");
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1032
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1033 #define X(A, B) \ #define X(A, B) \
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1034 do { \ <-> do { \ <- c-lineup-cpp-define
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1035 printf (A, B); \ printf (A, B); \
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1036 } while (0) } while (0)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1037
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1038 If `c-syntactic-indentation-in-macros' is non-nil, the function
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1039 returns the relative indentation to the macro start line to allow
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1040 accumulation with other offsets. E.g. in the following cases,
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1041 cpp-define-intro is combined with the statement-block-intro that comes
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1042 from the \"do {\" that hangs on the \"#define\" line:
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1043
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1044 int dribble() {
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1045 const char msg[] = if (!running)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1046 \"Some text.\"; error(\"Not running!\");
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1047
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1048 #define X(A, B) do { \ #define X(A, B) do { \
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1049 printf (A, B); \ <-> printf (A, B); \ <- c-lineup-cpp-define
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1050 this->refs++; \ this->refs++; \
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1051 } while (0) <-> } while (0) <- c-lineup-cpp-define
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1052
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1053 The relative indentation returned by `c-lineup-cpp-define' is zero and
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
1054 two, respectively, in these two examples. They are then added to the
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1055 two column indentation that statement-block-intro gives in both cases
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1056 here.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1057
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1058 If the relative indentation is zero, then nil is returned instead.
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
1059 That is useful in a list expression to specify the default indentation
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
1060 on the top level.
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1061
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1062 If `c-syntactic-indentation-in-macros' is nil then this function keeps
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1063 the current indentation, except for empty lines \(ignoring the ending
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1064 backslash) where it takes the indentation from the closest preceding
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1065 nonempty line in the macro. If there's no such line in the macro then
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1066 the indentation is taken from the construct preceding it, as described
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1067 above.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1068
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1069 Works with: cpp-define-intro."
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1070 (let (offset)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1071 (if c-syntactic-indentation-in-macros
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1072 ;; Go to the macro start and do a syntactic analysis of it.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1073 ;; Then remove the cpp-macro element it should contain and
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1074 ;; calculate the indentation it then would get.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1075 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1076 (c-beginning-of-macro)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1077 (setq offset (- (c-get-syntactic-indentation
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1078 (delete '(cpp-macro) (c-guess-basic-syntax)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1079 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1080 (back-to-indentation)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1081 (current-column))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1082 (if (zerop offset)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1083 nil
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1084 offset))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1085 ;; Do not indent syntactically inside the macro.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1086 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1087 (let ((macro-start-line (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1088 (goto-char (c-query-macro-start))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1089 (beginning-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1090 (point))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1091 (beginning-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1092 ;; Check every line while inside the macro.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1093 (while (and (> (point) macro-start-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1094 (looking-at "[ \t]*\\\\?$")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1095 (= (forward-line -1) 0)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1096 (if (<= (point) macro-start-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1097 ;; If we've stepped out of the macro we take the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1098 ;; syntactic offset.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1099 (setq offset (c-get-syntactic-indentation
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1100 (delete '(cpp-macro) (c-guess-basic-syntax))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1101 (setq offset (current-indentation)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1102 (if (zerop offset)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1103 nil
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1104 (vector offset)))))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1105
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1106 ;; Contributed by Kevin Ryde <user42@zip.com.au>.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1107 (defun c-lineup-gcc-asm-reg (elem)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1108 "Line up a gcc asm register under one on a previous line.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1109
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1110 asm (\"foo %1, %0\\n\"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1111 \"bar %0, %1\"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1112 : \"=r\" (w),
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1113 \"=r\" (x)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1114 : \"0\" (y),
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1115 \"1\" (z));
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1116
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1117 The \"x\" line is aligned to the text after the \":\" on the \"w\" line, and
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1118 similarly \"z\" under \"y\".
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1119
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1120 This is done only in an \"asm\" or \"__asm__\" block, and only to
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1121 those lines mentioned. Anywhere else nil is returned. The usual
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1122 arrangement is to have this routine as an extra feature at the start
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1123 of arglist line-ups, e.g.
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1124
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1125 (c-lineup-gcc-asm-reg c-lineup-arglist)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1126
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1127 Works with: arglist-cont, arglist-cont-nonempty."
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1128
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1129 (let ((orig-pos (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1130 alignto)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1131 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1132 (and
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1133 c-opt-asm-stmt-key
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1134
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
1135 ;; Don't do anything if the innermost open paren isn't our one.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
1136 ;; This can occur for arglist-cont-nonempty with nested arglist
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
1137 ;; starts on the same line.
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
1138 (or (not (eq (car elem) 'arglist-cont-nonempty))
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1139 (eq (c-langelem-2nd-pos c-syntactic-element)
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
1140 (c-most-enclosing-brace (c-parse-state))))
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
1141
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1142 ;; Find the ":" to align to. Look for this first so as to quickly
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1143 ;; eliminate pretty much all cases which are not for us.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1144 (re-search-backward "^[ \t]*:[ \t]*\\(.\\)?" (cdr elem) t)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1145
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1146 ;; Must have something after the ":".
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1147 (setq alignto (match-beginning 1))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1148
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1149 ;; Don't touch ":" lines themselves.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1150 (progn (goto-char orig-pos)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1151 (beginning-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1152 (not (looking-at "^[ \t]*:")))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1153
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1154 ;; Only operate in an asm statement.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1155 (progn (goto-char orig-pos)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1156 (c-in-gcc-asm-p))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1157
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1158 (vector (progn (goto-char alignto) (current-column)))))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1159
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1160 (defun c-lineup-dont-change (langelem)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
1161 "Do not change the indentation of the current line.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
1162
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
1163 Works with: Any syntactic symbol."
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1164 (save-excursion
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1165 (back-to-indentation)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
1166 (vector (current-column))))
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1167
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1168
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1169 (defun c-snug-do-while (syntax pos)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1170 "Dynamically calculate brace hanginess for do-while statements.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1171 Using this function, `while' clauses that end a `do-while' block will
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1172 remain on the same line as the brace that closes that block.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1173
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1174 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
1175 ACTION associated with `block-close' syntax."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1176 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1177 (let (langelem)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1178 (if (and (eq syntax 'block-close)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1179 (setq langelem (assq 'block-close c-syntactic-context))
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1180 (progn (goto-char (c-langelem-pos langelem))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1181 (if (eq (char-after) ?{)
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
1182 (c-safe (c-forward-sexp -1)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1183 (looking-at "\\<do\\>[^_]")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1184 '(before)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1185 '(before after)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1186
67252
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1187 (defun c-snug-1line-defun-close (syntax pos)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1188 "Determine the brace hanginess for an AWK defun-close.
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1189 If the action/function being closed is a one-liner, keep it so. Otherwise put
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1190 the closing brace on its own line."
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1191 (save-excursion
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1192 (goto-char pos)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1193 (if (> (c-point 'bol)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1194 (progn (up-list -1) (point)))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1195 '(before after)
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1196 '(after))))
04d2abb755d9 Update CC Mode to release 5.31.
Alan Mackenzie <acm@muc.de>
parents: 64699
diff changeset
1197
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1198 (defun c-gnu-impose-minimum ()
53073
49f65e04ba8e CC Mode update (5.30.8).
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
1199 "Imposes a minimum indentation for lines inside code blocks.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1200 The variable `c-label-minimum-indentation' specifies the minimum
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1201 indentation amount."
51714
bc91cbf50c24 Updated CC Mode to version 5.30.
Martin Stjernholm <mast@lysator.liu.se>
parents: 50860
diff changeset
1202
53073
49f65e04ba8e CC Mode update (5.30.8).
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
1203 (when (and (not
49f65e04ba8e CC Mode update (5.30.8).
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
1204 ;; Don't adjust macro or comment-only lines.
49f65e04ba8e CC Mode update (5.30.8).
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
1205 (or (assq 'cpp-macro c-syntactic-context)
49f65e04ba8e CC Mode update (5.30.8).
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
1206 (assq 'comment-intro c-syntactic-context)))
49f65e04ba8e CC Mode update (5.30.8).
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
1207 (c-intersect-lists c-inside-block-syms c-syntactic-context)
49f65e04ba8e CC Mode update (5.30.8).
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
1208 (save-excursion
49f65e04ba8e CC Mode update (5.30.8).
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
1209 (back-to-indentation)
49f65e04ba8e CC Mode update (5.30.8).
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
1210 (< (current-column) c-label-minimum-indentation)))
49f65e04ba8e CC Mode update (5.30.8).
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
1211 (c-shift-line-indentation (- c-label-minimum-indentation
49f65e04ba8e CC Mode update (5.30.8).
Martin Stjernholm <mast@lysator.liu.se>
parents: 52401
diff changeset
1212 (current-indentation)))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1213
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1214
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1215 ;; Useful for c-hanging-semi&comma-criteria
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24282
diff changeset
1216
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1217 (defun c-semi&comma-inside-parenlist ()
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1218 "Controls newline insertion after semicolons in parenthesis lists.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1219 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
1220 inserted inside a parenthesis list, no newline is added otherwise a
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1221 newline is added. In either case, checking is stopped. This supports
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1222 exactly the old newline insertion behavior."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1223 ;; newline only after semicolon, but only if that semicolon is not
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1224 ;; inside a parenthesis list (e.g. a for loop statement)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1225 (if (not (eq last-command-char ?\;))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1226 nil ; continue checking
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1227 (if (condition-case nil
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1228 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1229 (up-list -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1230 (not (eq (char-after) ?\()))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1231 (error t))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1232 t
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1233 'stop)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1234
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1235 ;; Suppresses newlines before non-blank lines
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1236 (defun c-semi&comma-no-newlines-before-nonblanks ()
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1237 "Controls newline insertion after semicolons.
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1238 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
1239 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
1240 Otherwise, no determination is made."
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1241 (save-excursion
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1242 (if (and (= last-command-char ?\;)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1243 ;;(/= (point-max)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1244 ;; (save-excursion (skip-syntax-forward " ") (point))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1245 (zerop (forward-line 1))
62641
27b53b1903b6 2005-05-23 Martin Stjernholm <bug-cc-mode@gnu.org>
Martin Stjernholm <mast@lysator.liu.se>
parents: 56646
diff changeset
1246 (bolp) ; forward-line has funny behavior at eob.
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1247 (not (looking-at "^[ \t]*$")))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1248 'stop
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1249 nil)))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1250
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1251 ;; Suppresses new lines after semicolons in one-liners methods
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1252 (defun c-semi&comma-no-newlines-for-oneline-inliners ()
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1253 "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
1254 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
1255 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
1256 For other semicolon contexts, no determination is made."
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1257 (let ((syntax (c-guess-basic-syntax))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1258 (bol (save-excursion
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1259 (if (c-safe (up-list -1) t)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1260 (c-point 'bol)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1261 -1))))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1262 (if (and (eq last-command-char ?\;)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1263 (eq (car (car syntax)) 'inclass)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1264 (eq (car (car (cdr syntax))) 'topmost-intro)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1265 (= (c-point 'bol) bol))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1266 'stop
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1267 nil)))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
1268
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1269
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34303
diff changeset
1270 (cc-provide 'cc-align)
38422
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 36920
diff changeset
1271
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 52341
diff changeset
1272 ;;; arch-tag: 4d71ed28-bf51-4509-a148-f39669669a2e
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1273 ;;; cc-align.el ends here