emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/multiple-cursors 0d89125 089/434: Added mc-version of mark


From: ELPA Syncer
Subject: [nongnu] elpa/multiple-cursors 0d89125 089/434: Added mc-version of mark-all-like-this
Date: Sat, 7 Aug 2021 09:20:01 -0400 (EDT)

branch: elpa/multiple-cursors
commit 0d89125f60c9e9e30b961a00e1dadbe18cad04e7
Author: Magnar Sveen <magnars@gmail.com>
Commit: Magnar Sveen <magnars@gmail.com>

    Added mc-version of mark-all-like-this
---
 features/mark-more.feature |  6 ++++++
 features/support/env.el    |  1 +
 mc-mark-more.el            | 23 +++++++++++++++++++++++
 3 files changed, 30 insertions(+)

diff --git a/features/mark-more.feature b/features/mark-more.feature
index 9e35a30..d8196f0 100644
--- a/features/mark-more.feature
+++ b/features/mark-more.feature
@@ -79,3 +79,9 @@ Feature: Marking multiple parts of the buffer
     And I press "C-- M-<"
     And I type "more"
     Then I should see "Here's text, more and more"
+
+  Scenario: Marking all
+    When I insert "Here's text, text and text"
+    And I select "text"
+    And I press "M-!"
+    Then I should have 3 cursors
diff --git a/features/support/env.el b/features/support/env.el
index ac605b0..d1534dc 100644
--- a/features/support/env.el
+++ b/features/support/env.el
@@ -22,6 +22,7 @@
  (global-set-key (kbd "C->") 'mark-next-like-this)
  (global-set-key (kbd "M->") 'mc/mark-next-like-this)
  (global-set-key (kbd "M-<") 'mc/mark-previous-like-this)
+ (global-set-key (kbd "M-!") 'mc/mark-all-like-this)
  (global-set-key (kbd "H-SPC") 'set-rectangular-region-anchor)
  (switch-to-buffer
   (get-buffer-create "*multiple-cursors*"))
diff --git a/mc-mark-more.el b/mc-mark-more.el
index e57f7ab..534052e 100644
--- a/mc-mark-more.el
+++ b/mc-mark-more.el
@@ -106,4 +106,27 @@ With zero ARG, skip the last one and mark next."
       (multiple-cursors-mode 1)
     (multiple-cursors-mode 0)))
 
+;;;###autoload
+(defun mc/mark-all-like-this ()
+  "Find and mark all the parts of the buffer matching the currently active 
region"
+  (interactive)
+  (unless (region-active-p)
+    (error "Mark a region to match first."))
+  (mc/remove-fake-cursors)
+  (let ((master (point))
+        (case-fold-search nil)
+        (point-first (< (point) (mark)))
+        (re (regexp-opt (mc/region-strings))))
+    (mc/save-excursion
+     (goto-char 0)
+     (while (search-forward-regexp re nil t)
+       (push-mark (match-beginning 0))
+       (when point-first (exchange-point-and-mark))
+       (unless (= master (point))
+         (mc/create-fake-cursor-at-point))
+       (when point-first (exchange-point-and-mark)))))
+  (if (> (mc/num-cursors) 1)
+      (multiple-cursors-mode 1)
+    (multiple-cursors-mode 0)))
+
 (provide 'mc-mark-more)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]