From 45c6cd0be44039f3c35dc0e37952716962c3e430 Mon Sep 17 00:00:00 2001 From: Maciej Katafiasz Date: Fri, 30 Aug 2013 22:36:01 +0200 Subject: [PATCH 01/10] Add mc/mark-all-dwim --- mc-mark-more.el | 16 ++++++++++++++++ multiple-cursors-core.el | 1 + 2 files changed, 17 insertions(+) diff --git a/mc-mark-more.el b/mc-mark-more.el index 7e240a1..26bbe6f 100644 --- a/mc-mark-more.el +++ b/mc-mark-more.el @@ -416,6 +416,22 @@ 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'. Otherwise, it will delegate to +`mc/mark-all-like-this-dwim' or `mc/mark-all-like-this' (if the +prefix ARG is present)" + (interactive "P") + (if (and (use-region-p) + (not (= (line-number-at-pos (region-beginning)) + (line-number-at-pos (region-end))))) + (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 From 49027c67178afadb314c885e5649b421c4b6de72 Mon Sep 17 00:00:00 2001 From: Maciej Katafiasz Date: Thu, 5 Sep 2013 17:03:33 +0200 Subject: [PATCH 02/10] Add basic tests for 'mc/mark-all-dwim' --- features/mark-all-dwim.feature | 26 ++++++++++++++++++++++++++ features/support/env.el | 1 + 2 files changed, 27 insertions(+) diff --git a/features/mark-all-dwim.feature b/features/mark-all-dwim.feature index 9eca714..7870a6a 100644 --- a/features/mark-all-dwim.feature +++ b/features/mark-all-dwim.feature @@ -17,6 +17,16 @@ Feature: Mark all do-what-I-mean (defun abc (hmm) (message hmm)) (defun def (ghi) (message some-other-ghi)) """ + 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 (foo) (message foo)) + (defun def (ghi) (message some-other-ghi)) + """ + Scenario: Mark all symbols by pressing twice Given I turn on emacs-lisp-mode @@ -36,3 +46,19 @@ Feature: Mark all do-what-I-mean (defun abc (hmm) (message hmm)) (defun def (hmm) (message hmm)) """ + When I press "C-g" + And I press "M-> RET" + 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 humm)) + (defun def (humm-humm) (message humm)) + """ 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) From 61388fedef4792fea3622db4951e5eee4add402d Mon Sep 17 00:00:00 2001 From: Maciej Katafiasz Date: Thu, 5 Sep 2013 18:07:52 +0200 Subject: [PATCH 03/10] Add 'mark-all-dwim' tests for selection --- features/mark-all-dwim.feature | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/features/mark-all-dwim.feature b/features/mark-all-dwim.feature index 7870a6a..d1674c2 100644 --- a/features/mark-all-dwim.feature +++ b/features/mark-all-dwim.feature @@ -62,3 +62,31 @@ Feature: Mark all do-what-I-mean (defun def (humm) (message humm)) (defun def (humm-humm) (message humm)) """ + + Scenario: Mark dwim from selection + 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)) + """ + 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)) + """ From af66635a0598f26fb9b08e74908496f7690e10e7 Mon Sep 17 00:00:00 2001 From: Maciej Katafiasz Date: Thu, 5 Sep 2013 18:16:39 +0200 Subject: [PATCH 04/10] Make 'mc/mark-all-dwim' into 'mc/edit-lines' if prefix arg is passed --- mc-mark-more.el | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mc-mark-more.el b/mc-mark-more.el index 26bbe6f..02afcab 100644 --- a/mc-mark-more.el +++ b/mc-mark-more.el @@ -420,14 +420,18 @@ With prefix, it behaves the same as original `mc/mark-all-like-this'" "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'. Otherwise, it will delegate to -`mc/mark-all-like-this-dwim' or `mc/mark-all-like-this' (if the -prefix ARG is present)" +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 (= (line-number-at-pos (region-beginning)) (line-number-at-pos (region-end))))) - (call-interactively 'mc/mark-all-in-region) + (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)))) From 45ed43e1f8a79d015c044b9ba659efdcc5507ae8 Mon Sep 17 00:00:00 2001 From: Maciej Katafiasz Date: Thu, 5 Sep 2013 18:22:12 +0200 Subject: [PATCH 05/10] Test edit-lines functionality in 'mc/mark-all-dwim' --- features/mark-all-dwim.feature | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/features/mark-all-dwim.feature b/features/mark-all-dwim.feature index d1674c2..a81ad92 100644 --- a/features/mark-all-dwim.feature +++ b/features/mark-all-dwim.feature @@ -70,6 +70,7 @@ Feature: Mark all do-what-I-mean """ (defun abc (ghi) (message ghi)) (defun def (ghi) (message some-other-ghi)) + """ When I press "M-<" And I press "S-M->" @@ -79,6 +80,7 @@ Feature: Mark all do-what-I-mean """ (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" @@ -89,4 +91,16 @@ Feature: Mark all do-what-I-mean """ (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)) + """ From bf4b0c669b91b5a227d539c76e7147047f87c080 Mon Sep 17 00:00:00 2001 From: Maciej Katafiasz Date: Thu, 5 Sep 2013 18:42:16 +0200 Subject: [PATCH 06/10] Refactor mark-dwim tests to share a common background --- features/mark-all-dwim.feature | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/features/mark-all-dwim.feature b/features/mark-all-dwim.feature index a81ad92..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-$" @@ -27,15 +30,7 @@ Feature: Mark all do-what-I-mean (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: - """ - (defun abc (ghi) (message ghi)) - (defun def (ghi) (message ghi)) - """ When I go to the end of the word "abc" And I press "M-f" And I press "M-$" @@ -44,10 +39,10 @@ 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-> RET" + And I press "M->" And I insert: """ (defun def (hmm-hmm) (message hmm)) @@ -59,19 +54,11 @@ Feature: Mark all do-what-I-mean Then I should see: """ (defun abc (humm) (message humm)) - (defun def (humm) (message humm)) + (defun def (humm) (message some-other-humm)) (defun def (humm-humm) (message humm)) """ Scenario: Mark dwim from selection - 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)) - - """ When I press "M-<" And I press "S-M->" And I press "C-$ ghi RET" @@ -80,7 +67,6 @@ Feature: Mark all do-what-I-mean """ (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" @@ -91,7 +77,6 @@ Feature: Mark all do-what-I-mean """ (defun abc (foo) (message foo)) (defun def (xyz) (message some-other-xyz)) - """ When I press "C-g" And I press "M-<" @@ -102,5 +87,4 @@ Feature: Mark all do-what-I-mean """ ;;(defun abc (foo) (message foo)) ;;(defun def (xyz) (message some-other-xyz)) - """ From 9f91a0455dc907f1664649b4c4e64c25a1565985 Mon Sep 17 00:00:00 2001 From: Maciej Katafiasz Date: Thu, 5 Sep 2013 18:51:51 +0200 Subject: [PATCH 07/10] Add 'mc/mark-all-dwim' to README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b4c50ad..3be2446 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ You can [watch an intro to multiple-cursors at Emacs Rocks](http://emacsrocks.co - `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`: Combines `mc/mark-all-like-this-dwim`, `mc/mark-all-in-region` and `mc/edit-lines`, guessing which one you want. ### Special From 18d858f0de1141b5b1864bf4f27bd9647bea1ee0 Mon Sep 17 00:00:00 2001 From: Maciej Katafiasz Date: Fri, 6 Sep 2013 14:52:16 +0200 Subject: [PATCH 08/10] Fall straight through in 'mc/mark-all-dwim' if multiple cursors are already active, as that means we can't sensibly edit lines or mark all in region --- mc-mark-more.el | 1 + 1 file changed, 1 insertion(+) diff --git a/mc-mark-more.el b/mc-mark-more.el index 02afcab..e07b360 100644 --- a/mc-mark-more.el +++ b/mc-mark-more.el @@ -427,6 +427,7 @@ 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) 0)) (not (= (line-number-at-pos (region-beginning)) (line-number-at-pos (region-end))))) (if arg From ad79ad8b52e3ac35c1b4b9d166f227efb1ec6086 Mon Sep 17 00:00:00 2001 From: Maciej Katafiasz Date: Fri, 6 Sep 2013 14:53:35 +0200 Subject: [PATCH 09/10] Mention only 'mc/mark-all-dwim' in README to prevent confusing redundancy --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 3be2446..015dfec 100644 --- a/README.md +++ b/README.md @@ -69,8 +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`: Combines `mc/mark-all-like-this-dwim`, `mc/mark-all-in-region` and `mc/edit-lines`, guessing which one you want. + - `mc/mark-all-dwim`: Tries to be smart about marking everything you want. Can be pressed multiple times. ### Special From ec4781394c23be73656da1c0f703f32bd85f602f Mon Sep 17 00:00:00 2001 From: Maciej Katafiasz Date: Fri, 6 Sep 2013 19:44:31 +0200 Subject: [PATCH 10/10] Derp, multiple cursors means > 1, not > 0. --- mc-mark-more.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mc-mark-more.el b/mc-mark-more.el index e07b360..48f15ae 100644 --- a/mc-mark-more.el +++ b/mc-mark-more.el @@ -427,7 +427,7 @@ 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) 0)) + (not (> (mc/num-cursors) 1)) (not (= (line-number-at-pos (region-beginning)) (line-number-at-pos (region-end))))) (if arg