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

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

[nongnu] elpa/paredit b7f234a 067/224: Preserve column in `paredit-reind


From: ELPA Syncer
Subject: [nongnu] elpa/paredit b7f234a 067/224: Preserve column in `paredit-reindent-defun'.
Date: Sat, 7 Aug 2021 09:22:20 -0400 (EDT)

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

    Preserve column in `paredit-reindent-defun'.
    
    Ignore-this: 9c3342808317128eefc0b83bf63cfb15
    
    Also use `lisp-fill-paragraph' rather than `fill-paragraph'.
    
    Thanks to Eitan Postavsky for the suggestion.
    
    darcs-hash:20110320183704-00fcc-d64d8a2d2e06db8a206a0fadb3b9dbe0f8c10abf
---
 paredit.el | 26 +++++++++++++++++++++-----
 1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/paredit.el b/paredit.el
index 23acb5f..637dd72 100644
--- a/paredit.el
+++ b/paredit.el
@@ -984,11 +984,22 @@ If the point is in a string or a comment, fill the 
paragraph instead,
   (interactive "P")
   (if (or (paredit-in-string-p)
           (paredit-in-comment-p))
-      (fill-paragraph argument)
-    (save-excursion
-      (end-of-defun)
-      (beginning-of-defun)
-      (indent-sexp))))
+      (lisp-fill-paragraph argument)
+    (let ((column (current-column))
+          (indentation (paredit-current-indentation)))
+      (save-excursion (end-of-defun) (beginning-of-defun) (indent-sexp))
+      ;; Preserve the point's position either in the indentation or in
+      ;; the code: if on code, move with the code; if in indentation,
+      ;; leave it in the indentation, either where it was (if that's
+      ;; still indentation) or at the end of the indentation (if the
+      ;; code moved far enough left).
+      (let ((indentation* (paredit-current-indentation)))
+        (goto-char
+         (+ (point-at-bol)
+            (cond ((not (< column indentation))
+                   (+ column (- indentation* indentation)))
+                  ((<= indentation* column) indentation*)
+                  (t column))))))))
 
 ;;;; Comment Insertion
 
@@ -2479,6 +2490,11 @@ If no parse state is supplied, compute one from the 
beginning of the
               (forward-sexp))))
         t)
     nil))
+
+(defun paredit-current-indentation ()
+  (save-excursion
+    (back-to-indentation)
+    (current-column)))
 
 ;;;; Initialization
 



reply via email to

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