Mercurial > emacs
comparison lisp/progmodes/cc-align.el @ 20911:8ec2d600e66d
(c-lineup-close-paren)
(c-indent-one-line-block): New indentation functions.
(c-semi&comma-no-newlines-before-nonblanks)
(c-semi&comma-no-newlines-for-oneline-inliners): New functions.
(c-lineup-dont-change): New lineup function that leaves the current
line's indentation unchanged. Used for the new cpp-macro-cont
syntactic symbol.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 17 Feb 1998 07:02:18 +0000 |
parents | 1a85b213eb6d |
children | 95f894e68525 |
comparison
equal
deleted
inserted
replaced
20910:e46446e4af2d | 20911:8ec2d600e66d |
---|---|
1 ;;; cc-align.el --- custom indentation functions for CC Mode | 1 ;;; cc-align.el --- custom indentation functions for CC Mode |
2 | 2 |
3 ;; Copyright (C) 1985,87,92,93,94,95,96,97 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc. |
4 | 4 |
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 |
86 (skip-chars-forward " \t" (c-point 'eol)) | 86 (skip-chars-forward " \t" (c-point 'eol)) |
87 (current-column)))) | 87 (current-column)))) |
88 (- ce-curcol langelem-col -1)))) | 88 (- ce-curcol langelem-col -1)))) |
89 | 89 |
90 (defun c-lineup-arglist-close-under-paren (langelem) | 90 (defun c-lineup-arglist-close-under-paren (langelem) |
91 ;; lineup an arglist-intro line to just after the open paren | 91 ;; lineup an arglist-close line under the corresponding open paren |
92 (save-excursion | 92 (save-excursion |
93 (let ((langelem-col (c-langelem-col langelem t)) | 93 (let ((langelem-col (c-langelem-col langelem t)) |
94 (ce-curcol (save-excursion | 94 (ce-curcol (save-excursion |
95 (beginning-of-line) | 95 (beginning-of-line) |
96 (backward-up-list 1) | 96 (backward-up-list 1) |
97 (current-column)))) | 97 (current-column)))) |
98 (- ce-curcol langelem-col)))) | 98 (- ce-curcol langelem-col)))) |
99 | |
100 (defun c-lineup-close-paren (langelem) | |
101 ;; Indents the closing paren under its corresponding open paren if | |
102 ;; the open paren is followed by code. If the open paren ends its | |
103 ;; line, no indentation is added. E.g: | |
104 ;; | |
105 ;; main (int, main ( | |
106 ;; char ** int, char ** | |
107 ;; ) <-> ) <- c-lineup-close-paren | |
108 ;; | |
109 ;; Works with any type of paren. | |
110 (save-excursion | |
111 (condition-case nil | |
112 (let (opencol spec) | |
113 (beginning-of-line) | |
114 (backward-up-list 1) | |
115 (setq spec (if (fboundp 'c-looking-at-special-brace-list) | |
116 (c-looking-at-special-brace-list))) | |
117 (if spec (goto-char (car spec))) | |
118 (setq opencol (current-column)) | |
119 (forward-char 1) | |
120 (if spec (progn | |
121 (c-forward-syntactic-ws) | |
122 (forward-char 1))) | |
123 (c-forward-syntactic-ws (c-point 'eol)) | |
124 (if (eolp) | |
125 0 | |
126 (- opencol (c-langelem-col langelem t)))) | |
127 (error 0)))) | |
99 | 128 |
100 (defun c-lineup-streamop (langelem) | 129 (defun c-lineup-streamop (langelem) |
101 ;; lineup stream operators | 130 ;; lineup stream operators |
102 (save-excursion | 131 (save-excursion |
103 (let ((langelem-col (c-langelem-col langelem))) | 132 (let ((langelem-col (c-langelem-col langelem))) |
150 (progn | 179 (progn |
151 (back-to-indentation) | 180 (back-to-indentation) |
152 (setq extra c-basic-offset)))) | 181 (setq extra c-basic-offset)))) |
153 (t (goto-char iopl))) | 182 (t (goto-char iopl))) |
154 (+ (- (current-column) langelem-col) extra)))) | 183 (+ (- (current-column) langelem-col) extra)))) |
184 | |
185 (defun c-indent-one-line-block (langelem) | |
186 ;; Adds c-basic-offset to the indentation if the line is a one line | |
187 ;; block, otherwise 0. E.g: | |
188 ;; | |
189 ;; if (n) if (n) | |
190 ;; {m+=n; n=0;} <-> { <- c-indent-one-line-block | |
191 ;; m+=n; n=0; | |
192 ;; } | |
193 (save-excursion | |
194 (let ((eol (progn (end-of-line) (point)))) | |
195 (beginning-of-line) | |
196 (skip-chars-forward " \t") | |
197 (if (and (eq (following-char) ?{) | |
198 (condition-case nil | |
199 (progn (forward-sexp) t) | |
200 (error nil)) | |
201 (<= (point) eol) | |
202 (eq (preceding-char) ?})) | |
203 c-basic-offset | |
204 0)))) | |
155 | 205 |
156 (defun c-lineup-C-comments (langelem) | 206 (defun c-lineup-C-comments (langelem) |
157 ;; line up C block comment continuation lines | 207 ;; line up C block comment continuation lines |
158 (save-excursion | 208 (save-excursion |
159 (let ((here (point)) | 209 (let ((here (point)) |
322 (skip-chars-forward "^:" eol) | 372 (skip-chars-forward "^:" eol) |
323 (if (eq (char-after) ?:) | 373 (if (eq (char-after) ?:) |
324 (+ curcol (- prev-col-column (current-column))) | 374 (+ curcol (- prev-col-column (current-column))) |
325 c-basic-offset))))) | 375 c-basic-offset))))) |
326 | 376 |
377 (defun c-lineup-dont-change (langelem) | |
378 ;; Do not change the indentation of the current line | |
379 (save-excursion | |
380 (back-to-indentation) | |
381 (current-column))) | |
382 | |
383 | |
384 | |
327 (defun c-snug-do-while (syntax pos) | 385 (defun c-snug-do-while (syntax pos) |
328 "Dynamically calculate brace hanginess for do-while statements. | 386 "Dynamically calculate brace hanginess for do-while statements. |
329 Using this function, `while' clauses that end a `do-while' block will | 387 Using this function, `while' clauses that end a `do-while' block will |
330 remain on the same line as the brace that closes that block. | 388 remain on the same line as the brace that closes that block. |
331 | 389 |
369 )))) | 427 )))) |
370 | 428 |
371 | 429 |
372 ;; Useful for c-hanging-semi&comma-criteria | 430 ;; Useful for c-hanging-semi&comma-criteria |
373 (defun c-semi&comma-inside-parenlist () | 431 (defun c-semi&comma-inside-parenlist () |
374 "Determine if a newline should be added after a semicolon. | 432 "Controls newline insertion after semicolons in parenthesis lists. |
375 If a comma was inserted, no determination is made. If a semicolon was | 433 If a comma was inserted, no determination is made. If a semicolon was |
376 inserted inside a parenthesis list, no newline is added otherwise a | 434 inserted inside a parenthesis list, no newline is added otherwise a |
377 newline is added. In either case, checking is stopped. This supports | 435 newline is added. In either case, checking is stopped. This supports |
378 exactly the old newline insertion behavior." | 436 exactly the old newline insertion behavior." |
379 ;; newline only after semicolon, but only if that semicolon is not | 437 ;; newline only after semicolon, but only if that semicolon is not |
386 (not (eq (char-after) ?\())) | 444 (not (eq (char-after) ?\())) |
387 (error t)) | 445 (error t)) |
388 t | 446 t |
389 'stop))) | 447 'stop))) |
390 | 448 |
449 ;; Suppresses newlines before non-blank lines | |
450 (defun c-semi&comma-no-newlines-before-nonblanks () | |
451 "Controls newline insertion after semicolons. | |
452 If a comma was inserted, no determination is made. If a semicolon was | |
453 inserted, and the following line is not blank, no newline is inserted. | |
454 Otherwise, no determination is made." | |
455 (save-excursion | |
456 (if (and (= last-command-char ?\;) | |
457 ;;(/= (point-max) | |
458 ;; (save-excursion (skip-syntax-forward " ") (point)) | |
459 (zerop (forward-line 1)) | |
460 (not (looking-at "^[ \t]*$"))) | |
461 'stop | |
462 nil))) | |
463 | |
464 ;; Suppresses new lines after semicolons in one-liners methods | |
465 (defun c-semi&comma-no-newlines-for-oneline-inliners () | |
466 "Controls newline insertion after semicolons for some one-line methods. | |
467 If a comma was inserted, no determination is made. Newlines are | |
468 suppressed in one-liners, if the line is an in-class inline function. | |
469 For other semicolon contexts, no determination is made." | |
470 (let ((syntax (c-guess-basic-syntax)) | |
471 (bol (save-excursion | |
472 (if (c-safe (up-list -1) t) | |
473 (c-point 'bol) | |
474 -1)))) | |
475 (if (and (eq last-command-char ?\;) | |
476 (eq (car (car syntax)) 'inclass) | |
477 (eq (car (car (cdr syntax))) 'topmost-intro) | |
478 (= (c-point 'bol) bol)) | |
479 'stop | |
480 nil))) | |
481 | |
391 | 482 |
392 (provide 'cc-align) | 483 (provide 'cc-align) |
393 ;;; cc-align.el ends here | 484 ;;; cc-align.el ends here |