mirror of
https://github.com/magnars/multiple-cursors.el.git
synced 2025-10-13 21:03:05 +00:00
Added mc-version of mark-next-like-this
This commit is contained in:
parent
f2da52aac0
commit
36b262c99e
41
features/mark-more.feature
Normal file
41
features/mark-more.feature
Normal file
@ -0,0 +1,41 @@
|
||||
Feature: Marking multiple parts of the buffer
|
||||
|
||||
Scenario: Marking next like this, cursors
|
||||
When I insert "This text has the word text in it"
|
||||
And I select "text"
|
||||
And I press "M->"
|
||||
Then I should have 2 cursors
|
||||
|
||||
Scenario: Marking next like this, region
|
||||
Given I turn on delete-selection-mode
|
||||
When I insert "This text has the word text in it"
|
||||
And I select "text"
|
||||
And I press "M->"
|
||||
And I type "sentence"
|
||||
Then I should see "This sentence has the word sentence in it"
|
||||
|
||||
Scenario: Skipping a mark
|
||||
Given I turn on delete-selection-mode
|
||||
When I insert "Here's text, text and text"
|
||||
And I select "text"
|
||||
And I press "M->"
|
||||
And I press "C-0 M->"
|
||||
And I type "more"
|
||||
Then I should see "Here's more, text and more"
|
||||
|
||||
Scenario: Removing last fake
|
||||
When I insert "Here's text, text and text"
|
||||
And I select "text"
|
||||
And I press "M->"
|
||||
And I press "C-- M->"
|
||||
Then I should have one cursor
|
||||
|
||||
Scenario: Removing furthest mark
|
||||
Given I turn on delete-selection-mode
|
||||
When I insert "Here's text, text and text"
|
||||
And I select "text"
|
||||
And I press "M->"
|
||||
And I press "M->"
|
||||
And I press "C-- M->"
|
||||
And I type "more"
|
||||
Then I should see "Here's more, more and text"
|
@ -20,6 +20,7 @@
|
||||
(rectangular-region-mode 0)
|
||||
(mm/clear-all)
|
||||
(global-set-key (kbd "C->") 'mark-next-like-this)
|
||||
(global-set-key (kbd "M->") 'mc/mark-next-like-this)
|
||||
(global-set-key (kbd "H-SPC") 'set-rectangular-region-anchor)
|
||||
(switch-to-buffer
|
||||
(get-buffer-create "*multiple-cursors*"))
|
||||
|
64
mc-mark-more.el
Normal file
64
mc-mark-more.el
Normal file
@ -0,0 +1,64 @@
|
||||
(defun mc/cursor-end (cursor)
|
||||
(if (overlay-get cursor 'mark-active)
|
||||
(max (overlay-get cursor 'point)
|
||||
(overlay-get cursor 'mark))
|
||||
(overlay-get cursor 'point)))
|
||||
|
||||
(defun mc/cursor-beg (cursor)
|
||||
(if (overlay-get cursor 'mark-active)
|
||||
(min (overlay-get cursor 'point)
|
||||
(overlay-get cursor 'mark))
|
||||
(overlay-get cursor 'point)))
|
||||
|
||||
(defun mc/furthest-region-end ()
|
||||
(let ((end (max (mark) (point))))
|
||||
(mc/for-each-fake-cursor
|
||||
(setq end (max end (mc/cursor-end cursor))))
|
||||
end))
|
||||
|
||||
(defun mc/furthest-cursor-after-point ()
|
||||
(let ((end (max (mark) (point)))
|
||||
furthest)
|
||||
(mc/for-each-fake-cursor
|
||||
(when (> (mc/cursor-end cursor) end)
|
||||
(setq end (mc/cursor-end cursor))
|
||||
(setq furthest cursor)))
|
||||
furthest))
|
||||
|
||||
(defun mc/region-strings ()
|
||||
(let ((strings (list (buffer-substring-no-properties (point) (mark)))))
|
||||
(mc/for-each-fake-cursor
|
||||
(add-to-list 'strings (buffer-substring-no-properties
|
||||
(mc/cursor-beg cursor)
|
||||
(mc/cursor-end cursor))))
|
||||
strings))
|
||||
|
||||
(defun mc/mark-next-like-this (arg)
|
||||
"Find and mark the next part of the buffer matching the currently active region
|
||||
With negative ARG, delete the last one instead.
|
||||
With zero ARG, skip the last one and mark next."
|
||||
(interactive "p")
|
||||
(unless (region-active-p)
|
||||
(error "Mark a region to match first."))
|
||||
(when (< arg 0)
|
||||
(mc/remove-fake-cursor (mc/furthest-cursor-after-point)))
|
||||
(when (>= arg 0)
|
||||
(let ((case-fold-search nil)
|
||||
(point-first (< (point) (mark)))
|
||||
(re (regexp-opt (mc/region-strings)))
|
||||
(furthest-cursor (mc/furthest-cursor-after-point)))
|
||||
(mc/save-excursion
|
||||
(goto-char (mc/furthest-region-end))
|
||||
(when (= arg 0)
|
||||
(mc/remove-fake-cursor furthest-cursor))
|
||||
(if (search-forward-regexp re nil t)
|
||||
(progn
|
||||
(push-mark (match-beginning 0))
|
||||
(when point-first (exchange-point-and-mark))
|
||||
(mc/create-fake-cursor-at-point))
|
||||
(error "no more found forward")))))
|
||||
(if (> (mc/num-cursors) 1)
|
||||
(multiple-cursors-mode 1)
|
||||
(multiple-cursors-mode 0)))
|
||||
|
||||
(provide 'mc-mark-more)
|
@ -75,6 +75,7 @@
|
||||
(require 'multiple-cursors-core)
|
||||
(require 'mc-edit-lines)
|
||||
(require 'mc-cycle-cursors)
|
||||
(require 'mc-mark-more)
|
||||
(require 'mc-mark-multiple-integration)
|
||||
(require 'rectangular-region-mode)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user