Last active
March 8, 2023 07:19
-
-
Save jdtsmith/bfa2d692c4fbbffe06b558e4bcf9abec to your computer and use it in GitHub Desktop.
Supercharge emacs rectangle-mark-mode with modal keys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use-package rect | |
:init | |
(defun my/rect-transient-map-info () | |
(interactive) | |
(with-help-window "Rectangle Mark Command Help" | |
(dolist | |
(l '("Rectangle Mark Mode Modal Commands\n" | |
"==================================\n\n" | |
"Insertion:\n\n" | |
" [o] open fill rectangle with spaces, moving adjacent text right\n" | |
" [t] string replace rectangle with prompt string\n\n" | |
"Killing:\n\n" | |
" [k] kill kill and save rectangle for yanking\n" | |
" [d] delete kill rectangle without saving\n" | |
" [SPC] del-ws delete all whitespace, starting from left column\n" | |
" [c] clear clear rectangle area by overwriting with spaces\n\n" | |
"Rectangles:\n\n" | |
" [n] new start a new rectangle from this location\n" | |
" [w] copy copy rectangle for future yanking\n" | |
" [y] yank yank rectangle, inserting at point\n\n" | |
"Etc:\n\n" | |
" [q] quit exit rectangle-mark-mode\n" | |
" [?] help view this Help buffer")) | |
(princ l)))) | |
:config | |
(cl-loop for (key def) in | |
'(("k" kill-rectangle) ("t" string-rectangle) | |
("o" open-rectangle) ("w" copy-rectangle-as-kill) | |
("y" yank-rectangle) ("c" clear-rectangle) | |
("d" delete-rectangle) ("N" rectangle-number-lines) | |
(" " delete-whitespace-rectangle) | |
("=" calc-grab-sum-across) ("+" calc-grab-sum-down) | |
("#" calc-grab-rectangle) ("n" set-mark-command) | |
("q" (lambda () (interactive) (deactivate-mark))) | |
("?" my/rect-transient-map-info)) | |
do (define-key rectangle-mark-mode-map key def))) |
Updated to use ?
for a help screen instead of the repeating message. Also added q
to quit, and n
to re-start drawing a new rectangle from point.
Why do you need use-package for this? Is it related to rect package?
I'm obviously biased, but I'd bind ?
to (lambda () (interactive) (embark-bindings-in-keymap rectangle-mark-mode-map))
instead. 😛
@raveensrk Just a convenient way to package it. See SpeedRect for a package version of this I put together. @oantolin nice idea. I went the "longer docs" route in the package.
@jdtsmith Thank you for this. Installed and using it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to use rectangle-mark-mode-map (with thanks to @oantolin).