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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/helm 08c5e33670: New function helm-take which replace helm


From: ELPA Syncer
Subject: [nongnu] elpa/helm 08c5e33670: New function helm-take which replace helm-take-first-elements
Date: Mon, 5 Dec 2022 13:59:27 -0500 (EST)

branch: elpa/helm
commit 08c5e3367049b17f1c9e68928d72f253a8eb528b
Author: Thierry Volpiatto <thievol@posteo.net>
Commit: Thierry Volpiatto <thievol@posteo.net>

    New function helm-take which replace helm-take-first-elements
    
    It is a generic function.
    Should now be compatible as we require emacs-25.1.
    Replace calls like (cl-subseq 0 n) by it.
---
 helm-adaptive.el |  2 +-
 helm-core.el     |  3 +--
 helm-files.el    |  2 +-
 helm-lib.el      | 18 +++++++++++++++---
 4 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/helm-adaptive.el b/helm-adaptive.el
index d535cfb0c8..b354be7bfc 100644
--- a/helm-adaptive.el
+++ b/helm-adaptive.el
@@ -158,7 +158,7 @@ Format: ((SOURCE-NAME
           ;; Truncate history if needed.
           (if (> (length (cdr selection-info)) helm-adaptive-history-length)
               (setcdr selection-info
-                      (cl-subseq (cdr selection-info) 0 
helm-adaptive-history-length))))))))
+                      (helm-take (cdr selection-info) 
helm-adaptive-history-length))))))))
 
 (defun helm-adaptive-maybe-load-history ()
   "Load `helm-adaptive-history-file' which contain `helm-adaptive-history'.
diff --git a/helm-core.el b/helm-core.el
index 0f01dd853d..afbba5254f 100644
--- a/helm-core.el
+++ b/helm-core.el
@@ -4832,8 +4832,7 @@ emacs-27 to provide such scoring in emacs<27."
            ;; display a list of  candidates even with an empty
            ;; pattern.
            (helm--initialize-one-by-one-candidates
-            (helm-take-first-elements
-             (helm-get-cached-candidates source) limit)
+            (helm-take (helm-get-cached-candidates source) limit)
             source)
          ;; Compute candidates according to pattern with their match
          ;; fns.
diff --git a/helm-files.el b/helm-files.el
index a06f17a68e..cf3a743004 100644
--- a/helm-files.el
+++ b/helm-files.el
@@ -5170,7 +5170,7 @@ Show the first `helm-ff-history-max-length' elements of
     (when history
       (setq helm-ff-history
             (if (>= (length history) helm-ff-history-max-length)
-                (cl-subseq history 0 helm-ff-history-max-length)
+                (helm-take history helm-ff-history-max-length)
               history))
       (if comp-read
           (let ((src (helm-build-sync-source "Helm Find Files History"
diff --git a/helm-lib.el b/helm-lib.el
index c0207fbc9a..490883d4ae 100644
--- a/helm-lib.el
+++ b/helm-lib.el
@@ -491,7 +491,7 @@ When CYCLE is specified the iterator never ends."
 (cl-defun helm-iter-sub-next-circular (seq elm &key (test 'eq))
   "Infinite iteration of SEQ starting at ELM."
   (let* ((pos      (1+ (helm-position elm seq :test test)))
-         (sub      (append (nthcdr pos seq) (cl-subseq seq 0 pos)))
+         (sub      (append (nthcdr pos seq) (helm-take seq pos)))
          (iterator (helm-iter-circular sub)))
     (lambda ()
       (helm-iter-next iterator))))
@@ -988,12 +988,24 @@ it will be wrapped inside a list automatically."
            (beg-part (butlast seq len)))
       (append beg-part elm end-part))))
 
-(defun helm-take-first-elements (seq n)
+(cl-defgeneric helm-take (seq n)
   "Return the first N elements of SEQ if SEQ is longer than N.
 It is used for narrowing list of candidates to the
 `helm-candidate-number-limit'."
   (if (> (length seq) n) (cl-subseq seq 0 n) seq))
 
+(cl-defmethod helm-take ((seq list) n)
+  "`helm-take' optimized for lists."
+  (let ((store '()))
+    (if (> n (length seq))
+        seq
+      (while (> (1+ (cl-decf n)) 0)
+        (push (pop seq) store))
+      (nreverse store))))
+
+(defalias 'helm-take-first-elements 'helm-take)
+(make-obsolete 'helm-take-first-elements 'helm-take "3.9.1")
+
 (defun helm-source-by-name (name &optional sources)
   "Get a Helm source in SOURCES by NAME.
 
@@ -1073,7 +1085,7 @@ Examples:
                        (reverse sequence)
                      sequence))
          (pos      (1+ (cl-position elm new-seq :test 'equal))))
-    (append (nthcdr pos new-seq) (cl-subseq new-seq 0 pos))))
+    (append (nthcdr pos new-seq) (helm-take new-seq pos))))
 
 ;;; Strings processing.
 ;;



reply via email to

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