Align numbers based on leading digits (not minus signs)

How to align this so that the minus sign is outside the aligned columns:

{
    0.0f, -1.0f, -2.2f,
    -1.1f, 0.0f, -100.0f,
    -3.32f, -5.1f, 0.0f
}

      

So:

{
     0.0f,  -1.0f, -2.2f,
    -1.1f,   0.0f, -100.0f,
    -3.32f, -5.1f,  0.0f
}

      

+3


source to share


1 answer


Found my answer:

C-u M-x align-regexp

RET \(\s-*-?\)[0-9.]+

RET -1

RET 1

RET y

RET



or you can create a rule for modes C and C:

(eval-after-load "align"
 '(add-to-list 'align-rules-list
               '(c-align-decimals
                  (regexp . "\\(\\s-*-?\\)[0-9.]+")
              (group . (1))
              (spacing . 1)
              (justify . 1)
              (repeat . t)
              (modes quote(c-mode c-common-mode)))))

      

0


source







All Articles