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

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

[elpa] externals/speedrect 94a9462ccf 03/12: increment: preserve space p


From: ELPA Syncer
Subject: [elpa] externals/speedrect 94a9462ccf 03/12: increment: preserve space padding when possible
Date: Mon, 16 Dec 2024 12:59:28 -0500 (EST)

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

    increment: preserve space padding when possible
---
 speedrect.el | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/speedrect.el b/speedrect.el
index 0a064d4031..155abbcbb0 100644
--- a/speedrect.el
+++ b/speedrect.el
@@ -209,12 +209,22 @@ The rectangle line spans columns from STARTCOL to ENDCOL."
        (let ((fmt (format "0x%%0%dx" (- (match-end 1) (match-beginning 1))))
              (num (string-to-number (match-string-no-properties 1) 16)))
          (replace-match (format fmt (+ num increment)))))
-       ((re-search-forward (rx (* space) (group (? (any ?- ?+)) (+ (any 
"0-9")))) end t)
-        (let* ((txt (match-string-no-properties 1))
-               (prefix (if (= (aref txt 0) ?0) "0" ""))
-               (num (string-to-number txt 10))
-               (fmt (format "%%%s%dd" prefix (length txt))))
-            (replace-match (format fmt (+ num increment)))))))))
+       ((re-search-forward (rx (* space)
+                              (group (? (any ?- ?+)) (+ (any "0-9")))
+                              (group (* space)))
+                          end t)
+        (let* ((len (length (match-string 0)))
+              (num-txt (match-string-no-properties 1))
+               (prefix (if (= (aref num-txt 0) ?0) "0" ""))
+               (num (string-to-number num-txt 10))
+               (fmt (format "%%%sd" prefix))
+              (replace (format fmt (+ num increment)))
+              (pad-avail (max 0 (- len (length replace))))
+              (rear-pad (min (length (match-string 2)) pad-avail))
+              (front-pad (- pad-avail rear-pad)))
+          (replace-match (concat (make-string front-pad ?\s)
+                                replace
+                                (make-string rear-pad ?\s)))))))))
 
 (defun speedrect-increment-first-number (start end &optional increment)
   "Increment the first integer or hexadecimal number in the rectangle.



reply via email to

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