Last active
November 30, 2023 19:54
-
-
Save arialdomartini/f6f274faa4ad88270f6633742236097a to your computer and use it in GitHub Desktop.
swap-marks.el
This file contains 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
(defun my-dired--first-char-or-ask () | |
(if (member (char-after (line-beginning-position)) `(?\s ,dired-marker-char)) | |
(read-char "Which mark are you targeting? ") | |
(char-after (line-beginning-position)))) | |
(defun my-dired-swap-marks-ask () | |
(interactive) | |
(let ((mark (my-dired--first-char-or-ask))) | |
(my-dired-swap-marks (string mark)))) | |
(defun my-dired-swap-marks (mark) | |
(save-excursion | |
(let ((inhibit-read-only t) | |
(beginning (dired-mark--region-beginning)) | |
(end (dired-mark--region-end)) | |
(active-marker (string dired-marker-char))) | |
(goto-char beginning) | |
(while (< (point) end) | |
(beginning-of-line) | |
(cond ((looking-at active-marker) | |
(replace-match mark nil nil nil nil)) | |
((looking-at mark) | |
(replace-match active-marker nil nil nil nil))) | |
(forward-line 1))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment