Add multiple-cursors support to execute-extended-command

Also add three new tests for this functionality and adapt some existing
tests as well as the testing harness.
This commit is contained in:
Leo Gaskin 2022-12-23 23:53:04 +01:00 committed by Magnar Sveen
parent 558198239e
commit 351eb6cbb5
4 changed files with 41 additions and 1 deletions

View File

@ -57,6 +57,28 @@ Feature: Multiple cursors core
And I press "C-!" And I press "C-!"
Then I should see "This aatext contains the word text twice" Then I should see "This aatext contains the word text twice"
Scenario: Multiple supported M-x command (forward-word in this case)
Given I have cursors at "text" in "This text contains the word text twice"
And I type "("
And I press "M-x forward-word"
And I press "M-x forward-word"
And I type ")"
Then I should see "This (text contains) the word (text twice)"
Scenario: Unknown M-x command: yes, do for all
Given I have cursors at "text" in "This text contains the word text twice"
And I press "C-SPC"
And I press "M-f"
And I press "M-x upcase-dwim RET y"
Then I should see "This TEXT contains the word TEXT twice"
Scenario: Unknown M-x command: no, don't do for all
Given I have cursors at "text" in "This text contains the word text twice"
And I press "C-SPC"
And I press "M-f"
And I press "M-x upcase-dwim RET n"
Then I should see "This TEXT contains the word text twice"
Scenario: Undo Scenario: Undo
Given I have cursors at "text" in "This text contains the word text twice" Given I have cursors at "text" in "This text contains the word text twice"
When I press "M-f" When I press "M-f"

View File

@ -8,6 +8,7 @@ Feature: Repeat last interactive command for fake cursors (mc/repeat-command)
And I press "RET" And I press "RET"
And I type "21" And I type "21"
And I press "RET" And I press "RET"
And I type "n"
And I press "C-:" And I press "C-:"
And I press "y" And I press "y"
And I execute the action chain And I execute the action chain
@ -27,6 +28,7 @@ Feature: Repeat last interactive command for fake cursors (mc/repeat-command)
Scenario: Disable prompt Scenario: Disable prompt
Given I have cursors at "text" in "This text/0000 contains the word text/1111 thrice (text/2222)" Given I have cursors at "text" in "This text/0000 contains the word text/1111 thrice (text/2222)"
When I set mc/always-repeat-command to t When I set mc/always-repeat-command to t
When I set mc/always-run-for-all to t
When I start an action chain When I start an action chain
And I press "M-x" And I press "M-x"
And I type "zap-to-char" And I type "zap-to-char"

View File

@ -45,6 +45,8 @@
(subword-mode 0) (subword-mode 0)
(wrap-region-mode 0) (wrap-region-mode 0)
(setq set-mark-default-inactive nil) (setq set-mark-default-inactive nil)
(deactivate-mark)) (deactivate-mark)
(setq mc/cmds-to-run-for-all nil)
(setq mc/cmds-to-run-once nil))
(After) (After)

View File

@ -664,6 +664,20 @@ from being executed if in multiple-cursors-mode."
(overlay-put cursor 'kill-ring kill-ring) (overlay-put cursor 'kill-ring kill-ring)
(overlay-put cursor 'kill-ring-yank-pointer kill-ring-yank-pointer))))))) (overlay-put cursor 'kill-ring-yank-pointer kill-ring-yank-pointer)))))))
(defadvice execute-extended-command (after execute-extended-command-for-all-cursors () activate)
(when multiple-cursors-mode
(unless (or mc/always-run-for-all
(not (symbolp this-command))
(memq this-command mc/cmds-to-run-for-all)
(memq this-command mc/cmds-to-run-once)
(memq this-command mc--default-cmds-to-run-for-all)
(memq this-command mc--default-cmds-to-run-once))
(mc/prompt-for-inclusion-in-whitelist this-command))
(when (or mc/always-run-for-all
(memq this-command mc/cmds-to-run-for-all)
(memq this-command mc--default-cmds-to-run-for-all))
(mc/execute-command-for-all-fake-cursors this-command))))
(defcustom mc/list-file (locate-user-emacs-file ".mc-lists.el") (defcustom mc/list-file (locate-user-emacs-file ".mc-lists.el")
"The position of the file that keeps track of your preferences "The position of the file that keeps track of your preferences
for running commands with multiple cursors." for running commands with multiple cursors."