[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/multiple-cursors 87169c8 040/434: Clean up multiple-cursor
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/multiple-cursors 87169c8 040/434: Clean up multiple-cursors-core |
Date: |
Sat, 7 Aug 2021 09:19:50 -0400 (EDT) |
branch: elpa/multiple-cursors
commit 87169c884c824e84f6a9eda9369cb7db1df68a46
Author: Magnar Sveen <magnars@gmail.com>
Commit: Magnar Sveen <magnars@gmail.com>
Clean up multiple-cursors-core
---
mc-edit-lines.el | 2 +-
multiple-cursors-core.el | 60 +++++++++++++++++++++++++++++-------------------
2 files changed, 37 insertions(+), 25 deletions(-)
diff --git a/mc-edit-lines.el b/mc-edit-lines.el
index 69538e1..8093da8 100644
--- a/mc-edit-lines.el
+++ b/mc-edit-lines.el
@@ -8,7 +8,7 @@ mark-multiple if point and mark is on different columns."
(interactive)
(when (not (use-region-p))
(error "Mark a set of lines first."))
- (mc/remove-additional-cursors)
+ (mc/remove-fake-cursors)
(let* ((point-line (line-number-at-pos))
(mark-line (progn (exchange-point-and-mark) (line-number-at-pos)))
(navigation-func (if (< point-line mark-line) 'previous-line
'next-line)))
diff --git a/multiple-cursors-core.el b/multiple-cursors-core.el
index 3304580..e1a074e 100644
--- a/multiple-cursors-core.el
+++ b/multiple-cursors-core.el
@@ -54,7 +54,7 @@ highlights the entire width of the window."
(setq mark-active (overlay-get o 'mark-active))
(when (boundp 'er/history) (setq er/history (overlay-get o 'er/history))))
-(defun mc/clean-up-state-overlay (o)
+(defun mc/remove-fake-cursor (o)
"Delete overlay with state, including dependent overlays and markers."
(set-marker (overlay-get o 'point) nil)
(set-marker (overlay-get o 'mark) nil)
@@ -64,7 +64,7 @@ highlights the entire width of the window."
(defun mc/pop-state-from-overlay (o)
"Restore the state stored in given overlay and then remove the overlay."
(mc/restore-state-from-overlay o)
- (mc/clean-up-state-overlay o))
+ (mc/remove-fake-cursor o))
(defun mc/delete-region-overlay (o)
"Remove the dependent region overlay for a given cursor overlay."
@@ -88,19 +88,29 @@ It works by moving point to the fake cursor, setting
up the proper kill-ring, and then removing the cursor.
After executing the command, it sets up a new fake
cursor with updated info."
- (let ((current-state (mc/store-current-state-in-overlay
- (make-overlay (point) (point) nil nil t)))
- (annoying-arrows-mode nil))
- (save-excursion
- (mapc #'(lambda (o)
- (when (eq (overlay-get o 'type) 'additional-cursor)
- (mc/pop-state-from-overlay o)
- (ignore-errors
- (call-interactively cmd)
- (when deactivate-mark (deactivate-mark))
- (mc/create-fake-cursor-at-point))))
- (overlays-in (point-min) (point-max))))
- (mc/pop-state-from-overlay current-state)))
+ (let ((annoying-arrows-mode nil))
+ (mc/save-excursion
+ (mc/for-each-fake-cursor
+ (mc/pop-state-from-overlay cursor)
+ (ignore-errors
+ (call-interactively cmd)
+ (when deactivate-mark (deactivate-mark))
+ (mc/create-fake-cursor-at-point))))))
+
+(defmacro mc/for-each-fake-cursor (&rest forms)
+ "Runs the body for each fake cursor, bound to the name cursor"
+ `(mapc #'(lambda (cursor)
+ (when (eq (overlay-get cursor 'type) 'additional-cursor)
+ ,@forms))
+ (overlays-in (point-min) (point-max))))
+
+(defmacro mc/save-excursion (&rest forms)
+ "Saves and restores all the state that multiple-cursors cares about."
+ `(let ((current-state (mc/store-current-state-in-overlay
+ (make-overlay (point) (point) nil nil t))))
+ (overlay-put current-state 'type 'original-cursor)
+ (save-excursion ,@forms)
+ (mc/pop-state-from-overlay current-state)))
(defun mc/execute-this-command-for-all-cursors ()
"Used with post-command-hook to execute supported commands for
@@ -117,14 +127,12 @@ cursors."
(message "Skipping %S" this-original-command)
(mc/execute-command-for-all-fake-cursors this-original-command))))
-(defun mc/remove-additional-cursors ()
+(defun mc/remove-fake-cursors ()
"Remove all fake cursors.
Do not use to conclude editing with multiple cursors. For that
you should disable multiple-cursors-mode."
- (mapc #'(lambda (o)
- (when (eq (overlay-get o 'type) 'additional-cursor)
- (mc/clean-up-state-overlay o)))
- (overlays-in (point-min) (point-max))))
+ (mc/for-each-fake-cursor
+ (mc/remove-fake-cursor cursor)))
(defun mc/keyboard-quit ()
"Deactivate mark if there are any active, otherwise exit
multiple-cursors-mode."
@@ -146,10 +154,10 @@ multiple cursors editing.")
(define-minor-mode multiple-cursors-mode
"Mode while multiple cursors are active."
nil " mc" mc/keymap
- (cond ((not multiple-cursors-mode)
- (remove-hook 'post-command-hook
'mc/execute-this-command-for-all-cursors t)
- (mc/remove-additional-cursors))
- (t (add-hook 'post-command-hook
'mc/execute-this-command-for-all-cursors t t))))
+ (if multiple-cursors-mode
+ (add-hook 'post-command-hook 'mc/execute-this-command-for-all-cursors t
t)
+ (remove-hook 'post-command-hook 'mc/execute-this-command-for-all-cursors t)
+ (mc/remove-fake-cursors)))
(defvar mc--unsupported-cmds '()
"List of commands that does not work well with multiple cursors.
@@ -168,6 +176,10 @@ from being executed if in multiple-cursors-mode."
;; Commands that make a giant mess of multiple cursors
(unsupported-cmd yank-pop)
+;; Commands to run only once (not yet in use)
+(setq mc--cmds-run-once '(mark-next-like-this
+ save-buffer))
+
;; Commands that should be mirrored by all cursors
(setq mc--cmds '(mc/keyboard-quit
self-insert-command
- [nongnu] elpa/multiple-cursors b218a13 185/434: Run tests in Emacs 23, Emacs 24 and snapshot., (continued)
- [nongnu] elpa/multiple-cursors b218a13 185/434: Run tests in Emacs 23, Emacs 24 and snapshot., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors a4f6ea1 205/434: Add transient-mark-mode to mc/cursor-specific-vars to fix other selections than C-SPC. Fixes #55, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 3ce6e4a 199/434: Avoid strange behavior with smartrep, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 16add89 211/434: Bugfix for sort/reverse regions w/similar contents, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 7a236d1 233/434: Add flyspell-mode to unsupported minor modes, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 6cff0c2 245/434: Add pre- & post-command-hook to be cursor specific, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 2186e1b 247/434: mc/mark-lines: Mark by logical lines., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors d3a29a2 034/434: Started working on multiple-cursor core tests., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 7ff9e9a 035/434: Only store er/history when it is defined., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 9875982 038/434: Add smart-forward to whitelist, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 87169c8 040/434: Clean up multiple-cursors-core,
ELPA Syncer <=
- [nongnu] elpa/multiple-cursors efd79f3 043/434: Add undo to list of known run-only-once commands., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors b60cbc3 044/434: Add support for yank-pop, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 1db643c 048/434: Add support for modes that remap commands., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 37ddaf2 053/434: Set this-command for each cursor., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors d7be50e 041/434: rectangular-region-mode, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 45488df 052/434: yank-pop is supported, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 6f9911f 054/434: Add more explanatory prose., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 466d036 063/434: Prompt for inclusion in white/black-lists when met with an unknown command, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 092b0a1 074/434: Cycle through cursors with C-v and M-v, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 0512561 076/434: Skip lines in rectangular-region-mode that are too short for the rectangle., ELPA Syncer, 2021/08/07