[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/multiple-cursors 576bf90 087/434: mc version of mark-previ
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/multiple-cursors 576bf90 087/434: mc version of mark-previous-like-this |
Date: |
Sat, 7 Aug 2021 09:20:01 -0400 (EDT) |
branch: elpa/multiple-cursors
commit 576bf90346193a9ddae435ee4e3d5d7bbbfdc2b6
Author: Magnar Sveen <magnars@gmail.com>
Commit: Magnar Sveen <magnars@gmail.com>
mc version of mark-previous-like-this
---
features/mark-more.feature | 40 +++++++++++++++++++
.../step-definitions/multiple-cursors-steps.el | 8 ++++
features/support/env.el | 1 +
mc-mark-more.el | 45 ++++++++++++++++++++++
multiple-cursors-core.el | 1 +
5 files changed, 95 insertions(+)
diff --git a/features/mark-more.feature b/features/mark-more.feature
index 6317823..9e35a30 100644
--- a/features/mark-more.feature
+++ b/features/mark-more.feature
@@ -39,3 +39,43 @@ Feature: Marking multiple parts of the buffer
And I press "C-- M->"
And I type "more"
Then I should see "Here's more, more and text"
+
+ Scenario: Marking prev like this, cursors
+ When I insert "This text has the word text in it"
+ And I select the last "text"
+ And I press "M-<"
+ Then I should have 2 cursors
+
+ Scenario: Marking prev like this, region
+ Given I turn on delete-selection-mode
+ When I insert "This text has the word text in it"
+ And I select the last "text"
+ And I press "M-<"
+ And I type "sentence"
+ Then I should see "This sentence has the word sentence in it"
+
+ Scenario: Skipping a prev mark
+ Given I turn on delete-selection-mode
+ When I insert "Here's text, text and text"
+ And I select the last "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 first fake
+ When I insert "Here's text, text and text"
+ And I select the last "text"
+ And I press "M-<"
+ And I press "C-- M-<"
+ Then I should have one cursor
+
+ Scenario: Removing first mark
+ Given I turn on delete-selection-mode
+ When I insert "Here's text, text and text"
+ And I select the last "text"
+ And I press "M-<"
+ And I press "M-<"
+ And I press "C-- M-<"
+ And I type "more"
+ Then I should see "Here's text, more and more"
diff --git a/features/step-definitions/multiple-cursors-steps.el
b/features/step-definitions/multiple-cursors-steps.el
index 3ecc367..fb4c075 100644
--- a/features/step-definitions/multiple-cursors-steps.el
+++ b/features/step-definitions/multiple-cursors-steps.el
@@ -82,3 +82,11 @@
(message "Can not go to character '%s' since it does not exist
in the current buffer: %s"))
(assert search nil message word (espuds-buffer-contents))
(if (string-equal "front" pos) (backward-word)))))
+
+(When "^I select the last \"\\(.+\\)\"$"
+ (lambda (text)
+ (goto-char (point-max))
+ (let ((search (re-search-backward text nil t)))
+ (assert search nil "The text '%s' was not found in the current
buffer." text))
+ (set-mark (point))
+ (re-search-forward text)))
diff --git a/features/support/env.el b/features/support/env.el
index 108e0b2..ac605b0 100644
--- a/features/support/env.el
+++ b/features/support/env.el
@@ -21,6 +21,7 @@
(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 "M-<") 'mc/mark-previous-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 75e93f7..e57f7ab 100644
--- a/mc-mark-more.el
+++ b/mc-mark-more.el
@@ -16,6 +16,21 @@
(setq end (max end (mc/cursor-end cursor))))
end))
+(defun mc/first-region-start ()
+ (let ((beg (min (mark) (point))))
+ (mc/for-each-fake-cursor
+ (setq beg (min beg (mc/cursor-beg cursor))))
+ beg))
+
+(defun mc/furthest-cursor-before-point ()
+ (let ((beg (min (mark) (point)))
+ furthest)
+ (mc/for-each-fake-cursor
+ (when (< (mc/cursor-beg cursor) beg)
+ (setq beg (mc/cursor-beg cursor))
+ (setq furthest cursor)))
+ furthest))
+
(defun mc/furthest-cursor-after-point ()
(let ((end (max (mark) (point)))
furthest)
@@ -33,6 +48,7 @@
(mc/cursor-end cursor))))
strings))
+;;;###autoload
(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.
@@ -61,4 +77,33 @@ With zero ARG, skip the last one and mark next."
(multiple-cursors-mode 1)
(multiple-cursors-mode 0)))
+;;;###autoload
+(defun mc/mark-previous-like-this (arg)
+ "Find and mark the previous 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-before-point)))
+ (when (>= arg 0)
+ (let ((case-fold-search nil)
+ (point-first (< (point) (mark)))
+ (re (regexp-opt (mc/region-strings)))
+ (furthest-cursor (mc/furthest-cursor-before-point)))
+ (mc/save-excursion
+ (goto-char (mc/first-region-start))
+ (when (= arg 0)
+ (mc/remove-fake-cursor furthest-cursor))
+ (if (search-backward-regexp re nil t)
+ (progn
+ (push-mark (match-end 0))
+ (unless point-first (exchange-point-and-mark))
+ (mc/create-fake-cursor-at-point))
+ (error "no more found backward")))))
+ (if (> (mc/num-cursors) 1)
+ (multiple-cursors-mode 1)
+ (multiple-cursors-mode 0)))
+
(provide 'mc-mark-more)
diff --git a/multiple-cursors-core.el b/multiple-cursors-core.el
index a24ebc7..fffacbb 100644
--- a/multiple-cursors-core.el
+++ b/multiple-cursors-core.el
@@ -333,6 +333,7 @@ for running commands with multiple cursors.")
mc/edit-ends-of-lines
mc/edit-beginnings-of-lines
mc/mark-next-like-this
+ mc/mark-previous-like-this
mc/cycle-forward
mc/cycle-backward
rrm/switch-to-multiple-cursors
- [nongnu] elpa/multiple-cursors 2d639b0 284/434: Added tests for new mc/edit-lines, (continued)
- [nongnu] elpa/multiple-cursors 2d639b0 284/434: Added tests for new mc/edit-lines, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 38e590c 292/434: Fix cycle-cursor behavior., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors adf86bd 320/434: Add @lexa to list of contributors, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors ff0ac1f 322/434: Add function to disable mc undo into undo-list., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 952877f 324/434: Revert undo-feature for multiple-cursors, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 72b4bf3 329/434: Enable to specify search word in mc/mark-all-in-region, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 97f7b1d 332/434: Merge pull request #197 from kissge/user-emacs-directory, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 533e157 335/434: Merge pull request #160 from P-Seebauer/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors ccdc025 079/434: Run prefix argument commands just once., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors df5f83a 082/434: Add more common commands to run only once., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 576bf90 087/434: mc version of mark-previous-like-this,
ELPA Syncer <=
- [nongnu] elpa/multiple-cursors 0d89125 089/434: Added mc-version of mark-all-like-this, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors f42e467 090/434: Added mc-version of mark-all-in-region, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors b912bf8 096/434: Always require multiple-cursors-core, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 0233ba8 092/434: Add commands to run-once-list, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors ef2226b 116/434: Consolidate kill-ring entries when exiting multiple-cursors-mode, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors d5a9d57 132/434: Add minibuffer-complete-and-exit to default run-once list., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors b48e2b7 137/434: mc/edit-lines: Don't include the 'invisible' line, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors ae0033f 140/434: Protect post-command-hook from errors to avoids undead cursors, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors fcbb7a4 152/434: Make mc/cycle-forward and mc/cycle-backward loop around by default., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 876937b 153/434: Use (interactive "P") instead of the weird (but equivalent) (interactive (list prefix-arg)), ELPA Syncer, 2021/08/07