This is one of those things that has bugged for a while, but that I just recently got around to fix. By default, Emacs uses tabs (and spaces) while indenting a line. As tabs aren’t the same in every editor, it will very often look weird when you look at the code. Therefor, having Emacs instead do the indentation with spaces will universally fix it. Just add the following lines to your ~/.emacs.d/init.el
:
;;Spaces instead of tabs
(setq-default indent-tabs-mode nil)
This will make Emacs only use spaces while performing indentation. If you wish to change the offset (number of spaces) of each level of indentation, then add the following lines:
;;Indent with 4 spaces
(setq-default c-basic-offset 4)
If you want brackets to not have an extra indentation, then add the following lines:
;;Don't indent brackets
(setq-default c-offsets-alist '((substatement-open . 0)))