【问题标题】:Emacs indent an extra level for every continued lineEmacs 为每个连续的行缩进一个额外的级别
【发布时间】:2011-05-17 18:41:09
【问题描述】:

你如何告诉 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 emacs indentation


    【解决方案1】:

    这对于内置缩进选项是不可能的。

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

    查看interactive customization 的文档。

    也许可以通过自定义c-special-indent-hook来做你想做的事情。

    【讨论】:

    • 嘿,Trey,我只想说,阅读您的答案总是很愉快!
    猜你喜欢
    • 2017-05-06
    • 1970-01-01
    • 1970-01-01
    • 2011-10-14
    • 1970-01-01
    • 1970-01-01
    • 2011-07-04
    • 1970-01-01
    • 2021-12-24
    相关资源
    最近更新 更多