aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1998-02-17 07:02:18 +0000
committerRichard M. Stallman1998-02-17 07:02:18 +0000
commiteae86618133fd47f48b0d41d6f9eac1b54c74933 (patch)
treeb061875ee9f6952cb1e09f6c0c0ff0cf93c64f21
parent881c84c72a15c9b785a5818500ef487c3077e041 (diff)
downloademacs-eae86618133fd47f48b0d41d6f9eac1b54c74933.tar.gz
emacs-eae86618133fd47f48b0d41d6f9eac1b54c74933.zip
(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.
-rw-r--r--lisp/progmodes/cc-align.el97
1 files changed, 94 insertions, 3 deletions
diff --git a/lisp/progmodes/cc-align.el b/lisp/progmodes/cc-align.el
index 3e6c51c0b31..98843455dc6 100644
--- a/lisp/progmodes/cc-align.el
+++ b/lisp/progmodes/cc-align.el
@@ -1,6 +1,6 @@
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
@@ -88,7 +88,7 @@
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
@@ -97,6 +97,35 @@
97 (current-column)))) 97 (current-column))))
98 (- ce-curcol langelem-col)))) 98 (- ce-curcol langelem-col))))
99 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))))
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
@@ -153,6 +182,27 @@
153 (t (goto-char iopl))) 182 (t (goto-char iopl)))
154 (+ (- (current-column) langelem-col) extra)))) 183 (+ (- (current-column) langelem-col) extra))))
155 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))))
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
@@ -324,6 +374,14 @@
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.
329Using this function, `while' clauses that end a `do-while' block will 387Using this function, `while' clauses that end a `do-while' block will
@@ -371,7 +429,7 @@ indentation amount."
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.
375If a comma was inserted, no determination is made. If a semicolon was 433If a comma was inserted, no determination is made. If a semicolon was
376inserted inside a parenthesis list, no newline is added otherwise a 434inserted inside a parenthesis list, no newline is added otherwise a
377newline is added. In either case, checking is stopped. This supports 435newline is added. In either case, checking is stopped. This supports
@@ -388,6 +446,39 @@ exactly the old newline insertion behavior."
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.
452If a comma was inserted, no determination is made. If a semicolon was
453inserted, and the following line is not blank, no newline is inserted.
454Otherwise, 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.
467If a comma was inserted, no determination is made. Newlines are
468suppressed in one-liners, if the line is an in-class inline function.
469For 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