summaryrefslogtreecommitdiff
path: root/lisp/emacs-lisp/seq.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/emacs-lisp/seq.el')
-rw-r--r--lisp/emacs-lisp/seq.el29
1 files changed, 28 insertions, 1 deletions
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index c5f5906e7e5..6f7f3c46e2a 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -4,7 +4,7 @@
;; Author: Nicolas Petton <nicolas@petton.fr>
;; Keywords: sequences
-;; Version: 1.3
+;; Version: 1.4
;; Package: seq
;; Maintainer: emacs-devel@gnu.org
@@ -240,6 +240,26 @@ negative integer or 0, nil is returned."
(setq seq (seq-drop seq n)))
(nreverse result))))
+(defun seq-intersection (seq1 seq2 &optional testfn)
+ "Return a list of the elements that appear in both SEQ1 and SEQ2.
+Equality is defined by TESTFN if non-nil or by `equal' if nil."
+ (seq-reduce (lambda (acc elt)
+ (if (seq-contains-p seq2 elt testfn)
+ (cons elt acc)
+ acc))
+ (seq-reverse seq1)
+ '()))
+
+(defun seq-difference (seq1 seq2 &optional testfn)
+ "Return a list of th elements that appear in SEQ1 but not in SEQ2.
+Equality is defined by TESTFN if non-nil or by `equal' if nil."
+ (seq-reduce (lambda (acc elt)
+ (if (not (seq-contains-p seq2 elt testfn))
+ (cons elt acc)
+ acc))
+ (seq-reverse seq1)
+ '()))
+
(defun seq-group-by (function seq)
"Apply FUNCTION to each element of SEQ.
Separate the elements of SEQ into an alist using the results as
@@ -318,6 +338,11 @@ This is an optimization for lists in `seq-take-while'."
(setq n (+ 1 n)))
n))
+(defun seq--activate-font-lock-keywords ()
+ "Activate font-lock keywords for some symbols defined in seq."
+ (font-lock-add-keywords 'emacs-lisp-mode
+ '("\\<seq-doseq\\>")))
+
(defalias 'seq-copy #'copy-sequence)
(defalias 'seq-elt #'elt)
(defalias 'seq-length #'length)
@@ -325,5 +350,7 @@ This is an optimization for lists in `seq-take-while'."
(defalias 'seq-each #'seq-do)
(defalias 'seq-map #'mapcar)
+(add-to-list 'emacs-lisp-mode-hook #'seq--activate-font-lock-keywords)
+
(provide 'seq)
;;; seq.el ends here