1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 06:20:55 -08:00
emacs/test/lisp/progmodes/c-ts-mode-resources/indent.erts
nverno 08fc6bace2
Fix c-ts-mode indentation (bug#67357)
1. In a compund_statement, we indent the first sibling against the
parent, and the rest siblings against their previous sibling.  But
this strategy falls apart when the first sibling is not on its own
line.  We should regard the first sibling that is on its own line as
the "first sibling"", and indent it against the parent.

2. In linux style, in a do-while statement, if the do-body is
bracket-less, the "while" keyword is indented to the same level as the
do-body.  It should be indented to align with the "do" keyword
instead.

* lisp/progmodes/c-ts-mode.el:
(c-ts-mode--no-prev-standalone-sibling): New function.
(c-ts-mode--indent-styles): Use
c-ts-mode--no-prev-standalone-sibling. Add while keyword indent rule.
* test/lisp/progmodes/c-ts-mode-resources/indent.erts: New tests.
2023-12-10 01:05:22 -08:00

546 lines
6.4 KiB
Text

Code:
(lambda ()
(c-ts-mode)
(setq-local indent-tabs-mode nil)
(setq-local c-ts-mode-indent-offset 2)
(c-ts-mode-set-style 'gnu)
(indent-region (point-min) (point-max)))
Point-Char: |
Name: Basic
=-=
int
main (void)
{
return 0;
}
=-=-=
Name: Hanging Braces (GNU Style)
=-=
int
main (void)
{
if (true)
{
}
}
=-=-=
Name: Labels (GNU Style)
=-=
int
main (void)
{
label:
return 0;
if (true)
{
label:
return 0;
}
else
{
if (true)
{
label:
return 0;
}
}
}
=-=-=
Name: For Loop with Multi-line Condition (GNU Style)
=-=
int main()
{
for (int i = 0;
i < b;
i++)
{
return 0;
}
}
=-=-=
Name: If-Else (GNU Style)
=-=
int main()
{
if (true)
{
return 0;
}
else
{
return 1;
}
}
=-=-=
Name: Concecutive blocks (GNU Style) (bug#60873)
=-=
int
main (int argc,
char *argv[])
{
{
int i = 0;
}
}
=-=-=
Name: Bracket-less Block-Statement (GNU Style) (bug#61026)
=-=
int main() {
while (true)
if (true)
{
puts ("Hello");
}
for (int i=0;
i<5;
i++)
if (true)
{
puts ("Hello");
}
do
if (true)
{
puts ("Hello");
}
while (true);
if (true)
if (true)
{
puts ("Hello");
}
}
=-=-=
Name: Multiline Parameter List (bug#60398)
=-=
int f2(int x,
int y) {
return x + y;
};
=-=-=
Name: Semi-colon in While Loop (bug#61291)
=-=
while (true)
;
for (int i = 0;
i < 5;
i++)
;
=-=-=
Name: Bracketless Simple Statement
=-=
for (int i = 0; i < 5; i++)
continue;
while (true)
return 1;
do
i++;
while (true)
if (true)
break;
else
break;
=-=
for (int i = 0; i < 5; i++)
continue;
while (true)
return 1;
do
i++;
while (true)
if (true)
break;
else
break;
=-=-=
Name: Nested If-Else
=-=
if (true)
return 0;
else if (false)
return 1;
else if (true)
return 2;
else if (false)
return 3;
=-=-=
Name: Initializer List (Bug#61398)
=-=
int main()
{
const char *emoticons[][2] =
{
{":-)", "SLIGHTLY SMILING FACE"},
{";-)", "WINKING FACE"},
{":-(", "SLIGHTLY FROWNING FACE"},
};
}
=-=-=
Name: Switch-Case statement
=-=
int main() {
switch (a) {
case 1:
b = c;
return 10;
case 2:
{
a = b;
return 12
}
}
}
=-=
int main() {
switch (a) {
case 1:
b = c;
return 10;
case 2:
{
a = b;
return 12
}
}
}
=-=-=
Name: Multiline Block Comments 1 (bug#60270)
=-=
/**
* @some_func:
* @arg1:
*/
=-=-=
Name: Multiline Block Comments 2 (bug#60270)
=-=
/*
some comment
*/
=-=-=
Name: Multiline Block Comments 3 (bug#60270)
=-=
/* some comment
*/
=-=-=
Name: Multiline Block Comments 4 (bug#60270)
=-=
/*
* Some comment
*/
=-=-=
Name: Multiline Block Comments 5 (bug#60270)
=-=
/*
line one
line 2
*/
=-=
/*
line one
line 2
*/
=-=-=
Name: Block Comment prefixes (Bug#61314)
=-=-=
/*
- item1
- item2
- item3
*/
=-=-=
/*
- item1
- item2
- item3
*/
=-=-=
Code:
(lambda ()
(c-ts-mode)
(setq-local indent-tabs-mode nil)
(setq-local c-ts-mode-indent-offset 8)
(c-ts-mode-set-style 'linux)
(indent-region (point-min) (point-max)))
Name: Labels (Linux Style)
=-=-=
int main (void)
{
label:
return 0;
if (true) {
label:
return 0;
}
else {
if (true) {
label:
return 0;
}
}
}
=-=-=
Name: Bracket-less Block-Statement (Linux Style) (bug#61026)
=-=
int main() {
while (true)
if (true) {
puts ("Hello");
}
for (int i=0;
i<5;
i++)
if (true) {
puts ("Hello");
}
do
if (true) {
puts ("Hello");
}
while (true);
if (true)
if (true) {
puts ("Hello");
}
else
puts("Hello");
}
=-=-=
Name: Complicated mixed bracket matching indentation (bug#61142)
=-=
void foo(
int foo) {
for (;;)
return 5;
if (a == 0
&& b == 1
&& foo)
{
return 0;
}
else if (a == 1)
{
return 1;
}
else if (true)
return 5;
else
{
if (a == 0
&& b == 1
&& foo)
for (
int i = 0;
i < 5;
i++)
if (true)
do
i = 5;
while (true);
else if (false)
{
return 6;
}
else
if (true
&& false)
return 6;
}
}
=-=-=
Name: Block-Statement where first siblings are comments (Linux Style)
=-=
int main() {
while (true) { /* foo */
if (true) { // bar
puts ("Hello");
}
}
for (;;) { // 1. fooo
/* 2. baaa */
/* 3. rrr */
if (true)
// 2. baaa
puts ("Hello");
}
if (1) { // 1
/*
* 2
*/
if (1) /*3*/ {
/* 4 */
puts("Hello");
}
}
}
=-=-=
Name: Initializer List (Linux Style) (Bug#61398)
=-=
int main()
{
const char *emoticons[][2] = {
{":-)", "SLIGHTLY SMILING FACE"},
{";-)", "WINKING FACE"},
{":-(", "SLIGHTLY FROWNING FACE"},
};
}
=-=-=
Code:
(lambda ()
(c++-ts-mode)
(setq-local indent-tabs-mode nil)
(setq-local c-ts-mode-indent-offset 2)
(indent-region (point-min) (point-max)))
Name: Declaration List (Namespace) (Bug#61635)
=-=
namespace test {
class Name {
};
}
=-=-=
Code:
(lambda ()
(c-ts-mode)
(setq-local indent-tabs-mode nil)
(setq-local c-ts-mode-indent-offset 2)
(c-ts-mode-set-style 'gnu)
(indent-for-tab-command))
Name: Empty Line
=-=
int main()
{
|
}
=-=-=
Name: Empty Line Previous Sibling
=-=
int main()
{
int a = 1;
|
}
=-=-=
Name: Prev-Sibling But Not Trailing Comment
=-=
static int
required_matrix_height (struct window *w)
{
#ifdef HAVE_WINDOW_SYSTEM
if (FRAME_WINDOW_P (f))
{
return 0;
}
#endif /* Don't align to this comment. */
|
}
=-=-=
Name: Empty Line
=-=
int
main (void)
{
|
}
=-=
int
main (void)
{
|
}
=-=-=
Name: Empty Line (Block Start)
=-=
int
main (void)
{
|
=-=
int
main (void)
{
|
=-=-=
Code:
(lambda ()
(c-ts-mode)
(setq-local indent-tabs-mode nil)
(goto-line 3)
(indent-for-tab-command))
Name: Block-Statement where previous sibling is comment
=-=
int main() {
puts ("Hello"); // unusual indent and has trailing comment.
return true; // Should align with previous non-comment sibling (rather than one level up against parent).
}
=-=-=