[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/compat 64dc62259f 3/4: compat-29: Add list-of-strings-p
From: |
ELPA Syncer |
Subject: |
[elpa] externals/compat 64dc62259f 3/4: compat-29: Add list-of-strings-p |
Date: |
Tue, 17 Jan 2023 17:57:27 -0500 (EST) |
branch: externals/compat
commit 64dc62259f1adc6ae70a38f7a874cee48dfa3626
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
compat-29: Add list-of-strings-p
---
NEWS.org | 1 +
compat-29.el | 7 +++++++
compat-tests.el | 8 ++++++++
compat.texi | 5 +++++
4 files changed, 21 insertions(+)
diff --git a/NEWS.org b/NEWS.org
index 89dda3a76f..31d5a52408 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -10,6 +10,7 @@
- compat-29: Add ~compiled-function-p~.
- compat-29: Add ~plist-get~ generalized variable.
- compat-29: Add ~plistp~.
+- compat-29: Add ~list-of-strings-p~.
* Release of "Compat" Version 29.1.2.0
diff --git a/compat-29.el b/compat-29.el
index 3c3dc51110..e84c628d96 100644
--- a/compat-29.el
+++ b/compat-29.el
@@ -84,6 +84,13 @@ 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 list-of-strings-p (object) ;; <compat-tests:lists-of-strings-p>
+ "Return t if OBJECT is nil or a list of strings."
+ (declare (pure t) (side-effect-free t))
+ (while (and (consp object) (stringp (car object)))
+ (setq object (cdr object)))
+ (null object))
+
(compat-defun plistp (object) ;; <compat-tests:plistp>
"Non-nil if and only if OBJECT is a valid plist."
(let ((len (proper-list-p object)))
diff --git a/compat-tests.el b/compat-tests.el
index 0b928e1e01..a15f3f5185 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -906,6 +906,14 @@
(should (string-prefix-p "compat" (symbol-name (gensym "compat"))))
(should-equal gensym-counter (+ orig 3))))
+(ert-deftest list-of-strings-p ()
+ (should-not (list-of-strings-p 1))
+ (should (list-of-strings-p nil))
+ (should (list-of-strings-p '("a" "b")))
+ (should-not (list-of-strings-p ["a" "b"]))
+ (should-not (list-of-strings-p '("a" nil "b")))
+ (should-not (list-of-strings-p '("a" "b" . "c"))))
+
(ert-deftest plistp ()
(should (plistp '(:a a :b b)))
(should (plistp '(1 2 3 4)))
diff --git a/compat.texi b/compat.texi
index 211eddee8e..6aec7f40ca 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 list-of-strings-p object
+Return @code{t} if @var{object} is @code{nil} or a list of strings.
+@end defun
+
@c based on lisp/subr.el
@defun plistp object
Non-nil if and only if @var{object} is a valid plist.