Merge from emacs-24; up to 2012-12-22T19:09:52Z!rgm@gnu.org
[bpt/emacs.git] / lisp / progmodes / cc-align.el
index c5ff081..cb8d2d2 100644 (file)
@@ -1,18 +1,17 @@
 ;;; cc-align.el --- custom indentation functions for CC Mode
 
-;; Copyright (C) 1985, 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
-;;   1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
-;;   Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1987, 1992-2013 Free Software Foundation, Inc.
 
 ;; Authors:    2004- Alan Mackenzie
 ;;             1998- Martin Stjernholm
 ;;             1992-1999 Barry A. Warsaw
-;;             1987 Dave Detlefs and Stewart Clamen
+;;             1987 Dave Detlefs
+;;             1987 Stewart Clamen
 ;;             1985 Richard M. Stallman
 ;; Maintainer: bug-cc-mode@gnu.org
 ;; Created:    22-Apr-1997 (split from cc-mode.el)
-;; Version:    See cc-mode.el
-;; Keywords:   c languages oop
+;; Keywords:   c languages
+;; Package:    cc-mode
 
 ;; This file is part of GNU Emacs.
 
@@ -54,7 +53,7 @@
 (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
@@ -166,7 +165,7 @@ Works with: 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]);
@@ -341,7 +340,7 @@ Works with: arglist-cont, arglist-cont-nonempty."
 (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 **
@@ -395,7 +394,7 @@ Works with: stream-op."
 
 (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),
@@ -440,7 +439,7 @@ Works with: inher-cont, member-init-cont."
 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,
@@ -462,7 +461,7 @@ If exception names follow on the same line as the throws keyword,
 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
@@ -486,7 +485,7 @@ Works with: func-decl-cont."
 
 (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
@@ -509,7 +508,7 @@ Work with: Almost all syntactic symbols, but most useful on *-open."
 
 (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,
@@ -671,7 +670,7 @@ Works with: comment-intro."
 (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
@@ -694,7 +693,7 @@ Works with: comment-intro."
 
 (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!\");
@@ -795,7 +794,7 @@ arglist-cont-nonempty."
   "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
@@ -840,7 +839,7 @@ arglist-cont-nonempty."
 (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
@@ -906,8 +905,48 @@ Works with: objc-method-call-cont."
           )
       (- target-col open-bracket-col extra))))
 
+(defun c-lineup-ObjC-method-call-colons (langelem)
+  "Line up selector args as Project Builder / XCode: colons of first
+   selector portions on successive lines are aligned.  If no decision can
+   be made return NIL, so that other lineup methods can be tried.  This is
+   typically chained with `c-lineup-ObjC-method-call'.
+
+Works with: objc-method-call-cont."
+  (save-excursion
+    (catch 'no-idea
+      (let* ((method-arg-len (progn
+                              (back-to-indentation)
+                              (if (search-forward ":" (c-point 'eol) 'move)
+                                  (- (point) (c-point 'boi))
+                                ; no complete argument to indent yet
+                                (throw 'no-idea nil))))
+
+            (extra (save-excursion
+                      ; indent parameter to argument if needed
+                     (back-to-indentation)
+                     (c-backward-syntactic-ws (c-langelem-pos langelem))
+                     (if (eq ?: (char-before))
+                         c-objc-method-parameter-offset 0)))
+
+            (open-bracket-col (c-langelem-col langelem))
+
+            (arg-ralign-colon-ofs (progn
+                       (forward-char) ; skip over '['
+                       ; skip over object/class name
+                       ; and first argument
+                       (c-forward-sexp 2)
+                       (if (search-forward ":" (c-point 'eol) 'move)
+                           (- (current-column) open-bracket-col
+                              method-arg-len extra)
+                         ; previous arg has no param
+                         c-objc-method-arg-unfinished-offset))))
+
+       (if (>= arg-ralign-colon-ofs c-objc-method-arg-min-delta-to-bracket)
+           (+ arg-ralign-colon-ofs extra)
+         (throw 'no-idea nil))))))
+
 (defun c-lineup-ObjC-method-args (langelem)
-  "Line up the colons that separate args.
+  "Line up the colons that separate args in a method declaration.
 The colon on the current line is aligned with the one on the first
 line.
 
@@ -931,7 +970,7 @@ Works with: objc-method-args-cont."
          c-basic-offset)))))
 
 (defun c-lineup-ObjC-method-args-2 (langelem)
-  "Line up the colons that separate args.
+  "Line up the colons that separate args in a method declaration.
 The colon on the current line is aligned with the one on the previous
 line.
 
@@ -984,7 +1023,7 @@ Works with: inlambda, inexpr-statement, inexpr-class."
 (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 {
@@ -1046,7 +1085,7 @@ arglist-cont."
 
 (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() {
@@ -1245,7 +1284,7 @@ newline is added.  In either case, checking is stopped.  This supports
 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-char ?\;))
+  (if (not (eq last-command-event ?\;))
       nil                              ; continue checking
     (if (condition-case nil
            (save-excursion
@@ -1262,7 +1301,7 @@ If a comma was inserted, no determination is made.  If a semicolon was
 inserted, and the following line is not blank, no newline is inserted.
 Otherwise, no determination is made."
   (save-excursion
-    (if (and (= last-command-char ?\;)
+    (if (and (= last-command-event ?\;)
             ;;(/= (point-max)
             ;;    (save-excursion (skip-syntax-forward " ") (point))
             (zerop (forward-line 1))
@@ -1282,7 +1321,7 @@ For other semicolon contexts, no determination is made."
                (if (c-safe (up-list -1) t)
                    (c-point 'bol)
                  -1))))
-    (if (and (eq last-command-char ?\;)
+    (if (and (eq last-command-event ?\;)
              (eq (car (car syntax)) 'inclass)
              (eq (car (car (cdr syntax))) 'topmost-intro)
              (= (c-point 'bol) bol))
@@ -1292,5 +1331,4 @@ For other semicolon contexts, no determination is made."
 \f
 (cc-provide 'cc-align)
 
-;; arch-tag: 4d71ed28-bf51-4509-a148-f39669669a2e
 ;;; cc-align.el ends here