emacs-elpa-diffs
[Top][All Lists]
Advanced

[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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]