Is there a way to have rhs statement breaks align with the equal sign on the lhs line? e.g.

some_value = a * b + c
    / some_other_value * x;


some_value = a * b + c
             / some_other_value * x;

I can only figure out how to have it a consistent offset, which means that different lhs variable names won't have the rhs equation lines align correctly.

  • 2
    which mode is this and which command are you using to align? perhaps there's an answer on the emacs wiki: emacswiki.org/emacs/AlignCommands
    – user10000
    Commented Jun 14, 2019 at 20:34
  • cmode and I've checked those, they give me column alignment for a series of assignment statements on the equals sign but not to align the line-broken rhs under the lhs equal sign. I'd like to be able to get it so I can just hit tab and let auto-indent sort it out, this feels like something that c-offset variables should deal with but I can't find anything in the documentation for this in particular.
    – Koala Bear
    Commented Jun 14, 2019 at 20:38
  • Do you see the same behavior when starting with emacs -Q?
    – Drew
    Commented Jun 14, 2019 at 20:40
  • Yes, running with emacs -Q yields the same behavior where the broken lines get one extra c-offset indent.
    – Koala Bear
    Commented Jun 14, 2019 at 21:24

1 Answer 1

(defun c-lineup-statement-cont-rhs (langelem)
  "Line up multi-line statements on the rhs in front of the assignment operator"
    (let* ((relpos (cdr langelem))
           (curcol (progn (goto-char relpos)
      (re-search-forward "=" (c-point 'eol) 'move)
      (goto-char (match-beginning 0))
      (+ 2 (- (current-column) curcol)))))

Where the +2 at the end will put it in front of the equal sign, rather than directly below it.

Full disclosure, I'm not entirely sure how this works. I basically just used the stream operator lineup function example from http://kirste.userpage.fu-berlin.de/chemnet/use/info/cc-mode/cc-mode_6.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.