[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/speedrect 2aac618746 26/90: speedrect-yank-from-calc: a
From: |
ELPA Syncer |
Subject: |
[elpa] externals/speedrect 2aac618746 26/90: speedrect-yank-from-calc: added |
Date: |
Fri, 6 Dec 2024 18:59:10 -0500 (EST) |
branch: externals/speedrect
commit 2aac6187460dc955fe296f2f115c287f20a39c64
Author: JD Smith <93749+jdtsmith@users.noreply.github.com>
Commit: JD Smith <93749+jdtsmith@users.noreply.github.com>
speedrect-yank-from-calc: added
---
README.md | 5 +++--
speedrect.el | 44 +++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 46 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index dca0e579e8..3d9317c2bf 100644
--- a/README.md
+++ b/README.md
@@ -13,8 +13,8 @@ SpeedRect is a small Emacs package that provides convenient
"modal" key bindings
- Additional command to _invert the deletion_, i.e. delete the _unmarked
columns_, keeping the marked rectangle.
- Save and restore the last rectangle's position.
- Start a new rectangle from point.
-- Calc grab and sum commands.
-- Column shift: slide a rectangle left or right, 1 or 5 columns at a time (or
any number, with a prefix).
+- Two-way interaction with Calc: grab, sum, and yank matrix from top of calc
stack.
+- Column shift: slide a rectangle left or right, 1 or 5 columns at a time (or
any number of columns, with a numerical prefix).
- A help page (hit `?`).
## Installation
@@ -70,6 +70,7 @@ Numerical:
[#] grab grab the rectangle as a matrix in calc
[=] across sum across rows and grab result in calc as a vector
[+] down sum down the columns and grab result in calc
+ [m] yank-mat yank matrix from top of calc stack, overwriting selected rect
Etc:
[?] help view this Help buffer
[q] quit exit rectangle-mark-mode
diff --git a/speedrect.el b/speedrect.el
index ea17787134..1ef133dab2 100644
--- a/speedrect.el
+++ b/speedrect.el
@@ -3,7 +3,7 @@
;; Author: JD Smith
;; Created: 2023
-;; Version: 0.1.2
+;; Version: 0.2.0
;; Package-Requires: ((emacs "25.1") (compat "29.1.4.0"))
;; Homepage: https://github.com/jdtsmith/speedrect
;; Keywords: convenience
@@ -32,6 +32,8 @@
;;; Code:
(require 'rect)
+(require 'calc)
+(require 'subr-x)
(require 'compat)
(eval-when-compile (require 'cl-lib))
@@ -110,6 +112,44 @@ 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)
+ "Insert RECT's 2nd element, replacing text between STARTCOL and ENDCOL.
+RECT's 2nd element is removed by side-effect."
+ (delete-rectangle-line startcol endcol nil)
+ (insert (pop (cdr rect))))
+
+(defun speedrect-yank-from-calc (start end)
+ "Yank matrix from top of calc stack, overwriting the marked rectangle.
+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."
+ (interactive "r")
+ (if-let ((rectangle-mark-mode)
+ (buf (get-buffer "*Calculator*")))
+ (let* ((b (region-beginning))
+ (e (region-end))
+ (height (+ (count-lines b e)
+ (if (eq (char-before e) ?\n) 1 0)))
+ crect)
+ (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))
+ (point))))
+ (cend (progn (calc-cursor-stack-index 0) (line-end-position
0))))
+ (setq crect (extract-rectangle cstart cend))))
+ (if (eq (length crect) height)
+ (progn
+ (push nil crect) ; dummy, for consuming in apply-on-rectangle
+ (apply-on-rectangle 'speedrect--replace-with-rect start end
crect)
+ (speedrect-stash))
+ (user-error "Row count of calc matrix (%d) does not match rectangle
height (%d)"
+ (length crect) height))))
+ (user-error "Calc rectangle yank not possible here")))
+
(defun speedrect-transient-map-info ()
"Documentation window for speedrect."
(interactive)
@@ -142,6 +182,7 @@ Note that point and mark will not move beyond the end of
text on their lines."
" [#] grab grab the rectangle as a matrix in calc\n"
" [=] across sum across rows and grab result in calc as a
vector\n"
" [+] down sum down the columns and grab result in calc\n\n"
+ " [m] yank-mat yank matrix from top of calc stack, overwriting
selected rect\n\n"
"Etc:\n\n"
" [?] help view this Help buffer\n"
" [q] quit exit rectangle-mark-mode"))
@@ -171,6 +212,7 @@ prior to deactivating mark."
("M-S-<left>" speedrect-shift-left-fast)
;; Calc commands
("=" calc-grab-sum-across) ("+" calc-grab-sum-down) ("#"
calc-grab-rectangle)
+ ("m" speedrect-yank-from-calc)
;; Special
("n" speedrect-restart) ("l" speedrect-recall-last)
("?" speedrect-transient-map-info) ("q" speedrect-quit))
- [elpa] externals/speedrect 685478097b 23/90: mention [N]umbers, (continued)
- [elpa] externals/speedrect 685478097b 23/90: mention [N]umbers, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 8902387c85 28/90: README: describe operation with calc, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 7c77c5832f 02/90: Update README.md, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 7f9293882d 04/90: Initial commit, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 48dcbdf02c 12/90: use compat to reach older Emacs versions; bump version, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 0f7fc6904d 13/90: Update README.md, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect e8169e86df 15/90: delete-rest: renamed and fixed insertion/end logic, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 83a60fa26e 18/90: Update README.md, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 9bd1354dee 22/90: Mention straight install, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 0ea0dba568 20/90: more doc tweaks, ELPA Syncer, 2024/12/06
- [elpa] externals/speedrect 2aac618746 26/90: speedrect-yank-from-calc: added,
ELPA Syncer <=
- [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