diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2017-06-18 22:32:31 +0100 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2017-06-18 22:32:31 +0100 |
commit | ff8d10f3d2534ab7c91af3d7ede7353d65d0f3a1 (patch) | |
tree | 59197dfc39a1a6fd18fc2337ef256b581b6e6517 | |
parent | 5e8ae421a2198ed30022c2e8596f175799d36015 (diff) |
New upstream version 2.20
-rw-r--r-- | ChangeLog | 29 | ||||
-rw-r--r-- | seq-24.el | 33 | ||||
-rw-r--r-- | seq-25.el | 33 | ||||
-rw-r--r-- | seq-pkg.el | 2 | ||||
-rw-r--r-- | seq.el | 2 | ||||
-rw-r--r-- | tests/seq-tests.el | 24 |
6 files changed, 107 insertions, 16 deletions
@@ -1,3 +1,32 @@ +2017-05-04 Nicolas Petton <nicolas@petton.fr> + + Update seq.el to 2.20 + +2016-12-16 Nicolas Petton <nicolas@petton.fr> + + Backport the latest changes to seq.el from Emacs master + + * packages/seq/seq-24.el: + * packages/seq/seq-25.el (seq-into): Do not convert the sequence if not + needed. + * packages/seq/tests/seq-tests.el: Add a regression test. + +2016-12-15 Nicolas Petton <nicolas@petton.fr> + + Backport seq-mapn fix from Emacs master + + * packages/seq/seq-24.el (seq-mapn): + * packages/seq/seq-25.el (seq-mapn): Fix for circular lists. + * packages/seq/tests/seq-tests.el: Add a regression test. + +2016-11-16 Nicolas Petton <nicolas@petton.fr> + + Do not use map.el in seq-tests.el + + * packages/seq/tests/seq-tests.el: Do not use map.el. map.el was + introduced in Emacs 25.1, but seq.el is also available in GNU ELPA for + Emacs 24.5. + 2016-10-25 Nicolas Petton <nicolas@petton.fr> Fix seq-random-elt docstring @@ -219,6 +219,12 @@ Equality is defined by TESTFN if non-nil or by `equal' if nil." (funcall (or testfn #'equal) elt e)) sequence)) +(defun seq-set-equal-p (sequence1 sequence2 &optional testfn) + "Return non-nil if SEQUENCE1 and SEQUENCE2 contain the same elements, regardless of order. +Equality is defined by TESTFN if non-nil or by `equal' if nil." + (and (seq-every-p (lambda (item1) (seq-contains sequence2 item1 testfn)) sequence1) + (seq-every-p (lambda (item2) (seq-contains sequence1 item2 testfn)) sequence2))) + (defun seq-position (sequence elt &optional testfn) "Return the index of the first element in SEQUENCE that is equal to ELT. Equality is defined by TESTFN if non-nil or by `equal' if nil." @@ -286,7 +292,8 @@ Return a list of the results. \(fn FUNCTION SEQS...)" (let ((result nil) - (seqs (seq-map (lambda (s) (seq-into s 'list)) + (seqs (seq-map (lambda (s) + (seq-into s 'list)) (cons sequence seqs)))) (while (not (memq nil seqs)) (push (apply function (seq-map #'car seqs)) result) @@ -356,9 +363,9 @@ See also the function `nreverse', which is used more often." "Convert the sequence SEQUENCE into a sequence of type TYPE. TYPE can be one of the following symbols: vector, string or list." (pcase type - (`vector (vconcat sequence)) - (`string (concat sequence)) - (`list (append sequence nil)) + (`vector (seq--into-vector sequence)) + (`string (seq--into-string sequence)) + (`list (seq--into-list sequence)) (_ (error "Not a sequence type name: %S" type)))) (defun seq-min (sequence) @@ -462,6 +469,24 @@ If no element is found, return nil." (defalias 'seq-map #'mapcar) (defalias 'seqp #'sequencep) +(defun seq--into-list (sequence) + "Concatenate the elements of SEQUENCE into a list." + (if (listp sequence) + sequence + (append sequence nil))) + +(defun seq--into-vector (sequence) + "Concatenate the elements of SEQUENCE into a vector." + (if (vectorp sequence) + sequence + (vconcat sequence))) + +(defun seq--into-string (sequence) + "Concatenate the elements of SEQUENCE into a string." + (if (stringp sequence) + sequence + (concat sequence))) + (unless (fboundp 'elisp--font-lock-flush-elisp-buffers) ;; In Emacsā„25, (via elisp--font-lock-flush-elisp-buffers and a few others) ;; we automatically highlight macros. @@ -171,7 +171,8 @@ Return a list of the results. \(fn FUNCTION SEQUENCES...)" (let ((result nil) - (sequences (seq-map (lambda (s) (seq-into s 'list)) + (sequences (seq-map (lambda (s) + (seq-into s 'list)) (cons sequence sequences)))) (while (not (memq nil sequences)) (push (apply function (seq-map #'car sequences)) result) @@ -265,9 +266,9 @@ of sequence." TYPE can be one of the following symbols: vector, string or list." (pcase type - (`vector (vconcat sequence)) - (`string (concat sequence)) - (`list (append sequence nil)) + (`vector (seq--into-vector sequence)) + (`string (seq--into-string sequence)) + (`list (seq--into-list sequence)) (_ (error "Not a sequence type name: %S" type)))) (cl-defgeneric seq-filter (pred sequence) @@ -345,6 +346,12 @@ Equality is defined by TESTFN if non-nil or by `equal' if nil." (funcall (or testfn #'equal) elt e)) sequence)) +(cl-defgeneric seq-set-equal-p (sequence1 sequence2 &optional testfn) + "Return non-nil if SEQUENCE1 and SEQUENCE2 contain the same elements, regardless of order. +Equality is defined by TESTFN if non-nil or by `equal' if nil." + (and (seq-every-p (lambda (item1) (seq-contains sequence2 item1 testfn)) sequence1) + (seq-every-p (lambda (item2) (seq-contains sequence1 item2 testfn)) sequence2))) + (cl-defgeneric seq-position (sequence elt &optional testfn) "Return the index of the first element in SEQUENCE that is equal to ELT. Equality is defined by TESTFN if non-nil or by `equal' if nil." @@ -461,6 +468,24 @@ SEQUENCE must be a sequence of numbers or markers." (null list)) +(defun seq--into-list (sequence) + "Concatenate the elements of SEQUENCE into a list." + (if (listp sequence) + sequence + (append sequence nil))) + +(defun seq--into-vector (sequence) + "Concatenate the elements of SEQUENCE into a vector." + (if (vectorp sequence) + sequence + (vconcat sequence))) + +(defun seq--into-string (sequence) + "Concatenate the elements of SEQUENCE into a string." + (if (stringp sequence) + sequence + (concat sequence))) + (defun seq--make-pcase-bindings (args) "Return a list of bindings of the variables in ARGS to the elements of a sequence." (let ((bindings '()) @@ -1,2 +1,2 @@ ;; Generated package description from seq.el -(define-package "seq" "2.19" "Sequence manipulation functions" 'nil :url "http://elpa.gnu.org/packages/seq.html" :keywords '("sequences")) +(define-package "seq" "2.20" "Sequence manipulation functions" 'nil :url "http://elpa.gnu.org/packages/seq.html" :keywords '("sequences")) @@ -4,7 +4,7 @@ ;; Author: Nicolas Petton <nicolas@petton.fr> ;; Keywords: sequences -;; Version: 2.19 +;; Version: 2.20 ;; Package: seq ;; Maintainer: emacs-devel@gnu.org diff --git a/tests/seq-tests.el b/tests/seq-tests.el index 53930fa..d53fa36 100644 --- a/tests/seq-tests.el +++ b/tests/seq-tests.el @@ -352,19 +352,31 @@ Evaluate BODY for each created sequence. (ert-deftest test-seq-random-elt-take-all () (let ((seq '(a b c d e)) - (count '())) - (should (= 0 (map-length count))) + (elts '())) + (should (= 0 (length elts))) (dotimes (_ 1000) (let ((random-elt (seq-random-elt seq))) - (map-put count - random-elt - (map-elt count random-elt 0)))) - (should (= 5 (map-length count))))) + (add-to-list 'elts + random-elt))) + (should (= 5 (length elts))))) (ert-deftest test-seq-random-elt-signal-on-empty () (should-error (seq-random-elt nil)) (should-error (seq-random-elt [])) (should-error (seq-random-elt ""))) +(ert-deftest test-seq-mapn-circular-lists () + (let ((l1 '#1=(1 . #1#))) + (should (equal (seq-mapn #'+ '(3 4 5 7) l1) + '(4 5 6 8))))) + +(ert-deftest test-seq-into-and-identity () + (let ((lst '(1 2 3)) + (vec [1 2 3]) + (str "foo bar")) + (should (eq (seq-into lst 'list) lst)) + (should (eq (seq-into vec 'vector) vec)) + (should (eq (seq-into str 'string) str)))) + (provide 'seq-tests) ;;; seq-tests.el ends here |