[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/multiple-cursors 36b262c 086/434: Added mc-version of mark
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/multiple-cursors 36b262c 086/434: Added mc-version of mark-next-like-this |
Date: |
Sat, 7 Aug 2021 09:20:01 -0400 (EDT) |
branch: elpa/multiple-cursors
commit 36b262c99eabb619dcc1bf733b0ffffef5f90a03
Author: Magnar Sveen <magnars@gmail.com>
Commit: Magnar Sveen <magnars@gmail.com>
Added mc-version of mark-next-like-this
---
features/mark-more.feature | 41 +++++++++++++++++++++++++++++
features/support/env.el | 1 +
mc-mark-more.el | 64 ++++++++++++++++++++++++++++++++++++++++++++++
multiple-cursors.el | 1 +
4 files changed, 107 insertions(+)
diff --git a/features/mark-more.feature b/features/mark-more.feature
new file mode 100644
index 0000000..6317823
--- /dev/null
+++ b/features/mark-more.feature
@@ -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"
diff --git a/features/support/env.el b/features/support/env.el
index d7a4748..108e0b2 100644
--- a/features/support/env.el
+++ b/features/support/env.el
@@ -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*"))
diff --git a/mc-mark-more.el b/mc-mark-more.el
new file mode 100644
index 0000000..75e93f7
--- /dev/null
+++ b/mc-mark-more.el
@@ -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)
diff --git a/multiple-cursors.el b/multiple-cursors.el
index 3ceeaef..ef09102 100644
--- a/multiple-cursors.el
+++ b/multiple-cursors.el
@@ -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)
- [nongnu] elpa/multiple-cursors 45488df 052/434: yank-pop is supported, (continued)
- [nongnu] elpa/multiple-cursors 45488df 052/434: yank-pop is supported, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 6f9911f 054/434: Add more explanatory prose., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 466d036 063/434: Prompt for inclusion in white/black-lists when met with an unknown command, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 092b0a1 074/434: Cycle through cursors with C-v and M-v, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 0512561 076/434: Skip lines in rectangular-region-mode that are too short for the rectangle., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 84ef509 072/434: Save users own white/black lists in .mc-lists.el, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 15e88c6 071/434: Move more mode-specific cmds into personal lists., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 0bfd611 068/434: More consistent naming., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors ca0e0ae 084/434: Tests for rectangular-region-mode, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors a4c4714 081/434: Remove multiple cursors when reverting buffer., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 36b262c 086/434: Added mc-version of mark-next-like-this,
ELPA Syncer <=
- [nongnu] elpa/multiple-cursors 491b206 103/434: Use forward-line instead of next/previous-line in lisp code., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors b1ea7f2 095/434: Add licences to all el-files., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors f6403ea 112/434: Fix assertion, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 6481972 113/434: Update ecukes, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 241e34e 123/434: Remove mark-multiple integration, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors f040a33 143/434: Add execute-extended-command to run-once list, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors ef7eddf 021/434: Started adding feature tests., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 00896cf 030/434: Refactor: simplify saving of state for cursors., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors c07d761 009/434: Some thoughts about combining with mark-multiple., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors d8f5116 013/434: Add more commands to multiple-cursors whitelist., ELPA Syncer, 2021/08/07