Best C++ Code Formatter/Beautifier - c++

Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
There are lots of source code formatting tools out there. Which ones work best for C++?
I'm interested in command-line tools or other things that can be automatically run when checking code in/out, preferably without needing to launch an editor or IDE.
(If you see the one you like already listed as an answer, vote it up. If it's not there, add it.)

AStyle can be customized in great detail for C++ and Java (and others too)
This is a source code formatting tool.
clang-format is a powerful command line tool bundled with the clang compiler which handles even the most obscure language constructs in a coherent way.
It can be integrated with Visual Studio, Emacs, Vim (and others) and can format just the selected lines (or with git/svn to format some diff).
It can be configured with a variety of options listed here.
When using config files (named .clang-format) styles can be per directory - the closest such file in parent directories shall be used for a particular file.
Styles can be inherited from a preset (say LLVM or Google) and can later override different options
It is used by Google and others and is production ready.
Also look at the project UniversalIndentGUI. You can experiment with several indenters using it: AStyle, Uncrustify, GreatCode, ... and select the best for you. Any of them can be run later from a command line.
Uncrustify has a lot of configurable options. You'll probably need Universal Indent GUI (in Konstantin's reply) as well to configure it.

Related

Minimum Profit Editor Autocomplete

because of the fact that I am working a lot via SSH I am using an text editor named Minimum Profit (link) its a terminal editor similar to vim, nano or emacs but it uses a lot of modern shortcuts like ctrl-s to save etc.
I am also programming a lot in c++ via terminal.
I have seen some ways so make emacs or vim enable autocomplete for some programming languages such as c++, perl, python etc.
Examples: 1. Emacs, 2. Vim
Heres my question:
Does anyone know a way to achieve this goal in the terminal version of the Minimum Profit Editor?
Other then changing its source code of course.
I am looking for plugins, scripts or fancy configurations to get it working.
My main goal it to have a c++ code completion for commands and object members.
(A linter would also be nice.)
Alternative if there is no easy way, I would also agree to use a similar editor as long as it features all the benefits of Minimum Profit, such as "normal" keyboard-shortcuts, mouse usage, being able to open multiple files at once, selection, copy/paste, git and build support, find and replace and syntax highlighting.
And no switching to emacs or vim is no option.

c++ source code formatter [duplicate]

Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.
There are lots of source code formatting tools out there. Which ones work best for C++?
I'm interested in command-line tools or other things that can be automatically run when checking code in/out, preferably without needing to launch an editor or IDE.
(If you see the one you like already listed as an answer, vote it up. If it's not there, add it.)
AStyle can be customized in great detail for C++ and Java (and others too)
This is a source code formatting tool.
clang-format is a powerful command line tool bundled with the clang compiler which handles even the most obscure language constructs in a coherent way.
It can be integrated with Visual Studio, Emacs, Vim (and others) and can format just the selected lines (or with git/svn to format some diff).
It can be configured with a variety of options listed here.
When using config files (named .clang-format) styles can be per directory - the closest such file in parent directories shall be used for a particular file.
Styles can be inherited from a preset (say LLVM or Google) and can later override different options
It is used by Google and others and is production ready.
Also look at the project UniversalIndentGUI. You can experiment with several indenters using it: AStyle, Uncrustify, GreatCode, ... and select the best for you. Any of them can be run later from a command line.
Uncrustify has a lot of configurable options. You'll probably need Universal Indent GUI (in Konstantin's reply) as well to configure it.

