View Full Version : How can I auto-format code?
KIAaze
June 24th, 2007, 03:17 PM
I'm looking for a command-line way to auto-format all my source files.
The "indent region" feature from xemacs works well, but it would be easier if I could do it by command-line.
A GUI doing it for all source files at once would also be OK.
xtacocorex
June 24th, 2007, 04:41 PM
There is a program called astyle which will do indenting for C/C++/C# and Java.
Ramses de Norre
June 24th, 2007, 05:28 PM
I use eclipse for programming and can right click a project and choose "format" to format all source files.
You can modify the formatting style as you like.
KIAaze
June 24th, 2007, 08:19 PM
There is a program called astyle which will do indenting for C/C++/C# and Java.
Thanks! That was exactly what I was looking for. :D
What is the most common style used? gnu, ansi, linux or kr? (when using C/C++)
Golyadkin
June 25th, 2007, 06:01 AM
I am old-school, so I go for kr (Brian Kernighan and Dennis Ritchie) which is also if I am not mistaken, what is used in the Linux kernel sourcecode.
Dennis Ritchie originally created the C programming language, and is one of the core developers of UNIX, which Linux originated from.
Also btw, it doesn't really matter which one you use, as long as you use one and use it consistently.
KIAaze
July 6th, 2007, 04:40 AM
Another similar question:
Is there an automatic shellscript formatting program?
I tried astyle and emacs with shellscripts, but they have problems when there's no ";" at the end of lines.
One line "if then fi" statements also get reformatted into multiple lines.
astyle even renders the shellscript non-executable. :/
vBulletin® v3.8.7, Copyright ©2000-2012, vBulletin Solutions, Inc.