;;; cc-align.el --- custom indentation functions for CC Mode
-;; Copyright (C) 1985, 1987, 1992-2012 Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1987, 1992-2015 Free Software Foundation, Inc.
;; Authors: 2004- Alan Mackenzie
;; 1998- Martin Stjernholm
(defun c-lineup-topmost-intro-cont (langelem)
"Line up declaration continuation lines zero or one indentation step.
For lines in the \"header\" of a definition, zero is used. For other
-lines, `c-basic-offset' is added to the indentation. E.g:
+lines, `c-basic-offset' is added to the indentation. E.g.:
int
neg (int i) <- c-lineup-topmost-intro-cont
As a special case, if the indented line is inside a brace block
construct, the indentation is `c-basic-offset' only. This is intended
as a \"DWIM\" measure in cases like macros that contains statement
-blocks, e.g:
+blocks, e.g.:
A_VERY_LONG_MACRO_NAME ({
some (code, with + long, lines * in[it]);
(defun c-lineup-close-paren (langelem)
"Line up the closing paren under its corresponding open paren if the
open paren is followed by code. If the open paren ends its line, no
-indentation is added. E.g:
+indentation is added. E.g.:
main (int, main (
char ** int, char **
(defun c-lineup-multi-inher (langelem)
"Line up the classes in C++ multiple inheritance clauses and member
-initializers under each other. E.g:
+initializers under each other. E.g.:
class Foo: Foo::Foo (int a, int b):
public Cyphr, Cyphr (a),
If class names follow on the same line as the implements/extends
keyword, they are lined up under each other. Otherwise, they are
indented by adding `c-basic-offset' to the column of the keyword.
-E.g:
+E.g.:
class Foo class Foo
extends extends Cyphr,
they are lined up under each other. Otherwise, they are indented by
adding `c-basic-offset' to the column of the throws keyword. The
throws keyword itself is also indented by `c-basic-offset' from the
-function declaration start if it doesn't hang. E.g:
+function declaration start if it doesn't hang. E.g.:
int foo() int foo() throws Cyphr,
throws <-> Bar, <- c-lineup-java-throws
(defun c-indent-one-line-block (langelem)
"Indent a one line block `c-basic-offset' extra.
-E.g:
+E.g.:
if (n > 0) if (n > 0)
{m+=n; n=0;} <-> { <- c-indent-one-line-block
(defun c-indent-multi-line-block (langelem)
"Indent a multi line block `c-basic-offset' extra.
-E.g:
+E.g.:
int *foo[] = { int *foo[] = {
NULL, NULL,
(defun c-lineup-knr-region-comment (langelem)
"Line up a comment in the \"K&R region\" with the declaration.
That is the region between the function or class header and the
-beginning of the block. E.g:
+beginning of the block. E.g.:
int main()
/* This is the main function. */ <- c-lineup-knr-region-comment
(defun c-lineup-runin-statements (langelem)
"Line up statements when the first statement is on the same line as
-the block opening brace. E.g:
+the block opening brace. E.g.:
int main()
{ puts (\"Hello world!\");
(setq startpos (c-langelem-pos langelem)))))
(setq startpos (c-langelem-pos langelem)
- endpos (point))
+ endpos (c-point 'bol))
;; Find a syntactically relevant and unnested "=" token on the
;; current line. equalp is in that case set to the number of
"Line up \"cascaded calls\" under each other.
If the line begins with \"->\" or \".\" and the preceding line ends
with one or more function calls preceded by the same token, then the
-arrow is lined up with the first of those tokens. E.g:
+arrow is lined up with the first of those tokens. E.g.:
result = proc->add(17)->add(18)
->add(19) + <- c-lineup-cascaded-calls
(defun c-lineup-string-cont (langelem)
"Line up a continued string under the one it continues.
A continued string in this sense is where a string literal follows
-directly after another one. E.g:
+directly after another one. E.g.:
result = prefix + \"A message \"
\"string.\"; <- c-lineup-string-cont
; no complete argument to indent yet
(throw 'no-idea nil))))
- (extra (save-excursion
+ (extra (save-excursion
; indent parameter to argument if needed
(back-to-indentation)
(c-backward-syntactic-ws (c-langelem-pos langelem))
(defun c-lineup-whitesmith-in-block (langelem)
"Line up lines inside a block in Whitesmith style.
It's done in a way that works both when the opening brace hangs and
-when it doesn't. E.g:
+when it doesn't. E.g.:
something
{ something {
arglist-intro, arglist-cont-nonempty, arglist-close, and all in*
symbols, e.g. inclass and inextern-lang."
(save-excursion
+ (beginning-of-line)
(if (and (c-go-up-list-backward)
(= (point) (c-point 'boi)))
nil
(defun c-lineup-cpp-define (langelem)
"Line up macro continuation lines according to the indentation of
-the construct preceding the macro. E.g:
+the construct preceding the macro. E.g.:
v beg of preceding constr v beg of preceding constr
int dribble() {
(let ((orig-pos (point))
alignto)
(save-excursion
+ (beginning-of-line)
(and
c-opt-asm-stmt-key
(back-to-indentation)
(vector (current-column))))
+(defun c-lineup-respect-col-0 (langelem)
+ "If the current line starts at column 0, return [0]. Otherwise return nil.
+
+This can be used for comments (in conjunction with, say,
+`c-lineup-comment'), to keep comments already at column 0
+anchored there, but reindent other comments."
+ (save-excursion
+ (back-to-indentation)
+ (if (eq (current-column) 0)
+ [0]
+ nil)))
+
\f
(defun c-snug-do-while (syntax pos)
"Dynamically calculate brace hanginess for do-while statements.
exactly the old newline insertion behavior."
;; newline only after semicolon, but only if that semicolon is not
;; inside a parenthesis list (e.g. a for loop statement)
- (if (not (eq last-command-event ?\;))
+ (if (not (eq (c-last-command-char) ?\;))
nil ; continue checking
(if (condition-case nil
(save-excursion
inserted, and the following line is not blank, no newline is inserted.
Otherwise, no determination is made."
(save-excursion
- (if (and (= last-command-event ?\;)
+ (if (and (= (c-last-command-char) ?\;)
;;(/= (point-max)
;; (save-excursion (skip-syntax-forward " ") (point))
(zerop (forward-line 1))
For other semicolon contexts, no determination is made."
(let ((syntax (c-guess-basic-syntax))
(bol (save-excursion
- (if (c-safe (up-list -1) t)
- (c-point 'bol)
- -1))))
- (if (and (eq last-command-event ?\;)
- (eq (car (car syntax)) 'inclass)
- (eq (car (car (cdr syntax))) 'topmost-intro)
- (= (c-point 'bol) bol))
+ (if (c-safe (up-list -1) t)
+ (c-point 'bol)
+ -1))))
+ (if (and (eq (c-last-command-char) ?\;)
+ (eq (car (car syntax)) 'inclass)
+ (eq (car (car (cdr syntax))) 'topmost-intro)
+ (= (c-point 'bol) bol))
'stop
nil)))
\f
(cc-provide 'cc-align)
+;;; Local Variables:
+;;; indent-tabs-mode: t
+;;; tab-width: 8
+;;; End:
;;; cc-align.el ends here