[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/speedrect 874f0be40c 81/90: calc: allow mismatched rect
From: |
ELPA Syncer |
Subject: |
[elpa] externals/speedrect 874f0be40c 81/90: calc: allow mismatched rect/vector heights with warning + format |
Date: |
Fri, 6 Dec 2024 18:59:18 -0500 (EST) |
branch: externals/speedrect
commit 874f0be40c92b2341cce2c4ec2ff917fcdb1a7a3
Author: JD Smith <93749+jdtsmith@users.noreply.github.com>
Commit: JD Smith <93749+jdtsmith@users.noreply.github.com>
calc: allow mismatched rect/vector heights with warning + format
Note calc appends an additional space to the last line of a
vector (which we now trim).
---
speedrect.el | 46 ++++++++++++++++++++++++++++++----------------
1 file changed, 30 insertions(+), 16 deletions(-)
diff --git a/speedrect.el b/speedrect.el
index 471f9c4db8..a13c37eda4 100644
--- a/speedrect.el
+++ b/speedrect.el
@@ -160,12 +160,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 &optional from to)
- "Insert RECT's 2nd element, replacing text between STARTCOL and ENDCOL.
-The element is removed from RECT by side effect. FROM and TO are
-optional substring positions to insert."
+(defun speedrect--replace-with-rect (startcol endcol lines width
+ &optional from to)
+ "Insert LINES' 1st element, replacing text between STARTCOL and ENDCOL.
+Each string in LINES is space-padded to occupy at least WIDTH
+characters. The element is removed from LINES by side effect.
+FROM and TO are optional substring positions to insert. WIDTH is
+used to insert spaces if the LINES list is not long enough to
+full the full rectangle."
(delete-rectangle-line startcol endcol nil)
- (insert (substring (pop (cdr rect)) from to)))
+ (let ((el (car lines))
+ (w (- width (or from 0) (- (or to 0)))))
+ (if el
+ (progn
+ (insert (substring el from (+ width to)))
+ (setcar lines (cadr lines))
+ (setcdr lines (cddr lines)))
+ (insert (make-string w ?\s)))))
(defun speedrect--lr-space (rect)
"Compute and return the minimum number of flanking spaces.
@@ -198,17 +209,20 @@ inserted text."
(math-format-value (calc-top))))))
(b (region-beginning))
(e (region-end))
- (height (+ (count-lines b e) (if (eq (char-before e) ?\n) 1 0))))
- (if (eq (length lines) height)
- (let* ((lr (speedrect--lr-space lines))
- (low (max 0 (1- (car lr))))
- (high (- (1- (cdr lr)))))
- (when (>= high 0) (setq high nil))
- (push nil lines) ; dummy, for consuming lines in
apply-on-rectangle
- (apply-on-rectangle 'speedrect--replace-with-rect
- start end lines low high))
- (user-error "Row count of calc matrix (%d) does not match rectangle
height (%d)"
- (length lines) height)))
+ (rect-height (+ (count-lines b e) (if (eq (char-before e) ?\n) 1
0))))
+ (unless (= (length lines) rect-height)
+ (warn "Row count of calc matrix (%d) does not match rectangle height
(%d), %s"
+ (length lines) rect-height
+ (if (> rect-height (length lines)) "inserting blanks"
"truncating"))
+ (when (< rect-height (length lines))
+ (setq lines (cl-subseq lines 0 rect-height))))
+ (let* ((lr (speedrect--lr-space lines))
+ (wdth (length (car lines))) ; note: last line may differ
+ (low (max 0 (1- (car lr))))
+ (high (min 0 (- (1- (cdr lr)))))
+ (lst (last lines)))
+ (apply-on-rectangle 'speedrect--replace-with-rect
+ start end lines wdth low high)))
(user-error "Calc rectangle yank not possible here")))
(declare-function mc/edit-lines "mc-edit-lines")
- [elpa] externals/speedrect 85b281d045 61/90: f - fill-text in rectangle, (continued)
- [elpa] externals/speedrect 85b281d045 61/90: f - fill-text in rectangle, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 6886e5c604 66/90: Update README.md, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 932d983f02 65/90: Document fill, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 1e1b713d65 57/90: Update README.md, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 3e981896f1 71/90: Bump version, require Emacs v29.1, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 1e897cc0d5 76/90: copy-rectangle-as-text, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect a8015aea6f 79/90: Bump version, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect c068c528e3 69/90: Update README.md, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect ed85814e48 72/90: help: correct typo, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 94ed5cbc6c 80/90: README NEWS, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 874f0be40c 81/90: calc: allow mismatched rect/vector heights with warning + format,
ELPA Syncer <=
- [elpa] externals/speedrect 040d12b907 83/90: Update README.md, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 2b864a4a41 86/90: Proposed for ELPA: speedrect, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 463aae4f1b 78/90: Update README.md, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect bae04ed3a3 67/90: amalgamate fill changes, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect ce32628339 73/90: Update README.md, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect aaf72e49c8 77/90: README: improve calc note, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 93182dd080 89/90: correct autoload, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 4603a1ff09 90/90: ELPA version bump and Created date, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 0696ca6ffd 87/90: yank-from-calc: remove unused let-binding, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 2a34fca350 37/90: Update README.md, ELPA Syncer, 2024/12/06