aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Petton2015-03-09 12:46:29 +0100
committerNicolas Petton2015-03-09 12:50:24 +0100
commitb7ed48c3ce8e77acc08d4948684333bef3238d2d (patch)
treef391b49af05d99cdde85b933bdaeb1e6598d146c
parent8854b9cf5283cac3e4a5a3726325a82b88c1fcb5 (diff)
downloademacs-b7ed48c3ce8e77acc08d4948684333bef3238d2d.tar.gz
emacs-b7ed48c3ce8e77acc08d4948684333bef3238d2d.zip
Add seq-into as a public function
* lisp/emacs-lisp/seq.el: Make seq-into a public function (replacing seq--into) * test/automated/seq-tests.el: Add tests for seq-into * doc/lispref/sequences.texi: Add documentation for seq-into
-rw-r--r--doc/lispref/ChangeLog5
-rw-r--r--doc/lispref/sequences.texi22
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/emacs-lisp/seq.el12
-rw-r--r--test/ChangeLog4
-rw-r--r--test/automated/seq-tests.el22
6 files changed, 65 insertions, 5 deletions
diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog
index 42bff7c865a..260656c6cf7 100644
--- a/doc/lispref/ChangeLog
+++ b/doc/lispref/ChangeLog
@@ -1,3 +1,8 @@
12015-03-09 Nicolas Petton <nicolas@petton.fr>
2
3 * sequences.texi (seq-into): Add documentation for the new
4 seq-into function.
5
12015-03-03 Eli Zaretskii <eliz@gnu.org> 62015-03-03 Eli Zaretskii <eliz@gnu.org>
2 7
3 * processes.texi (Synchronous Processes): Update documentation of 8 * processes.texi (Synchronous Processes): Update documentation of
diff --git a/doc/lispref/sequences.texi b/doc/lispref/sequences.texi
index 04404f886e0..1af353590cf 100644
--- a/doc/lispref/sequences.texi
+++ b/doc/lispref/sequences.texi
@@ -740,6 +740,28 @@ of @var{sequence}. Keys are compared using @code{equal}.
740@end example 740@end example
741@end defun 741@end defun
742 742
743@defun seq-into sequence type
744 This function converts the sequence @var{sequence} into a sequence
745of type @var{type}. @var{type} can be one of the following symbols:
746@code{vector}, @code{string} or @code{list}.
747
748@example
749@group
750(seq-into [1 2 3] 'list)
751@result{} (1 2 3)
752@end group
753@group
754(seq-into nil 'vector)
755@result{} []
756@end group
757@group
758(seq-into "hello" 'vector)
759@result{} [104 101 108 108 111]
760@end group
761@end example
762@end defun
763
764
743@defmac seq-doseq (var sequence [result]) body@dots{} 765@defmac seq-doseq (var sequence [result]) body@dots{}
744@cindex sequence iteration 766@cindex sequence iteration
745 This macro is like @code{dolist}, except that @var{sequence} can be a list, 767 This macro is like @code{dolist}, except that @var{sequence} can be a list,
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index b284ef16eaf..d8330a46c89 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
12015-03-09 Nicolas Petton <nicolas@petton.fr>
2
3 * emacs-lisp/seq.el (seq-into): New function.
4 Bump seq.el version to 1.3.
5
12015-03-09 Dmitry Gutov <dgutov@yandex.ru> 62015-03-09 Dmitry Gutov <dgutov@yandex.ru>
2 7
3 * progmodes/ruby-mode.el (ruby-font-lock-keywords): Don't consider 8 * progmodes/ruby-mode.el (ruby-font-lock-keywords): Don't consider
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index ad4c3536b44..59b91408d09 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -4,7 +4,8 @@
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.2 7;; Version: 1.3
8;; Package: seq
8 9
9;; Maintainer: emacs-devel@gnu.org 10;; Maintainer: emacs-devel@gnu.org
10 11
@@ -171,7 +172,7 @@ The result is a sequence of the same type as SEQ."
171 (if (listp seq) 172 (if (listp seq)
172 (sort (seq-copy seq) pred) 173 (sort (seq-copy seq) pred)
173 (let ((result (seq-sort pred (append seq nil)))) 174 (let ((result (seq-sort pred (append seq nil))))
174 (seq--into result (type-of seq))))) 175 (seq-into result (type-of seq)))))
175 176
176(defun seq-contains-p (seq elt &optional testfn) 177(defun seq-contains-p (seq elt &optional testfn)
177 "Return the first element in SEQ that equals to ELT. 178 "Return the first element in SEQ that equals to ELT.
@@ -265,10 +266,11 @@ See also the function `nreverse', which is used more often."
265 seq) 266 seq)
266 (if (listp seq) 267 (if (listp seq)
267 result 268 result
268 (seq--into result (type-of seq))))))) 269 (seq-into result (type-of seq)))))))
269 270
270(defun seq--into (seq type) 271(defun seq-into (seq type)
271 "Convert the sequence SEQ into a sequence of type TYPE." 272 "Convert the sequence SEQ into a sequence of type TYPE.
273TYPE can be one of the following symbols: vector, string or list."
272 (pcase type 274 (pcase type
273 (`vector (vconcat seq)) 275 (`vector (vconcat seq))
274 (`string (concat seq)) 276 (`string (concat seq))
diff --git a/test/ChangeLog b/test/ChangeLog
index 301cc4046e5..876b9462611 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,7 @@
12015-03-09 Nicolas Petton <nicolas@petton.fr>
2
3 * automated/seq-tests.el (test-seq-into): Add a test for seq-into.
4
12015-03-08 Dmitry Gutov <dgutov@yandex.ru> 52015-03-08 Dmitry Gutov <dgutov@yandex.ru>
2 6
3 * indent/ruby.rb: Add an example for bug#20026. 7 * indent/ruby.rb: Add an example for bug#20026.
diff --git a/test/automated/seq-tests.el b/test/automated/seq-tests.el
index badb3267f43..d3536b6f9a6 100644
--- a/test/automated/seq-tests.el
+++ b/test/automated/seq-tests.el
@@ -228,5 +228,27 @@ Evaluate BODY for each created sequence.
228 (should (equal (type-of (seq-reverse seq)) 228 (should (equal (type-of (seq-reverse seq))
229 (type-of seq))))) 229 (type-of seq)))))
230 230
231(ert-deftest test-seq-into ()
232 (let* ((vector [1 2 3])
233 (list (seq-into vector 'list)))
234 (should (same-contents-p vector list))
235 (should (listp list)))
236 (let* ((list '(hello world))
237 (vector (seq-into list 'vector)))
238 (should (same-contents-p vector list))
239 (should (vectorp vector)))
240 (let* ((string "hello")
241 (list (seq-into string 'list)))
242 (should (same-contents-p string list))
243 (should (stringp string)))
244 (let* ((string "hello")
245 (vector (seq-into string 'vector)))
246 (should (same-contents-p string vector))
247 (should (stringp string)))
248 (let* ((list nil)
249 (vector (seq-into list 'vector)))
250 (should (same-contents-p list vector))
251 (should (vectorp vector))))
252
231(provide 'seq-tests) 253(provide 'seq-tests)
232;;; seq-tests.el ends here 254;;; seq-tests.el ends here