user6307369
user6307369

Reputation:

Spacing between brace and comment

Given the file alfa.c:

#include <stdio.h>
int main() { // this is a comment
  puts("hello world");
}

I can format it with GNU Indent like so:

$ indent -st alfa.c
#include <stdio.h>
int
main ()
{                               // this is a comment
  puts ("hello world");
}

However the comment is now way off to the right. I did try adding an option:

$ indent -st -c0 alfa.c
#include <stdio.h>
int
main ()
{       // this is a comment
  puts ("hello world");
}

but this is still not quite right. Can Indent be invoked such a way that the comment starts after only 1 or 2 spaces?

Upvotes: 1

Views: 62

Answers (2)

cup
cup

Reputation: 8267

It is putting the comment one tab after the brace. To get around that, set the tab size, indent and replace tabs with spaces. Say we want the standard indent to be 3 spaces

indent -st -c0 -i3 -ts3 -nut alfa.c

Upvotes: 0

engineer14
engineer14

Reputation: 617

indent -c0 -nut -ts2

This will change all your tabs to spaces.

the -c0 removes indentation for comments after code (so this will affect all comments).

edit: reduced the spaces in a tab

Upvotes: 0

Related Questions