gpt4 book ai didi

c++ - Emacs 为每个连续的行缩进一个额外的级别

转载 作者:太空狗 更新时间:2023-10-29 21:50:30 25 4
gpt4 key购买 nike

如何告诉 emacs 缩进当前的续行(例如在点或间接运算符之后)比上一行深一层?关于哪个更漂亮的争论在这里无关紧要,因为这是我们在工作中使用的风格,所以我真的别无选择。

我猜它是一个偏移量(也许是 statement-cont?),但我不确定如何动态地做到这一点......

相关种类:How to control indentation after an open parenthesis in Emacs

#include <stdio.h>

struct thing {
int the_first_piece_of_data;
};

struct stuff {
struct thing the_first_thing_in_this_stuff;
struct thing *pointer_to_the_first_thing_in_this_stuff;
};

int main(int argc, char *argv[])
{
struct stuff some_stuff_to_work_with;
struct stuff *pointer_to_stuff = &some_stuff_to_work_with;
some_stuff_to_work_with.
pointer_to_the_first_thing_in_this_stuff =
&(some_stuff_to_work_with.
the_first_thing_in_this_stuff);

some_stuff_to_work_with.
the_first_thing_in_this_stuff.
the_first_piece_of_data = 42;

printf("The piece of data is => %d\n",
some_stuff_to_work_with.
the_first_thing_in_this_stuff.
the_first_piece_of_data);

pointer_to_stuff->
pointer_to_the_first_thing_in_this_stuff->
the_first_piece_of_data++;

printf("The piece of data is => %d\n",
pointer_to_stuff->
pointer_to_the_first_thing_in_this_stuff->
the_first_piece_of_data);

return 0;
}

想要

#include <stdio.h>

struct thing {
int the_first_piece_of_data;
};

struct stuff {
struct thing the_first_thing_in_this_stuff;
struct thing *pointer_to_the_first_thing_in_this_stuff;
};

int main(int argc, char *argv[])
{
struct stuff some_stuff_to_work_with;
struct stuff *pointer_to_stuff = &some_stuff_to_work_with;
some_stuff_to_work_with.
pointer_to_the_first_thing_in_this_stuff =
&(some_stuff_to_work_with. /*exra indent*/
the_first_thing_in_this_stuff);

some_stuff_to_work_with.
the_first_thing_in_this_stuff.
the_first_piece_of_data = 42; /*exra indent*/

printf("The piece of data is => %d\n",
some_stuff_to_work_with.
the_first_thing_in_this_stuff. /*exra indent*/
the_first_piece_of_data); /*exra indent*/

pointer_to_stuff->
pointer_to_the_first_thing_in_this_stuff->
the_first_piece_of_data++; /*exra indent*/

printf("The piece of data is => %d\n",
pointer_to_stuff->
pointer_to_the_first_thing_in_this_stuff-> /*exra indent*/
the_first_piece_of_data); /*exra indent*/

return 0;
}

最佳答案

内置缩进选项无法做到这一点。

您可以在需要 /* 额外缩进的行上使用 C-c C-s(又名 c-show-syntactic-information)来验证这一点 */ 和它们上面的行,你会看到这些行的语法信息总是相同的。换句话说,就缩进引擎所知,这些行在语法上是相同的。

查看 interactive customization 的文档.

通过自定义 c-special-indent-hook 可能会做您想做的事.

关于c++ - Emacs 为每个连续的行缩进一个额外的级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6035555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com