[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/speedrect d4d89acb50 27/90: yank-from-calc: preserve at
From: |
ELPA Syncer |
Subject: |
[elpa] externals/speedrect d4d89acb50 27/90: yank-from-calc: preserve at least one space padding each side |
Date: |
Fri, 6 Dec 2024 18:59:10 -0500 (EST) |
branch: externals/speedrect
commit d4d89acb501c6ecf75613fd1ffdbbbb1f6a6567b
Author: JD Smith <93749+jdtsmith@users.noreply.github.com>
Commit: JD Smith <93749+jdtsmith@users.noreply.github.com>
yank-from-calc: preserve at least one space padding each side
---
speedrect.el | 33 +++++++++++++++++++++++++--------
1 file changed, 25 insertions(+), 8 deletions(-)
diff --git a/speedrect.el b/speedrect.el
index 1ef133dab2..f18e7e502f 100644
--- a/speedrect.el
+++ b/speedrect.el
@@ -112,11 +112,23 @@ Note that point and mark will not move beyond the end of
text on their lines."
(progn (goto-char end) (line-end-position)))
(insert (string-join rect "\n"))))
-(defun speedrect--replace-with-rect (startcol endcol rect)
+(defun speedrect--replace-with-rect (startcol endcol rect &optional from to)
"Insert RECT's 2nd element, replacing text between STARTCOL and ENDCOL.
-RECT's 2nd element is removed by side-effect."
+The element is removed from RECT by side effect. FROM and TO are
+optional substring positions to insert."
(delete-rectangle-line startcol endcol nil)
- (insert (pop (cdr rect))))
+ (insert (substring (pop (cdr rect)) from to)))
+
+(defun speedrect--lr-space (rect)
+ "Compute and return the minimum number of flanking spaces.
+Returns a cons of the minimum number of space characters
+appearing on the left- and right-hand ends of all strings in
+RECT (a list of strings)."
+ (cl-loop for s in rect
+ if (string-match "^\\( *\\)[^ ].*?\\( *\\)$" s)
+ minimize (match-end 1) into left
+ minimize (- (length s) (match-beginning 2)) into right
+ finally return (cons left right)))
(defun speedrect-yank-from-calc (start end)
"Yank matrix from top of calc stack, overwriting the marked rectangle.
@@ -124,7 +136,8 @@ START and END are the interactively-defined region
beginning and
end. The (matrix) value at the top of the calc stack is used,
and must have the same number of rows as the height of the marked
rectangle. To avoid copying brackets and commas, v [ and v , may
-be used in calc."
+be used in calc. A minimum of one padding space is preserved on
+each side of the inserted text."
(interactive "r")
(if-let ((rectangle-mark-mode)
(buf (get-buffer "*Calculator*")))
@@ -132,19 +145,23 @@ be used in calc."
(e (region-end))
(height (+ (count-lines b e)
(if (eq (char-before e) ?\n) 1 0)))
- crect)
+ crect lr)
(save-excursion
(with-current-buffer buf
(let* ((cstart (progn (calc-cursor-stack-index 1)
- (if (looking-at (if calc-line-numbering
"[0-9]+: *[^ \n]" " *[^ \n]"))
- (1- (match-end 0))
+ (if (and calc-line-numbering (looking-at
"[0-9]+: "))
+ (match-end 0)
(point))))
(cend (progn (calc-cursor-stack-index 0) (line-end-position
0))))
(setq crect (extract-rectangle cstart cend))))
(if (eq (length crect) height)
(progn
+ (setq lr (speedrect--lr-space crect))
(push nil crect) ; dummy, for consuming in apply-on-rectangle
- (apply-on-rectangle 'speedrect--replace-with-rect start end
crect)
+ (apply-on-rectangle 'speedrect--replace-with-rect
+ start end crect
+ (max 0 (1- (car lr)))
+ (min 0 (- (1- (cdr lr)))))
(speedrect-stash))
(user-error "Row count of calc matrix (%d) does not match rectangle
height (%d)"
(length crect) height))))
- [elpa] externals/speedrect f0de893e1a 14/90: kill-rest: added on "r", (continued)
- [elpa] externals/speedrect f0de893e1a 14/90: kill-rest: added on "r", ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 1e9b598017 21/90: Update README.md, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 952899587f 24/90: doc: extend bar, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 395c578693 25/90: doc tweaks, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 496f6e7473 31/90: Update README.md, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 0d899fc06d 34/90: Update README.md, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 7abd0d9337 33/90: Update README.md, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect bb9d61cba6 39/90: Update README.md, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 629e9d935b 42/90: add move up/down commands and [M-]S-<up>/<down>, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect f81a17461d 53/90: Update README.md, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect d4d89acb50 27/90: yank-from-calc: preserve at least one space padding each side,
ELPA Syncer <=
- [elpa] externals/speedrect a8b179b738 41/90: Remove superfluous \n, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 1ffb2c76ca 30/90: Update README.md, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 3cab9dfcc5 35/90: Update README.md, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect d9d7f79977 36/90: calc-grab-sum-down/across: switch to `_` and `:` to mirror calc, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 1e732a5b35 44/90: bump version, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect a9086d65e5 45/90: speedrect-right-char: correct rectangle-right logic, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 6867945e0b 54/90: Update README.md, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 2a4d4f0bcd 59/90: Properly handle point/mark crutches for saving rects, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect d2af235ca3 60/90: stash: save point and mark crutches to stash, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 6dc047f54b 64/90: bump version, ELPA Syncer, 2024/12/06