3

If I'm editing certain filetypes then sometimes when I hit return at the end of a line the cursor will move to the next line and the previous line will suddenly be heavily indented.

This behavior seems to happen in a few different filetypes under various conditions but I can reliably reproduce this in an .el file on a comment line.

For example, with the cursor indicated by _, if I'm on a line that reads

; word_

and then I press return I get the following.

                            ; word
_

What's going on? I commented out all tabbing related settings from my configuration files and I still get this behavior.

  • 2
    a single semicolon conventionally indicates a margin comment or an annotation. For full line comments a double-semicolon is used instead. – rekado Feb 25 '15 at 10:16
1

This is caused by electric-indent-mode. If you disable it, the behavior you describe will go away.

A similar question has been asked on here before. The accepted answer describes how to disable electric indentation for specific characters. Adapting the code to your specific situation, we get:

(defun electric-indent-mode-configure ()
  "Delete newline (?\n) from `electric-indent-chars'."
  (setq electric-indent-chars (delq 10 electric-indent-chars)))

(add-hook 'emacs-lisp-mode-hook #'electric-indent-mode-configure)

With this in place, you can have electric-indent-mode turned on without getting the behavior you describe.

  • Is there a way to get electric indentation only for a new line and only immediately after hitting return? – Praxeolitic Feb 25 '15 at 11:49
  • @Praxeolitic I'm not sure what you mean, can you give a concrete example of the behavior you are looking for? – itsjeyd Feb 25 '15 at 11:54
  • Found it! I was looking for the behavior of electric-indent-just-newline. emacs.stackexchange.com/a/3217/2139 – Praxeolitic Feb 25 '15 at 11:56

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.