Emacs: formatting C code over SSH

I do quite often edit remote files with Emacs by means of TRAMP, that means over SSH.
It works simply great!

However, a problem I found while editing some strict-style project written in C, is about instrumenting Emacs to observe a per-project c-style configuration. .dir-locals.el files can rescue you, but the problem is about their scope: such file are local only,
Or that is what I thought!
TRAMP has a special variable named enable-remote-dir-locals that can be set to a non-nil value to make Emacs aware of .dir-locals.el files on the remote side.
Therefore, on the remote machine, I’ve:

$ cat .dir-locals.el
;; Directory Local Variables
;;; For more information see (info "(emacs) Directory Variables")

((c-mode . ((c-file-style . "ellemtel")
            (indent-tabs-mode . nil))))


and on my local Emacs instance I placed:

(setq enable-remote-dir-locals t)


and that’s all I need!
See the Emacs documentation about dir-locals for more information.

The article Emacs: formatting C code over SSH has been posted by Luca Ferrari on May 9, 2022

Tags: emacs , c