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

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

[elpa] externals/speedrect 67bd27132c 07/12: fill: use last killed recta


From: ELPA Syncer
Subject: [elpa] externals/speedrect 67bd27132c 07/12: fill: use last killed rectangle if selected rect is fully blank
Date: Mon, 16 Dec 2024 12:59:28 -0500 (EST)

branch: externals/speedrect
commit 67bd27132c5af1e611e09559273b5a0071c97b86
Author: JD Smith <93749+jdtsmith@users.noreply.github.com>
Commit: JD Smith <93749+jdtsmith@users.noreply.github.com>

    fill: use last killed rectangle if selected rect is fully blank
---
 speedrect.el | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/speedrect.el b/speedrect.el
index 4ef6f740f1..6452cd7db2 100644
--- a/speedrect.el
+++ b/speedrect.el
@@ -341,7 +341,11 @@ inserted text."
     (message "Copied rectangle as %d lines" (length rect))))
 
 (defun speedrect-fill-text (width)
-  "Fill text in the rectangle to the given WIDTH."
+  "Fill text in the selected rectangle to the given WIDTH.
+WIDTH defaults to the selected rectangle's width, but can be set
+with numeric prefix arg.  If the marked rectangle is entirely
+blank, yank and fill the last killed rectangle instead.
+Whitespace is not preserved."
   (interactive
    (list (cond ((null current-prefix-arg)
                (car (rectangle-dimensions (point) (mark))))
@@ -350,17 +354,23 @@ inserted text."
               (t (prefix-numeric-value current-prefix-arg)))))
   (when (<= width 0) (user-error "Fill width must be >0"))
   (with-undo-amalgamate
-    (let ((height (cdr (rectangle-dimensions (point) (mark))))
-         (rect (apply #'delete-extract-rectangle
-                      (if (< (point) (mark))
-                          (list (point) (mark))
-                        (list (mark) (point)))))
-         filled-height)
+    (let* ((height (cdr (rectangle-dimensions (point) (mark))))
+          (rect (delete-extract-rectangle (region-beginning) (region-end)))
+          (blankp (cl-every
+                   (lambda (l) (string-match-p (rx bos (* space) eos) l))
+                   rect))
+          filled-height)
       (with-temp-buffer
-       (dolist (line rect) (insert line " "))
-       (let ((fill-column (point-max)))
+       (if blankp
+           (progn
+             (yank-rectangle)
+             (goto-char (point-min))
+             (when (skip-syntax-forward " " (line-end-position))
+               (delete-region (point-min) (point))))
+         (dolist (line rect) (insert (string-trim line) " \n")))
+       (let ((fill-column (point-max))) ; unfill
          (fill-region (point-min) (point-max)))
-       (let ((fill-column width))
+       (let ((fill-column width))      ; fill@width
          (fill-region (point-min) (point-max) nil 'nosqueeze))
        (goto-char (point-min))
        (set-mark (point))



reply via email to

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