# Customize electric indent

I would like to change the "electric-indent" behavior in emacs, at least in the LaTeX major mode, but possibly in some other ones as well. What I would like is to retain the behavior that when hitting return, the next line is automatically indented to the level that the previous line was indented, but to disable all other ways of setting off auto indentation. So for example, in LaTeX mode, when I type followed by return, the next line should not be indented automatically any further than the may have already been. But after I manually indent the next line, the following line would then be indented to that level. E.g.:

$$% No *auto* indent when hitting 'return' on this line y = f(x), % Manually indented; but now 'return' should indent next line x \in D$$


This is the behavior I'm used to from using TeXShop. It also seems to be the behavior of emacs in the Text major mode.

If it helps I should note that I am a new emacs user (I've gone through the very first tutorial, am currently going through the "Emacs Lisp Intro", and have cut-and-paste lisp code into my .emacs file from various places online to get certain customized behavior, but do not understand all of it yet).

I have searched through other questions, and there are many similar ones, for example this, this, this, this, and this, but I couldn't find something exactly fitting this one. But it could be I missed it, or simply didn't understand how to adapt one of the answers to these to my situation.

Finally, this should perhaps be a separate question, but if anyone could recommend to me a good way to learn how emacs works, something appropriate to my experience level, I would appreciate it.

I'd suggest you try and use a dumb-indentation function, then:

(add-hook 'latex-mode-hook
(lambda ()
(setq-local indent-line-function #'indent-relative)))


[ And use LaTeX-mode-hook instead if you're using AUCTeX. ]