Fix c-ts-mode indentation for initializer lists (bug#73661)
authorJørgen Kvalsvik <j@lambda.is>
Fri, 4 Oct 2024 19:38:33 +0000 (21:38 +0200)
committerYuan Fu <casouri@gmail.com>
Thu, 10 Oct 2024 07:05:42 +0000 (00:05 -0700)
commite49b479f8692573379a1ee3417bdda9e1f777888
tree6b2bcdc4175f5ce5a5883a605b2745d6f65a6696
parentf520008744b1eb71accded4108888d1f2055402e
Fix c-ts-mode indentation for initializer lists (bug#73661)

The intentation behavior differed between c-mode/c++-mode
and *-ts-mode for initializer lists where the first element was
not at beginning-of-line.  The anchor-prev-sibling function gave
up and returned nil, but it should (probably) anchor on the
first element in the initializer list, such as this:

return { v1, v2, ...,
         y1, y2, ... };

c-ts-mode behaved better and figured out how to align, but I
added a test for a similar compound literal to prevent
regressions.

* lisp/progmodes/c-ts-mode.el (c-ts-mode--anchor-prev-sibling):
Anchor at first sibling unless bol is found.

* test/lisp/progmodes/c-ts-mode-resources/indent.erts: New
initializer list and compound literal test.

Copyright-paperwork-exempt: yes
lisp/progmodes/c-ts-mode.el
test/lisp/progmodes/c-ts-mode-resources/indent.erts