Emacs Lisp: Sequence Functions
Here's a collection of functions that works on Sequence type.
Note, this page does not include specialized functions for Association List nor Property List .
Convert/Join Sequence/List/Vector/String
Sequence Functions
These functions work on any Sequence Type .
Those starting with “seq-” are new in emacs 25.1, released in 2016-09. They are from “seq.el”, and the file is loaded when emacs starts. You may want to explicitly declare (require 'seq)
.
Some of these provide new functionalities, some gives a unified interface to old functions.
length
sequencep
elt
copy-sequence
reverse
nreverse
sort
seq-elt
seq-length
seqp
seq-drop
seq-take
seq-take-while
seq-drop-while
seq-do
seq-map
seq-mapn
seq-filter
seq-remove
seq-reduce
seq-some
seq-find
seq-every-p
seq-empty-p
seq-count
seq-sort
seq-contains
seq-position
seq-uniq
seq-subseq
seq-concatenate
seq-mapcat
seq-partition
seq-intersection
seq-difference
seq-group-by
seq-into
seq-min
seq-max
seq-doseq
seq-let
Check Existence
(member x list)
- Check if x is in list. If so, return a list starting with the first occurrence of object. Else return nil.
Comparison done using
equal
. [see Emacs Lisp: Test Equality](member "4" '("3" "4" "5")) ;; ("4" "5")
(member-ignore-case x list)
-
same as
member
, except that x should be a string, and comparison ignores letter-case.(member-ignore-case "A" '("b" "a")) ; ("a")
(memq x list)
- Same as
member
, but comparison done usingeq
. Use this if all items are Symbols. (memql x list)
- Same as
member
, but comparison done usingeql
.
Delete Elements
(delete x sequence)
-
- Remove all x in sequence.
- The original sequence is destroyed if it's a list.
- Returns a new sequence.
- Comparison is done with
equal
. [see Emacs Lisp: Test Equality]
(setq xx '(3 4 5)) ;; always set result to the same var. because original is usually destroyed (setq xx (delete 4 xx)) ; (3 5) ;; on vector (setq xx [3 4 5]) (setq xx (delete 4 xx)) ; [3 5]
(delq x sequence)
- Same as
delete
, except the comparison is done witheq
. Use this if all items are Symbols.(setq xx '(3 4 5)) ;; always set result to the same var (setq xx (delq 4 xx)) ; (3 5)
(remove x sequence)
-
- Remove all x in sequence.
- The original sequence is unchanged.
- Returns a new sequence.
- Comparison is done with
equal
. [see Emacs Lisp: Test Equality]
(setq xx '(3 4 5)) (remove 4 xx) ;; (3 5) xx ; (3 4 5)
(remq x list)
- Same as
remove
, except the comparison is done witheq
.(setq xx '(3 4 5)) (remq 4 xx) ; (3 5) xx ; (3 4 5)
Delete Duplicates
(delete-dups list)
- This function destructively removes all duplicates from list, return a new list. The first one is kept among duplicates.
Comparison done using
equal
. [see Emacs Lisp: Test Equality](setq xx '(3 4 5 3 2)) (setq xx (delete-dups xx)) ; (3 4 5 2)
Misc
nconc