Last active
December 7, 2023 09:31
-
-
Save unhammer/f4a26e7de42cd9600ef9f7318ad0caab to your computer and use it in GitHub Desktop.
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
(defvar-keymap embark-org-column-map | |
:doc "Keymap for Embark org-column actions." | |
:parent embark-org-table-map | |
"M-r" #'my-cua-enable-and-replace-in-rectangle-embark) | |
(defun my-embark-org-column-at-point () | |
"Target the org-column at point." | |
(when-let ((org-column | |
(and (org-at-table-p) | |
(not (looking-at-p "|")) ; since then we don't know which column you mean | |
(let (beg | |
end) | |
(save-excursion | |
(let ((col (or (save-excursion | |
(and (re-search-backward "|" | |
(line-beginning-position) | |
'noerror) | |
(current-column))) | |
(current-column)))) | |
(while (org-at-table-p) | |
(move-to-column col) | |
(setq beg (point)) | |
(forward-line -1)))) | |
(save-excursion | |
(let ((col (or (save-excursion | |
(and (re-search-forward "|" | |
(line-end-position) | |
'noerror) | |
(1- (current-column)))) | |
(current-column)))) | |
(while (org-at-table-p) | |
(move-to-column col) | |
(setq end (point)) | |
(forward-line +1)))) | |
(goto-char end) | |
(push-mark beg 'nomsg 'activate) | |
(rectangle-mark-mode) | |
(string-join (extract-rectangle beg end) "\n"))))) | |
(cons 'org-column org-column))) | |
(add-to-list 'embark-target-finders #'my-embark-org-column-at-point) | |
(add-to-list 'embark-keymap-alist '(org-column . embark-org-column-map)) | |
(defun my-cua-enable-and-replace-in-rectangle () | |
"Ensure CUA rectangle active, run replace in rectangle." | |
(interactive) | |
(unless cua--rectangle | |
(unless cua--rectangle-initialized | |
(cua--init-rectangles)) | |
(cua--activate-rectangle)) | |
(call-interactively #'cua-replace-in-rectangle)) | |
(add-to-list 'embark-around-action-hooks (list #'my-cua-enable-and-replace-in-rectangle #'embark--mark-target)) | |
(add-to-list 'embark-target-injection-hooks (list #'my-cua-enable-and-replace-in-rectangle #'embark--ignore-target)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment