aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/ChangeLog12
-rw-r--r--lisp/emacs-lisp/seq.el28
-rw-r--r--test/ChangeLog6
-rw-r--r--test/automated/seq-tests.el11
4 files changed, 47 insertions, 10 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index ece253b1336..7e45b9db64c 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,7 +1,8 @@
12015-02-09 Nicolas Petton <nicolas@petton.fr> 12015-02-11 Nicolas Petton <nicolas@petton.fr>
2 2
3 * emacs-lisp/seq.el (seq-group-by): Improves seq-group-by to 3 * emacs-lisp/seq.el (seq-reverse): Add a backward-compatible
4 return sequence elements in correct order. 4 version of seq-reverse that works on sequences in Emacs 24.
5 Bump seq.el version to 1.2.
5 6
62015-02-11 Martin Rudalics <rudalics@gmx.at> 72015-02-11 Martin Rudalics <rudalics@gmx.at>
7 8
@@ -74,6 +75,11 @@
74 (python-shell-font-lock-turn-off): Fix typo. 75 (python-shell-font-lock-turn-off): Fix typo.
75 (python-util-text-properties-replace-name): Delete function. 76 (python-util-text-properties-replace-name): Delete function.
76 77
782015-02-09 Nicolas Petton <nicolas@petton.fr>
79
80 * emacs-lisp/seq.el (seq-group-by): Improves seq-group-by to
81 return sequence elements in correct order.
82
772015-02-09 Simen Heggestøyl <simenheg@gmail.com> (tiny change) 832015-02-09 Simen Heggestøyl <simenheg@gmail.com> (tiny change)
78 84
79 * textmodes/css-mode.el (css-smie-rules): Fix paren indent (bug#19815). 85 * textmodes/css-mode.el (css-smie-rules): Fix paren indent (bug#19815).
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index 5fbec185b76..ad4c3536b44 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -4,7 +4,7 @@
4 4
5;; Author: Nicolas Petton <nicolas@petton.fr> 5;; Author: Nicolas Petton <nicolas@petton.fr>
6;; Keywords: sequences 6;; Keywords: sequences
7;; Version: 1.1.1 7;; Version: 1.2
8 8
9;; Maintainer: emacs-devel@gnu.org 9;; Maintainer: emacs-devel@gnu.org
10 10
@@ -171,9 +171,7 @@ The result is a sequence of the same type as SEQ."
171 (if (listp seq) 171 (if (listp seq)
172 (sort (seq-copy seq) pred) 172 (sort (seq-copy seq) pred)
173 (let ((result (seq-sort pred (append seq nil)))) 173 (let ((result (seq-sort pred (append seq nil))))
174 (cond ((stringp seq) (concat result)) 174 (seq--into result (type-of seq)))))
175 ((vectorp seq) (vconcat result))
176 (t (error "Unsupported sequence: %s" seq))))))
177 175
178(defun seq-contains-p (seq elt &optional testfn) 176(defun seq-contains-p (seq elt &optional testfn)
179 "Return the first element in SEQ that equals to ELT. 177 "Return the first element in SEQ that equals to ELT.
@@ -256,6 +254,27 @@ keys. Keys are compared using `equal'."
256 (seq-reverse seq) 254 (seq-reverse seq)
257 nil)) 255 nil))
258 256
257(defalias 'seq-reverse
258 (if (ignore-errors (reverse [1 2]))
259 #'reverse
260 (lambda (seq)
261 "Return the reversed copy of list, vector, or string SEQ.
262See also the function `nreverse', which is used more often."
263 (let ((result '()))
264 (seq-map (lambda (elt) (push elt result))
265 seq)
266 (if (listp seq)
267 result
268 (seq--into result (type-of seq)))))))
269
270(defun seq--into (seq type)
271 "Convert the sequence SEQ into a sequence of type TYPE."
272 (pcase type
273 (`vector (vconcat seq))
274 (`string (concat seq))
275 (`list (append seq nil))
276 (t (error "Not a sequence type name: %s" type))))
277
259(defun seq--drop-list (list n) 278(defun seq--drop-list (list n)
260 "Return a list from LIST without its first N elements. 279 "Return a list from LIST without its first N elements.
261This is an optimization for lists in `seq-drop'." 280This is an optimization for lists in `seq-drop'."
@@ -299,7 +318,6 @@ This is an optimization for lists in `seq-take-while'."
299 318
300(defalias 'seq-copy #'copy-sequence) 319(defalias 'seq-copy #'copy-sequence)
301(defalias 'seq-elt #'elt) 320(defalias 'seq-elt #'elt)
302(defalias 'seq-reverse #'reverse)
303(defalias 'seq-length #'length) 321(defalias 'seq-length #'length)
304(defalias 'seq-do #'mapc) 322(defalias 'seq-do #'mapc)
305(defalias 'seq-each #'seq-do) 323(defalias 'seq-each #'seq-do)
diff --git a/test/ChangeLog b/test/ChangeLog
index b080961f681..979214c45da 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,9 @@
12015-02-11 Nicolas Petton <nicolas@petton.fr>
2
3 * automated/seq-tests.el (test-seq-reverse, test-seq-group-by):
4 Add a test for seq-reverse and update test for seq-group-by to
5 test vectors and strings, not only lists.
6
12015-02-10 Glenn Morris <rgm@gnu.org> 72015-02-10 Glenn Morris <rgm@gnu.org>
2 8
3 * automated/package-test.el (package-test-signed): 9 * automated/package-test.el (package-test-signed):
diff --git a/test/automated/seq-tests.el b/test/automated/seq-tests.el
index b92a15cacc5..badb3267f43 100644
--- a/test/automated/seq-tests.el
+++ b/test/automated/seq-tests.el
@@ -216,10 +216,17 @@ Evaluate BODY for each created sequence.
216 (should (equal (seq-partition '(1 2 3) -1) '()))) 216 (should (equal (seq-partition '(1 2 3) -1) '())))
217 217
218(ert-deftest test-seq-group-by () 218(ert-deftest test-seq-group-by ()
219 (should (equal (seq-group-by #'test-sequences-oddp '(1 2 3 4)) 219 (with-test-sequences (seq '(1 2 3 4))
220 '((t 1 3) (nil 2 4)))) 220 (should (equal (seq-group-by #'test-sequences-oddp seq)
221 '((t 1 3) (nil 2 4)))))
221 (should (equal (seq-group-by #'car '((a 1) (b 3) (c 4) (a 2))) 222 (should (equal (seq-group-by #'car '((a 1) (b 3) (c 4) (a 2)))
222 '((b (b 3)) (c (c 4)) (a (a 1) (a 2)))))) 223 '((b (b 3)) (c (c 4)) (a (a 1) (a 2))))))
223 224
225(ert-deftest test-seq-reverse ()
226 (with-test-sequences (seq '(1 2 3 4))
227 (should (same-contents-p (seq-reverse seq) '(4 3 2 1)))
228 (should (equal (type-of (seq-reverse seq))
229 (type-of seq)))))
230
224(provide 'seq-tests) 231(provide 'seq-tests)
225;;; seq-tests.el ends here 232;;; seq-tests.el ends here