[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/multiple-cursors 19b1a83 160/434: Refactor mc/first-cursor
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/multiple-cursors 19b1a83 160/434: Refactor mc/first-cursor-after and mc/last-cursor-before to not use extreme. |
Date: |
Sat, 7 Aug 2021 09:20:17 -0400 (EDT) |
branch: elpa/multiple-cursors
commit 19b1a83925ba3831e3db3b153dfaf886cdc30376
Author: Marco Baringer <mb@bese.it>
Commit: Marco Baringer <mb@bese.it>
Refactor mc/first-cursor-after and mc/last-cursor-before to not use extreme.
Sometimes imperative code is more readable.
Suggested by magnars
(https://github.com/magnars/multiple-cursors.el/pull/23#commitcomment-1983268)
---
mc-cycle-cursors.el | 44 ++++++++++++++++++--------------------------
1 file changed, 18 insertions(+), 26 deletions(-)
diff --git a/mc-cycle-cursors.el b/mc-cycle-cursors.el
index 8c3f1a9..9dea266 100644
--- a/mc-cycle-cursors.el
+++ b/mc-cycle-cursors.el
@@ -66,6 +66,24 @@
(warn (message error-message))
(continue nil)))
+(defun mc/first-cursor-after (point)
+ "Very similar to mc/furthest-cursor-before-point, but ignores (mark) and
(point)."
+ (let* ((cursors (mc/all-fake-cursors))
+ (cursors-after-point (remove-if (lambda (cursor)
+ (< (mc/cursor-beg cursor) point))
+ cursors))
+ (cursors-in-order (sort* cursors-after-point '< :key 'mc/cursor-beg)))
+ (first cursors-in-order)))
+
+(defun mc/last-cursor-before (point)
+ "Very similar to mc/furthest-cursor-before-point, but ignores (mark) and
(point)."
+ (let* ((cursors (mc/all-fake-cursors))
+ (cursors-before-point (remove-if (lambda (cursor)
+ (> (mc/cursor-end cursor) point))
+ cursors))
+ (cursors-in-order (sort* cursors-before-point '> :key
'mc/cursor-end)))
+ (first cursors-in-order)))
+
(defun mc/cycle (next-cursor fallback-cursor loop-message)
(when (null next-cursor)
(mc/handle-loop-condition loop-message)
@@ -74,32 +92,6 @@
(mc/pop-state-from-overlay next-cursor)
(recenter))
-(defun extreme (sequence predicate &optional key)
- "Returns the most predicate-y element of sequence; equivalent
-to (first (sort sequence text)). The extreme of the empty list is
-always nil."
- (let ((extreme (first sequence)))
- (dolist (i (rest sequence))
- (when (funcall predicate
- (funcall (or key 'identity) i)
- (funcall (or key 'identity) extreme))
- (setf extreme i)))
- extreme))
-
-(defun mc/first-cursor-after (point)
- "Very similar to mc/furthest-cursor-before-point, but ignores (mark) and
(point)."
- (extreme (remove-if (lambda (cursor)
- (< (mc/cursor-beg cursor) point))
- (mc/all-fake-cursors))
- '< 'mc/cursor-beg))
-
-(defun mc/last-cursor-before (point)
- "Very similar to mc/furthest-cursor-before-point, but ignores (mark) and
(point)."
- (extreme (remove-if (lambda (cursor)
- (> (mc/cursor-end cursor) point))
- (mc/all-fake-cursors))
- '> 'mc/cursor-end))
-
(defun mc/cycle-forward ()
(interactive)
(mc/cycle (mc/next-cursor-after-point)
- [nongnu] elpa/multiple-cursors 608ceb4 069/434: Disable multiple-cursors-mode if there's only one cursor (the real one)., (continued)
- [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, 2021/08/07
- [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 <=
- [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
- [nongnu] elpa/multiple-cursors 49027c6 262/434: Add basic tests for 'mc/mark-all-dwim', ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 61388fe 263/434: Add 'mark-all-dwim' tests for selection, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors bf4b0c6 266/434: Refactor mark-dwim tests to share a common background, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 9f91a04 267/434: Add 'mc/mark-all-dwim' to README, ELPA Syncer, 2021/08/07
- [nongnu] elpa/multiple-cursors 2682e48 285/434: Merge pull request #116 from gvol/master, ELPA Syncer, 2021/08/07