/[emacs]/emacs/lisp/progmodes/cc-align.el
ViewVC logotype

Diff of /emacs/lisp/progmodes/cc-align.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.19 by lektu, Tue May 6 17:44:11 2003 UTC revision 1.20 by mast, Thu Jul 3 12:30:59 2003 UTC
# Line 1  Line 1 
1  ;;; cc-align.el --- custom indentation functions for CC Mode  ;;; cc-align.el --- custom indentation functions for CC Mode
2    
3  ;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.  ;; Copyright (C) 1985,1987,1992-2003 Free Software Foundation, Inc.
4    
5  ;; Authors:    2000- Martin Stjernholm  ;; Authors:    1998- Martin Stjernholm
6  ;;             1998-1999 Barry A. Warsaw and Martin Stjernholm  ;;             1992-1999 Barry A. Warsaw
 ;;             1992-1997 Barry A. Warsaw  
7  ;;             1987 Dave Detlefs and Stewart Clamen  ;;             1987 Dave Detlefs and Stewart Clamen
8  ;;             1985 Richard M. Stallman  ;;             1985 Richard M. Stallman
9  ;; Maintainer: bug-cc-mode@gnu.org  ;; Maintainer: bug-cc-mode@gnu.org
# Line 39  Line 38 
38                    (stringp byte-compile-dest-file))                    (stringp byte-compile-dest-file))
39               (cons (file-name-directory byte-compile-dest-file) load-path)               (cons (file-name-directory byte-compile-dest-file) load-path)
40             load-path)))             load-path)))
41      (require 'cc-bytecomp)))      (load "cc-bytecomp" nil t)))
42    
43  (cc-require 'cc-defs)  (cc-require 'cc-defs)
44  (cc-require 'cc-vars)  (cc-require 'cc-vars)
 (cc-require 'cc-langs)  
45  (cc-require 'cc-engine)  (cc-require 'cc-engine)
46    
47    
48  ;; Standard indentation line-ups  ;; Standard indentation line-ups
49    
50    ;; Calling convention:
51    ;;
52    ;; The single argument is a cons cell containing the syntactic symbol
53    ;; in the car, and the relpos (a.k.a. anchor position) in the cdr.
54    ;; The cdr may be nil for syntactic symbols which doesn't have an
55    ;; associated relpos.
56    ;;
57    ;; Some syntactic symbols provide more information, usually more
58    ;; interesting positions.  The complete list for the syntactic element
59    ;; (beginning with the symbol itself) is available in
60    ;; `c-syntactic-element'.
61    
62  (defun c-lineup-topmost-intro-cont (langelem)  (defun c-lineup-topmost-intro-cont (langelem)
63    "Line up declaration continuation lines zero or one indentation step.    "Line up declaration continuation lines zero or one indentation step.
64  For lines in the \"header\" of a definition, zero is used.  For other  For lines in the \"header\" of a definition, zero is used.  For other
# Line 88  Works with: topmost-intro-cont." Line 98  Works with: topmost-intro-cont."
98  (defun c-lineup-arglist (langelem)  (defun c-lineup-arglist (langelem)
99    "Line up the current argument line under the first argument.    "Line up the current argument line under the first argument.
100    
101    As a special case, if an argument on the same line as the open
102    parenthesis starts with a brace block opener, the indentation is
103    `c-basic-offset' only.  This is intended as a \"DWIM\" measure in
104    cases like macros that contains statement blocks, e.g:
105    
106    A_VERY_LONG_MACRO_NAME ({
107            some (code, with + long, lines * in[it]);
108        });
109    <--> c-basic-offset
110    
111    This is motivated partly because it's more in line with how code
112    blocks are handled, and partly since it approximates the behavior of
113    earlier CC Mode versions, which due to inaccurate analysis tended to
114    indent such cases this way.
115    
116  Works with: arglist-cont-nonempty, arglist-close."  Works with: arglist-cont-nonempty, arglist-close."
117    (save-excursion    (save-excursion
118      (beginning-of-line)      (goto-char (1+ (elt c-syntactic-element 2)))
119      (let ((containing-sexp (c-most-enclosing-brace (c-parse-state))))  
120        (goto-char (1+ containing-sexp))      ;; Don't stop in the middle of a special brace list opener
121        (let ((eol (c-point 'eol)))      ;; like "({".
122        (when c-special-brace-lists
123          (let ((special-list (c-looking-at-special-brace-list)))
124            (when special-list
125              (goto-char (+ (car (car special-list)) 2)))))
126    
127        (let ((savepos (point))
128              (eol (c-point 'eol)))
129    
130          ;; Find out if an argument on the same line starts with an
131          ;; unclosed open brace paren.  Note similar code in
132          ;; `c-lineup-close-paren' and
133          ;; `c-lineup-arglist-close-under-paren'.
134          (if (and (c-syntactic-re-search-forward "{" eol t t)
135                   (looking-at c-syntactic-eol)
136                   (progn (backward-char)
137                          (not (c-looking-at-special-brace-list)))
138                   (progn (c-backward-syntactic-ws)
139                          (or (= (point) savepos)
140                              (eq (char-before) ?,))))
141              c-basic-offset
142    
143            ;; Normal case.  Indent to the token after the arglist open paren.
144            (goto-char savepos)
145          (c-forward-syntactic-ws)          (c-forward-syntactic-ws)
146          (when (< (point) eol)          (when (< (point) eol)
147            (goto-char (1+ containing-sexp))            (goto-char savepos)
148            (skip-chars-forward " \t")))            (skip-chars-forward " \t"))
149        (vector (current-column)))))          (vector (current-column))))))
150    
151  ;; Contributed by Kevin Ryde <user42@zip.com.au>.  ;; Contributed by Kevin Ryde <user42@zip.com.au>.
152  (defun c-lineup-argcont (elem)  (defun c-lineup-argcont (elem)
# Line 118  Works with: arglist-cont, arglist-cont-n Line 166  Works with: arglist-cont, arglist-cont-n
166    
167    (save-excursion    (save-excursion
168      (beginning-of-line)      (beginning-of-line)
     (let ((bol (point)))  
   
       ;; Previous line ending in a comma means we're the start of an  
       ;; argument.  This should quickly catch most cases not for us.  
       (c-backward-syntactic-ws)  
       (let ((c (char-before)))  
         (unless (eq c ?,)  
169    
170            ;; In a gcc asm, ":" on the previous line means the start of an      (when (eq (car elem) 'arglist-cont-nonempty)
171            ;; argument.  And lines starting with ":" are not for us, don't        ;; Our argument list might not be the innermost one.  If it
172            ;; want them to indent to the preceding operand.        ;; isn't, go back to the last position in it.  We do this by
173            (let ((gcc-asm (save-excursion        ;; stepping back over open parens until we get to the open paren
174                             (goto-char bol)        ;; of our argument list.
175                             (c-in-gcc-asm-p))))        (let ((open-paren (elt c-syntactic-element 2))
176              (unless (and gcc-asm              (paren-state (c-parse-state)))
177                           (or (eq c ?:)          (while (not (eq (car paren-state) open-paren))
178                               (save-excursion            (goto-char (car paren-state))
179                                 (goto-char bol)            (setq paren-state (cdr paren-state)))))
180                                 (looking-at "[ \t]*:"))))  
181        (let ((start (point)) c)
182    
183          (when (bolp)
184            ;; Previous line ending in a comma means we're the start of an
185            ;; argument.  This should quickly catch most cases not for us.
186            ;; This case is only applicable if we're the innermost arglist.
187            (c-backward-syntactic-ws)
188            (setq c (char-before)))
189    
190          (unless (eq c ?,)
191            ;; In a gcc asm, ":" on the previous line means the start of an
192            ;; argument.  And lines starting with ":" are not for us, don't
193            ;; want them to indent to the preceding operand.
194            (let ((gcc-asm (save-excursion
195                             (goto-char start)
196                             (c-in-gcc-asm-p))))
197              (unless (and gcc-asm
198                           (or (eq c ?:)
199                               (save-excursion
200                                 (goto-char start)
201                                 (looking-at "[ \t]*:"))))
202    
203                (c-lineup-argcont-scan (if gcc-asm ?:))              (c-lineup-argcont-scan (if gcc-asm ?:))
204                (vector (current-column)))))))))              (vector (current-column))))))))
205    
206  (defun c-lineup-argcont-scan (&optional other-match)  (defun c-lineup-argcont-scan (&optional other-match)
207    ;; Find the start of an argument, for `c-lineup-argcont'.    ;; Find the start of an argument, for `c-lineup-argcont'.
208    (when (eq 0 (c-backward-token-1 1 t))    (when (zerop (c-backward-token-2 1 t))
209      (let ((c (char-after)))      (let ((c (char-after)))
210        (if (or (eq c ?,) (eq c other-match))        (if (or (eq c ?,) (eq c other-match))
211            (progn            (progn
# Line 152  Works with: arglist-cont, arglist-cont-n Line 214  Works with: arglist-cont, arglist-cont-n
214          (c-lineup-argcont-scan other-match)))))          (c-lineup-argcont-scan other-match)))))
215    
216  (defun c-lineup-arglist-intro-after-paren (langelem)  (defun c-lineup-arglist-intro-after-paren (langelem)
217    "Line up a line just after the open paren of the surrounding paren or    "Line up a line to just after the open paren of the surrounding paren
218  brace block.  or brace block.
219    
220  Works with: defun-block-intro, brace-list-intro,  Works with: defun-block-intro, brace-list-intro,
221  statement-block-intro, statement-case-intro, arglist-intro."  statement-block-intro, statement-case-intro, arglist-intro."
# Line 164  statement-block-intro, statement-case-in Line 226  statement-block-intro, statement-case-in
226      (vector (1+ (current-column)))))      (vector (1+ (current-column)))))
227    
228  (defun c-lineup-arglist-close-under-paren (langelem)  (defun c-lineup-arglist-close-under-paren (langelem)
229    "Line up a closing paren line under the corresponding open paren.    "Line up a line under the enclosing open paren.
230    Normally used to line up a closing paren in the same column as its
231    corresponding open paren, but can also be used with arglist-cont and
232    arglist-cont-nonempty to line up all lines inside a parenthesis under
233    the open paren.
234    
235    As a special case, if a brace block is opened at the same line as the
236    open parenthesis of the argument list, the indentation is
237    `c-basic-offset' only.  See `c-lineup-arglist' for further discussion
238    of this \"DWIM\" measure.
239    
240    Works with: Almost all symbols, but are typically most useful on
241    arglist-close, brace-list-close, arglist-cont and arglist-cont-nonempty."
242      (save-excursion
243        (let (special-list paren-start savepos)
244          (if (memq (car langelem) '(arglist-cont-nonempty arglist-close))
245              (goto-char (elt c-syntactic-element 2))
246            (beginning-of-line)
247            (c-go-up-list-backward))
248    
249          (if (and c-special-brace-lists
250                   (setq special-list (c-looking-at-special-brace-list)))
251              ;; Don't stop in the middle of a special brace list opener
252              ;; like "({".
253              (progn
254                (setq paren-start (car (car special-list)))
255                (goto-char (+ paren-start 2)))
256            (setq paren-start (point))
257            (forward-char 1))
258    
259          (setq savepos (point))
260          ;; Find out if an argument on the same line starts with an
261          ;; unclosed open brace paren.  Note similar code in
262          ;; `c-lineup-arglist' and `c-lineup-close-paren'.
263          (if (and (c-syntactic-re-search-forward "{" (c-point 'eol) t t)
264                   (looking-at c-syntactic-eol)
265                   (progn (backward-char)
266                          (not (c-looking-at-special-brace-list)))
267                   (progn (c-backward-syntactic-ws)
268                          (or (= (point) savepos)
269                              (eq (char-before) ?,))))
270              c-basic-offset
271    
272  Works with: defun-close, class-close, inline-close, block-close,          ;; Normal case.  Indent to the arglist open paren.
273  brace-list-close, arglist-close, extern-lang-close, namespace-close          (goto-char paren-start)
274  \(for most of these, a zero offset will normally produce the same          (vector (current-column))))))
275  result, though)."  
276    (defun c-lineup-arglist-operators (langelem)
277      "Line up lines starting with an infix operator under the open paren.
278    Return nil on lines that don't start with an operator, to leave those
279    cases to other lineup functions.  Example:
280    
281    if (  x < 10
282       || at_limit (x,       <- c-lineup-arglist-operators
283                    list)    <- c-lineup-arglist-operators returns nil
284       )
285    
286    Since this function doesn't do anything for lines without an infix
287    operator you typically want to use it together with some other lineup
288    settings, e.g. as follows \(the arglist-close setting is just a
289    suggestion to get a consistent style):
290    
291    \(c-set-offset 'arglist-cont '(c-lineup-arglist-operators 0))
292    \(c-set-offset 'arglist-cont-nonempty '(c-lineup-arglist-operators
293                                            c-lineup-arglist))
294    \(c-set-offset 'arglist-close '(c-lineup-arglist-close-under-paren))
295    
296    Works with: arglist-cont, arglist-cont-nonempty."
297    (save-excursion    (save-excursion
298      (beginning-of-line)      (back-to-indentation)
299      (backward-up-list 1)      (when (looking-at "[-+|&*%<>=]\\|\\(/[^/*]\\)")
300      (vector (current-column))))        ;; '-' can be both an infix and a prefix operator, but I'm lazy now..
301          (c-lineup-arglist-close-under-paren langelem))))
302    
303  (defun c-lineup-close-paren (langelem)  (defun c-lineup-close-paren (langelem)
304    "Line up the closing paren under its corresponding open paren if the    "Line up the closing paren under its corresponding open paren if the
# Line 184  main (int,              main ( Line 309  main (int,              main (
309        char **               int, char **        char **               int, char **
310       )           <->    )                 <- c-lineup-close-paren       )           <->    )                 <- c-lineup-close-paren
311    
312  Works with: defun-close, class-close, inline-close, block-close,  As a special case, if a brace block is opened at the same line as the
313  brace-list-close, arglist-close, extern-lang-close, namespace-close."  open parenthesis of the argument list, the indentation is
314    `c-basic-offset' instead of the open paren column.  See
315    `c-lineup-arglist' for further discussion of this \"DWIM\" measure.
316    
317    Works with: All *-close symbols."
318    (save-excursion    (save-excursion
319      (condition-case nil      (beginning-of-line)
320          (let (opencol spec)      (c-go-up-list-backward)
321            (beginning-of-line)  
322            (backward-up-list 1)      (let ((spec (c-looking-at-special-brace-list)) savepos argstart)
323            (setq spec (c-looking-at-special-brace-list))        (if spec (goto-char (car (car spec))))
324            (if spec (goto-char (car (car spec))))        (setq savepos (point))
325            (setq opencol (current-column))        (forward-char 1)
326            (forward-char 1)        (when spec
327            (if spec (progn          (c-forward-syntactic-ws)
328                       (c-forward-syntactic-ws)          (forward-char 1))
329                       (forward-char 1)))  
330            (c-forward-syntactic-ws (c-point 'eol))        (if (looking-at c-syntactic-eol)
331            (if (eolp)            ;; The arglist is "empty".
332                0            0
333              (vector opencol)))  
334        (error nil))))          ;; Find out if an argument on the same line starts with an
335            ;; unclosed open brace paren.  Note similar code in
336            ;; `c-lineup-arglist' and
337            ;; `c-lineup-arglist-close-under-paren'.
338            (setq argstart (point))
339            (if (and (c-syntactic-re-search-forward "{" (c-point 'eol) t t)
340                     (looking-at c-syntactic-eol)
341                     (progn (backward-char)
342                            (not (c-looking-at-special-brace-list)))
343                     (progn (c-backward-syntactic-ws)
344                            (or (= (point) argstart)
345                                (eq (char-before) ?,))))
346                c-basic-offset
347    
348              ;; Normal case.  Indent to the arglist open paren.
349              (goto-char savepos)
350              (vector (current-column)))))))
351    
352  (defun c-lineup-streamop (langelem)  (defun c-lineup-streamop (langelem)
353    "Line up C++ stream operators under each other.    "Line up C++ stream operators under each other.
# Line 232  class Foo                 Foo::Foo (int Line 377  class Foo                 Foo::Foo (int
377    
378  Works with: inher-cont, member-init-cont."  Works with: inher-cont, member-init-cont."
379    (save-excursion    (save-excursion
380        (back-to-indentation)
381      (let* ((eol (c-point 'eol))      (let* ((eol (c-point 'eol))
382             (here (point))             (here (point))
383             (char-after-ip (progn             (char-after-ip (progn
# Line 253  Works with: inher-cont, member-init-cont Line 399  Works with: inher-cont, member-init-cont
399        (if (or (eolp)        (if (or (eolp)
400                (looking-at c-comment-start-regexp))                (looking-at c-comment-start-regexp))
401            (c-forward-syntactic-ws here))            (c-forward-syntactic-ws here))
402        (vector (current-column))        (if (< (point) here)
403              (vector (current-column)))
404        )))        )))
405    
406  (defun c-lineup-java-inher (langelem)  (defun c-lineup-java-inher (langelem)
407    "Line up Java implements and extends declarations.    "Line up Java implements and extends declarations.
408  If class names follows on the same line as the implements/extends  If class names follow on the same line as the implements/extends
409  keyword, they are lined up under each other.  Otherwise, they are  keyword, they are lined up under each other.  Otherwise, they are
410  indented by adding `c-basic-offset' to the column of the keyword.  indented by adding `c-basic-offset' to the column of the keyword.
411  E.g:  E.g:
# Line 279  Works with: inher-cont." Line 426  Works with: inher-cont."
426    
427  (defun c-lineup-java-throws (langelem)  (defun c-lineup-java-throws (langelem)
428    "Line up Java throws declarations.    "Line up Java throws declarations.
429  If exception names follows on the same line as the throws keyword,  If exception names follow on the same line as the throws keyword,
430  they are lined up under each other.  Otherwise, they are indented by  they are lined up under each other.  Otherwise, they are indented by
431  adding `c-basic-offset' to the column of the throws keyword.  The  adding `c-basic-offset' to the column of the throws keyword.  The
432  throws keyword itself is also indented by `c-basic-offset' from the  throws keyword itself is also indented by `c-basic-offset' from the
# Line 295  Works with: func-decl-cont." Line 442  Works with: func-decl-cont."
442      (let* ((lim (1- (c-point 'bol)))      (let* ((lim (1- (c-point 'bol)))
443             (throws (catch 'done             (throws (catch 'done
444                       (goto-char (cdr langelem))                       (goto-char (cdr langelem))
445                       (while (zerop (c-forward-token-1 1 t lim))                       (while (zerop (c-forward-token-2 1 t lim))
446                         (if (looking-at "throws\\>[^_]")                         (if (looking-at "throws\\>[^_]")
447                             (throw 'done t))))))                             (throw 'done t))))))
448        (if throws        (if throws
449            (if (zerop (c-forward-token-1 1 nil (c-point 'eol)))            (if (zerop (c-forward-token-2 1 nil (c-point 'eol)))
450                (vector (current-column))                (vector (current-column))
451              (back-to-indentation)              (back-to-indentation)
452              (vector (+ (current-column) c-basic-offset)))              (vector (+ (current-column) c-basic-offset)))
# Line 470  Works with: comment-intro." Line 617  Works with: comment-intro."
617        (cond        (cond
618         ;; CASE 1: preserve aligned comments         ;; CASE 1: preserve aligned comments
619         ((save-excursion         ((save-excursion
620            (and (c-forward-comment -1)            (and (c-backward-single-comment)
621                 (= col (current-column))))                 (= col (current-column))))
622          (vector col))                   ; Return an absolute column.          (vector col))                   ; Return an absolute column.
623         ;; indent as specified by c-comment-only-line-offset         ;; indent as specified by c-comment-only-line-offset
# Line 534  the statement.  If there isn't any, inde Line 681  the statement.  If there isn't any, inde
681  the current line contains an equal sign too, try to align it with the  the current line contains an equal sign too, try to align it with the
682  first one.  first one.
683    
684  Works with: statement-cont, arglist-cont, arglist-cont-nonempty."  Works with: topmost-intro-cont, statement-cont, arglist-cont,
685    (save-excursion  arglist-cont-nonempty."
686      (let ((equalp (save-excursion    (let (startpos endpos equalp)
687                      (goto-char (c-point 'boi))  
688                      (let ((eol (c-point 'eol)))      (if (eq (car langelem) 'arglist-cont-nonempty)
689                        (c-forward-token-1 0 t eol)          ;; If it's an arglist-cont-nonempty then we're only interested
690                        (while (and (not (eq (char-after) ?=))          ;; in equal signs outside it.  We don't search for a "=" on
691                                    (= (c-forward-token-1 1 t eol) 0))))          ;; the current line since that'd have a different nesting
692                      (and (eq (char-after) ?=)          ;; compared to the one we should align with.
693                           (- (point) (c-point 'boi)))))          (save-excursion
694            donep)            (save-restriction
695        (if (cdr langelem) (goto-char (cdr langelem)))              (setq endpos (nth 2 c-syntactic-element))
696        (while (and (not donep)              (narrow-to-region (cdr langelem) endpos)
697                    (< (point) (c-point 'eol)))              (if (setq startpos (c-up-list-backward endpos))
698          (skip-chars-forward "^=" (c-point 'eol))                  (setq startpos (1+ startpos))
699          (if (c-in-literal (cdr langelem))                (setq startpos (cdr langelem)))))
700              (forward-char 1)  
701            (setq donep t)))        (setq startpos (cdr langelem)
702        (if (or (not (eq (char-after) ?=))              endpos (point))
703    
704          ;; Find a syntactically relevant and unnested "=" token on the
705          ;; current line.  equalp is in that case set to the number of
706          ;; columns to left shift the current line to align it with the
707          ;; goal column.
708          (save-excursion
709            (beginning-of-line)
710            (when (c-syntactic-re-search-forward
711                   ;; This regexp avoids matches on ==.
712                   "\\(\\=\\|[^=]\\)=\\([^=]\\|$\\)"
713                   (c-point 'eol) t t)
714              (setq equalp (- (match-beginning 2) (c-point 'boi))))))
715    
716        (save-excursion
717          (goto-char startpos)
718          (if (or (if (c-syntactic-re-search-forward
719                       "\\(\\=\\|[^=]\\)=\\([^=]\\|$\\)"
720                       (min endpos (c-point 'eol)) t t)
721                      (progn
722                        (goto-char (match-beginning 2))
723                        nil)
724                    t)
725                (save-excursion                (save-excursion
                 (forward-char 1)  
726                  (c-forward-syntactic-ws (c-point 'eol))                  (c-forward-syntactic-ws (c-point 'eol))
727                  (eolp)))                  (eolp)))
728            ;; there's no equal sign on the line            ;; There's no equal sign on the line, or there is one but
729              ;; nothing follows it.
730            c-basic-offset            c-basic-offset
731    
732          ;; calculate indentation column after equals and ws, unless          ;; calculate indentation column after equals and ws, unless
733          ;; our line contains an equals sign          ;; our line contains an equals sign
734          (if (not equalp)          (if (not equalp)
735              (progn              (progn
               (forward-char 1)  
736                (skip-chars-forward " \t")                (skip-chars-forward " \t")
737                (setq equalp 0)))                (setq equalp 0)))
738    
739          (vector (- (current-column) equalp)))          (vector (- (current-column) equalp)))
740        )))        )))
741    
742  (defun c-lineup-cascaded-calls (langelem)  (defun c-lineup-cascaded-calls (langelem)
743    "Line up \"cascaded calls\" under each other.    "Line up \"cascaded calls\" under each other.
744  If the line begins with \"->\" and the preceding line ends with one or  If the line begins with \"->\" or \".\" and the preceding line ends
745  more function calls preceded by \"->\", then the arrow is lined up with  with one or more function calls preceded by the same token, then the
746  the first of those \"->\". E.g:  arrow is lined up with the first of those tokens.  E.g:
747    
748  result = proc->add(17)->add(18)  result = proc->add(17)->add(18)
749               ->add(19) +           <- c-lineup-cascaded-calls               ->add(19) +           <- c-lineup-cascaded-calls
# Line 582  result = proc->add(17)->add(18) Line 752  result = proc->add(17)->add(18)
752  In any other situation nil is returned to allow use in list  In any other situation nil is returned to allow use in list
753  expressions.  expressions.
754    
755  Works with: statement-cont, arglist-cont, arglist-cont-nonempty."  Works with: topmost-intro-cont, statement-cont, arglist-cont,
756    (save-excursion  arglist-cont-nonempty."
757      (let ((bopl (c-point 'bopl)) col)  
758      (if (and (eq (car langelem) 'arglist-cont-nonempty)
759               (not (eq (nth 2 c-syntactic-element)
760                        (c-most-enclosing-brace (c-parse-state)))))
761          ;; The innermost open paren is not our one, so don't do
762          ;; anything.  This can occur for arglist-cont-nonempty with
763          ;; nested arglist starts on the same line.
764          nil
765    
766        (save-excursion
767        (back-to-indentation)        (back-to-indentation)
768        (when (and (looking-at "->")        (let ((operator (and (looking-at "->\\|\\.")
769                   (= (c-backward-token-1 1 t bopl) 0)                             (regexp-quote (match-string 0))))
770                   (eq (char-after) ?\()              (stmt-start (cdr langelem)) col)
771                   (= (c-backward-token-1 3 t bopl) 0)  
772                   (looking-at "->"))          (when (and operator
773          (setq col (current-column))                     (looking-at operator)
774          (while (and (= (c-backward-token-1 1 t bopl) 0)                     (zerop (c-backward-token-2 1 t stmt-start))
775                      (eq (char-after) ?\()                     (eq (char-after) ?\()
776                      (= (c-backward-token-1 3 t bopl) 0)                     (zerop (c-backward-token-2 2 t stmt-start))
777                      (looking-at "->"))                     (looking-at operator))
778            (setq col (current-column)))            (setq col (current-column))
779          (vector col)))))  
780              (while (and (zerop (c-backward-token-2 1 t stmt-start))
781                          (eq (char-after) ?\()
782                          (zerop (c-backward-token-2 2 t stmt-start))
783                          (looking-at operator))
784                (setq col (current-column)))
785    
786              (vector col))))))
787    
788    (defun c-lineup-string-cont (langelem)
789      "Line up a continued string under the one it continues.
790    A continued string in this sense is where a string literal follows
791    directly after another one.  E.g:
792    
793    result = prefix + \"A message \"
794                      \"string.\";      <- c-lineup-string-cont
795    
796    Nil is returned in other situations, to allow stacking with other
797    lineup functions.
798    
799    Works with: topmost-intro-cont, statement-cont, arglist-cont,
800    arglist-cont-nonempty."
801      (save-excursion
802        (back-to-indentation)
803        (and (looking-at "\\s\"")
804             (let ((quote (char-after)) pos)
805               (while (and (progn (c-backward-syntactic-ws)
806                                  (eq (char-before) quote))
807                           (c-safe (c-backward-sexp) t)
808                           (/= (setq pos (point)) (c-point 'boi))))
809               (when pos
810                 (goto-char pos)
811                 (vector (current-column)))))))
812    
813  (defun c-lineup-template-args (langelem)  (defun c-lineup-template-args (langelem)
814    "Line up template argument lines under the first argument.    "Line up template argument lines under the first argument.
# Line 610  Works with: template-args-cont." Line 821  Works with: template-args-cont."
821        (beginning-of-line)        (beginning-of-line)
822        (backward-up-list 1)        (backward-up-list 1)
823        (if (and (eq (char-after) ?<)        (if (and (eq (char-after) ?<)
824                 (zerop (c-forward-token-1 1 nil (c-point 'eol))))                 (zerop (c-forward-token-2 1 nil (c-point 'eol))))
825            (vector (current-column))))))            (vector (current-column))))))
826    
827  (defun c-lineup-ObjC-method-call (langelem)  (defun c-lineup-ObjC-method-call (langelem)
828    "Line up selector args as elisp-mode does with function args:    "Line up selector args as Emacs Lisp mode does with function args:
829  Go to the position right after the message receiver, and if you are at  Go to the position right after the message receiver, and if you are at
830  the end of the line, indent the current line c-basic-offset columns  the end of the line, indent the current line c-basic-offset columns
831  from the opening bracket; otherwise you are looking at the first  from the opening bracket; otherwise you are looking at the first
# Line 736  In the first case the indentation is kep Line 947  In the first case the indentation is kep
947  second `c-basic-offset' is added.  second `c-basic-offset' is added.
948    
949  Works with: defun-close, defun-block-intro, block-close,  Works with: defun-close, defun-block-intro, block-close,
950  brace-list-close, brace-list-intro, statement-block-intro, inclass,  brace-list-close, brace-list-intro, statement-block-intro and all in*
951  inextern-lang, innamespace."  symbols, e.g. inclass and inextern-lang."
952    (save-excursion    (save-excursion
953      (goto-char (cdr langelem))      (goto-char (cdr langelem))
954      (back-to-indentation)      (back-to-indentation)
# Line 775  const char msg[] =             if (!runn Line 986  const char msg[] =             if (!runn
986  } while (0)             <->    } while (0)           <- c-lineup-cpp-define  } while (0)             <->    } while (0)           <- c-lineup-cpp-define
987    
988  The relative indentation returned by `c-lineup-cpp-define' is zero and  The relative indentation returned by `c-lineup-cpp-define' is zero and
989  two, respectively, in these two examples. They are then added to the  two, respectively, in these two examples.  They are then added to the
990  two column indentation that statement-block-intro gives in both cases  two column indentation that statement-block-intro gives in both cases
991  here.  here.
992    
993  If the relative indentation is zero, then nil is returned instead.  If the relative indentation is zero, then nil is returned instead.
994  This useful in a list expression to specify the default indentation on  That is useful in a list expression to specify the default indentation
995  the top level.  on the top level.
996    
997  If `c-syntactic-indentation-in-macros' is nil then this function keeps  If `c-syntactic-indentation-in-macros' is nil then this function keeps
998  the current indentation, except for empty lines \(ignoring the ending  the current indentation, except for empty lines \(ignoring the ending
# Line 855  Works with: arglist-cont, arglist-cont-n Line 1066  Works with: arglist-cont, arglist-cont-n
1066        (and        (and
1067         c-opt-asm-stmt-key         c-opt-asm-stmt-key
1068    
1069           ;; Don't do anything if the innermost open paren isn't our one.
1070           ;; This can occur for arglist-cont-nonempty with nested arglist
1071           ;; starts on the same line.
1072           (or (not (eq (car elem) 'arglist-cont-nonempty))
1073               (eq (elt c-syntactic-element 2)
1074                   (c-most-enclosing-brace (c-parse-state))))
1075    
1076         ;; Find the ":" to align to.  Look for this first so as to quickly         ;; Find the ":" to align to.  Look for this first so as to quickly
1077         ;; eliminate pretty much all cases which are not for us.         ;; eliminate pretty much all cases which are not for us.
1078         (re-search-backward "^[ \t]*:[ \t]*\\(.\\)?" (cdr elem) t)         (re-search-backward "^[ \t]*:[ \t]*\\(.\\)?" (cdr elem) t)
# Line 893  ACTION associated with `block-close' syn Line 1111  ACTION associated with `block-close' syn
1111      (let (langelem)      (let (langelem)
1112        (if (and (eq syntax 'block-close)        (if (and (eq syntax 'block-close)
1113                 (setq langelem (assq 'block-close c-syntactic-context))                 (setq langelem (assq 'block-close c-syntactic-context))
1114                 (progn (goto-char (cdr langelem))                 (progn (goto-char (elt langelem 1))
1115                        (if (eq (char-after) ?{)                        (if (eq (char-after) ?{)
1116                            (c-safe (c-forward-sexp -1)))                            (c-safe (c-forward-sexp -1)))
1117                        (looking-at "\\<do\\>[^_]")))                        (looking-at "\\<do\\>[^_]")))
# Line 904  ACTION associated with `block-close' syn Line 1122  ACTION associated with `block-close' syn
1122    "Imposes a minimum indentation for lines inside a top-level construct.    "Imposes a minimum indentation for lines inside a top-level construct.
1123  The variable `c-label-minimum-indentation' specifies the minimum  The variable `c-label-minimum-indentation' specifies the minimum
1124  indentation amount."  indentation amount."
1125    (let ((non-top-levels '(defun-block-intro statement statement-cont  
1126                             statement-block-intro statement-case-intro    ;; Don't adjust macro or comment-only lines.
1127                             statement-case-open substatement substatement-open    (unless (or (assq 'cpp-macro c-syntactic-context)
1128                             case-label label do-while-closure else-clause                (assq 'comment-intro c-syntactic-context))
1129                             ))  
1130          (syntax c-syntactic-context)      (let ((paren-state (save-excursion
1131          langelem)                           ;; Get the parenthesis state, but skip past
1132      (while syntax                           ;; an initial closing paren on the line since
1133        (setq langelem (car (car syntax))                           ;; the close brace of a block shouldn't be
1134              syntax (cdr syntax))                           ;; considered to be inside the block.
1135        ;; don't adjust macro or comment-only lines                           (back-to-indentation)
1136        (cond ((memq langelem '(cpp-macro comment-intro))                           (when (looking-at "\\s\)")
1137               (setq syntax nil))                             (forward-char))
1138              ((memq langelem non-top-levels)                           (c-parse-state))))
1139               (save-excursion  
1140                 (setq syntax nil)        ;; Search for an enclosing brace on paren-state.
1141                 (back-to-indentation)        (while (and paren-state
1142                 (if (zerop (current-column))                    (not (and (integer-or-marker-p (car paren-state))
1143                     (insert-char ?\  c-label-minimum-indentation t))                              (eq (char-after (car paren-state)) ?{))))
1144                 ))          (setq paren-state (cdr paren-state)))
1145              ))))  
1146          (when paren-state
1147            (save-excursion
1148              (back-to-indentation)
1149              (if (zerop (current-column))
1150                  (insert-char ?\  c-label-minimum-indentation t)))))))
1151    
1152    
1153  ;; Useful for c-hanging-semi&comma-criteria  ;; Useful for c-hanging-semi&comma-criteria

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.20

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26