3

How do you tell emacs to indent the current continued line (e.g. after a dot or indirection operator) one level deeper than the previous one? Arguments about which one is prettier are irrelevant here since this is the style we use at my work, so I don't really have a choice.

I'm guessing it's an offset (maybe statement-cont?), but I'm not sure how to do it dynamically like that...

Kind of related: How to control indentation after an open parenthesis in Emacs

Have

#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;
}

Want

#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;
}
Community
  • 1
  • 1
mgalgs
  • 15,671
  • 11
  • 61
  • 74

1 Answers1

2

This is not possible with the built-in indentation options.

You can verify this by using C-c C-s (aka c-show-syntactic-information) on the lines where you want the /* extra indent */ and the line above them, and you'll see that the syntactic information for those lines is always the same. In other words, as far as the indentation engine knows, those lines are the same syntactically.

Check out the documentation for interactive customization.

It might be possible to do what you want by customizing c-special-indent-hook.

Trey Jackson
  • 73,529
  • 11
  • 197
  • 229