Emacs LLVM coding style dir-locals

Hi all,

Just wanted to share a trick I found for using the LLVM coding style in Emacs, although I’m sure this is nothing new to veterans around here. There’s an LLVM coding style emacs plugin in /utils/emacs/emacs.el. However this uses a string match against “llvm” to try to guess if the current directory contains llvm sources. A simpler method is to use Emacs directory variable support (https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html). Just drop the following lines into a .dir-locals.el file in the root of the LLVM sources, and all files in the source tree will pick up the correct formatting settings:

((nil . ((indent-tabs-mode . nil)
(fill-column . 80)
(c+±indent-level . 2)
(c-base-offset . 2)
(c-offsets-alist . ((innamespace . 0))))))

I hope this helps someone!

  • stephen