emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/compat 897d9fbbba 2/4: compat-29: Add plistp


From: ELPA Syncer
Subject: [elpa] externals/compat 897d9fbbba 2/4: compat-29: Add plistp
Date: Tue, 17 Jan 2023 17:57:27 -0500 (EST)

branch: externals/compat
commit 897d9fbbbad2e7552137fff1bea7b9c0daa68b61
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    compat-29: Add plistp
---
 NEWS.org        |  3 ++-
 compat-29.el    |  5 +++++
 compat-tests.el | 10 ++++++++++
 compat.texi     |  5 +++++
 4 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/NEWS.org b/NEWS.org
index bc43a7dece..89dda3a76f 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 bae8f07fca..3c3dc51110 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 4f758870b8..0b928e1e01 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 16dc70a3af..211eddee8e 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]