mirror of
https://github.com/magnars/multiple-cursors.el.git
synced 2025-10-13 13:03:03 +00:00
Integrate with rect.el instead of consolidating/splitting on kill-ring
This commit is contained in:
parent
067063a346
commit
719fe40ca3
@ -115,7 +115,7 @@ Feature: Multiple cursors core
|
|||||||
And I press "C-y"
|
And I press "C-y"
|
||||||
Then I should see "This externaltext contains the word externaltext twice"
|
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"
|
Given I have cursors at "text" in "This text contains the word text twice"
|
||||||
When I press "M-f"
|
When I press "M-f"
|
||||||
And I press "C-f"
|
And I press "C-f"
|
||||||
@ -124,33 +124,10 @@ Feature: Multiple cursors core
|
|||||||
And I press "M-w"
|
And I press "M-w"
|
||||||
And I press "<return>"
|
And I press "<return>"
|
||||||
And I press "C-a"
|
And I press "C-a"
|
||||||
And I press "C-y"
|
|
||||||
And I press "C-k"
|
And I press "C-k"
|
||||||
|
And I press "C-x r y"
|
||||||
Then I should see:
|
Then I should see:
|
||||||
"""
|
"""
|
||||||
contains
|
contains
|
||||||
twice
|
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
|
|
||||||
"""
|
|
||||||
|
@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
(eval-when-compile (require 'cl))
|
(eval-when-compile (require 'cl))
|
||||||
|
|
||||||
|
(require 'rect)
|
||||||
|
|
||||||
(defface mc/cursor-face
|
(defface mc/cursor-face
|
||||||
'((t (:inverse-video t)))
|
'((t (:inverse-video t)))
|
||||||
"The face used for fake cursors"
|
"The face used for fake cursors"
|
||||||
@ -316,31 +318,10 @@ multiple cursors editing.")
|
|||||||
(setq entries (cons (car (overlay-get cursor 'kill-ring)) entries)))
|
(setq entries (cons (car (overlay-get cursor 'kill-ring)) entries)))
|
||||||
(reverse entries)))
|
(reverse entries)))
|
||||||
|
|
||||||
(defun mc--maybe-consolidate-kill-rings ()
|
(defun mc--maybe-set-killed-rectangle ()
|
||||||
(let ((entries (mc--kill-ring-entries)))
|
(let ((entries (mc--kill-ring-entries)))
|
||||||
(unless (mc--all-equal entries)
|
(unless (mc--all-equal entries)
|
||||||
(kill-new (mapconcat 'identity entries "\n")))))
|
(setq killed-rectangle entries))))
|
||||||
|
|
||||||
(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)))
|
|
||||||
|
|
||||||
(define-minor-mode multiple-cursors-mode
|
(define-minor-mode multiple-cursors-mode
|
||||||
"Mode while multiple cursors are active."
|
"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)
|
(add-hook 'post-command-hook 'mc/execute-this-command-for-all-cursors t t)
|
||||||
(run-hooks 'multiple-cursors-mode-enabled-hook))
|
(run-hooks 'multiple-cursors-mode-enabled-hook))
|
||||||
(remove-hook 'post-command-hook 'mc/execute-this-command-for-all-cursors t)
|
(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)
|
(mc/remove-fake-cursors)
|
||||||
(run-hooks 'multiple-cursors-mode-disabled-hook)))
|
(run-hooks 'multiple-cursors-mode-disabled-hook)))
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user