[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/multiple-cursors 2e904a0 342/434: Add safety ceiling to cu
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/multiple-cursors 2e904a0 342/434: Add safety ceiling to cursor count at creation |
Date: |
Sat, 7 Aug 2021 09:20:56 -0400 (EDT) |
branch: elpa/multiple-cursors
commit 2e904a0be21f0755f65e64c89dd506eb54a4604d
Author: Sean Allred <code@seanallred.com>
Commit: Sean Allred <code@seanallred.com>
Add safety ceiling to cursor count at creation
The customizable option `mc/max-cursors' now provides a soft maximum for
the number of cursors allowable. This is helpful for slower emacsen who
may freeze up when adding too many cursors (as in `mark-all' variants).
Fix: #206
---
multiple-cursors-core.el | 45 ++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 42 insertions(+), 3 deletions(-)
diff --git a/multiple-cursors-core.el b/multiple-cursors-core.el
index 8971a42..0388631 100644
--- a/multiple-cursors-core.el
+++ b/multiple-cursors-core.el
@@ -157,7 +157,8 @@ highlights the entire width of the window."
(set-marker (overlay-get o 'point) nil)
(set-marker (overlay-get o 'mark) nil)
(mc/delete-region-overlay o)
- (delete-overlay o))
+ (delete-overlay o)
+ (decf mc--active-cursor-count))
(defun mc/pop-state-from-overlay (o)
"Restore the state stored in given overlay and then remove the overlay."
@@ -176,9 +177,43 @@ highlights the entire width of the window."
"Returns a unique cursor id"
(incf mc--current-cursor-id))
+(defvar mc--active-cursor-count 1
+ "Number of active cursors.
+This number is incremented by `mc/create-fake-cursor-at-point'
+and decremented by `mc/remove-fake-cursor'.")
+
+(defvar mc--max-cursors-original nil
+ "This variable maintains the original maximum number of cursors.
+When `mc/create-fake-cursor-at-point' is called and
+`mc/max-cursors' is overridden, this value serves as a backup so
+that `mc/max-cursors' can take on a new value. When
+`mc/remove-fake-cursors' is called, the values are reset.")
+
+(defcustom mc/max-cursors nil
+ "Safety ceiling for the number of active cursors.
+If your emacs slows down or freezes when using too many cursors,
+customize this value appropriately.
+
+Cursors will be added until this value is reached, at which point
+you can either temporarily override the value or abort the
+operation entirely.
+
+If this value is nil, there is no ceiling."
+ :type '(integer)
+ :group 'multiple-cursors)
+
(defun mc/create-fake-cursor-at-point (&optional id)
"Add a fake cursor and possibly a fake active region overlay based on point
and mark.
Saves the current state in the overlay to be restored later."
+ (unless mc--max-cursors-original
+ (setq mc--max-cursors-original mc/max-cursors))
+ (when mc/max-cursors
+ (unless (< mc--active-cursor-count mc/max-cursors)
+ (if (yes-or-no-p (format "%d active cursors. Continue? "
mc--active-cursor-count))
+ (setq mc/max-cursors (read-number "Enter a new, temporary maximum:
"))
+ (mc/remove-fake-cursors)
+ (error "Aborted: too many cursors"))))
+ (incf mc--active-cursor-count)
(let ((overlay (mc/make-cursor-overlay-at-point)))
(overlay-put overlay 'mc-id (or id (mc/create-cursor-id)))
(overlay-put overlay 'type 'fake-cursor)
@@ -382,7 +417,10 @@ the original cursor, to inform about the lack of support."
Do not use to conclude editing with multiple cursors. For that
you should disable multiple-cursors-mode."
(mc/for-each-fake-cursor
- (mc/remove-fake-cursor cursor)))
+ (mc/remove-fake-cursor cursor))
+ (when mc--max-cursors-original
+ (setq mc/max-cursors mc--max-cursors-original))
+ (setq mc--max-cursors-original nil))
(defun mc/keyboard-quit ()
"Deactivate mark if there are any active, otherwise exit
multiple-cursors-mode."
@@ -424,7 +462,8 @@ The entries are returned in the order they are found in the
buffer."
(defun mc--maybe-set-killed-rectangle ()
"Add the latest kill-ring entry for each cursor to killed-rectangle.
So you can paste it in later with `yank-rectangle'."
- (let ((entries (mc--kill-ring-entries)))
+ (let ((entries (let ((mc--active-cursor-count -1))
+ (mc--kill-ring-entries))))
(unless (mc--all-equal entries)
(setq killed-rectangle entries))))
- [nongnu] elpa/multiple-cursors ad79ad8 273/434: Mention only 'mc/mark-all-dwim' in README to prevent confusing redundancy, (continued)
- [nongnu] elpa/multiple-cursors ad79ad8 273/434: Mention only 'mc/mark-all-dwim' in README to prevent confusing redundancy, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 54e408f 279/434: Update README.md, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors aed5d59 287/434: fix compilation warnings (#66), ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 00aea4c 289/434: Show appropriate error messages on trying skipping/unmarking commands with no fake cursors, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors b3fd49c 306/434: Revert "Change file load timing", ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 38d6013 307/434: Merge pull request #156 from magnars/revert-152-master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 49fe803 316/434: Merge pull request #163 from Silex/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 7cf6374 326/434: Typo fixo., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 142fdd6 337/434: Use locate-user-emacs-file to find directory for .mc-lists.el, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 2588cce 338/434: Revert "Support unmarking with no region. Change mc/mark-lines to preserve point.", ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 2e904a0 342/434: Add safety ceiling to cursor count at creation,
ELPA Syncer <=
- [nongnu] elpa/multiple-cursors 9a5c9cd 005/434: Refactored setup of unsupported commands., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 6cac5f4 018/434: Even more white-listing., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors f2da52a 085/434: Update readme with new testing info., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 8bc7916 094/434: Updated README., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 3e31cc6 101/434: Merge pull request #5 from milkypostman/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors f2add1d 107/434: Suggest C-c C-< instead of the often used M-<, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 810636b 120/434: Avoid smooth-scroll issues with multiple cursors, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 2d639b0 284/434: Added tests for new mc/edit-lines, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 38e590c 292/434: Fix cycle-cursor behavior., ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors adf86bd 320/434: Add @lexa to list of contributors, ELPA Syncer, 2021/08/07