mirror of
https://github.com/magnars/multiple-cursors.el.git
synced 2025-10-13 21:03:05 +00:00
Merge pull request #63 from tkf/select-thing-at-point
Automatically select word/symbol
This commit is contained in:
commit
980a8808dd
137
features/mark-things.feature
Normal file
137
features/mark-things.feature
Normal file
@ -0,0 +1,137 @@
|
|||||||
|
Feature: Mark things
|
||||||
|
|
||||||
|
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:
|
||||||
|
"""
|
||||||
|
(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))
|
||||||
|
"""
|
||||||
|
|
||||||
|
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))
|
||||||
|
"""
|
||||||
|
|
||||||
|
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))
|
||||||
|
"""
|
@ -95,3 +95,11 @@
|
|||||||
(assert search nil "The text '%s' was not found in the current buffer." text))
|
(assert search nil "The text '%s' was not found in the current buffer." text))
|
||||||
(set-mark (point))
|
(set-mark (point))
|
||||||
(re-search-forward text)))
|
(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))))
|
||||||
|
@ -225,15 +225,28 @@ With zero ARG, skip the last one and mark next."
|
|||||||
(multiple-cursors-mode 1)
|
(multiple-cursors-mode 1)
|
||||||
(multiple-cursors-mode 0)))
|
(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
|
;;;###autoload
|
||||||
(defun mc/mark-all-words-like-this ()
|
(defun mc/mark-all-words-like-this ()
|
||||||
(interactive)
|
(interactive)
|
||||||
|
(mc--select-thing-at-point-or-bark 'word)
|
||||||
(let ((mc/enclose-search-term 'words))
|
(let ((mc/enclose-search-term 'words))
|
||||||
(mc/mark-all-like-this)))
|
(mc/mark-all-like-this)))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun mc/mark-all-symbols-like-this ()
|
(defun mc/mark-all-symbols-like-this ()
|
||||||
(interactive)
|
(interactive)
|
||||||
|
(mc--select-thing-at-point-or-bark 'symbol)
|
||||||
(let ((mc/enclose-search-term 'symbols))
|
(let ((mc/enclose-search-term 'symbols))
|
||||||
(mc/mark-all-like-this)))
|
(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 ()
|
(defun mc/mark-all-words-like-this-in-defun ()
|
||||||
"Mark all words like this in defun."
|
"Mark all words like this in defun."
|
||||||
(interactive)
|
(interactive)
|
||||||
|
(mc--select-thing-at-point-or-bark 'word)
|
||||||
(if (mc--in-defun)
|
(if (mc--in-defun)
|
||||||
(save-restriction
|
(save-restriction
|
||||||
(widen)
|
(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 ()
|
(defun mc/mark-all-symbols-like-this-in-defun ()
|
||||||
"Mark all symbols like this in defun."
|
"Mark all symbols like this in defun."
|
||||||
(interactive)
|
(interactive)
|
||||||
|
(mc--select-thing-at-point-or-bark 'symbol)
|
||||||
(if (mc--in-defun)
|
(if (mc--in-defun)
|
||||||
(save-restriction
|
(save-restriction
|
||||||
(widen)
|
(widen)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user