Using Electric Indent with Org Mode

Recently I've been using electric indent mode to handle automatic indentation. It's very useful when writing code, as it indents blocks automatically when the enter key is pressed. But some of that behaviour isn't desirable when using other modes, such as org mode.

One thing I like about org-mode is the keyboard shortcuts for inserting new headlines and todo items. For example, ALT+ENTER will create a new headline beneath the current line at the correct depth.

Unfortunately, when using electric indent the headlines are indented:

Emacs org-mode with electric indentation

Thankfully the solution is relatively simple. The following code in your emacs intialization will disable electric indentation when working with org files.

(add-hook 'electric-indent-functions
          (lambda (x) (when (eq 'org-mode major-mode) 'no-indent)))

So now you'll get the expected behaviour:

Emacs org-mode with electric indentation

Posted in: Emacs | Comments (0)

Post a comment

org-mode tags allowed: /italic/, *bold* and =code=