aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorNicolas Petton2015-02-11 09:21:03 +0100
committerNicolas Petton2015-02-11 14:48:18 +0100
commit4fb5565d0a0cd9640a242028c92b8b4e2bd4683e (patch)
tree67f5e8b5595d3b92d3a1f3c2b6b8a26d107d7501 /lisp
parentc49e769d8f141b0307db19ed2a5fa80e0696b1dc (diff)
downloademacs-4fb5565d0a0cd9640a242028c92b8b4e2bd4683e.tar.gz
emacs-4fb5565d0a0cd9640a242028c92b8b4e2bd4683e.zip
Add a backward-compatible version of seq-reverse
* lisp/emacs-lisp/seq.el (seq-reverse): Add a backward-compatible version of seq-reverse that works on sequences in Emacs 24. Bump version to 1.2. * test/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.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog12
-rw-r--r--lisp/emacs-lisp/seq.el28
2 files changed, 32 insertions, 8 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)