mirror of
https://github.com/masscollaborationlabs/emacs.git
synced 2025-07-05 11:49:37 +00:00
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
This commit is contained in:
parent
f520008744
commit
e49b479f86
2 changed files with 45 additions and 3 deletions
|
@ -324,10 +324,13 @@ characters of the current line."
|
||||||
;; If the start of the previous sibling isn't at the
|
;; If the start of the previous sibling isn't at the
|
||||||
;; beginning of a line, something's probably not quite
|
;; beginning of a line, something's probably not quite
|
||||||
;; right, go a step further. (E.g., comment after a
|
;; right, go a step further. (E.g., comment after a
|
||||||
;; statement.)
|
;; statement.) If the previous sibling is the first named
|
||||||
|
;; node then anchor to that, e.g. when returning an aggregate
|
||||||
|
;; and starting the items on the same line as {.
|
||||||
(_ (goto-char (treesit-node-start prev-sibling))
|
(_ (goto-char (treesit-node-start prev-sibling))
|
||||||
(if (looking-back (rx bol (* whitespace))
|
(if (or (looking-back (rx bol (* whitespace))
|
||||||
(line-beginning-position))
|
(line-beginning-position)))
|
||||||
|
(null (treesit-node-prev-sibling prev-sibling t))
|
||||||
(setq continue nil)
|
(setq continue nil)
|
||||||
(setq prev-sibling
|
(setq prev-sibling
|
||||||
(treesit-node-prev-sibling prev-sibling)))))))
|
(treesit-node-prev-sibling prev-sibling)))))))
|
||||||
|
|
|
@ -208,6 +208,21 @@ int main()
|
||||||
}
|
}
|
||||||
=-=-=
|
=-=-=
|
||||||
|
|
||||||
|
Name: Return Compund Literal
|
||||||
|
|
||||||
|
=-=
|
||||||
|
struct pair { int fst, snd; };
|
||||||
|
struct pair
|
||||||
|
make_pair(int long_identifier_a[], int long_identifier_b[],
|
||||||
|
int offset_a, int offset_b)
|
||||||
|
{
|
||||||
|
int base_offset = 10;
|
||||||
|
return (struct pair) { long_identifier_a[base_offset + offset_b],
|
||||||
|
long_identifier_b[base_offset + offset_b] };
|
||||||
|
}
|
||||||
|
|
||||||
|
=-=-=
|
||||||
|
|
||||||
Name: Switch-Case statement
|
Name: Switch-Case statement
|
||||||
|
|
||||||
=-=
|
=-=
|
||||||
|
@ -486,6 +501,30 @@ namespace A {
|
||||||
}
|
}
|
||||||
=-=-=
|
=-=-=
|
||||||
|
|
||||||
|
Name: Return Aggregate Initialized Struct
|
||||||
|
|
||||||
|
=-=
|
||||||
|
struct pair { int x, y; }
|
||||||
|
pair
|
||||||
|
make_pair(int long_identifier_a[], int long_identifier_b[],
|
||||||
|
int offset_a, int offset_b)
|
||||||
|
{
|
||||||
|
int base_offset = 10;
|
||||||
|
return { long_identifier_a[base_offset + offset_b],
|
||||||
|
long_identifier_b[base_offset + offset_b] };
|
||||||
|
}
|
||||||
|
=-=
|
||||||
|
struct pair { int x, y; }
|
||||||
|
pair
|
||||||
|
make_pair(int long_identifier_a[], int long_identifier_b[],
|
||||||
|
int offset_a, int offset_b)
|
||||||
|
{
|
||||||
|
int base_offset = 10;
|
||||||
|
return { long_identifier_a[base_offset + offset_b],
|
||||||
|
long_identifier_b[base_offset + offset_b] };
|
||||||
|
}
|
||||||
|
=-=-=
|
||||||
|
|
||||||
Code:
|
Code:
|
||||||
(lambda ()
|
(lambda ()
|
||||||
(c-ts-mode)
|
(c-ts-mode)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue