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

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

[nongnu] elpa/paredit 3889955 212/224: Don't reindent single-line edits


From: ELPA Syncer
Subject: [nongnu] elpa/paredit 3889955 212/224: Don't reindent single-line edits in paredit-raise-sexp.
Date: Sat, 7 Aug 2021 09:22:53 -0400 (EDT)

branch: elpa/paredit
commit 38899558cf242187966d8bf1771a3c8e48eb5090
Author: Taylor R Campbell <campbell+paredit@mumble.net>
Commit: Taylor R Campbell <campbell+paredit@mumble.net>

    Don't reindent single-line edits in paredit-raise-sexp.
    
    Add a couple trivial tests for paredit-raise-sexp.
    
    Bug reported by Alex Plotnick.
---
 paredit.el | 10 +++++++++-
 test.el    |  8 ++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/paredit.el b/paredit.el
index 3b69058..c54997d 100644
--- a/paredit.el
+++ b/paredit.el
@@ -2156,7 +2156,15 @@ If the point is on an S-expression, such as a string or 
a symbol, not
       (delete-region (point) (scan-sexps (point) 1))
       (let* ((indent-start (point))
              (indent-end (save-excursion (insert sexps) (point))))
-        (indent-region indent-start indent-end nil)))))
+        ;; If the expression spans multiple lines, its indentation is
+        ;; probably broken, so reindent it -- but don't reindent
+        ;; anything that we didn't touch outside the expression.
+        ;;
+        ;; XXX What if the *column* of the starting point was preserved
+        ;; too?  Should we avoid reindenting in that case?
+        (if (not (eq (save-excursion (goto-char indent-start) (point-at-eol))
+                     (save-excursion (goto-char indent-end) (point-at-eol))))
+            (indent-region indent-start indent-end nil))))))
 
 ;;; The effects of convolution on the surrounding whitespace are pretty
 ;;; random.  If you have better suggestions, please let me know.
diff --git a/test.el b/test.el
index f3444af..307747b 100644
--- a/test.el
+++ b/test.el
@@ -1409,3 +1409,11 @@ Four arguments: the paredit command, the text of the 
buffer
     ("(let ((x 0)) a (progn|) b)" "(progn |(let ((x 0)) a b))")
     ("(let ((x 0)) a (progn| ) b)" "(progn |(let ((x 0)) a b))")
     ("(let ((x 0)) a (progn |) b)" "(progn |(let ((x 0)) a b))")))
+
+(paredit-test 'paredit-raise-sexp
+  `((,(concat
+       "(let ((x 5))\n  (let ((y 3))\n    |(foo bar\n         baz)\n"
+       "    (quux))\n   (wrong indent))")
+     "(let ((x 5))\n  |(foo bar\n       baz)\n   (wrong indent))")
+    ("(define (f x #!optional\n (|wrong indent))\n  (+ 1 2))"
+     "(define (f x #!optional\n |wrong)\n  (+ 1 2))")))



reply via email to

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