Emacs is an ideal text editor for programmers, especially C/C++ programmers. I have been using Emacs since I began learning C while my classmates used vim, which was taught by the lecturer. Now I haven’t found any better solution for me in C/C++ programming.
Basic configuartion
By default, Emacs automatically enables major C/C++ mode whenever you open a file with extension .h, .c or .cpp. In case your Emacs does not behave that way, add this to your .emacs
You will also want Emacs to indent the code for you so that it will be much easier for you to follow. To do that, add this to your .emacs
Another thing to consider is the brackets. Often when I program, I want the computer to add the closing bracket for me so that I can avoid those silly errors. Autopair is a plugin package for emacs that can help us achieve that task. You can install it through package.el or cloning it from the source. After finishing installation, make sure that it’s in your load-path and then add this to your .emacs
ECB - Transform Emacs to a real IDE
Have a look at this post Install and Config ECB on Emacs and the screenshot below to see how powerful and useful ECB is. You can also find the installation and configuration guide in that post above.
Auto Completion and Code Snippets
Emacs cannot compete with the other IDE if it doesn’t have those auto completion and snippet inserting function. They improve the programmers’ effeciency very much. Read this article Config Yasnippet and Autocomplete on Emacs to know how to config autocomplete and yasnippet so that they can work together.
Another package that you must have is auto-complete-clang, a clang source for autocomplete. Make sure to install autocomplete and yasnipper before installing auto-complete-clang (you can easily install it using packages.el). When you finish the installation, bind it with a key sequence for quick access (remember to check whether it is in the load-path).
The last package that I’d like to recomend you is the member-functions package. It is extemely useful for those who program C++. This package helps you expand the function headers defined in .h file to a .cpp file. Install it using package.el and then add this to your init file
The instruction on how to use Emacs package manager to install packages is presented here Emacs Packages Manager using package.el.
Continue to Part 2 here: Emacs - Setting up Perfect C/C++ programming environment - Part 2