annotate lisp/cc-mode/cc-align.el @ 165:5a88923fcbfe r20-3b9

Import from CVS: tag r20-3b9
author cvs
date Mon, 13 Aug 2007 09:44:42 +0200
parents
children 929b76928fce
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
165
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
1 ;;; cc-align.el --- custom indentation functions for CC Mode
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
2
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985,87,92,93,94,95,96,97 Free Software Foundation, Inc.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
4
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
5 ;; Authors: 1992-1997 Barry A. Warsaw
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
6 ;; 1987 Dave Detlefs and Stewart Clamen
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
7 ;; 1985 Richard M. Stallman
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
8 ;; Maintainer: cc-mode-help@python.org
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
9 ;; Created: 22-Apr-1997 (split from cc-mode.el)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
10 ;; Version: 5.11
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
11 ;; Keywords: c languages oop
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
12
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
13 ;; This file is part of GNU Emacs.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
14
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
15 ;; GNU Emacs is free software; you can redistribute it and/or modify
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
16 ;; it under the terms of the GNU General Public License as published by
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
17 ;; the Free Software Foundation; either version 2, or (at your option)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
18 ;; any later version.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
19
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
20 ;; GNU Emacs is distributed in the hope that it will be useful,
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
23 ;; GNU General Public License for more details.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
24
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
25 ;; You should have received a copy of the GNU General Public License
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
28 ;; Boston, MA 02111-1307, USA.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
29
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
30
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
31 (eval-when-compile
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
32 (load-file "./cc-engine.el"))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
33
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
34 (defsubst c-langelem-col (langelem &optional preserve-point)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
35 ;; convenience routine to return the column of langelem's relpos.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
36 ;; Leaves point at the relpos unless preserve-point is non-nil.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
37 (let ((here (point)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
38 (goto-char (cdr langelem))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
39 (prog1 (current-column)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
40 (if preserve-point
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
41 (goto-char here))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
42 )))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
43
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
44
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
45 ;; Standard indentation line-ups
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
46 (defun c-lineup-arglist (langelem)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
47 ;; lineup the current arglist line with the arglist appearing just
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
48 ;; after the containing paren which starts the arglist.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
49 (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
50 (let* ((containing-sexp
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
51 (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
52 ;; arglist-cont-nonempty gives relpos ==
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
53 ;; to boi of containing-sexp paren. This
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
54 ;; is good when offset is +, but bad
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
55 ;; when it is c-lineup-arglist, so we
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
56 ;; have to special case a kludge here.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
57 (if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
58 (progn
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
59 (beginning-of-line)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
60 (backward-up-list 1)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
61 (skip-chars-forward " \t" (c-point 'eol)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
62 (goto-char (cdr langelem)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
63 (point)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
64 (langelem-col (c-langelem-col langelem t)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
65 (if (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
66 (beginning-of-line)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
67 (looking-at "[ \t]*)"))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
68 (progn (goto-char (match-end 0))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
69 (forward-sexp -1)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
70 (forward-char 1)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
71 (c-forward-syntactic-ws)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
72 (- (current-column) langelem-col))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
73 (goto-char containing-sexp)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
74 (or (eolp)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
75 (not (memq (following-char) '(?{ ?\( )))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
76 (let ((eol (c-point 'eol))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
77 (here (progn
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
78 (forward-char 1)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
79 (skip-chars-forward " \t")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
80 (point))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
81 (c-forward-syntactic-ws)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
82 (if (< (point) eol)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
83 (goto-char here))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
84 (- (current-column) langelem-col)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
85 ))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
86
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
87 (defun c-lineup-arglist-intro-after-paren (langelem)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
88 ;; lineup an arglist-intro line to just after the open paren
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
89 (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
90 (let ((langelem-col (c-langelem-col langelem t))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
91 (ce-curcol (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
92 (beginning-of-line)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
93 (backward-up-list 1)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
94 (skip-chars-forward " \t" (c-point 'eol))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
95 (current-column))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
96 (- ce-curcol langelem-col -1))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
97
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
98 (defun c-lineup-arglist-close-under-paren (langelem)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
99 ;; lineup an arglist-intro line to just after the open paren
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
100 (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
101 (let ((langelem-col (c-langelem-col langelem t))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
102 (ce-curcol (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
103 (beginning-of-line)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
104 (backward-up-list 1)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
105 (current-column))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
106 (- ce-curcol langelem-col))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
107
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
108 (defun c-lineup-streamop (langelem)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
109 ;; lineup stream operators
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
110 (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
111 (let ((langelem-col (c-langelem-col langelem)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
112 (re-search-forward "<<\\|>>" (c-point 'eol) 'move)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
113 (goto-char (match-beginning 0))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
114 (- (current-column) langelem-col))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
115
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
116 (defun c-lineup-multi-inher (langelem)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
117 ;; line up multiple inheritance lines
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
118 (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
119 (let ((eol (c-point 'eol))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
120 (here (point))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
121 (langelem-col (c-langelem-col langelem)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
122 (skip-chars-forward "^:" eol)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
123 (skip-chars-forward " \t:" eol)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
124 (if (or (eolp)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
125 (looking-at c-comment-start-regexp))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
126 (c-forward-syntactic-ws here))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
127 (- (current-column) langelem-col)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
128 )))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
129
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
130 (defun c-lineup-java-inher (langelem)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
131 ;; line up Java implements and extends continuations
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
132 (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
133 (let ((langelem-col (c-langelem-col langelem)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
134 (forward-word 1)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
135 (if (looking-at "[ \t]*$")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
136 langelem-col
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
137 (c-forward-syntactic-ws)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
138 (- (current-column) langelem-col)))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
139
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
140 (defun c-lineup-java-throws (langelem)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
141 ;; lineup func-decl-cont's in Java which are continuations of throws
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
142 ;; declarations. If `throws' starts the previous line, line up to
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
143 ;; just after that keyword. If not, lineup under the previous line.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
144 (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
145 (let ((iopl (c-point 'iopl))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
146 (langelem-col (c-langelem-col langelem t))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
147 (extra 0))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
148 (back-to-indentation)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
149 (cond
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
150 ((looking-at "throws[ \t\n]")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
151 (goto-char (cdr langelem))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
152 (setq extra c-basic-offset))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
153 ((and (goto-char iopl)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
154 (looking-at "throws[ \t\n]"))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
155 (forward-word 1)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
156 (skip-chars-forward " \t")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
157 (when (eolp)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
158 (back-to-indentation)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
159 (setq extra c-basic-offset)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
160 (t (goto-char iopl)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
161 (+ (- (current-column) langelem-col) extra))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
162
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
163 (defun c-lineup-C-comments (langelem)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
164 ;; line up C block comment continuation lines
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
165 (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
166 (let ((here (point))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
167 (stars (progn (back-to-indentation)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
168 (skip-chars-forward "*")))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
169 (langelem-col (c-langelem-col langelem)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
170 (back-to-indentation)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
171 (if (not (re-search-forward "/\\([*]+\\)" (c-point 'eol) t))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
172 (progn
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
173 (if (not (looking-at "[*]+"))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
174 (progn
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
175 ;; we now have to figure out where this comment begins.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
176 (goto-char here)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
177 (back-to-indentation)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
178 (if (looking-at "[*]+/")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
179 (progn (goto-char (match-end 0))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
180 (forward-comment -1))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
181 (goto-char (cdr langelem))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
182 (back-to-indentation))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
183 (- (current-column) langelem-col))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
184 (if (zerop stars)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
185 (progn
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
186 (skip-chars-forward " \t")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
187 (- (current-column) langelem-col))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
188 ;; how many stars on comment opening line? if greater than
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
189 ;; on current line, align left. if less than or equal,
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
190 ;; align right. this should also pick up Javadoc style
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
191 ;; comments.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
192 (if (> (length (match-string 1)) stars)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
193 (progn
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
194 (back-to-indentation)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
195 (- (current-column) -1 langelem-col))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
196 (- (current-column) stars langelem-col))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
197 )))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
198
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
199 (defun c-lineup-comment (langelem)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
200 ;; support old behavior for comment indentation. we look at
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
201 ;; c-comment-only-line-offset to decide how to indent comment
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
202 ;; only-lines
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
203 (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
204 (back-to-indentation)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
205 ;; this highly kludgiforous flag prevents the mapcar over
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
206 ;; c-syntactic-context from entering an infinite loop
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
207 (let ((recurse-prevention-flag (boundp 'recurse-prevention-flag)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
208 (cond
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
209 ;; CASE 1: preserve comment-column
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
210 (recurse-prevention-flag 0)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
211 ((= (current-column) comment-column)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
212 ;; we have to subtract out all other indentation
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
213 (- comment-column (apply '+ (mapcar 'c-get-offset
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
214 c-syntactic-context))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
215 ;; indent as specified by c-comment-only-line-offset
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
216 ((not (bolp))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
217 (or (car-safe c-comment-only-line-offset)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
218 c-comment-only-line-offset))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
219 (t
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
220 (or (cdr-safe c-comment-only-line-offset)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
221 (car-safe c-comment-only-line-offset)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
222 -1000)) ;jam it against the left side
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
223 ))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
224
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
225 (defun c-lineup-runin-statements (langelem)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
226 ;; line up statements in coding standards which place the first
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
227 ;; statement on the same line as the block opening brace.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
228 (if (= (char-after (cdr langelem)) ?{)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
229 (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
230 (let ((langelem-col (c-langelem-col langelem)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
231 (forward-char 1)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
232 (skip-chars-forward " \t")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
233 (- (current-column) langelem-col)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
234 0))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
235
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
236 (defun c-lineup-math (langelem)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
237 ;; line up math statement-cont after the equals
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
238 (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
239 (let ((equalp (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
240 (goto-char (c-point 'boi))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
241 (skip-chars-forward "^=" (c-point 'eol))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
242 (and (= (following-char) ?=)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
243 (- (point) (c-point 'boi)))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
244 (langelem-col (c-langelem-col langelem))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
245 donep)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
246 (while (and (not donep)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
247 (< (point) (c-point 'eol)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
248 (skip-chars-forward "^=" (c-point 'eol))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
249 (if (c-in-literal (cdr langelem))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
250 (forward-char 1)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
251 (setq donep t)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
252 (if (/= (following-char) ?=)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
253 ;; there's no equal sign on the line
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
254 c-basic-offset
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
255 ;; calculate indentation column after equals and ws, unless
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
256 ;; our line contains an equals sign
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
257 (if (not equalp)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
258 (progn
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
259 (forward-char 1)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
260 (skip-chars-forward " \t")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
261 (setq equalp 0)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
262 (- (current-column) equalp langelem-col))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
263 )))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
264
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
265 (defun c-lineup-ObjC-method-call (langelem)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
266 ;; Line up methods args as elisp-mode does with function args: go to
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
267 ;; the position right after the message receiver, and if you are at
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
268 ;; (eolp) indent the current line by a constant offset from the
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
269 ;; opening bracket; otherwise we are looking at the first character
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
270 ;; of the first method call argument, so lineup the current line
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
271 ;; with it.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
272 (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
273 (let* ((extra (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
274 (back-to-indentation)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
275 (c-backward-syntactic-ws (cdr langelem))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
276 (if (= (preceding-char) ?:)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
277 (- c-basic-offset)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
278 0)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
279 (open-bracket-pos (cdr langelem))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
280 (open-bracket-col (progn
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
281 (goto-char open-bracket-pos)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
282 (current-column)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
283 (target-col (progn
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
284 (forward-char)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
285 (forward-sexp)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
286 (skip-chars-forward " \t")
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
287 (if (eolp)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
288 (+ open-bracket-col c-basic-offset)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
289 (current-column))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
290 )
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
291 (- target-col open-bracket-col extra))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
292
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
293 (defun c-lineup-ObjC-method-args (langelem)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
294 ;; Line up the colons that separate args. This is done trying to
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
295 ;; align colons vertically.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
296 (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
297 (let* ((here (c-point 'boi))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
298 (curcol (progn (goto-char here) (current-column)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
299 (eol (c-point 'eol))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
300 (relpos (cdr langelem))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
301 (first-col-column (progn
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
302 (goto-char relpos)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
303 (skip-chars-forward "^:" eol)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
304 (and (= (following-char) ?:)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
305 (current-column)))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
306 (if (not first-col-column)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
307 c-basic-offset
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
308 (goto-char here)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
309 (skip-chars-forward "^:" eol)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
310 (if (= (following-char) ?:)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
311 (+ curcol (- first-col-column (current-column)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
312 c-basic-offset)))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
313
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
314 (defun c-lineup-ObjC-method-args-2 (langelem)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
315 ;; Line up the colons that separate args. This is done trying to
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
316 ;; align the colon on the current line with the previous one.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
317 (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
318 (let* ((here (c-point 'boi))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
319 (curcol (progn (goto-char here) (current-column)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
320 (eol (c-point 'eol))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
321 (relpos (cdr langelem))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
322 (prev-col-column (progn
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
323 (skip-chars-backward "^:" relpos)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
324 (and (= (preceding-char) ?:)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
325 (- (current-column) 1)))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
326 (if (not prev-col-column)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
327 c-basic-offset
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
328 (goto-char here)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
329 (skip-chars-forward "^:" eol)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
330 (if (= (following-char) ?:)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
331 (+ curcol (- prev-col-column (current-column)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
332 c-basic-offset)))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
333
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
334 (defun c-snug-do-while (syntax pos)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
335 "Dynamically calculate brace hanginess for do-while statements.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
336 Using this function, `while' clauses that end a `do-while' block will
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
337 remain on the same line as the brace that closes that block.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
338
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
339 See `c-hanging-braces-alist' for how to utilize this function as an
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
340 ACTION associated with `block-close' syntax."
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
341 (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
342 (let (langelem)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
343 (if (and (eq syntax 'block-close)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
344 (setq langelem (assq 'block-close c-syntactic-context))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
345 (progn (goto-char (cdr langelem))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
346 (if (= (following-char) ?{)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
347 (c-safe (forward-sexp -1)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
348 (looking-at "\\<do\\>[^_]")))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
349 '(before)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
350 '(before after)))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
351
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
352 (defun c-gnu-impose-minimum ()
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
353 "Imposes a minimum indentation for lines inside a top-level construct.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
354 The variable `c-label-minimum-indentation' specifies the minimum
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
355 indentation amount."
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
356 (let ((non-top-levels '(defun-block-intro statement statement-cont
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
357 statement-block-intro statement-case-intro
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
358 statement-case-open substatement substatement-open
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
359 case-label label do-while-closure else-clause
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
360 ))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
361 (syntax c-syntactic-context)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
362 langelem)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
363 (while syntax
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
364 (setq langelem (car (car syntax))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
365 syntax (cdr syntax))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
366 ;; don't adjust comment-only lines
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
367 (cond ((eq langelem 'comment-intro)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
368 (setq syntax nil))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
369 ((memq langelem non-top-levels)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
370 (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
371 (setq syntax nil)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
372 (back-to-indentation)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
373 (if (zerop (current-column))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
374 (insert (make-string c-label-minimum-indentation 32)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
375 ))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
376 ))))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
377
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
378
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
379 ;; Useful for c-hanging-semi&comma-criteria
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
380 (defun c-semi&comma-inside-parenlist ()
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
381 "Determine if a newline should be added after a semicolon.
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
382 If a comma was inserted, no determination is made. If a semicolon was
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
383 inserted inside a parenthesis list, no newline is added otherwise a
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
384 newline is added. In either case, checking is stopped. This supports
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
385 exactly the old newline insertion behavior."
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
386 ;; newline only after semicolon, but only if that semicolon is not
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
387 ;; inside a parenthesis list (e.g. a for loop statement)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
388 (if (/= last-command-char ?\;)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
389 nil ; continue checking
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
390 (if (condition-case nil
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
391 (save-excursion
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
392 (up-list -1)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
393 (/= (following-char) ?\())
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
394 (error t))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
395 t
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
396 'stop)))
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
397
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
398
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
399 (provide 'cc-align)
5a88923fcbfe Import from CVS: tag r20-3b9
cvs
parents:
diff changeset
400 ;;; cc-align.el ends here