Question

I am trying to use "indent" program to indent C++ programs. But it does not seem to work fine. It is messing up the indentation much more.

It is a Class file. Can you please suggest the right options for it or another program that works?

Thanks

Was it helpful?

Solution

Try Artistic Style:

Artistic Style is a source code indenter, formatter, and beautifier for the C, C++, C# and Java programming languages.

OTHER TIPS

in visual studio, CTRL+a, CTRL+k, CTRL+f will auto-indent the entire file you're working in.

Another tool for automated formatting of C++ code is clang-format.

Many editors like Vim and Emacs have a feature that reindents code according to its built-in indentation standard.

In Vim, you can type = with any motion. (Like =% at any block delimiter or S-v to select a region and then = to reformat.) The gq command can be used to reformat comments and other text.

In Emacs, you can type M-x indent-region after selecting a region. (Such as with M-< and M->.) You can also reformat comments with M-x fill-paragraph.

This is in reply to the OP and other posters: I work under Windows and was looking for an indent as well. This is what I learned:

I tried bcpp. It seems to be quite old (more or less from 1996) and you need to find a windows exe. I found one here: http://www.zeusedit.com/zforum/viewtopic.php?t=1067. Still I think it's not really worth the bother, since it can only do space/tab, indentation level and brace conversion.

Then there is Artistic Style, which is newer and on sourceforge. It seems to be quite capable, but it can not, for example, reformat spaces around function names and parameters (like, turn if ( a ( b ) ) into if (a(b)).

I like Cygwin indent ( http://www.cygwin.com/ ) best, but it works only well on newline separated files, so you have to use it like "dos2unix < infile | indent ...". But indent will not reformat boxed comments... :)

Maybe a combi of Artistic Style and Cygwin indent works best. Now I use this command line: astyle --style=kr -s3 --break-closing-brackets < infile.cpp | dos2unix | indent --no-tabs --k-and-r-style --indent-level 3 --dont-cuddle-else | unix2dos. I bit long, I agree, but apart from that it produces a very good result. :)

bcpp, available in any linux distro (and probably for mingw/cygwin, but I have not checked it) is a C++ indenter and beautifier. You can parametrize how it works with the code.

Another short key in Visual Studio 2008:

Ctrl+A, Alt+F8

In netbeans, you can simply do

Alt + Shift + F

Please make sure that the plugins are installed for corresponding language. For example, for PHP code indentation, you have to choose netbeans PHP or install PHP plugins from repository.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top