[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/multiple-cursors ef2226b 116/434: Consolidate kill-ring en
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/multiple-cursors ef2226b 116/434: Consolidate kill-ring entries when exiting multiple-cursors-mode |
Date: |
Sat, 7 Aug 2021 09:20:07 -0400 (EDT) |
branch: elpa/multiple-cursors
commit ef2226b993ccf8af6982d6a46961ba4215bc9a72
Author: Magnar Sveen <magnars@gmail.com>
Commit: Magnar Sveen <magnars@gmail.com>
Consolidate kill-ring entries when exiting multiple-cursors-mode
---
features/multiple-cursors-core.feature | 17 +++++++++++++++++
multiple-cursors-core.el | 26 +++++++++++++++++++++++++-
2 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/features/multiple-cursors-core.feature
b/features/multiple-cursors-core.feature
index cf0121a..c7ebbec 100644
--- a/features/multiple-cursors-core.feature
+++ b/features/multiple-cursors-core.feature
@@ -114,3 +114,20 @@ Feature: Multiple cursors core
When I copy "external" in another program
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
+ Given I have cursors at "text" in "This text contains the word text twice"
+ When I press "M-f"
+ And I press "C-f"
+ And I press "C-SPC"
+ And I press "M-f"
+ And I press "M-w"
+ And I press "<return>"
+ And I press "C-a"
+ And I press "C-y"
+ And I press "C-k"
+ Then I should see:
+ """
+ contains
+ twice
+ """
diff --git a/multiple-cursors-core.el b/multiple-cursors-core.el
index fbf7c24..eaeb2ad 100644
--- a/multiple-cursors-core.el
+++ b/multiple-cursors-core.el
@@ -62,6 +62,12 @@
(save-excursion ,@forms)
(mc/pop-state-from-overlay current-state)))
+(defmacro mc/for-each-cursor (&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)))
+
(defmacro mc/save-window-scroll (&rest forms)
"Saves and restores the window scroll position"
`(let ((p (set-marker (make-marker) (point)))
@@ -137,6 +143,7 @@ highlights the entire width of the window."
"Restore the state stored in given overlay and then remove the overlay."
(mc/restore-state-from-overlay o)
(mc/remove-fake-cursor o))
+
(defun mc/delete-region-overlay (o)
"Remove the dependent region overlay for a given cursor overlay."
(ignore-errors
@@ -159,7 +166,8 @@ Saves the current state in the overlay to be restored
later."
(mc/store-current-state-in-overlay overlay)
(when (use-region-p)
(overlay-put overlay 'region-overlay
- (mc/make-region-overlay-between-point-and-mark)))))
+ (mc/make-region-overlay-between-point-and-mark)))
+ overlay))
(defun mc/execute-command (cmd)
"Run command, simulating the parts of the command loop that makes sense for
fake cursors."
@@ -285,6 +293,21 @@ multiple cursors editing.")
(define-key mc/keymap (kbd "C-g") 'mc/keyboard-quit)
(define-key mc/keymap (kbd "<return>") 'multiple-cursors-mode))
+(defun mc--all-equal (entries)
+ (let ((first (car entries))
+ (all-equal t))
+ (while (and all-equal entries)
+ (setq all-equal (equal first (car entries)))
+ (setq entries (cdr entries)))
+ all-equal))
+
+(defun mc--maybe-consolidate-kill-rings ()
+ (let (entries)
+ (mc/for-each-cursor
+ (setq entries (cons (car (overlay-get cursor 'kill-ring)) entries)))
+ (unless (mc--all-equal entries)
+ (kill-new (mapconcat 'identity entries "\n")))))
+
(define-minor-mode multiple-cursors-mode
"Mode while multiple cursors are active."
nil " mc" mc/keymap
@@ -293,6 +316,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/remove-fake-cursors)
(run-hooks 'multiple-cursors-mode-disabled-hook)))
- [nongnu] elpa/multiple-cursors 72b4bf3 329/434: Enable to specify search word in mc/mark-all-in-region, (continued)
- [nongnu] elpa/multiple-cursors 72b4bf3 329/434: Enable to specify search word in mc/mark-all-in-region, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 97f7b1d 332/434: Merge pull request #197 from kissge/user-emacs-directory, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 533e157 335/434: Merge pull request #160 from P-Seebauer/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors ccdc025 079/434: Run prefix argument commands just once., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors df5f83a 082/434: Add more common commands to run only once., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 576bf90 087/434: mc version of mark-previous-like-this, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 0d89125 089/434: Added mc-version of mark-all-like-this, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors f42e467 090/434: Added mc-version of mark-all-in-region, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors b912bf8 096/434: Always require multiple-cursors-core, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 0233ba8 092/434: Add commands to run-once-list, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors ef2226b 116/434: Consolidate kill-ring entries when exiting multiple-cursors-mode,
ELPA Syncer <=
- [nongnu] elpa/multiple-cursors d5a9d57 132/434: Add minibuffer-complete-and-exit to default run-once list., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors b48e2b7 137/434: mc/edit-lines: Don't include the 'invisible' line, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors ae0033f 140/434: Protect post-command-hook from errors to avoids undead cursors, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors fcbb7a4 152/434: Make mc/cycle-forward and mc/cycle-backward loop around by default., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 876937b 153/434: Use (interactive "P") instead of the weird (but equivalent) (interactive (list prefix-arg)), ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 1ec78e1 162/434: Don't let mc/mark-lines create 'double' cursors., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 1074c88 178/434: Added mc/mark-all-like-this-dwim, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 9582c72 204/434: Add mc/insert-numbers, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors d534132 122/434: Remove todo.org - use issues instead, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors f7d393d 128/434: Don't use next-line and previous-line in non-interactive ways., ELPA Syncer, 2021/08/07