1

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;

becoming

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 – Rudolf Olah Jun 14 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 Jun 14 at 20:38
  • Do you see the same behavior when starting with emacs -Q? – Drew Jun 14 at 20:40
  • Yes, running with emacs -Q yields the same behavior where the broken lines get one extra c-offset indent. – Koala Bear Jun 14 at 21:24
0
(defun c-lineup-statement-cont-rhs (langelem)
  "Line up multi-line statements on the rhs in front of the assignment operator"
  (save-excursion
    (let* ((relpos (cdr langelem))
           (curcol (progn (goto-char relpos)
                          (current-column)))
      (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, privacy policy and cookie policy

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