Merge pull request #104 from mathrick/mark-all-dwim

Add new command, mark-all-dwim
This commit is contained in:
Magnar Sveen 2013-09-06 12:57:31 -07:00
commit 65c0c0c6fe
5 changed files with 94 additions and 19 deletions

View File

@ -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-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-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-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 ### Special

View File

@ -1,13 +1,16 @@
Feature: Mark all do-what-I-mean Feature: Mark all do-what-I-mean
Scenario: Mark symbols in defun Background:
Given I turn on emacs-lisp-mode Given I turn on emacs-lisp-mode
And I turn on delete-selection-mode And I turn on delete-selection-mode
And I insert: And I insert:
""" """
(defun abc (ghi) (message ghi)) (defun abc (ghi) (message ghi))
(defun def (ghi) (message some-other-ghi)) (defun def (ghi) (message some-other-ghi))
""" """
Scenario: Mark symbols in defun
When I go to the end of the word "abc" When I go to the end of the word "abc"
And I press "M-f" And I press "M-f"
And I press "M-$" And I press "M-$"
@ -17,15 +20,17 @@ Feature: Mark all do-what-I-mean
(defun abc (hmm) (message hmm)) (defun abc (hmm) (message hmm))
(defun def (ghi) (message some-other-ghi)) (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 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" When I go to the end of the word "abc"
And I press "M-f" And I press "M-f"
And I press "M-$" And I press "M-$"
@ -34,5 +39,52 @@ Feature: Mark all do-what-I-mean
Then I should see: Then I should see:
""" """
(defun abc (hmm) (message hmm)) (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))
""" """

View File

@ -24,6 +24,7 @@
(global-set-key (kbd "C-<") 'mc/mark-previous-like-this) (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)
(global-set-key (kbd "M-$") 'mc/mark-all-like-this-dwim) (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 "M-#") 'mc/mark-all-in-region)
(global-set-key (kbd "H-0") 'mc/insert-numbers) (global-set-key (kbd "H-0") 'mc/insert-numbers)
(global-set-key (kbd "H-1") 'mc/reverse-regions) (global-set-key (kbd "H-1") 'mc/reverse-regions)

View File

@ -419,6 +419,27 @@ With prefix, it behaves the same as original `mc/mark-all-like-this'"
(when (<= (mc/num-cursors) before) (when (<= (mc/num-cursors) before)
(mc/mark-all-like-this)))))) (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 () (defun mc--in-defun ()
(bounds-of-thing-at-point 'defun)) (bounds-of-thing-at-point 'defun))

View File

@ -573,6 +573,7 @@ for running commands with multiple cursors.")
mc/mark-all-words-like-this-in-defun mc/mark-all-words-like-this-in-defun
mc/mark-all-symbols-like-this-in-defun mc/mark-all-symbols-like-this-in-defun
mc/mark-all-like-this-dwim mc/mark-all-like-this-dwim
mc/mark-all-dwim
mc/mark-sgml-tag-pair mc/mark-sgml-tag-pair
mc/insert-numbers mc/insert-numbers
mc/sort-regions mc/sort-regions