(eval-when-compile
(require 'cc-defs)
(require 'cc-vars)
(require 'cc-engine)
(require 'cc-langs))
(defun c-lineup-arglist (langelem)
(save-excursion
(let* ((containing-sexp
(save-excursion
(if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
(progn
(beginning-of-line)
(backward-up-list 1)
(skip-chars-forward " \t" (c-point 'eol)))
(goto-char (cdr langelem)))
(point)))
(langelem-col (c-langelem-col langelem t)))
(if (save-excursion
(beginning-of-line)
(looking-at "[ \t]*)"))
(progn (goto-char (match-end 0))
(c-forward-sexp -1)
(forward-char 1)
(c-forward-syntactic-ws)
(- (current-column) langelem-col))
(goto-char containing-sexp)
(or (eolp)
(not (memq (char-after) '(?{ ?\( )))
(let ((eol (c-point 'eol))
(here (progn
(forward-char 1)
(skip-chars-forward " \t")
(point))))
(c-forward-syntactic-ws)
(if (< (point) eol)
(goto-char here))))
(- (current-column) langelem-col)
))))
(defun c-lineup-arglist-intro-after-paren (langelem)
(save-excursion
(let ((langelem-col (c-langelem-col langelem t))
(ce-curcol (save-excursion
(beginning-of-line)
(backward-up-list 1)
(skip-chars-forward " \t" (c-point 'eol))
(current-column))))
(- ce-curcol langelem-col -1))))
(defun c-lineup-arglist-close-under-paren (langelem)
(save-excursion
(let ((langelem-col (c-langelem-col langelem t))
(ce-curcol (save-excursion
(beginning-of-line)
(backward-up-list 1)
(current-column))))
(- ce-curcol langelem-col))))
(defun c-lineup-close-paren (langelem)
(save-excursion
(condition-case nil
(let (opencol spec)
(beginning-of-line)
(backward-up-list 1)
(setq spec (c-looking-at-special-brace-list))
(if spec (goto-char (car (car spec))))
(setq opencol (current-column))
(forward-char 1)
(if spec (progn
(c-forward-syntactic-ws)
(forward-char 1)))
(c-forward-syntactic-ws (c-point 'eol))
(if (eolp)
0
(- opencol (c-langelem-col langelem t))))
(error 0))))
(defun c-lineup-streamop (langelem)
(save-excursion
(let ((langelem-col (c-langelem-col langelem)))
(re-search-forward "<<\\|>>" (c-point 'eol) 'move)
(goto-char (match-beginning 0))
(- (current-column) langelem-col))))
(defun c-lineup-multi-inher (langelem)
(save-excursion
(let ((eol (c-point 'eol))
(here (point))
(langelem-col (c-langelem-col langelem)))
(skip-chars-forward "^:" eol)
(skip-chars-forward " \t:" eol)
(if (or (eolp)
(looking-at c-comment-start-regexp))
(c-forward-syntactic-ws here))
(- (current-column) langelem-col)
)))
(defun c-lineup-java-inher (langelem)
(save-excursion
(let ((langelem-col (c-langelem-col langelem)))
(forward-word 1)
(if (looking-at "[ \t]*$")
langelem-col
(c-forward-syntactic-ws)
(- (current-column) langelem-col)))))
(defun c-lineup-java-throws (langelem)
(save-excursion
(let ((iopl (c-point 'iopl))
(langelem-col (c-langelem-col langelem t))
(extra 0))
(back-to-indentation)
(cond
((looking-at "throws[ \t\n]")
(goto-char (cdr langelem))
(setq extra c-basic-offset))
((and (goto-char iopl)
(looking-at "throws[ \t\n]"))
(forward-word 1)
(skip-chars-forward " \t")
(if (eolp)
(progn
(back-to-indentation)
(setq extra c-basic-offset))))
(t (goto-char iopl)))
(+ (- (current-column) langelem-col) extra))))
(defun c-indent-one-line-block (langelem)
(save-excursion
(let ((eol (progn (end-of-line) (point))))
(beginning-of-line)
(skip-chars-forward " \t")
(if (and (eq (following-char) ?{)
(c-safe (progn (c-forward-sexp) t))
(<= (point) eol)
(eq (preceding-char) ?}))
c-basic-offset
0))))
(defun c-lineup-C-comments (langelem)
(save-excursion
(let ((here (point))
(stars (progn (back-to-indentation)
(skip-chars-forward "*")))
(langelem-col (c-langelem-col langelem)))
(back-to-indentation)
(if (not (re-search-forward "/\\([*]+\\)" (c-point 'eol) t))
(progn
(if (not (looking-at "[*]+"))
(progn
(goto-char here)
(back-to-indentation)
(if (looking-at "[*]+/")
(progn (goto-char (match-end 0))
(forward-comment -1))
(goto-char (cdr langelem))
(back-to-indentation))))
(- (current-column) langelem-col))
(if (zerop stars)
(progn
(skip-chars-forward " \t")
(- (current-column) langelem-col))
(if (> (length (match-string 1)) stars)
(progn
(back-to-indentation)
(- (current-column) -1 langelem-col))
(- (current-column) stars langelem-col))
)))))
(defun c-lineup-comment (langelem)
(save-excursion
(back-to-indentation)
(let ((recurse-prevention-flag (boundp 'recurse-prevention-flag)))
(cond
(recurse-prevention-flag 0)
((= (current-column) comment-column)
(- comment-column (apply '+ (mapcar 'c-get-offset
c-syntactic-context))))
((not (bolp))
(or (car-safe c-comment-only-line-offset)
c-comment-only-line-offset))
(t
(or (cdr-safe c-comment-only-line-offset)
(car-safe c-comment-only-line-offset)
-1000)) ))))
(defun c-lineup-runin-statements (langelem)
(if (eq (char-after (cdr langelem)) ?{)
(save-excursion
(let ((langelem-col (c-langelem-col langelem)))
(forward-char 1)
(skip-chars-forward " \t")
(- (current-column) langelem-col)))
0))
(defun c-lineup-math (langelem)
(save-excursion
(let ((equalp (save-excursion
(goto-char (c-point 'boi))
(skip-chars-forward "^=" (c-point 'eol))
(and (eq (char-after) ?=)
(- (point) (c-point 'boi)))))
(langelem-col (c-langelem-col langelem))
donep)
(while (and (not donep)
(< (point) (c-point 'eol)))
(skip-chars-forward "^=" (c-point 'eol))
(if (c-in-literal (cdr langelem))
(forward-char 1)
(setq donep t)))
(if (or (not (eq (char-after) ?=))
(save-excursion
(forward-char 1)
(c-forward-syntactic-ws (c-point 'eol))
(eolp)))
c-basic-offset
(if (not equalp)
(progn
(forward-char 1)
(skip-chars-forward " \t")
(setq equalp 0)))
(- (current-column) equalp langelem-col))
)))
(defun c-lineup-ObjC-method-call (langelem)
(save-excursion
(let* ((extra (save-excursion
(back-to-indentation)
(c-backward-syntactic-ws (cdr langelem))
(if (eq (char-before) ?:)
(- c-basic-offset)
0)))
(open-bracket-pos (cdr langelem))
(open-bracket-col (progn
(goto-char open-bracket-pos)
(current-column)))
(target-col (progn
(forward-char)
(c-forward-sexp)
(skip-chars-forward " \t")
(if (eolp)
(+ open-bracket-col c-basic-offset)
(current-column))))
)
(- target-col open-bracket-col extra))))
(defun c-lineup-ObjC-method-args (langelem)
(save-excursion
(let* ((here (c-point 'boi))
(curcol (progn (goto-char here) (current-column)))
(eol (c-point 'eol))
(relpos (cdr langelem))
(first-col-column (progn
(goto-char relpos)
(skip-chars-forward "^:" eol)
(and (eq (char-after) ?:)
(current-column)))))
(if (not first-col-column)
c-basic-offset
(goto-char here)
(skip-chars-forward "^:" eol)
(if (eq (char-after) ?:)
(+ curcol (- first-col-column (current-column)))
c-basic-offset)))))
(defun c-lineup-ObjC-method-args-2 (langelem)
(save-excursion
(let* ((here (c-point 'boi))
(curcol (progn (goto-char here) (current-column)))
(eol (c-point 'eol))
(relpos (cdr langelem))
(prev-col-column (progn
(skip-chars-backward "^:" relpos)
(and (eq (char-before) ?:)
(- (current-column) 1)))))
(if (not prev-col-column)
c-basic-offset
(goto-char here)
(skip-chars-forward "^:" eol)
(if (eq (char-after) ?:)
(+ curcol (- prev-col-column (current-column)))
c-basic-offset)))))
(defun c-lineup-inexpr-block (langelem)
(save-excursion
(back-to-indentation)
(let ((res (or (c-looking-at-inexpr-block)
(if (c-safe (backward-up-list 1)
(eq (char-after) ?{))
(c-looking-at-inexpr-block)))))
(if (not res)
0
(goto-char (cdr res))
(- (current-column)
(progn
(back-to-indentation)
(current-column)))))))
(defun c-lineup-dont-change (langelem)
(save-excursion
(back-to-indentation)
(current-column)))
(defun c-snug-do-while (syntax pos)
"Dynamically calculate brace hanginess for do-while statements.
Using this function, `while' clauses that end a `do-while' block will
remain on the same line as the brace that closes that block.
See `c-hanging-braces-alist' for how to utilize this function as an
ACTION associated with `block-close' syntax."
(save-excursion
(let (langelem)
(if (and (eq syntax 'block-close)
(setq langelem (assq 'block-close c-syntactic-context))
(progn (goto-char (cdr langelem))
(if (eq (char-after) ?{)
(c-safe (c-forward-sexp -1)))
(looking-at "\\<do\\>[^_]")))
'(before)
'(before after)))))
(defun c-gnu-impose-minimum ()
"Imposes a minimum indentation for lines inside a top-level construct.
The variable `c-label-minimum-indentation' specifies the minimum
indentation amount."
(let ((non-top-levels '(defun-block-intro statement statement-cont
statement-block-intro statement-case-intro
statement-case-open substatement substatement-open
case-label label do-while-closure else-clause
))
(syntax c-syntactic-context)
langelem)
(while syntax
(setq langelem (car (car syntax))
syntax (cdr syntax))
(cond ((eq langelem 'comment-intro)
(setq syntax nil))
((memq langelem non-top-levels)
(save-excursion
(setq syntax nil)
(back-to-indentation)
(if (zerop (current-column))
(insert (make-string c-label-minimum-indentation 32)))
))
))))
(defun c-semi&comma-inside-parenlist ()
"Controls newline insertion after semicolons in parenthesis lists.
If a comma was inserted, no determination is made. If a semicolon was
inserted inside a parenthesis list, no newline is added otherwise a
newline is added. In either case, checking is stopped. This supports
exactly the old newline insertion behavior."
(if (not (eq last-command-char ?\ nil (if (condition-case nil
(save-excursion
(up-list -1)
(not (eq (char-after) ?\()))
(error t))
t
'stop)))
(defun c-semi&comma-no-newlines-before-nonblanks ()
"Controls newline insertion after semicolons.
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 ?\ (zerop (forward-line 1))
(not (looking-at "^[ \t]*$")))
'stop
nil)))
(defun c-semi&comma-no-newlines-for-oneline-inliners ()
"Controls newline insertion after semicolons for some one-line methods.
If a comma was inserted, no determination is made. Newlines are
suppressed in one-liners, if the line is an in-class inline function.
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-char ?\ (eq (car (car syntax)) 'inclass)
(eq (car (car (cdr syntax))) 'topmost-intro)
(= (c-point 'bol) bol))
'stop
nil)))
(provide 'cc-align)