emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[nongnu] elpa/evil 08b824eac7: Fix up evil-indent (#1613)


From: ELPA Syncer
Subject: [nongnu] elpa/evil 08b824eac7: Fix up evil-indent (#1613)
Date: Tue, 3 May 2022 03:58:01 -0400 (EDT)

branch: elpa/evil
commit 08b824eac7e261a1dc5e2a12ae71e8144f2d04c6
Author: rbrtb <104695105+rbrtb@users.noreply.github.com>
Commit: GitHub <noreply@github.com>

    Fix up evil-indent (#1613)
    
    * Fix up evil-indent
    
    * Add evil-test-indent
    
    * Fix up
    
    * Improve test
---
 evil-commands.el | 49 +++++++++++++++++++++++++++----------------------
 evil-tests.el    |  9 +++++++++
 2 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/evil-commands.el b/evil-commands.el
index 2bb14baa0b..d6b2e622af 100644
--- a/evil-commands.el
+++ b/evil-commands.el
@@ -1922,28 +1922,33 @@ but doesn't insert or remove any spaces."
   "Indent text."
   :move-point nil
   :type line
-  (if (and (= beg (line-beginning-position))
-           (= end (line-beginning-position 2)))
-      ;; since some Emacs modes can only indent one line at a time,
-      ;; implement "==" as a call to `indent-according-to-mode'
-      (indent-according-to-mode)
-    (goto-char beg)
-    (indent-region beg end))
-  ;; We also need to tabify or untabify the leading white characters
-  (when evil-indent-convert-tabs
-    (let* ((beg-line (line-number-at-pos beg))
-           (end-line (line-number-at-pos end))
-           (ln beg-line)
-           (convert-white (if indent-tabs-mode 'tabify 'untabify)))
-      (save-excursion
-        (while (<= ln end-line)
-          (goto-char (point-min))
-          (forward-line (- ln 1))
-          (back-to-indentation)
-          ;; Whether tab or space should be used is determined by 
indent-tabs-mode
-          (funcall convert-white (line-beginning-position) (point))
-          (setq ln (1+ ln)))))
-    (back-to-indentation)))
+  (save-restriction
+    (narrow-to-region beg end)
+    (if (and (= beg (line-beginning-position))
+             (= end (line-beginning-position 2)))
+        ;; since some Emacs modes can only indent one line at a time,
+        ;; implement "==" as a call to `indent-according-to-mode'
+        (indent-according-to-mode)
+      (goto-char beg)
+      (indent-region beg end))
+    ;; Update `beg' and `end'
+    (setq beg (point-min)
+          end (point-max))
+    ;; We also need to tabify or untabify the leading white characters
+    (when evil-indent-convert-tabs
+      (let* ((beg-line (line-number-at-pos beg))
+             (end-line (line-number-at-pos end))
+             (ln beg-line)
+             (convert-white (if indent-tabs-mode 'tabify 'untabify)))
+        (save-excursion
+          (while (<= ln end-line)
+            (goto-char (point-min))
+            (forward-line (- ln 1))
+            (back-to-indentation)
+            ;; Whether tab or space should be used is determined by 
indent-tabs-mode
+            (funcall convert-white (line-beginning-position) (point))
+            (setq ln (1+ ln)))))
+      (back-to-indentation))))
 
 (evil-define-operator evil-indent-line (beg end)
   "Indent the line."
diff --git a/evil-tests.el b/evil-tests.el
index e3c251d034..5aa9013831 100644
--- a/evil-tests.el
+++ b/evil-tests.el
@@ -1614,6 +1614,15 @@ New Tex[t]
 
 ;;; Operators
 
+(ert-deftest evil-test-indent ()
+  "Test `evil-indent'"
+  :tags '(evil visual operator)
+  (evil-test-buffer
+    :state visual
+    "<    Line with too much indentation.>"
+    ("=")
+    "Line with too much indentation."))
+
 (ert-deftest evil-test-keypress-parser ()
   "Test `evil-keypress-parser'"
   :tags '(evil operator)



reply via email to

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