C++ Code Autoformatting [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
After years of using Visual Studio for C++ programming, I am just now making the switch to linux for work. Everything is going great so far with one minor exception - gedit. After writing some code in a basic text editor, I am really starting to miss the auto formatting features that I have grown accustomed to.
Is there some type of "programmer's notepad" which would help with on-the-fly auto formatting or would I have to use a standard IDE for this functionality? Do most linux developers format their code manually using a basic text editor?
I am not looking for a full blown IDE, just something that will automatically format my C++ code as I type.
There is a pretty wide spectrum of text editors to IDEs on Linux. Here are a few that come to mind, from most "notepad-like" to most "VS-like".
In the "text editor" department (meaning no integrated compilation, build configs, debugger, etc.. just editing text / code):
gedit (most basic notepad-like app, IMO)
Kate (enhanced notepad but without "commands", and with nice auto-formatting and highlighting)
Emacs (enhanced notepad, with commands and advanced options, can be hard to use)
VIM (same category as emacs, can be hard to use, I don't like it)
Sublime-text (cool enhanced text editor, lots of neat features, but also a bit hard to master)
In the IDE department (meaning some build tools integration, and usually some code-completion and semantics analysis of code (detect variables, classes, etc.., can link to dox for them)):
Geany (lightweight IDE, not much more than an enhanced text editor with a "build" button)
NetBeans (average-sized IDE, quality is so-so, IMO)
Eclipse (average-sized IDE, easy to use, i.e., good for small projects, e.g., school assignments)
Qt Creator (average-to-large IDE, mainly aimed at working with Qt)
Code::Blocks (average-sized IDE, quality is so-so but OK, IMO)
KDevelop (an IDE a bit on the heavy side, but great features overall, and has the best code completion I have ever seen, beats Intellisense for C++ like a rented mule)
Of course, this is just a partial list, including only those I've been exposed to or have heard a lot about. There are probably many others out there.
Is there some type of "programmer's notepad" which would help with on-the-fly auto formatting or would I have to use a standard IDE for this functionality?
All the applications I've listed above in the "text editor" department all support this kind of feature (but I'm not 100% sure on Gedit, because it's kind of basic and I don't use it much, cause I don't like it). The only main jump you get as far as writing code from a text editor to an IDE is the code-completion / background-parser, i.e., the "Intellisense" type of features, including tooltip documentation on classes or functions. You cannot get that in a text editor because it would have to be aware of your build configuration (e.g., your cmake files or equivalent) to know where to pull headers from to be able to "understand" your code beyond trivial syntax rules, keywords and indentation.
Do most linux developers format their code manually using a basic text editor?
No. But it's a diverse world. Some like basic text editors where auto-indentation is about as much as you get, while others prefer feature-rich IDEs, and then, there are those who choose their text editor by how cool-looking the color themes are. ;)
And btw, there are also pretty powerful command-line code formatters, like clang-format, which can re-format your code in a much smarter way because it has an actual full-blown C++ compiler front-end parsing your code.
As far as I know, gedit have auto indent support, Try Edit -> Preferences -> Editor and check "Enable automatic indentation".
However, personally, I recommend you to use VIM, a professional text editor, although is not for everybody. Vim is not an IDE, just a text editor, but it's very powerful.
If vim seems too much by the moment, I think that kate is better than gedit.

setting up vim project space with 4 different code but related code bases

I'm a novice vim user who really likes vim and wants to take it to the next step in my development workflow.
I have 4 different C/C++ code bases which are compiled using 3 different compilers. Each of the code bases has its own project and makefiles for the compilers. I keep the compilers open to compile the different projects. Two code bases are for firmware of a device, one code base is for a library and the last code base is for a cross platform desktop app that uses the library to talk to the device.
I mainly use vim for my code editing, and right now I have several different vim windows that I keep open, i.e. one per code base. I exit the vim editors a lot to open different code files, which is very unproductive. I often have to look up functions in different files within the same code base. I often have to switch between code bases because the software compiled from one code base processes data generated by a program from another code base and I have to double check defines and such.
I'm wondering if there is a better way to organize this using vim? How does an expert vim user set up his development workflow to work with multiple related code bases within the same vim environment and how does he/she navigate the code bases efficiently?
If your projects are related, and files from one project are referred to in another, I would recommend to open them all in one GVIM instance. I personally often use tab pages to segregate different projects within one Vim instance, but Vim (together with your favorite plugins) is so flexible in this regard that virtually any workflow can be reflected.
For a more precise comment and recommendation, your question is missing details like:
How (through which plugin) do you open project files / recently opened files?
Is your current working directory set to the project root, and does this matter to your workflow?
How is your window layout, do you have any sidebars, and how do you organize your files (buffer list, minimized splits, arg list, etc.)?
There are some blog posts about how individuals have set up their Vim environments, but these naturally are bound to personal preferences and the particular programming environment. So, use them for inspiration, but be aware that there's no perfect recipe, and you'll have to find your own, personal way.

Emacs tutorial for large projects

can someone be kind enough to direct me to emacs tutorials for large C++ project using gdb as debugger, the project does contain make file.
I did search for emacs tutorials but some are too advanced for beginners and some only target one single file tutorial. I did read the previous posts too but did not find an answer suitable for large projects. Also I am not used to using 'git', one of the answers in previous posts.
Actually, learning Emacs is a thing that just can't be easy. You'll have to learn the basics before you will be able to read "advanced" tutorials.
The first thing you should do is to work through the builtin tutorial (C-h t). It's really good.
Then you should try to familiarize yourself with Emacs configuration basics. The easy way suggested by many users is to get a ready-for-use configuration (such as Emacs Starter Kit) and try to understand it and then tailor to your own needs and preferences. The advantages of using a ready-made configuration kit are:
It's a working code useful for learning the basics of Elisp. This learning path is way faster than reading Elisp manuals and gathering configuration code one small piece at a time.
It demonstrates a lot of useful Emacs features which otherwise might require you long time (sometimes years) to discover.
It offers a framework which you can base on writing your own configuration.
Still you should undoubtedly get rid of whatever parts of configuration you don't need.
Then (or along with the previous step) read some tutorial about using Emacs as a development platform. You can easily find a lot of tutorials via "emacs for [c] development" queries to Google. Here is one of many.
Then install Cedet (Alex Ott has written a great tutorial about it) and start feeling the power.
After that you'll know what to do next.
By the way, there is a great collection of Emacs resources maintained by Bozhidar Batsov.
Start simple. Launch Emacs without any customisations and start editing your source files. The only "tutorial" you'll need to do basic editing is the inbuilt one you'll get by hitting Control H followed by t (Referred to as C-h t in Emacs speak).
Compiling can be done by typing M-x (Alt x) compile and hitting enter. It will prompt you for the compile command which is by default make. Change it to whatever suits you.
Running gdb is done using M-x gdb and hitting enter. The interface is similar to the M-x make.
Don't use things like the Emacs starter kit which makes assumptions on your behalf. While useful as a starting point for newbies, it suppresses curiosity and that's the key to learning Emacs. The above things should be enough for you to start. Once you hit problems and are not satisfied with the ways of doing things, you can search for resources and things. Emacs is not an "IDE" and so you won't have the tight integration which many custom editors have. Don't expect it.