From 373dcbe0022061c0ab14298b9dca07f4a7216ef2 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sun, 10 Mar 2013 06:43:50 +0100 Subject: [PATCH 1/4] Add a scenario for mc/mark-all-symbols-like-this --- features/mark-things.feature | 18 ++++++++++++++++++ .../step-definitions/multiple-cursors-steps.el | 8 ++++++++ 2 files changed, 26 insertions(+) create mode 100644 features/mark-things.feature diff --git a/features/mark-things.feature b/features/mark-things.feature new file mode 100644 index 0000000..cfe880a --- /dev/null +++ b/features/mark-things.feature @@ -0,0 +1,18 @@ +Feature: Mark things + + Scenario: Mark symbols in defun with select + 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 select "ghi" + And I mark all symbols like this in defun + And I type "hmm" + Then I should see: + """ + (defun abc (hmm) (message hmm)) + (defun def (ghi) (message some-other-ghi)) + """ diff --git a/features/step-definitions/multiple-cursors-steps.el b/features/step-definitions/multiple-cursors-steps.el index 900eeed..ba25181 100644 --- a/features/step-definitions/multiple-cursors-steps.el +++ b/features/step-definitions/multiple-cursors-steps.el @@ -95,3 +95,11 @@ (assert search nil "The text '%s' was not found in the current buffer." text)) (set-mark (point)) (re-search-forward text))) + +(When "^I mark all \\(.+\\)$" + (lambda (rest) + (let ((func (intern (mapconcat 'identity + (cons "mc/mark-all" + (split-string rest)) + "-")))) + (call-interactively func)))) From 25dd14d3503a6f22c70eb80210a90199931dac61 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sun, 10 Mar 2013 06:49:25 +0100 Subject: [PATCH 2/4] Add more scenarios for mark-all-*-like-this --- features/mark-things.feature | 53 +++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/features/mark-things.feature b/features/mark-things.feature index cfe880a..a3a0b02 100644 --- a/features/mark-things.feature +++ b/features/mark-things.feature @@ -1,6 +1,40 @@ Feature: Mark things - Scenario: Mark symbols in defun with select + Scenario: Mark all symbols like this with select + 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 select "ghi" + And I mark all symbols like this + And I type "hmm" + Then I should see: + """ + (defun abc (hmm) (message hmm)) + (defun def (hmm) (message some-other-ghi)) + """ + + Scenario: Mark all words like this with select + 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 select "ghi" + And I mark all words like this + And I type "hmm" + Then I should see: + """ + (defun abc (hmm) (message hmm)) + (defun def (hmm) (message some-other-hmm)) + """ + + Scenario: Mark all symbols like this in defun with select Given I turn on emacs-lisp-mode And I turn on delete-selection-mode And I insert: @@ -16,3 +50,20 @@ Feature: Mark things (defun abc (hmm) (message hmm)) (defun def (ghi) (message some-other-ghi)) """ + + Scenario: Mark all words like this in defun with select + 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 select "ghi" + And I mark all words like this in defun + And I type "hmm" + Then I should see: + """ + (defun abc (hmm) (message hmm)) + (defun def (ghi) (message some-other-ghi)) + """ From aa9a1ece7bcfbd2b73ae0a77b7b3c79f19089af0 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sun, 10 Mar 2013 06:52:12 +0100 Subject: [PATCH 3/4] Add failing scenarios for mark-all-symbols/words --- features/mark-things.feature | 68 ++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/features/mark-things.feature b/features/mark-things.feature index a3a0b02..c99c24f 100644 --- a/features/mark-things.feature +++ b/features/mark-things.feature @@ -67,3 +67,71 @@ Feature: Mark things (defun abc (hmm) (message hmm)) (defun def (ghi) (message some-other-ghi)) """ + + Scenario: Mark all symbols like this with no select + 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 go to word "ghi" + And I mark all symbols like this + And I type "hmm" + Then I should see: + """ + (defun abc (hmm) (message hmm)) + (defun def (hmm) (message some-other-ghi)) + """ + + Scenario: Mark all words like this with no select + 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 go to word "ghi" + And I mark all words like this + And I type "hmm" + Then I should see: + """ + (defun abc (hmm) (message hmm)) + (defun def (hmm) (message some-other-hmm)) + """ + + Scenario: Mark all symbols like this in defun with no select + 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 go to word "ghi" + And I mark all symbols like this in defun + And I type "hmm" + Then I should see: + """ + (defun abc (hmm) (message hmm)) + (defun def (ghi) (message some-other-ghi)) + """ + + Scenario: Mark all words like this in defun with no select + 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 go to word "ghi" + And I mark all words like this in defun + And I type "hmm" + Then I should see: + """ + (defun abc (hmm) (message hmm)) + (defun def (ghi) (message some-other-ghi)) + """ From 1cdd73037fd3a0d789846da144bc16fb471d7b35 Mon Sep 17 00:00:00 2001 From: Takafumi Arakaki Date: Sun, 10 Mar 2013 06:53:53 +0100 Subject: [PATCH 4/4] Automatically select word/symbol --- mc-mark-more.el | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mc-mark-more.el b/mc-mark-more.el index ca239e0..eba7bed 100644 --- a/mc-mark-more.el +++ b/mc-mark-more.el @@ -225,15 +225,28 @@ With zero ARG, skip the last one and mark next." (multiple-cursors-mode 1) (multiple-cursors-mode 0))) +(defun mc--select-thing-at-point (thing) + (let ((bound (bounds-of-thing-at-point thing))) + (when bound + (set-mark (car bound)) + (goto-char (cdr bound)) + bound))) + +(defun mc--select-thing-at-point-or-bark (thing) + (unless (or (region-active-p) (mc--select-thing-at-point thing)) + (error "Mark a region or set cursor on a %s." thing))) + ;;;###autoload (defun mc/mark-all-words-like-this () (interactive) + (mc--select-thing-at-point-or-bark 'word) (let ((mc/enclose-search-term 'words)) (mc/mark-all-like-this))) ;;;###autoload (defun mc/mark-all-symbols-like-this () (interactive) + (mc--select-thing-at-point-or-bark 'symbol) (let ((mc/enclose-search-term 'symbols)) (mc/mark-all-like-this))) @@ -355,6 +368,7 @@ With prefix, it behaves the same as original `mc/mark-all-like-this'" (defun mc/mark-all-words-like-this-in-defun () "Mark all words like this in defun." (interactive) + (mc--select-thing-at-point-or-bark 'word) (if (mc--in-defun) (save-restriction (widen) @@ -366,6 +380,7 @@ With prefix, it behaves the same as original `mc/mark-all-like-this'" (defun mc/mark-all-symbols-like-this-in-defun () "Mark all symbols like this in defun." (interactive) + (mc--select-thing-at-point-or-bark 'symbol) (if (mc--in-defun) (save-restriction (widen)