[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/multiple-cursors 067063a 118/434: Split multiline kill-rin
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/multiple-cursors 067063a 118/434: Split multiline kill-ring entry over cursors when num lines match |
Date: |
Sat, 7 Aug 2021 09:20:07 -0400 (EDT) |
branch: elpa/multiple-cursors
commit 067063a3467abeffee1903a5a2be42e02b36ba93
Author: Magnar Sveen <magnars@gmail.com>
Commit: Magnar Sveen <magnars@gmail.com>
Split multiline kill-ring entry over cursors when num lines match
---
features/multiple-cursors-core.feature | 23 +++++++++++++++++
multiple-cursors-core.el | 46 +++++++++++++++++++++++++++++-----
2 files changed, 63 insertions(+), 6 deletions(-)
diff --git a/features/multiple-cursors-core.feature
b/features/multiple-cursors-core.feature
index c7ebbec..cba589b 100644
--- a/features/multiple-cursors-core.feature
+++ b/features/multiple-cursors-core.feature
@@ -131,3 +131,26 @@ Feature: Multiple cursors core
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
+ """
diff --git a/multiple-cursors-core.el b/multiple-cursors-core.el
index eaeb2ad..bf45e97 100644
--- a/multiple-cursors-core.el
+++ b/multiple-cursors-core.el
@@ -62,11 +62,17 @@
(save-excursion ,@forms)
(mc/pop-state-from-overlay current-state)))
-(defmacro mc/for-each-cursor (&rest forms)
+(defun mc--compare-by-overlay-start (o1 o2)
+ (< (overlay-start o1) (overlay-start o2)))
+
+(defmacro mc/for-each-cursor-ordered (&rest forms)
"Runs the body for each cursor, fake and real, bound to the name cursor"
`(let ((real-cursor (mc/create-fake-cursor-at-point)))
- (mc/for-each-fake-cursor ,@forms)
- (mc/remove-fake-cursor real-cursor)))
+ (mapc #'(lambda (cursor)
+ (when (mc/fake-cursor-p cursor)
+ ,@forms))
+ (sort (overlays-in (point-min) (point-max))
'mc--compare-by-overlay-start))
+ (mc/pop-state-from-overlay real-cursor)))
(defmacro mc/save-window-scroll (&rest forms)
"Saves and restores the window scroll position"
@@ -177,6 +183,8 @@ Saves the current state in the overlay to be restored
later."
(call-interactively cmd))
(when deactivate-mark (deactivate-mark)))
+(defvar mc--executing-command-for-fake-cursor nil)
+
(defun mc/execute-command-for-all-fake-cursors (cmd)
"Calls CMD interactively for each cursor.
It works by moving point to the fake cursor, setting
@@ -187,7 +195,8 @@ cursor with updated info."
(mc/save-window-scroll
(mc/for-each-fake-cursor
(save-excursion
- (let ((id (overlay-get cursor 'mc-id))
+ (let ((mc--executing-command-for-fake-cursor t)
+ (id (overlay-get cursor 'mc-id))
(annoying-arrows-mode nil))
(mc/add-fake-cursor-to-undo-list
(mc/pop-state-from-overlay cursor)
@@ -301,13 +310,38 @@ multiple cursors editing.")
(setq entries (cdr entries)))
all-equal))
-(defun mc--maybe-consolidate-kill-rings ()
+(defun mc--kill-ring-entries ()
(let (entries)
- (mc/for-each-cursor
+ (mc/for-each-cursor-ordered
(setq entries (cons (car (overlay-get cursor 'kill-ring)) entries)))
+ (reverse entries)))
+
+(defun mc--maybe-consolidate-kill-rings ()
+ (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)))
+
(define-minor-mode multiple-cursors-mode
"Mode while multiple cursors are active."
nil " mc" mc/keymap
- [nongnu] elpa/multiple-cursors fc6a6a7 422/434: Merge pull request #355 from flatwhatson/lazy-list-file, (continued)
- [nongnu] elpa/multiple-cursors fc6a6a7 422/434: Merge pull request #355 from flatwhatson/lazy-list-file, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 7763f4f 429/434: Load mc-cycle-cursors and mc-hide-unmatched-lines-mode after loading multiple-cursors-core, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors a9d7764 431/434: Add option to disable bar-style fake cursors (#367), ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 616fbdd 434/434: Document existing functions in Readme, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 7ab8a8c 067/434: Better support for undo., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 608ceb4 069/434: Disable multiple-cursors-mode if there's only one cursor (the real one)., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 61280ae 100/434: autoload integration for package.el compatibility, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors d82e252 106/434: Don't let fake cursors scroll the buffer, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors dc22766 108/434: Macros must be defined before they are used to be expanded properly, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 7a655b0 117/434: Disable emacs-snapshot tests until it is in order., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 067063a 118/434: Split multiline kill-ring entry over cursors when num lines match,
ELPA Syncer <=
- [nongnu] elpa/multiple-cursors bdc4d9a 124/434: Add some more commands to default run-once/run-for-all lists., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 0f54f98 133/434: Bump to 1.1.1 for bugfix, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors a0f771f 151/434: Include interactive commands for deselecting prev/next, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 8a12e97 148/434: Mention region-bindings-mode in README, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 19b1a83 160/434: Refactor mc/first-cursor-after and mc/last-cursor-before to not use extreme., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 9ac7675 155/434: Added tests for mc/cycle-forward and mc/cycle-backward with their new looping behaviour, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors dce196c 167/434: Merge pull request #28 from gvol/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors c3b2d84 164/434: Merge pull request #23 from segv/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors be4067d 169/434: Fixed mode-line not showing up, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 2345958 260/434: Run ecukes tests in --no-win mode, ELPA Syncer, 2021/08/07