I've recently upgraded emacs to version 24.4.1 and something has changed in the indentation of new lines. When I hit enter I expect just "bare" new line character at point where cursor was present, in particular if I'm in the middle of the line, that line should be splitted and none character be deleted including spaces. Unfortunately this is not the case.

Here is example:

a b

When I put the cursor just after a and hit enter I get:


while it should be


I googled a bit and probably this is due to auto-indentation, how can I disable this? I'm talking about text or fundamental mode if that matters.

  • 8
    For posterity, I have a comment to add to this. Many "recent upgrade" problems can be solved by reading the NEWS with M-x view-emacs-news (or C-h n). You can read the NEWS for any previous version by adding a prefix arg. Upon viewing the NEWS and doing an isearch for "indent", the first result is extremely similar to Drew's answer. Just a helpful tip for any issues relating to upgrades.
    – nanny
    Jan 2, 2015 at 14:06

5 Answers 5


Disable electric-indent-mode:

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

That works with any Emacs version. This annoyance or shiny-new-feature, depending on your point of view, was introduced as the default in Emacs 24.4.

See also this similar post on StackOverflow.

(However, it sounds like you are saying the reverse, and that you want RET to indent but are not getting that indentation. What has changed is that RET ("Enter") now indents automatically, and you need to hit C-j to get just a newline with no indentation. They swapped RET and C-j, in effect. If you want RET to indent, then the new default behavior should give you what you want. In any case, the mode is electric-indent-mode: turn it on or off, as you like.)


There is the possibility to insert a newline char with C-q C-j and there are 3 commands to split the line: open-line C-o, split-line C-M-o and the newline RET, C-m you used. If you position the cursor like you said after the a and press C-o the current line will be broken after the cursor and every char will be in the next line. split-line will keep the column-position so that an extra blank is inserted before the content.

Hmm, interesting, with C-M-o the current line also gets an extra blank in the end so that the b and the cursor positions line up after the change.

In fundamental mode C-j changes the buffer to your expectation on my machine, and C-j is bound to electric-newline-and-maybe-indent


You can effectively disable line indentation this way:

(defun singpolyma/indent-line ()
    "Don't auto indent lines."


    (add-hook 'prog-mode-hook (lambda ()
        (setq indent-line-function 'singpolyma/indent-line)
    (add-hook 'text-mode-hook (lambda ()
        (setq indent-line-function 'singpolyma/indent-line)

When you want to disable electric-indent-mode for a particular major mode, you can add a hook as follows:

  (add-hook 'sml-mode-hook
            (lambda () (electric-indent-local-mode -1)))

In my case, this has happened when I added the next line in my configuration.

(setq indent-line-function 'insert-tab)

I have commented out to fix.

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.