0

Using C/C++ (cc-mode), emacs sometimes re-indents text as I'm typing.

For example (# for indentation, the first 4 are a tab):

enum {
####/

Typing *, becomes:

enum {
######/*

(inserting 2 extra spaces)


Is there a way to disable this?

4
  • This has nothing to do with Evil.
    – wasamasa
    Mar 8, 2017 at 9:48
  • Right, I wasn't sure when asking.
    – ideasman42
    Mar 8, 2017 at 9:49
  • This must be a duplicate, but I don't have time to track it down. Maybe search for electric-indent-mode...
    – Drew
    Mar 8, 2017 at 16:47
  • emacs.stackexchange.com/questions/31038/… is related, if not an exact duplicate.
    – npostavs
    Mar 8, 2017 at 20:11

1 Answer 1

1

It turns out electric-mode causes re-indentation, it can be disabled:

To disable, add this to your startup.

(when (fboundp 'electric-indent-mode) (electric-indent-mode -1))

An alternative is to disable re-indenting just for comment characters (since its handy to keep for braces).

;; Prefer no indentation for comment chars.
(define-key c-mode-base-map "/" 'self-insert-command)
(define-key c-mode-base-map "*" 'self-insert-command)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.