6 Commits

Author SHA1 Message Date
Magnar Sveen 6d4979db46 Bump to 1.1.3 2012-09-28 07:26:17 +02:00
Magnar Sveen f040a33e3c Add execute-extended-command to run-once list 2012-09-28 07:24:38 +02:00
Magnar Sveen 64ffd81491 Add quoted-insert to run-for-all list. 2012-09-27 19:44:48 +02:00
Magnar Sveen 97da9778fd Intercept some reading commands
- so you won't have to answer them for every single cursor

Fixes #15
2012-09-27 19:42:38 +02:00
Magnar Sveen ae0033fe3d Protect post-command-hook from errors to avoids undead cursors 2012-09-27 18:53:57 +02:00
Magnar Sveen 5fcc69cc54 Skip keyboard macros
- since they will generate actual commands that are also run in the
   command loop - we'll handle those later instead.
2012-09-27 18:53:05 +02:00
4 changed files with 76 additions and 24 deletions
+7
View File
@@ -119,6 +119,13 @@ Feature: Multiple cursors core
And I type "!" And I type "!"
Then I should see "This ! contains the word ! twice" Then I should see "This ! contains the word ! twice"
Scenario: Bound keyboard macros
Given I have bound C-! to a keyboard macro that insert "_"
And I have cursors at "text" in "This text contains the word text twice"
When I press "C-!"
When I press "C-!"
Then I should see "This __text contains the word __text twice"
Scenario: Interprogram paste Scenario: Interprogram paste
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 copy "external" in another program When I copy "external" in another program
@@ -68,6 +68,11 @@
(defun mc-test-temp-command-2 () (interactive) (insert ins)) (defun mc-test-temp-command-2 () (interactive) (insert ins))
(global-set-key (kbd "C-!") 'mc-test-temp-command-2)))) (global-set-key (kbd "C-!") 'mc-test-temp-command-2))))
(Given "^I have bound C-! to a keyboard macro that insert \"_\"$"
(lambda ()
(fset 'mc-test-temp-kmacro "\C-q_")
(global-set-key (kbd "C-!") 'mc-test-temp-kmacro)))
(When "^I go to character \"\\(.+\\)\"$" (When "^I go to character \"\\(.+\\)\"$"
(lambda (char) (lambda (char)
(goto-char (point-min)) (goto-char (point-min))
+63 -23
View File
@@ -205,7 +205,31 @@ cursor with updated info."
(mc/pop-state-from-overlay cursor) (mc/pop-state-from-overlay cursor)
(ignore-errors (ignore-errors
(mc/execute-command cmd) (mc/execute-command cmd)
(mc/create-fake-cursor-at-point id))))))))) (mc/create-fake-cursor-at-point id))))))))
(mc--reset-read-prompts))
;; Intercept some reading commands so you won't have to
;; answer them for every single cursor
(defadvice read-char (around mc-support activate)
(if (not multiple-cursors-mode)
ad-do-it
(unless mc--read-char
(setq mc--read-char ad-do-it))
(setq ad-return-value mc--read-char)))
(defadvice read-quoted-char (around mc-support activate)
(if (not multiple-cursors-mode)
ad-do-it
(unless mc--read-quoted-char
(setq mc--read-quoted-char ad-do-it))
(setq ad-return-value mc--read-quoted-char)))
(defun mc--reset-read-prompts ()
(setq mc--read-char nil)
(setq mc--read-quoted-char nil))
(mc--reset-read-prompts)
(defun mc/fake-cursor-p (o) (defun mc/fake-cursor-p (o)
"Predicate to check if an overlay is a fake cursor" "Predicate to check if an overlay is a fake cursor"
@@ -266,6 +290,14 @@ not be recognized through the command-remapping lookup."
this-original-command)))) this-original-command))))
(defun mc/execute-this-command-for-all-cursors () (defun mc/execute-this-command-for-all-cursors ()
"Wrap around `mc/execute-this-command-for-all-cursors-1' to protect hook."
(condition-case error
(mc/execute-this-command-for-all-cursors-1)
(error
(message "[mc] problem in `mc/execute-this-command-for-all-cursors': %s"
(error-message-string error)))))
(defun mc/execute-this-command-for-all-cursors-1 ()
"Used with post-command-hook to execute supported commands for all cursors. "Used with post-command-hook to execute supported commands for all cursors.
It uses two lists of commands to know what to do: the run-once It uses two lists of commands to know what to do: the run-once
@@ -274,31 +306,37 @@ it will prompt for the proper action and then save that preference.
Some commands are so unsupported that they are even prevented for Some commands are so unsupported that they are even prevented for
the original cursor, to inform about the lack of support." the original cursor, to inform about the lack of support."
(if (eq 1 (mc/num-cursors)) ;; no fake cursors? disable mc-mode (unless mc--executing-command-for-fake-cursor
(multiple-cursors-mode 0)
(when this-original-command (if (eq 1 (mc/num-cursors)) ;; no fake cursors? disable mc-mode
(let ((original-command (or mc--this-command (multiple-cursors-mode 0)
(command-remapping this-original-command)
this-original-command)))
;; if it's a lambda, we can't know if it's supported or not (when this-original-command
;; - so go ahead and assume it's ok, because we're just optimistic like that (let ((original-command (or mc--this-command
(if (not (symbolp original-command)) (command-remapping this-original-command)
(mc/execute-command-for-all-fake-cursors original-command) this-original-command)))
;; otherwise it's a symbol, and we can be more thorough ;; skip keyboard macros, since they will generate actual commands that are
(if (get original-command 'mc--unsupported) ;; also run in the command loop - we'll handle those later instead.
(message "%S is not supported with multiple cursors%s" (when (functionp original-command)
original-command
(get original-command 'mc--unsupported)) ;; if it's a lambda, we can't know if it's supported or not
(when (and original-command ;; - so go ahead and assume it's ok, because we're just optimistic like that
(not (memq original-command mc--default-cmds-to-run-once)) (if (not (symbolp original-command))
(not (memq original-command mc/cmds-to-run-once)) (mc/execute-command-for-all-fake-cursors original-command)
(or (memq original-command mc--default-cmds-to-run-for-all)
(memq original-command mc/cmds-to-run-for-all) ;; otherwise it's a symbol, and we can be more thorough
(mc/prompt-for-inclusion-in-whitelist original-command))) (if (get original-command 'mc--unsupported)
(mc/execute-command-for-all-fake-cursors original-command)))))))) (message "%S is not supported with multiple cursors%s"
original-command
(get original-command 'mc--unsupported))
(when (and original-command
(not (memq original-command mc--default-cmds-to-run-once))
(not (memq original-command mc/cmds-to-run-once))
(or (memq original-command mc--default-cmds-to-run-for-all)
(memq original-command mc/cmds-to-run-for-all)
(mc/prompt-for-inclusion-in-whitelist original-command)))
(mc/execute-command-for-all-fake-cursors original-command))))))))))
(defun mc/remove-fake-cursors () (defun mc/remove-fake-cursors ()
"Remove all fake cursors. "Remove all fake cursors.
@@ -479,6 +517,7 @@ for running commands with multiple cursors.")
ido-exit-minibuffer ido-exit-minibuffer
exit-minibuffer exit-minibuffer
minibuffer-complete-and-exit minibuffer-complete-and-exit
execute-extended-command
undo undo
redo redo
undo-tree-undo undo-tree-undo
@@ -516,6 +555,7 @@ for running commands with multiple cursors.")
(setq mc--default-cmds-to-run-for-all '(mc/keyboard-quit (setq mc--default-cmds-to-run-for-all '(mc/keyboard-quit
self-insert-command self-insert-command
quoted-insert
previous-line previous-line
next-line next-line
newline newline
+1 -1
View File
@@ -1,2 +1,2 @@
(define-package "multiple-cursors" "1.1.2" (define-package "multiple-cursors" "1.1.3"
"Multiple cursors for Emacs.") "Multiple cursors for Emacs.")