1

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?

2 Answers2

0

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
cup
  • 7,589
  • 4
  • 19
  • 42
0

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

engineer14
  • 607
  • 4
  • 13