Search code examples
c++emacsminor-mode

Change indentation with Emacs minor mode


I have a CS class that requires (or at least strongly suggests) 8 spaces for C++ indentation. I normally use 2, so this is quite different for me.

I have until recently been just toggling the indent code in my .emacs and running eval-buffer, but that seems like a poor solution with a programmable editor.

So I am wondering: how might I go about creating a minor Mode (or is there a better function for this?)? I'd like to be able to enable it with M-x comp-mode or something similar.

I have seen minor modes, but they seem to instead focus on key mappings. Perhaps I am looking at the wrong Emacs feature.

Perhaps I can extend the C++ mode to create a comp-mode with different indentation settings?


Solution

  • You could probably do this with a minor mode, but an easier solution is to use directory variables. Create a file called .dir-locals.el in the directory containing your coursework and put something like this in it:

    ((c++-mode . ((indent-tabs-mode . nil)
                  (c-basic-offset . 8))))