aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2023-01-17 23:41:53 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2023-01-17 23:41:53 +0100
commit897d9fbbbad2e7552137fff1bea7b9c0daa68b61 (patch)
tree99cbd847d60bc83b64577dd417186dad80258e6f
parent64dfe9f910954392925a8114b8cf2301af4fbe4d (diff)
compat-29: Add plistp
-rw-r--r--NEWS.org3
-rw-r--r--compat-29.el5
-rw-r--r--compat-tests.el10
-rw-r--r--compat.texi5
4 files changed, 22 insertions, 1 deletions
diff --git a/NEWS.org b/NEWS.org
index bc43a7d..89dda3a 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -7,8 +7,9 @@
- compat-27: Add ~make-decoded-time~.
- compat-28: Add ~color-dark-p~.
- compat-28: Add ~with-window-non-dedicated~.
-- compat-29: Add ~plist-get~ generalized variable.
- compat-29: Add ~compiled-function-p~.
+- compat-29: Add ~plist-get~ generalized variable.
+- compat-29: Add ~plistp~.
* Release of "Compat" Version 29.1.2.0
diff --git a/compat-29.el b/compat-29.el
index bae8f07..3c3dc51 100644
--- a/compat-29.el
+++ b/compat-29.el
@@ -84,6 +84,11 @@ Unibyte strings are converted to multibyte for comparison."
(declare (pure t) (side-effect-free t))
(eq t (compare-strings string1 0 nil string2 0 nil t)))
+(compat-defun plistp (object) ;; <compat-tests:plistp>
+ "Non-nil if and only if OBJECT is a valid plist."
+ (let ((len (proper-list-p object)))
+ (and len (zerop (% len 2)))))
+
(compat-defun plist-get (plist prop &optional predicate) ;; <compat-tests:plist-get>
"Handle optional argument PREDICATE."
:explicit t
diff --git a/compat-tests.el b/compat-tests.el
index 4f75887..0b928e1 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -906,6 +906,16 @@
(should (string-prefix-p "compat" (symbol-name (gensym "compat"))))
(should-equal gensym-counter (+ orig 3))))
+(ert-deftest plistp ()
+ (should (plistp '(:a a :b b)))
+ (should (plistp '(1 2 3 4)))
+ (should-not (plistp '(1 2 3)))
+ (should-not (plistp '(1 . 2)))
+ (should-not (plistp '(1 2 . 3)))
+ (should-not (let ((l (list 1 2 3)))
+ (setf (nthcdr 3 l) l)
+ (plistp l))))
+
(ert-deftest plist-get ()
(let (list)
(setq list (compat-call plist-put list 'first 1))
diff --git a/compat.texi b/compat.texi
index 16dc70a..211edde 100644
--- a/compat.texi
+++ b/compat.texi
@@ -2012,6 +2012,11 @@ provided by Compat. Note that due to upstream changes, it might happen
that there will be the need for changes, so use these functions with
care.
+@c based on lisp/subr.el
+@defun plistp object
+Non-nil if and only if @var{object} is a valid plist.
+@end defun
+
@c copied from lispref/cl.texi
@defmac with-memoization @var{place} @var{code}@dots{}
This macro provides a simple way to do memoization. @var{code} is