Skip to content

Commit

Permalink
* lisp/simple.el (newline-and-indent): Disable electric-indent-mode
Browse files Browse the repository at this point in the history
With `electric-indent-mode` enabled, `newline-and-indent` ends up indenting
3 times: once for the original line and twice on the new line.
`reindent-then-newline-and-indent` is even worse, indenting twice
both lines.
None of those commands should be affected by `electric-indent-mode`
since they even explicitly say in their name when and how they do
indentation.

(reindent-then-newline-and-indent): Temporarily disable
`electric-indent-mode` as well.
  • Loading branch information
monnier committed Jan 22, 2021
1 parent ba25a82 commit b9d0cdc
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lisp/simple.el
Expand Up @@ -820,9 +820,10 @@ With ARG, perform this action that many times."
(delete-horizontal-space t)
(unless arg
(setq arg 1))
(dotimes (_ arg)
(newline nil t)
(indent-according-to-mode)))
(let ((electric-indent-mode nil))
(dotimes (_ arg)
(newline nil t)
(indent-according-to-mode))))

(defun reindent-then-newline-and-indent ()
"Reindent current line, insert newline, then indent the new line.
Expand All @@ -832,7 +833,8 @@ In programming language modes, this is the same as TAB.
In some text modes, where TAB inserts a tab, this indents to the
column specified by the function `current-left-margin'."
(interactive "*")
(let ((pos (point)))
(let ((pos (point))
(electric-indent-mode nil))
;; Be careful to insert the newline before indenting the line.
;; Otherwise, the indentation might be wrong.
(newline)
Expand Down

0 comments on commit b9d0cdc

Please sign in to comment.