emacs-diffs
[Top][All Lists]
Advanced

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

master dedd19a2f5: Add new type predicate plistp


From: Lars Ingebrigtsen
Subject: master dedd19a2f5: Add new type predicate plistp
Date: Mon, 27 Jun 2022 06:37:34 -0400 (EDT)

branch: master
commit dedd19a2f5cbf16c8ac8a122b0c39ee4e178b9e8
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add new type predicate plistp
    
    * lisp/subr.el (plistp): New type predicate (bug#47427).  This
    referred to in the error message from plist-put: "Debugger
    entered--Lisp error: (wrong-type-argument plistp (a b c))".
---
 lisp/subr.el            | 6 ++++++
 test/lisp/subr-tests.el | 9 +++++++++
 2 files changed, 15 insertions(+)

diff --git a/lisp/subr.el b/lisp/subr.el
index b05471f0c3..69cff23cba 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -4006,6 +4006,12 @@ Otherwise, return nil."
       (setq object (indirect-function object)))
   (and (subrp object) (eq (cdr (subr-arity object)) 'unevalled)))
 
+(defun plistp (object)
+  "Non-nil if and only if OBJECT is a valid plist."
+  (and (listp object)
+       (proper-list-p object)
+       (zerop (mod (length object) 2))))
+
 (defun macrop (object)
   "Non-nil if and only if OBJECT is a macro."
   (let ((def (indirect-function object)))
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index 45dd2d7160..ced2bc5c4e 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -1081,5 +1081,14 @@ final or penultimate step during initialization."))
   (dolist (c (list ?a ?b ?α ?β))
     (should-not (char-uppercase-p c))))
 
+(ert-deftest test-plistp ()
+  (should (plistp nil))
+  (should-not (plistp 1))
+  (should (plistp '(1 2)))
+  (should-not (plistp '(1 . 2)))
+  (should (plistp '(1 2 3 4)))
+  (should-not (plistp '(1 2 3)))
+  (should-not (plistp '(1 2 3 . 4))))
+
 (provide 'subr-tests)
 ;;; subr-tests.el ends here



reply via email to

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