Function: c-lineup-assignments
c-lineup-assignments is a byte-compiled function defined in
cc-align.el.gz.
Signature
(c-lineup-assignments LANGELEM)
Documentation
Line up the current line after the assignment operator on the first line in the statement. If there isn't any, return nil to allow stacking with other line-up functions. If the current line contains an assignment operator too, try to align it with the first one.
Works with: topmost-intro-cont, statement-cont, arglist-cont, arglist-cont-nonempty.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/cc-align.el.gz
(defun c-lineup-assignments (langelem)
"Line up the current line after the assignment operator on the first
line in the statement. If there isn't any, return nil to allow
stacking with other line-up functions. If the current line contains
an assignment operator too, try to align it with the first one.
Works with: topmost-intro-cont, statement-cont, arglist-cont,
arglist-cont-nonempty."
(let (startpos endpos equalp)
(if (eq (c-langelem-sym langelem) 'arglist-cont-nonempty)
;; If it's an arglist-cont-nonempty then we're only interested
;; in equal signs outside it. We don't search for a "=" on
;; the current line since that'd have a different nesting
;; compared to the one we should align with.
(save-excursion
(save-restriction
(setq endpos (c-langelem-2nd-pos c-syntactic-element))
(narrow-to-region (c-langelem-pos langelem) endpos)
(if (setq startpos (c-up-list-backward endpos))
(setq startpos (1+ startpos))
(setq startpos (c-langelem-pos langelem)))))
(setq startpos (c-langelem-pos langelem)
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
;; columns to left shift the current line to align it with the
;; goal column.
(save-excursion
(beginning-of-line)
(when (c-syntactic-re-search-forward
c-assignment-op-regexp
(c-point 'eol) t t t)
(setq equalp (- (or (match-beginning 1)
(match-end 0))
(c-point 'boi))))))
(save-excursion
(goto-char startpos)
(if (or (if (c-syntactic-re-search-forward
c-assignment-op-regexp
(min endpos (c-point 'eol)) t t t)
(progn
(goto-char (or (match-beginning 1)
(match-end 0)))
nil)
t)
(save-excursion
(c-forward-syntactic-ws (c-point 'eol))
(eolp)))
;; There's no equal sign on the line, or there is one but
;; nothing follows it.
nil
;; calculate indentation column after equals and ws, unless
;; our line contains an equals sign
(if (not equalp)
(progn
(skip-chars-forward " \t")
(setq equalp 0)))
(vector (- (current-column) equalp)))
)))