-2015-02-09 Nicolas Petton <nicolas@petton.fr>
+2015-02-11 Nicolas Petton <nicolas@petton.fr>
- * emacs-lisp/seq.el (seq-group-by): Improves seq-group-by to
- return sequence elements in correct order.
+ * emacs-lisp/seq.el (seq-reverse): Add a backward-compatible
+ version of seq-reverse that works on sequences in Emacs 24.
+ Bump seq.el version to 1.2.
2015-02-11 Martin Rudalics <rudalics@gmx.at>
(python-shell-font-lock-turn-off): Fix typo.
(python-util-text-properties-replace-name): Delete function.
+2015-02-09 Nicolas Petton <nicolas@petton.fr>
+
+ * emacs-lisp/seq.el (seq-group-by): Improves seq-group-by to
+ return sequence elements in correct order.
+
2015-02-09 Simen Heggestøyl <simenheg@gmail.com> (tiny change)
* textmodes/css-mode.el (css-smie-rules): Fix paren indent (bug#19815).
;; Author: Nicolas Petton <nicolas@petton.fr>
;; Keywords: sequences
-;; Version: 1.1.1
+;; Version: 1.2
;; Maintainer: emacs-devel@gnu.org
(if (listp seq)
(sort (seq-copy seq) pred)
(let ((result (seq-sort pred (append seq nil))))
- (cond ((stringp seq) (concat result))
- ((vectorp seq) (vconcat result))
- (t (error "Unsupported sequence: %s" seq))))))
+ (seq--into result (type-of seq)))))
(defun seq-contains-p (seq elt &optional testfn)
"Return the first element in SEQ that equals to ELT.
(seq-reverse seq)
nil))
+(defalias 'seq-reverse
+ (if (ignore-errors (reverse [1 2]))
+ #'reverse
+ (lambda (seq)
+ "Return the reversed copy of list, vector, or string SEQ.
+See also the function `nreverse', which is used more often."
+ (let ((result '()))
+ (seq-map (lambda (elt) (push elt result))
+ seq)
+ (if (listp seq)
+ result
+ (seq--into result (type-of seq)))))))
+
+(defun seq--into (seq type)
+ "Convert the sequence SEQ into a sequence of type TYPE."
+ (pcase type
+ (`vector (vconcat seq))
+ (`string (concat seq))
+ (`list (append seq nil))
+ (t (error "Not a sequence type name: %s" type))))
+
(defun seq--drop-list (list n)
"Return a list from LIST without its first N elements.
This is an optimization for lists in `seq-drop'."
(defalias 'seq-copy #'copy-sequence)
(defalias 'seq-elt #'elt)
-(defalias 'seq-reverse #'reverse)
(defalias 'seq-length #'length)
(defalias 'seq-do #'mapc)
(defalias 'seq-each #'seq-do)
+2015-02-11 Nicolas Petton <nicolas@petton.fr>
+
+ * automated/seq-tests.el (test-seq-reverse, test-seq-group-by):
+ Add a test for seq-reverse and update test for seq-group-by to
+ test vectors and strings, not only lists.
+
2015-02-10 Glenn Morris <rgm@gnu.org>
* automated/package-test.el (package-test-signed):
(should (equal (seq-partition '(1 2 3) -1) '())))
(ert-deftest test-seq-group-by ()
- (should (equal (seq-group-by #'test-sequences-oddp '(1 2 3 4))
- '((t 1 3) (nil 2 4))))
+ (with-test-sequences (seq '(1 2 3 4))
+ (should (equal (seq-group-by #'test-sequences-oddp seq)
+ '((t 1 3) (nil 2 4)))))
(should (equal (seq-group-by #'car '((a 1) (b 3) (c 4) (a 2)))
'((b (b 3)) (c (c 4)) (a (a 1) (a 2))))))
+(ert-deftest test-seq-reverse ()
+ (with-test-sequences (seq '(1 2 3 4))
+ (should (same-contents-p (seq-reverse seq) '(4 3 2 1)))
+ (should (equal (type-of (seq-reverse seq))
+ (type-of seq)))))
+
(provide 'seq-tests)
;;; seq-tests.el ends here