branch: elpa/multiple-cursors
commit 8e59a8a22693d14d97d76c0be1bf92ef2406030a
Merge: ad95d28 6d8c6fc
Author: Magnar Sveen <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #262 from AndreaOrru/master
mark-previous-like-this-word/symbol.
---
README.md | 2 ++
features/mark-more.feature | 16 ++++++++++
.../step-definitions/multiple-cursors-steps.el | 12 ++++++++
features/support/env.el | 2 ++
mc-mark-more.el | 36 ++++++++++++++++++++++
multiple-cursors-core.el | 2 ++
6 files changed, 70 insertions(+)
diff --git a/README.md b/README.md
index 10e7e4d..83a413f 100644
--- a/README.md
+++ b/README.md
@@ -57,6 +57,8 @@ You can [watch an intro to multiple-cursors at Emacs
Rocks](http://emacsrocks.co
- `mc/mark-next-word-like-this`: Like `mc/mark-next-like-this` but only for
whole words.
- `mc/mark-next-symbol-like-this`: Like `mc/mark-next-like-this` but only for
whole symbols.
- `mc/mark-previous-like-this`: Adds a cursor and region at the next part of
the buffer backwards that matches the current region.
+ - `mc/mark-previous-like-this-word`: Adds a cursor and region at the next
part of the buffer backwards that matches the current region, if no region is
selected it selects the word at the point.
+ - `mc/mark-previous-like-this-symbol`: Adds a cursor and region at the next
part of the buffer backwards that matches the current region, if no region is
selected it selects the symbol at the point.
- `mc/mark-previous-word-like-this`: Like `mc/mark-previous-like-this` but
only for whole words.
- `mc/mark-previous-symbol-like-this`: Like `mc/mark-previous-like-this` but
only for whole symbols.
- `mc/mark-more-like-this-extended`: Use arrow keys to quickly mark/skip
next/previous occurances.
diff --git a/features/mark-more.feature b/features/mark-more.feature
index d8d1025..f057678 100644
--- a/features/mark-more.feature
+++ b/features/mark-more.feature
@@ -14,6 +14,14 @@ Feature: Marking multiple parts of the buffer
And I type "sentence"
Then I should see "This sentence has the word sentence in it"
+ Scenario: Marking next like this, word
+ Given I turn on delete-selection-mode
+ When I insert "This text has the word text in it"
+ And I go to word "text"
+ And I press "C-S-c C->"
+ 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"
@@ -54,6 +62,14 @@ Feature: Marking multiple parts of the buffer
And I type "sentence"
Then I should see "This sentence has the word sentence in it"
+ Scenario: Marking prev like this, word
+ Given I turn on delete-selection-mode
+ When I insert "This text has the word text in it"
+ And I go to last word "text"
+ And I press "C-S-c C-<"
+ 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"
diff --git a/features/step-definitions/multiple-cursors-steps.el
b/features/step-definitions/multiple-cursors-steps.el
index b57bd03..2eb442e 100644
--- a/features/step-definitions/multiple-cursors-steps.el
+++ b/features/step-definitions/multiple-cursors-steps.el
@@ -12,6 +12,12 @@
(When "^I mark previous like this$"
(lambda () (call-interactively 'mc/mark-previous-like-this)))
+(When "^I mark previous like this word$"
+ (lambda () (call-interactively 'mc/mark-previous-like-this-word)))
+
+(When "^I mark previous like this symbol$"
+ (lambda () (call-interactively 'mc/mark-previous-like-this-symbol)))
+
(When "^I mark all like this$"
(lambda () (call-interactively 'mc/mark-all-like-this)))
@@ -144,6 +150,12 @@
(cl-assert search nil message word (espuds-buffer-contents))
(if (string-equal "front" pos) (backward-word)))))
+(When "^I go to last word \"\\(.+\\)\"$"
+ (lambda (text)
+ (goto-char (point-max))
+ (let ((search (re-search-backward text nil t)))
+ (cl-assert search nil "The text '%s' was not found in the current
buffer." text))))
+
(When "^I select the last \"\\(.+\\)\"$"
(lambda (text)
(goto-char (point-max))
diff --git a/features/support/env.el b/features/support/env.el
index 225c429..8410ca3 100644
--- a/features/support/env.el
+++ b/features/support/env.el
@@ -24,6 +24,8 @@
(global-set-key (kbd "C-S-c C->") 'mc/mark-next-like-this-word)
(global-set-key (kbd "C-S-c M->") 'mc/mark-next-like-this-symbol)
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
+ (global-set-key (kbd "C-S-c C-<") 'mc/mark-previous-like-this-word)
+ (global-set-key (kbd "C-S-c M-<") 'mc/mark-previous-like-this-symbol)
(global-set-key (kbd "M-!") 'mc/mark-all-like-this)
(global-set-key (kbd "M-$") 'mc/mark-all-like-this-dwim)
(global-set-key (kbd "C-$") 'mc/mark-all-dwim)
diff --git a/mc-mark-more.el b/mc-mark-more.el
index 25f4ae3..27a84b7 100644
--- a/mc-mark-more.el
+++ b/mc-mark-more.el
@@ -226,6 +226,42 @@ With zero ARG, skip the last one and mark next."
(mc/maybe-multiple-cursors-mode))
;;;###autoload
+(defun mc/mark-previous-like-this-word (arg)
+ "Find and mark the previous part of the buffer matching the currently active
region
+If no region is active, mark the word at the point and find the previous match
+With negative ARG, delete the last one instead.
+With zero ARG, skip the last one and mark previous."
+ (interactive "p")
+ (if (< arg 0)
+ (let ((cursor (mc/furthest-cursor-after-point)))
+ (if cursor
+ (mc/remove-fake-cursor cursor)
+ (error "No cursors to be unmarked")))
+ (if (region-active-p)
+ (mc/mark-more-like-this (= arg 0) 'backwards)
+ (mc--select-thing-at-point 'word)
+ (mc/mark-more-like-this (= arg 0) 'backwards)))
+ (mc/maybe-multiple-cursors-mode))
+
+(defun mc/mark-previous-like-this-symbol (arg)
+ "Find and mark the previous part of the buffer matching the currently active
region
+If no region is active, mark the symbol at the point and find the previous
match
+With negative ARG, delete the last one instead.
+With zero ARG, skip the last one and mark previous."
+ (interactive "p")
+ (if (< arg 0)
+ (let ((cursor (mc/furthest-cursor-after-point)))
+ (if cursor
+ (mc/remove-fake-cursor cursor)
+ (error "No cursors to be unmarked")))
+ (if (region-active-p)
+ (mc/mark-more-like-this (= arg 0) 'backwards)
+ (mc--select-thing-at-point 'symbol)
+ (mc/mark-more-like-this (= arg 0) 'backwards)))
+ (mc/maybe-multiple-cursors-mode))
+
+
+;;;###autoload
(defun mc/mark-previous-word-like-this (arg)
"Find and mark the previous part of the buffer matching the currently active
region
The matching region must be a whole word to be a match
diff --git a/multiple-cursors-core.el b/multiple-cursors-core.el
index 558b724..5e9ed76 100644
--- a/multiple-cursors-core.el
+++ b/multiple-cursors-core.el
@@ -621,6 +621,8 @@ for running commands with multiple cursors.")
mc/mark-next-word-like-this
mc/mark-next-symbol-like-this
mc/mark-previous-like-this
+ mc/mark-previous-like-this-word
+ mc/mark-previous-like-this-symbol
mc/mark-previous-word-like-this
mc/mark-previous-symbol-like-this
mc/mark-all-like-this