[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master b9d0cdc: * lisp/simple.el (newline-and-indent): Disable `electric

From: Stefan Monnier
Subject: master b9d0cdc: * lisp/simple.el (newline-and-indent): Disable `electric-indent-mode`
Date: Fri, 22 Jan 2021 16:57:06 -0500 (EST)

branch: master
commit b9d0cdcacbd3da93b4ebfa10d778efb618881ccc
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    * lisp/simple.el (newline-and-indent): Disable `electric-indent-mode`
    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
    (reindent-then-newline-and-indent): Temporarily disable
    `electric-indent-mode` as well.
 lisp/simple.el | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index 2c6e391..8d4e4a7 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -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.
@@ -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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]