comparison lisp/cc-mode/cc-align.el @ 171:929b76928fce r20-3b12

Import from CVS: tag r20-3b12
author cvs
date Mon, 13 Aug 2007 09:47:52 +0200
parents 5a88923fcbfe
children 2d532a89d707
comparison
equal deleted inserted replaced
170:98a42ee61975 171:929b76928fce
5 ;; Authors: 1992-1997 Barry A. Warsaw 5 ;; Authors: 1992-1997 Barry A. Warsaw
6 ;; 1987 Dave Detlefs and Stewart Clamen 6 ;; 1987 Dave Detlefs and Stewart Clamen
7 ;; 1985 Richard M. Stallman 7 ;; 1985 Richard M. Stallman
8 ;; Maintainer: cc-mode-help@python.org 8 ;; Maintainer: cc-mode-help@python.org
9 ;; Created: 22-Apr-1997 (split from cc-mode.el) 9 ;; Created: 22-Apr-1997 (split from cc-mode.el)
10 ;; Version: 5.11 10 ;; Version: 5.12
11 ;; Keywords: c languages oop 11 ;; Keywords: c languages oop
12 12
13 ;; This file is part of GNU Emacs. 13 ;; This file is part of GNU Emacs.
14 14
15 ;; GNU Emacs is free software; you can redistribute it and/or modify 15 ;; GNU Emacs is free software; you can redistribute it and/or modify
25 ;; You should have received a copy of the GNU General Public License 25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs; see the file COPYING. If not, write to the 26 ;; along with GNU Emacs; see the file COPYING. If not, write to the
27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, 27 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
28 ;; Boston, MA 02111-1307, USA. 28 ;; Boston, MA 02111-1307, USA.
29 29
30
31 (eval-when-compile 30 (eval-when-compile
32 (load-file "./cc-engine.el")) 31 (require 'cc-defs)
33 32 (require 'cc-vars)
34 (defsubst c-langelem-col (langelem &optional preserve-point) 33 (require 'cc-engine)
35 ;; convenience routine to return the column of langelem's relpos. 34 (require 'cc-langs))
36 ;; Leaves point at the relpos unless preserve-point is non-nil.
37 (let ((here (point)))
38 (goto-char (cdr langelem))
39 (prog1 (current-column)
40 (if preserve-point
41 (goto-char here))
42 )))
43 35
44 36
45 ;; Standard indentation line-ups 37 ;; Standard indentation line-ups
46 (defun c-lineup-arglist (langelem) 38 (defun c-lineup-arglist (langelem)
47 ;; lineup the current arglist line with the arglist appearing just 39 ;; lineup the current arglist line with the arglist appearing just
70 (forward-char 1) 62 (forward-char 1)
71 (c-forward-syntactic-ws) 63 (c-forward-syntactic-ws)
72 (- (current-column) langelem-col)) 64 (- (current-column) langelem-col))
73 (goto-char containing-sexp) 65 (goto-char containing-sexp)
74 (or (eolp) 66 (or (eolp)
75 (not (memq (following-char) '(?{ ?\( ))) 67 (not (memq (char-after) '(?{ ?\( )))
76 (let ((eol (c-point 'eol)) 68 (let ((eol (c-point 'eol))
77 (here (progn 69 (here (progn
78 (forward-char 1) 70 (forward-char 1)
79 (skip-chars-forward " \t") 71 (skip-chars-forward " \t")
80 (point)))) 72 (point))))
223 )))) 215 ))))
224 216
225 (defun c-lineup-runin-statements (langelem) 217 (defun c-lineup-runin-statements (langelem)
226 ;; line up statements in coding standards which place the first 218 ;; line up statements in coding standards which place the first
227 ;; statement on the same line as the block opening brace. 219 ;; statement on the same line as the block opening brace.
228 (if (= (char-after (cdr langelem)) ?{) 220 (if (eq (char-after (cdr langelem)) ?{)
229 (save-excursion 221 (save-excursion
230 (let ((langelem-col (c-langelem-col langelem))) 222 (let ((langelem-col (c-langelem-col langelem)))
231 (forward-char 1) 223 (forward-char 1)
232 (skip-chars-forward " \t") 224 (skip-chars-forward " \t")
233 (- (current-column) langelem-col))) 225 (- (current-column) langelem-col)))
237 ;; line up math statement-cont after the equals 229 ;; line up math statement-cont after the equals
238 (save-excursion 230 (save-excursion
239 (let ((equalp (save-excursion 231 (let ((equalp (save-excursion
240 (goto-char (c-point 'boi)) 232 (goto-char (c-point 'boi))
241 (skip-chars-forward "^=" (c-point 'eol)) 233 (skip-chars-forward "^=" (c-point 'eol))
242 (and (= (following-char) ?=) 234 (and (eq (char-after) ?=)
243 (- (point) (c-point 'boi))))) 235 (- (point) (c-point 'boi)))))
244 (langelem-col (c-langelem-col langelem)) 236 (langelem-col (c-langelem-col langelem))
245 donep) 237 donep)
246 (while (and (not donep) 238 (while (and (not donep)
247 (< (point) (c-point 'eol))) 239 (< (point) (c-point 'eol)))
248 (skip-chars-forward "^=" (c-point 'eol)) 240 (skip-chars-forward "^=" (c-point 'eol))
249 (if (c-in-literal (cdr langelem)) 241 (if (c-in-literal (cdr langelem))
250 (forward-char 1) 242 (forward-char 1)
251 (setq donep t))) 243 (setq donep t)))
252 (if (/= (following-char) ?=) 244 (if (not (eq (char-after) ?=))
253 ;; there's no equal sign on the line 245 ;; there's no equal sign on the line
254 c-basic-offset 246 c-basic-offset
255 ;; calculate indentation column after equals and ws, unless 247 ;; calculate indentation column after equals and ws, unless
256 ;; our line contains an equals sign 248 ;; our line contains an equals sign
257 (if (not equalp) 249 (if (not equalp)
271 ;; with it. 263 ;; with it.
272 (save-excursion 264 (save-excursion
273 (let* ((extra (save-excursion 265 (let* ((extra (save-excursion
274 (back-to-indentation) 266 (back-to-indentation)
275 (c-backward-syntactic-ws (cdr langelem)) 267 (c-backward-syntactic-ws (cdr langelem))
276 (if (= (preceding-char) ?:) 268 (if (eq (char-before) ?:)
277 (- c-basic-offset) 269 (- c-basic-offset)
278 0))) 270 0)))
279 (open-bracket-pos (cdr langelem)) 271 (open-bracket-pos (cdr langelem))
280 (open-bracket-col (progn 272 (open-bracket-col (progn
281 (goto-char open-bracket-pos) 273 (goto-char open-bracket-pos)
299 (eol (c-point 'eol)) 291 (eol (c-point 'eol))
300 (relpos (cdr langelem)) 292 (relpos (cdr langelem))
301 (first-col-column (progn 293 (first-col-column (progn
302 (goto-char relpos) 294 (goto-char relpos)
303 (skip-chars-forward "^:" eol) 295 (skip-chars-forward "^:" eol)
304 (and (= (following-char) ?:) 296 (and (eq (char-after) ?:)
305 (current-column))))) 297 (current-column)))))
306 (if (not first-col-column) 298 (if (not first-col-column)
307 c-basic-offset 299 c-basic-offset
308 (goto-char here) 300 (goto-char here)
309 (skip-chars-forward "^:" eol) 301 (skip-chars-forward "^:" eol)
310 (if (= (following-char) ?:) 302 (if (eq (char-after) ?:)
311 (+ curcol (- first-col-column (current-column))) 303 (+ curcol (- first-col-column (current-column)))
312 c-basic-offset))))) 304 c-basic-offset)))))
313 305
314 (defun c-lineup-ObjC-method-args-2 (langelem) 306 (defun c-lineup-ObjC-method-args-2 (langelem)
315 ;; Line up the colons that separate args. This is done trying to 307 ;; Line up the colons that separate args. This is done trying to
319 (curcol (progn (goto-char here) (current-column))) 311 (curcol (progn (goto-char here) (current-column)))
320 (eol (c-point 'eol)) 312 (eol (c-point 'eol))
321 (relpos (cdr langelem)) 313 (relpos (cdr langelem))
322 (prev-col-column (progn 314 (prev-col-column (progn
323 (skip-chars-backward "^:" relpos) 315 (skip-chars-backward "^:" relpos)
324 (and (= (preceding-char) ?:) 316 (and (eq (char-before) ?:)
325 (- (current-column) 1))))) 317 (- (current-column) 1)))))
326 (if (not prev-col-column) 318 (if (not prev-col-column)
327 c-basic-offset 319 c-basic-offset
328 (goto-char here) 320 (goto-char here)
329 (skip-chars-forward "^:" eol) 321 (skip-chars-forward "^:" eol)
330 (if (= (following-char) ?:) 322 (if (eq (char-after) ?:)
331 (+ curcol (- prev-col-column (current-column))) 323 (+ curcol (- prev-col-column (current-column)))
332 c-basic-offset))))) 324 c-basic-offset)))))
333 325
334 (defun c-snug-do-while (syntax pos) 326 (defun c-snug-do-while (syntax pos)
335 "Dynamically calculate brace hanginess for do-while statements. 327 "Dynamically calculate brace hanginess for do-while statements.
341 (save-excursion 333 (save-excursion
342 (let (langelem) 334 (let (langelem)
343 (if (and (eq syntax 'block-close) 335 (if (and (eq syntax 'block-close)
344 (setq langelem (assq 'block-close c-syntactic-context)) 336 (setq langelem (assq 'block-close c-syntactic-context))
345 (progn (goto-char (cdr langelem)) 337 (progn (goto-char (cdr langelem))
346 (if (= (following-char) ?{) 338 (if (eq (char-after) ?{)
347 (c-safe (forward-sexp -1))) 339 (c-safe (forward-sexp -1)))
348 (looking-at "\\<do\\>[^_]"))) 340 (looking-at "\\<do\\>[^_]")))
349 '(before) 341 '(before)
350 '(before after))))) 342 '(before after)))))
351 343
383 inserted inside a parenthesis list, no newline is added otherwise a 375 inserted inside a parenthesis list, no newline is added otherwise a
384 newline is added. In either case, checking is stopped. This supports 376 newline is added. In either case, checking is stopped. This supports
385 exactly the old newline insertion behavior." 377 exactly the old newline insertion behavior."
386 ;; newline only after semicolon, but only if that semicolon is not 378 ;; newline only after semicolon, but only if that semicolon is not
387 ;; inside a parenthesis list (e.g. a for loop statement) 379 ;; inside a parenthesis list (e.g. a for loop statement)
388 (if (/= last-command-char ?\;) 380 (if (not (eq last-command-char ?\;))
389 nil ; continue checking 381 nil ; continue checking
390 (if (condition-case nil 382 (if (condition-case nil
391 (save-excursion 383 (save-excursion
392 (up-list -1) 384 (up-list -1)
393 (/= (following-char) ?\()) 385 (not (eq (char-after) ?\()))
394 (error t)) 386 (error t))
395 t 387 t
396 'stop))) 388 'stop)))
397 389
398 390