diff --git a/features/mark-more.feature b/features/mark-more.feature index d8196f0..625fbbb 100644 --- a/features/mark-more.feature +++ b/features/mark-more.feature @@ -85,3 +85,12 @@ Feature: Marking multiple parts of the buffer And I select "text" And I press "M-!" Then I should have 3 cursors + + Scenario: Marking in region + Given I turn on delete-selection-mode + When I insert "Here's text, text and text" + And I select "text, text" + And I press "M-# text " + And I type "more" + Then I should have 2 cursors + And I should see "Here's more, more and text" diff --git a/features/support/env.el b/features/support/env.el index d1534dc..51adda1 100644 --- a/features/support/env.el +++ b/features/support/env.el @@ -23,6 +23,7 @@ (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 "M-#") 'mc/mark-all-in-region) (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 534052e..fdffc78 100644 --- a/mc-mark-more.el +++ b/mc-mark-more.el @@ -129,4 +129,25 @@ With zero ARG, skip the last one and mark next." (multiple-cursors-mode 1) (multiple-cursors-mode 0))) +;;;###autoload +(defun mc/mark-all-in-region (beg end) + "Find and mark all the parts in the region matching the given search" + (interactive "r") + (let ((search (read-from-minibuffer "Mark all in region: ")) + (case-fold-search nil)) + (mc/remove-fake-cursors) + (goto-char beg) + (while (search-forward search end t) + (push-mark (match-beginning 0)) + (mc/create-fake-cursor-at-point)) + (let ((first (mc/furthest-cursor-before-point))) + (if (not first) + (error "Search failed for %S" search) + (mc/pop-state-from-overlay first)))) + (if (> (mc/num-cursors) 1) + (multiple-cursors-mode 1) + (multiple-cursors-mode 0))) + + + (provide 'mc-mark-more) diff --git a/todo.org b/todo.org index 3687b23..dcf7553 100644 --- a/todo.org +++ b/todo.org @@ -10,9 +10,7 @@ Possible to do C-s ... Any way to make M-z just prompt for letter once? ** TODO mark-multiple-mode - mark-multiple has some advantages - -> simpler visuals, no extra cursors (matter of taste?) - -> moving out of the marked area quits the mode + mark-multiple has some advantages -> moving out of the marked area quits the mode ** DONE unknown command: Do for (a)ll, (o)nce or (i)gnore -> (did that work ok? (k)eep doing that or (d)on't) unknown-command ran once - what now? (o)nce is enough, repeat for (a)ll, (u)ndo - that did NOT work. unknown-command ran for all - did that work as expected? (y)es, (n)o