branch: elpa/multiple-cursors
commit 65c0c0c6fe9cd4dd407d4697d656d5963344d138
Merge: 68dfa46 ec47813
Author: Magnar Sveen <[email protected]>
Commit: Magnar Sveen <[email protected]>
Merge pull request #104 from mathrick/mark-all-dwim
Add new command, mark-all-dwim
---
README.md | 2 +-
features/mark-all-dwim.feature | 70 ++++++++++++++++++++++++++++++++++++------
features/support/env.el | 1 +
mc-mark-more.el | 21 +++++++++++++
multiple-cursors-core.el | 1 +
5 files changed, 85 insertions(+), 10 deletions(-)
diff --git a/README.md b/README.md
index 8001df3..a6a1189 100644
--- a/README.md
+++ b/README.md
@@ -69,7 +69,7 @@ You can [watch an intro to multiple-cursors at Emacs
Rocks](http://emacsrocks.co
- `mc/mark-all-like-this-in-defun`: Marks all parts of the current defun that
matches the current region.
- `mc/mark-all-words-like-this-in-defun`: Like
`mc/mark-all-like-this-in-defun` but only for whole words.
- `mc/mark-all-symbols-like-this-in-defun`: Like
`mc/mark-all-like-this-in-defun` but only for whole symbols.
- - `mc/mark-all-like-this-dwim`: Tries to be smart about marking everything
you want. Can be pressed multiple times.
+ - `mc/mark-all-dwim`: Tries to be smart about marking everything you want.
Can be pressed multiple times.
### Special
diff --git a/features/mark-all-dwim.feature b/features/mark-all-dwim.feature
index 9eca714..4bb1702 100644
--- a/features/mark-all-dwim.feature
+++ b/features/mark-all-dwim.feature
@@ -1,13 +1,16 @@
Feature: Mark all do-what-I-mean
- Scenario: Mark symbols in defun
+ Background:
Given I turn on emacs-lisp-mode
And I turn on delete-selection-mode
And I insert:
"""
(defun abc (ghi) (message ghi))
(defun def (ghi) (message some-other-ghi))
+
"""
+
+ Scenario: Mark symbols in defun
When I go to the end of the word "abc"
And I press "M-f"
And I press "M-$"
@@ -17,15 +20,17 @@ Feature: Mark all do-what-I-mean
(defun abc (hmm) (message hmm))
(defun def (ghi) (message some-other-ghi))
"""
-
- Scenario: Mark all symbols by pressing twice
- Given I turn on emacs-lisp-mode
- And I turn on delete-selection-mode
- And I insert:
+ When I press "C-g"
+ And I go to the front of the word "hmm"
+ And I press "C-$"
+ And I type "foo"
+ Then I should see:
"""
- (defun abc (ghi) (message ghi))
- (defun def (ghi) (message ghi))
+ (defun abc (foo) (message foo))
+ (defun def (ghi) (message some-other-ghi))
"""
+
+ Scenario: Mark all symbols by pressing twice
When I go to the end of the word "abc"
And I press "M-f"
And I press "M-$"
@@ -34,5 +39,52 @@ Feature: Mark all do-what-I-mean
Then I should see:
"""
(defun abc (hmm) (message hmm))
- (defun def (hmm) (message hmm))
+ (defun def (hmm) (message some-other-hmm))
+ """
+ When I press "C-g"
+ And I press "M->"
+ And I insert:
+ """
+ (defun def (hmm-hmm) (message hmm))
+ """
+ And I go to the front of the word "hmm"
+ And I press "C-$"
+ And I press "C-$"
+ And I type "humm"
+ Then I should see:
+ """
+ (defun abc (humm) (message humm))
+ (defun def (humm) (message some-other-humm))
+ (defun def (humm-humm) (message humm))
+ """
+
+ Scenario: Mark dwim from selection
+ When I press "M-<"
+ And I press "S-M->"
+ And I press "C-$ ghi RET"
+ And I type "xyz"
+ Then I should see:
+ """
+ (defun abc (xyz) (message xyz))
+ (defun def (xyz) (message some-other-xyz))
+ """
+ When I press "C-g"
+ And I go to the front of the word "xyz"
+ And I press "C-M-SPC"
+ And I press "C-$"
+ And I type "foo"
+ Then I should see:
+ """
+ (defun abc (foo) (message foo))
+ (defun def (xyz) (message some-other-xyz))
+ """
+ When I press "C-g"
+ And I press "M-<"
+ And I press "S-M->"
+ And I press "C-u C-$"
+ And I type ";;"
+ Then I should see:
+ """
+ ;;(defun abc (foo) (message foo))
+ ;;(defun def (xyz) (message some-other-xyz))
"""
diff --git a/features/support/env.el b/features/support/env.el
index 4f6af30..3ce7c91 100644
--- a/features/support/env.el
+++ b/features/support/env.el
@@ -24,6 +24,7 @@
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this)
(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)
(global-set-key (kbd "M-#") 'mc/mark-all-in-region)
(global-set-key (kbd "H-0") 'mc/insert-numbers)
(global-set-key (kbd "H-1") 'mc/reverse-regions)
diff --git a/mc-mark-more.el b/mc-mark-more.el
index 627b401..5b66224 100644
--- a/mc-mark-more.el
+++ b/mc-mark-more.el
@@ -419,6 +419,27 @@ With prefix, it behaves the same as original
`mc/mark-all-like-this'"
(when (<= (mc/num-cursors) before)
(mc/mark-all-like-this))))))
+(defun mc/mark-all-dwim (arg)
+ "Tries even harder to guess what you want to mark all of.
+
+If the region is active and spans multiple lines, it will behave
+as if `mc/mark-all-in-region'. With the prefix ARG, it will call
+`mc/edit-lines' instead.
+
+If the region is inactive or on a single line, it will behave like
+`mc/mark-all-like-this-dwim'."
+ (interactive "P")
+ (if (and (use-region-p)
+ (not (> (mc/num-cursors) 1))
+ (not (= (line-number-at-pos (region-beginning))
+ (line-number-at-pos (region-end)))))
+ (if arg
+ (call-interactively 'mc/edit-lines)
+ (call-interactively 'mc/mark-all-in-region))
+ (progn
+ (setq this-command 'mc/mark-all-like-this-dwim)
+ (mc/mark-all-like-this-dwim arg))))
+
(defun mc--in-defun ()
(bounds-of-thing-at-point 'defun))
diff --git a/multiple-cursors-core.el b/multiple-cursors-core.el
index d073090..4b30cf9 100644
--- a/multiple-cursors-core.el
+++ b/multiple-cursors-core.el
@@ -573,6 +573,7 @@ for running commands with multiple cursors.")
mc/mark-all-words-like-this-in-defun
mc/mark-all-symbols-like-this-in-defun
mc/mark-all-like-this-dwim
+ mc/mark-all-dwim
mc/mark-sgml-tag-pair
mc/insert-numbers
mc/sort-regions