9

I don't like the way electric indent mode works in latex-mode. Everywhere else (at least everywhere I use), it's great.

How can I permanently disable electric indent mode for latex mode only, but keep it everywhere else?

I'm guessing it's a one-line lisp hack in my config file, or something like that, but I'm horrible at lisp, so I can't figure it out.

7

The command you need is electric-indent-local-mode. You can use this to turn off electric-indent-mode in any buffer by calling it manually: M-x electric-indent-local-mode. This is a toggle, so calling it again in the same buffer turns it back on again.

To do this automatically from your init file, you need to set up a hook. First, define the hook:

(defun remove-electric-indent-mode ()
  (electric-indent-local-mode -1))

Then add it to the appropriate mode hooks. To turn off electric-indent-mode for the LaTeX mode provided by AUCTex, use this:

(add-hook 'LaTeX-mode-hook 'remove-electric-indent-mode)

For the default texmode, use:

(add-hook 'tex-mode-hook 'remove-electric-indent-mode)

The same pattern holds for any other mode you want to turn off electric indentation.

For more details on mode hooks, see the built-in Emacs manual node [(emacs) Hooks][1]. You can get there from Emacs via C-h i r m Hooks <enter>: C-h for help, i for info, r for read the manual, m for menu item, and Hooks to pick the menu item. (or you can follow the link above to see the html version).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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