Emacs has a lot of options for C++ development.

[[TOC]]

# Code completion

## Tags

Various tags database solutions exist, but those are old and sometimes hard to use. You can take a look at the EmacsWiki page for tag systems if you'd like to try them out. One of the major pros of a tags database is that it works entirely within Emacs, so you don't need to spin up a compilation/completion server to search the codebase.

## Servers

The other major option for Emacs code completion is server-based solution. You do have to configure and run a server (this is usually done by the associated Emacs package), which is a drawback. Server-based solutions are hit-and-miss in a lot of languages, but there are some good ones out there. A nice modern completion package that I like is Irony mode. A nice bonus is that this also works for C code as well.

# Code style

For coding style, I like to use the "linux" default style, but with two spaces:

;; Configure tabs to be two spaces in C/C++
(setq c-default-style "linux")
(setq c-basic-offset 2)


Since .h files can be C++ files as well, I add those to my auto-mode-alist:

(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))

Note: Emacs will try and match the code in the file to either C or C++. If you have anything C++-specific, like a class declaration, it will activate c++-mode. If not, it goes with the safe assumption and picks c-mode.

# Syntax checking

I generally use flycheck for on-the-fly syntax checking.

(add-hook 'c++-mode-hook 'flycheck-mode)