diff options
author | Thomas Voss <mail@thomasvoss.com> | 2024-10-17 03:02:09 +0200 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2024-10-17 03:02:09 +0200 |
commit | dafe19e36e50b0fee932013186ddfe18145f0a3e (patch) | |
tree | 9a4690e2da708e94e2f69969a4fcb4889dbf7710 /.config/emacs/modules/mm-editing.el | |
parent | c6184c2611d0493197f6d1ae2134089c17a583f9 (diff) |
emacs: Add functions to mark all in region
Diffstat (limited to '.config/emacs/modules/mm-editing.el')
-rw-r--r-- | .config/emacs/modules/mm-editing.el | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/.config/emacs/modules/mm-editing.el b/.config/emacs/modules/mm-editing.el index fb1475d..4628474 100644 --- a/.config/emacs/modules/mm-editing.el +++ b/.config/emacs/modules/mm-editing.el @@ -98,12 +98,53 @@ those should be listed in `mm-editing-indentation-settings'." ;;; Multiple Cursors +(defmacro mm--define-mc-marking-command (name search-function noun) + (let ((noun-symbol (intern noun))) + `(defun ,name (beg end ,noun-symbol) + ,(format "Mark all occurances of %s between BEG and END. +If called interactively with an active region then all matches in the +region are marked, otherwise all matches in the buffer are marked." + (upcase noun)) + (interactive + (list (or (use-region-beginning) (point-min)) + (or (use-region-end) (point-max)) + (read-string + (format-prompt ,(concat "Match " noun) nil)))) + (require 'multiple-cursors) + (if (string-empty-p ,noun-symbol) + (message "Command aborted") + (catch 'mm--no-match + (mc/remove-fake-cursors) + (goto-char beg) + (let (did-match-p) + (while (,search-function ,noun-symbol end :noerror) + (setq did-match-p t) + (push-mark (match-beginning 0)) + (exchange-point-and-mark) + (mc/create-fake-cursor-at-point) + (goto-char (mark))) + (unless did-match-p + (message "No match for `%s'" ,noun-symbol) + (throw 'mm--no-match nil))) + (when-let ((first (mc/furthest-cursor-before-point))) + (mc/pop-state-from-overlay first)) + (if (> (mc/num-cursors) 1) + (multiple-cursors-mode 1) + (multiple-cursors-mode 0))))))) + +(mm--define-mc-marking-command + mm-mark-all-in-region search-forward "string") +(mm--define-mc-marking-command + mm-mark-all-in-region-regexp re-search-forward "regexp") + (use-package multiple-cursors :ensure t :bind (("C->" . #'mc/mark-next-like-this) ("C-<" . #'mc/mark-previous-like-this) ("C-M-<" . #'mc/mark-all-like-this-dwim) - ("C-M->" . #'mc/edit-lines)) + ("C-M->" . #'mc/edit-lines) + ("C-$" . #'mm-mark-all-in-region) + ("M-$" . #'mm-mark-all-in-region-regexp)) :init (with-eval-after-load 'multiple-cursors-core (dolist (command #'(delete-backward-char |