Skip to content

Instantly share code, notes, and snippets.

@jdtsmith
Last active March 8, 2023 07:19
Show Gist options
  • Save jdtsmith/bfa2d692c4fbbffe06b558e4bcf9abec to your computer and use it in GitHub Desktop.
Save jdtsmith/bfa2d692c4fbbffe06b558e4bcf9abec to your computer and use it in GitHub Desktop.
Supercharge emacs rectangle-mark-mode with modal keys
(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)))
@raveensrk
Copy link

@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