annotate lisp/progmodes/cc-align.el @ 24920:d95c8bcfe8ae

(init_callproc): Set exec_directory if installation_directory is non-nil, without a test of exec_path.
author Richard M. Stallman <rms@gnu.org>
date Fri, 02 Jul 1999 12:57:10 +0000
parents 5b0864259a4b
children 03befb219d03
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
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
3 ;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
5 ;; Authors: 1998 Barry A. Warsaw and Martin Stjernholm
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
6 ;; 1992-1997 Barry A. Warsaw
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; 1987 Dave Detlefs and Stewart Clamen
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; 1985 Richard M. Stallman
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
9 ;; Maintainer: bug-cc-mode@gnu.org
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; Created: 22-Apr-1997 (split from cc-mode.el)
20141
1a85b213eb6d Remove version number.
Karl Heuer <kwzh@gnu.org>
parents: 20140
diff changeset
11 ;; Version: See cc-mode.el
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; Keywords: c languages oop
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; This file is part of GNU Emacs.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is free software; you can redistribute it and/or modify
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; 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
18 ;; the Free Software Foundation; either version 2, or (at your option)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; any later version.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; GNU Emacs is distributed in the hope that it will be useful,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; GNU General Public License for more details.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;; You should have received a copy of the GNU General Public License
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; Boston, MA 02111-1307, USA.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 (eval-when-compile
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
32 (require 'cc-defs)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 (require 'cc-vars)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 (require 'cc-engine)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 (require 'cc-langs))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; Standard indentation line-ups
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 (defun c-lineup-arglist (langelem)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;; lineup the current arglist line with the arglist appearing just
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;; after the containing paren which starts the arglist.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 (let* ((containing-sexp
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;; arglist-cont-nonempty gives relpos ==
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; to boi of containing-sexp paren. This
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;; is good when offset is +, but bad
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;; when it is c-lineup-arglist, so we
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;; have to special case a kludge here.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (backward-up-list 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 (skip-chars-forward " \t" (c-point 'eol)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 (goto-char (cdr langelem)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 (langelem-col (c-langelem-col langelem t)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 (if (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (looking-at "[ \t]*)"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 (progn (goto-char (match-end 0))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
62 (c-forward-sexp -1)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 (forward-char 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (c-forward-syntactic-ws)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (- (current-column) langelem-col))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 (goto-char containing-sexp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (or (eolp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (not (memq (char-after) '(?{ ?\( )))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 (let ((eol (c-point 'eol))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 (here (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (forward-char 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 (skip-chars-forward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (point))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 (c-forward-syntactic-ws)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (if (< (point) eol)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 (goto-char here))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 (- (current-column) langelem-col)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 (defun c-lineup-arglist-intro-after-paren (langelem)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;; lineup an arglist-intro line to just after the open paren
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 (let ((langelem-col (c-langelem-col langelem t))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 (ce-curcol (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 (backward-up-list 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 (skip-chars-forward " \t" (c-point 'eol))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 (current-column))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 (- ce-curcol langelem-col -1))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (defun c-lineup-arglist-close-under-paren (langelem)
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
92 ;; lineup an arglist-close line under the corresponding open paren
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 (let ((langelem-col (c-langelem-col langelem t))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 (ce-curcol (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 (backward-up-list 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (current-column))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 (- ce-curcol langelem-col))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
101 (defun c-lineup-close-paren (langelem)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
102 ;; Indents the closing paren under its corresponding open paren if
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
103 ;; the open paren is followed by code. If the open paren ends its
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
104 ;; line, no indentation is added. E.g:
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
105 ;;
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
106 ;; main (int, main (
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
107 ;; char ** int, char **
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
108 ;; ) <-> ) <- c-lineup-close-paren
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
109 ;;
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
110 ;; Works with any type of paren.
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
111 (save-excursion
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
112 (condition-case nil
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
113 (let (opencol spec)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
114 (beginning-of-line)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
115 (backward-up-list 1)
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
116 (setq spec (c-looking-at-special-brace-list))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
117 (if spec (goto-char (car (car spec))))
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
118 (setq opencol (current-column))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
119 (forward-char 1)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
120 (if spec (progn
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
121 (c-forward-syntactic-ws)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
122 (forward-char 1)))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
123 (c-forward-syntactic-ws (c-point 'eol))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
124 (if (eolp)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
125 0
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
126 (- opencol (c-langelem-col langelem t))))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
127 (error 0))))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
128
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 (defun c-lineup-streamop (langelem)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 ;; lineup stream operators
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (let ((langelem-col (c-langelem-col langelem)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (re-search-forward "<<\\|>>" (c-point 'eol) 'move)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (goto-char (match-beginning 0))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (- (current-column) langelem-col))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (defun c-lineup-multi-inher (langelem)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 ;; line up multiple inheritance lines
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (let ((eol (c-point 'eol))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (here (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (langelem-col (c-langelem-col langelem)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (skip-chars-forward "^:" eol)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (skip-chars-forward " \t:" eol)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (if (or (eolp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (looking-at c-comment-start-regexp))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (c-forward-syntactic-ws here))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (- (current-column) langelem-col)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 )))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (defun c-lineup-java-inher (langelem)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 ;; line up Java implements and extends continuations
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (let ((langelem-col (c-langelem-col langelem)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (forward-word 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (if (looking-at "[ \t]*$")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 langelem-col
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (c-forward-syntactic-ws)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (- (current-column) langelem-col)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (defun c-lineup-java-throws (langelem)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 ;; lineup func-decl-cont's in Java which are continuations of throws
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 ;; declarations. If `throws' starts the previous line, line up to
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 ;; just after that keyword. If not, lineup under the previous line.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (let ((iopl (c-point 'iopl))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (langelem-col (c-langelem-col langelem t))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (extra 0))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (back-to-indentation)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (cond
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 ((looking-at "throws[ \t\n]")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (goto-char (cdr langelem))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (setq extra c-basic-offset))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 ((and (goto-char iopl)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (looking-at "throws[ \t\n]"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (forward-word 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (skip-chars-forward " \t")
19296
885a72deec97 (c-lineup-java-throws): Change the `when' clause to an `if-progn'.
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
178 (if (eolp)
885a72deec97 (c-lineup-java-throws): Change the `when' clause to an `if-progn'.
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
179 (progn
885a72deec97 (c-lineup-java-throws): Change the `when' clause to an `if-progn'.
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
180 (back-to-indentation)
885a72deec97 (c-lineup-java-throws): Change the `when' clause to an `if-progn'.
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
181 (setq extra c-basic-offset))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (t (goto-char iopl)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (+ (- (current-column) langelem-col) extra))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
185 (defun c-indent-one-line-block (langelem)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
186 ;; Adds c-basic-offset to the indentation if the line is a one line
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
187 ;; block, otherwise 0. E.g:
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
188 ;;
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
189 ;; if (n) if (n)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
190 ;; {m+=n; n=0;} <-> { <- c-indent-one-line-block
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
191 ;; m+=n; n=0;
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
192 ;; }
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
193 (save-excursion
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
194 (let ((eol (progn (end-of-line) (point))))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
195 (beginning-of-line)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
196 (skip-chars-forward " \t")
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
197 (if (and (eq (following-char) ?{)
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
198 (c-safe (progn (c-forward-sexp) t))
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
199 (<= (point) eol)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
200 (eq (preceding-char) ?}))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
201 c-basic-offset
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
202 0))))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
203
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (defun c-lineup-C-comments (langelem)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 ;; line up C block comment continuation lines
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (let ((here (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (stars (progn (back-to-indentation)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (skip-chars-forward "*")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (langelem-col (c-langelem-col langelem)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 (back-to-indentation)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (if (not (re-search-forward "/\\([*]+\\)" (c-point 'eol) t))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (if (not (looking-at "[*]+"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 ;; we now have to figure out where this comment begins.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (goto-char here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 (back-to-indentation)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (if (looking-at "[*]+/")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (progn (goto-char (match-end 0))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (forward-comment -1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (goto-char (cdr langelem))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (back-to-indentation))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (- (current-column) langelem-col))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (if (zerop stars)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (skip-chars-forward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (- (current-column) langelem-col))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 ;; how many stars on comment opening line? if greater than
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 ;; on current line, align left. if less than or equal,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 ;; align right. this should also pick up Javadoc style
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 ;; comments.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (if (> (length (match-string 1)) stars)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (back-to-indentation)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (- (current-column) -1 langelem-col))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (- (current-column) stars langelem-col))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 )))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 (defun c-lineup-comment (langelem)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 ;; support old behavior for comment indentation. we look at
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 ;; c-comment-only-line-offset to decide how to indent comment
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 ;; only-lines
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (back-to-indentation)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 ;; this highly kludgiforous flag prevents the mapcar over
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 ;; c-syntactic-context from entering an infinite loop
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (let ((recurse-prevention-flag (boundp 'recurse-prevention-flag)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (cond
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 ;; CASE 1: preserve comment-column
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (recurse-prevention-flag 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 ((= (current-column) comment-column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 ;; we have to subtract out all other indentation
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (- comment-column (apply '+ (mapcar 'c-get-offset
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 c-syntactic-context))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 ;; indent as specified by c-comment-only-line-offset
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 ((not (bolp))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (or (car-safe c-comment-only-line-offset)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 c-comment-only-line-offset))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (t
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 (or (cdr-safe c-comment-only-line-offset)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (car-safe c-comment-only-line-offset)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 -1000)) ;jam it against the left side
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 ))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (defun c-lineup-runin-statements (langelem)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 ;; line up statements in coding standards which place the first
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 ;; statement on the same line as the block opening brace.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (if (eq (char-after (cdr langelem)) ?{)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (let ((langelem-col (c-langelem-col langelem)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (forward-char 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (skip-chars-forward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (- (current-column) langelem-col)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 0))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 (defun c-lineup-math (langelem)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 ;; line up math statement-cont after the equals
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (let ((equalp (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (goto-char (c-point 'boi))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282 (skip-chars-forward "^=" (c-point 'eol))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (and (eq (char-after) ?=)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (- (point) (c-point 'boi)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (langelem-col (c-langelem-col langelem))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 donep)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (while (and (not donep)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (< (point) (c-point 'eol)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (skip-chars-forward "^=" (c-point 'eol))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (if (c-in-literal (cdr langelem))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (forward-char 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 (setq donep t)))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
293 (if (or (not (eq (char-after) ?=))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
294 (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
295 (forward-char 1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
296 (c-forward-syntactic-ws (c-point 'eol))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
297 (eolp)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 ;; there's no equal sign on the line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 c-basic-offset
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 ;; calculate indentation column after equals and ws, unless
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 ;; our line contains an equals sign
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (if (not equalp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (forward-char 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 (skip-chars-forward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 (setq equalp 0)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 (- (current-column) equalp langelem-col))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 )))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 (defun c-lineup-ObjC-method-call (langelem)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 ;; Line up methods args as elisp-mode does with function args: go to
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 ;; the position right after the message receiver, and if you are at
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 ;; (eolp) indent the current line by a constant offset from the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 ;; opening bracket; otherwise we are looking at the first character
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 ;; of the first method call argument, so lineup the current line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 ;; with it.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 (let* ((extra (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 (back-to-indentation)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (c-backward-syntactic-ws (cdr langelem))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 (if (eq (char-before) ?:)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 (- c-basic-offset)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 0)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 (open-bracket-pos (cdr langelem))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (open-bracket-col (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 (goto-char open-bracket-pos)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (current-column)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 (target-col (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (forward-char)
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
330 (c-forward-sexp)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 (skip-chars-forward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (if (eolp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (+ open-bracket-col c-basic-offset)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (current-column))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 )
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (- target-col open-bracket-col extra))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (defun c-lineup-ObjC-method-args (langelem)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 ;; Line up the colons that separate args. This is done trying to
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 ;; align colons vertically.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 (let* ((here (c-point 'boi))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 (curcol (progn (goto-char here) (current-column)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (eol (c-point 'eol))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 (relpos (cdr langelem))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (first-col-column (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (goto-char relpos)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (skip-chars-forward "^:" eol)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 (and (eq (char-after) ?:)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 (current-column)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (if (not first-col-column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 c-basic-offset
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (goto-char here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (skip-chars-forward "^:" eol)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (if (eq (char-after) ?:)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 (+ curcol (- first-col-column (current-column)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 c-basic-offset)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 (defun c-lineup-ObjC-method-args-2 (langelem)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 ;; Line up the colons that separate args. This is done trying to
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 ;; align the colon on the current line with the previous one.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 (let* ((here (c-point 'boi))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 (curcol (progn (goto-char here) (current-column)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 (eol (c-point 'eol))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 (relpos (cdr langelem))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 (prev-col-column (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 (skip-chars-backward "^:" relpos)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 (and (eq (char-before) ?:)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 (- (current-column) 1)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 (if (not prev-col-column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 c-basic-offset
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 (goto-char here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (skip-chars-forward "^:" eol)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (if (eq (char-after) ?:)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 (+ curcol (- prev-col-column (current-column)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 c-basic-offset)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
379 (defun c-lineup-inexpr-block (langelem)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
380 ;; This function lines up the block for the various constructs that
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
381 ;; uses a block inside an expression. For constructs matching
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
382 ;; c-lambda-key and c-inexpr-block-key, indentation to the column of
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
383 ;; the beginning of the match is added. For standalone statement
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
384 ;; blocks, indentation to the column of the opening brace is added.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
385 (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
386 (back-to-indentation)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
387 (let ((res (or (c-looking-at-inexpr-block)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
388 (if (c-safe (backward-up-list 1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
389 (eq (char-after) ?{))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
390 (c-looking-at-inexpr-block)))))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
391 (if (not res)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
392 0
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
393 (goto-char (cdr res))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
394 (- (current-column)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
395 (progn
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
396 (back-to-indentation)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
397 (current-column)))))))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
398
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
399 (defun c-lineup-dont-change (langelem)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
400 ;; Do not change the indentation of the current line
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
401 (save-excursion
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
402 (back-to-indentation)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
403 (current-column)))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
404
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
405
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
406
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 (defun c-snug-do-while (syntax pos)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 "Dynamically calculate brace hanginess for do-while statements.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 Using this function, `while' clauses that end a `do-while' block will
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 remain on the same line as the brace that closes that block.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 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
413 ACTION associated with `block-close' syntax."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 (let (langelem)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 (if (and (eq syntax 'block-close)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 (setq langelem (assq 'block-close c-syntactic-context))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 (progn (goto-char (cdr langelem))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 (if (eq (char-after) ?{)
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21110
diff changeset
420 (c-safe (c-forward-sexp -1)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 (looking-at "\\<do\\>[^_]")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 '(before)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 '(before after)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 (defun c-gnu-impose-minimum ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 "Imposes a minimum indentation for lines inside a top-level construct.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 The variable `c-label-minimum-indentation' specifies the minimum
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 indentation amount."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 (let ((non-top-levels '(defun-block-intro statement statement-cont
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 statement-block-intro statement-case-intro
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 statement-case-open substatement substatement-open
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432 case-label label do-while-closure else-clause
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 ))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 (syntax c-syntactic-context)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 langelem)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 (while syntax
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 (setq langelem (car (car syntax))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 syntax (cdr syntax))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 ;; don't adjust comment-only lines
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 (cond ((eq langelem 'comment-intro)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 (setq syntax nil))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
442 ((memq langelem non-top-levels)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
443 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (setq syntax nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 (back-to-indentation)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 (if (zerop (current-column))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (insert (make-string c-label-minimum-indentation 32)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 ))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 ))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 ;; Useful for c-hanging-semi&comma-criteria
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 (defun c-semi&comma-inside-parenlist ()
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
454 "Controls newline insertion after semicolons in parenthesis lists.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 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
456 inserted inside a parenthesis list, no newline is added otherwise a
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 newline is added. In either case, checking is stopped. This supports
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 exactly the old newline insertion behavior."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 ;; newline only after semicolon, but only if that semicolon is not
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 ;; inside a parenthesis list (e.g. a for loop statement)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 (if (not (eq last-command-char ?\;))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 nil ; continue checking
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 (if (condition-case nil
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 (up-list -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 (not (eq (char-after) ?\()))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 (error t))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 t
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 'stop)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470
20911
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
471 ;; Suppresses newlines before non-blank lines
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
472 (defun c-semi&comma-no-newlines-before-nonblanks ()
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
473 "Controls newline insertion after semicolons.
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
474 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
475 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
476 Otherwise, no determination is made."
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
477 (save-excursion
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
478 (if (and (= last-command-char ?\;)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
479 ;;(/= (point-max)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
480 ;; (save-excursion (skip-syntax-forward " ") (point))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
481 (zerop (forward-line 1))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
482 (not (looking-at "^[ \t]*$")))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
483 'stop
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
484 nil)))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
485
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
486 ;; Suppresses new lines after semicolons in one-liners methods
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
487 (defun c-semi&comma-no-newlines-for-oneline-inliners ()
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
488 "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
489 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
490 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
491 For other semicolon contexts, no determination is made."
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
492 (let ((syntax (c-guess-basic-syntax))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
493 (bol (save-excursion
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
494 (if (c-safe (up-list -1) t)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
495 (c-point 'bol)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
496 -1))))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
497 (if (and (eq last-command-char ?\;)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
498 (eq (car (car syntax)) 'inclass)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
499 (eq (car (car (cdr syntax))) 'topmost-intro)
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
500 (= (c-point 'bol) bol))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
501 'stop
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
502 nil)))
8ec2d600e66d (c-lineup-close-paren)
Richard M. Stallman <rms@gnu.org>
parents: 20141
diff changeset
503
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 (provide 'cc-align)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 ;;; cc-align.el ends here