Integrate with rect.el instead of consolidating/splitting on kill-ring

This commit is contained in:
Magnar Sveen 2012-09-23 19:12:42 +02:00
parent 067063a346
commit 719fe40ca3
2 changed files with 7 additions and 49 deletions

View File

@ -115,7 +115,7 @@ Feature: Multiple cursors core
And I press "C-y"
Then I should see "This externaltext contains the word externaltext twice"
Scenario: Consolidated kill-ring after exiting multiple-cursors-mode
Scenario: Added to killed-rectangle after exiting multiple-cursors-mode
Given I have cursors at "text" in "This text contains the word text twice"
When I press "M-f"
And I press "C-f"
@ -124,33 +124,10 @@ Feature: Multiple cursors core
And I press "M-w"
And I press "<return>"
And I press "C-a"
And I press "C-y"
And I press "C-k"
And I press "C-x r y"
Then I should see:
"""
contains
twice
"""
Scenario: Split multiline kill-ring entry over cursors when num lines match
When I insert:
"""
a
b
c
"""
And I go to the front of the word "a"
And I press "C-SPC"
And I go to the end of the word "c"
And I press "M-w"
And I go to the end of the word "a"
And I press "H-SPC"
And I press "C-n"
And I press "C-n"
And I press "C-y"
Then I should see:
"""
aa
bb
cc
"""

View File

@ -27,6 +27,8 @@
(eval-when-compile (require 'cl))
(require 'rect)
(defface mc/cursor-face
'((t (:inverse-video t)))
"The face used for fake cursors"
@ -316,31 +318,10 @@ multiple cursors editing.")
(setq entries (cons (car (overlay-get cursor 'kill-ring)) entries)))
(reverse entries)))
(defun mc--maybe-consolidate-kill-rings ()
(defun mc--maybe-set-killed-rectangle ()
(let ((entries (mc--kill-ring-entries)))
(unless (mc--all-equal entries)
(kill-new (mapconcat 'identity entries "\n")))))
(defun mc--kill-new (entries)
(mc/for-each-cursor-ordered
(let ((kill-ring (overlay-get cursor 'kill-ring))
(kill-ring-yank-pointer (overlay-get cursor 'kill-ring-yank-pointer)))
(kill-new (car entries))
(setq entries (cdr entries))
(overlay-put cursor 'kill-ring kill-ring)
(overlay-put cursor 'kill-ring-yank-pointer kill-ring-yank-pointer))))
(defun mc--maybe-split-kill-ring ()
(let ((entries (mc--kill-ring-entries)))
(when (mc--all-equal entries)
(let ((lines (split-string (car entries) "\n")))
(when (= (mc/num-cursors) (length lines))
(mc--kill-new lines))))))
(defadvice yank (before maybe-split-kill-ring activate)
(when (and (or multiple-cursors-mode rectangular-region-mode)
(not mc--executing-command-for-fake-cursor))
(mc--maybe-split-kill-ring)))
(setq killed-rectangle entries))))
(define-minor-mode multiple-cursors-mode
"Mode while multiple cursors are active."
@ -350,7 +331,7 @@ multiple cursors editing.")
(add-hook 'post-command-hook 'mc/execute-this-command-for-all-cursors t t)
(run-hooks 'multiple-cursors-mode-enabled-hook))
(remove-hook 'post-command-hook 'mc/execute-this-command-for-all-cursors t)
(mc--maybe-consolidate-kill-rings)
(mc--maybe-set-killed-rectangle)
(mc/remove-fake-cursors)
(run-hooks 'multiple-cursors-mode-disabled-hook)))