[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/compat 9aac0f55d1 23/84: Add prefixed plist-member from
From: |
ELPA Syncer |
Subject: |
[elpa] externals/compat 9aac0f55d1 23/84: Add prefixed plist-member from Emacs 29 |
Date: |
Tue, 3 Jan 2023 08:57:32 -0500 (EST) |
branch: externals/compat
commit 9aac0f55d1935201f274b80477b5f109d70d4833
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>
Add prefixed plist-member from Emacs 29
---
compat-29.el | 20 ++++++++++++++++++++
compat-tests.el | 20 ++++++++++++++++++++
compat.texi | 15 +++++++++++++++
3 files changed, 55 insertions(+)
diff --git a/compat-29.el b/compat-29.el
index 68fd657961..0e03b1fc01 100644
--- a/compat-29.el
+++ b/compat-29.el
@@ -149,6 +149,26 @@ The PLIST is modified by side effects."
(setq tail (cddr tail))))
(nconc plist (list prop val)))))
+(compat-defun plist-member (plist prop &optional predicate)
+ "Return non-nil if PLIST has the property PROP.
+PLIST is a property list, which is a list of the form
+\(PROP1 VALUE1 PROP2 VALUE2 ...).
+
+The comparison with PROP is done using PREDICATE, which defaults to
+`eq'.
+
+Unlike `plist-get', this allows you to distinguish between a missing
+property and a property with the value nil.
+The value is actually the tail of PLIST whose car is PROP."
+ :prefix t
+ (if (or (null predicate) (eq predicate 'eq))
+ (plist-member plist prop)
+ (catch 'found
+ (while (consp plist)
+ (when (funcall predicate prop (car plist))
+ (throw 'found plist))
+ (setq plist (cddr plist))))))
+
;;;; Defined in subr.el
(compat-defun function-alias-p (func &optional noerror)
diff --git a/compat-tests.el b/compat-tests.el
index 76e640e0cf..567be85797 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -2077,6 +2077,26 @@ being compared against."
'(1 :one 2 :two 3 :three)
4 :vier #'>))
+(compat-deftests compat-plist-get-member
+ (ought '(:one 1 :two 2 :three 3)
+ '(:one 1 :two 2 :three 3)
+ :one)
+ (ought '(:two 2 :three 3)
+ '(:one 1 :two 2 :three 3)
+ :two)
+ (ought '(:three 3)
+ '(:one 1 :two 2 :three 3)
+ :three)
+ (ought nil '(:one 1 :two 2 :three 3) :four)
+ ;; With a custom predicate
+ (ought '(1 :one 2 :two 3 :three)
+ '(1 :one 2 :two 3 :three)
+ 3 #'>)
+ (ought '(3 :three)
+ '(1 :one 2 :two 3 :three)
+ 3 #'<=)
+ (ought nil '(1 :one 2 :two 3 :three) 4 #'<=))
+
(provide 'compat-tests)
;;; compat-tests.el ends here
diff --git a/compat.texi b/compat.texi
index 0fb1ff2438..77df3082a1 100644
--- a/compat.texi
+++ b/compat.texi
@@ -2424,6 +2424,21 @@ This compatibility version handles the optional argument
@var{predicate}.
@end defun
+@c copied from lispref/lists.texi
+@defun compat-plist-member plist prop &optional predicate
+This returns non-@code{nil} if @var{plist} contains the given
+@var{property}. Comparisons are done with @var{predicate}, and
+defaults to @code{eq}. Unlike @code{plist-get}, this allows you to
+distinguish between a missing property and a property with the value
+@code{nil}. The value is actually the tail of @var{plist} whose
+@code{car} is @var{property}.
+
+@xref{Plist Access,,,elisp}.
+
+This compatibility version handles the optional argument
+@var{predicate}.
+@end defun
+
@subsection Missing Definitions
Compat does not provide support for the following Lisp features
implemented in 29.1:
- [elpa] externals/compat 252d33e897 31/84: Fix incompatible function calls in compat-29, (continued)
- [elpa] externals/compat 252d33e897 31/84: Fix incompatible function calls in compat-29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 9e0eb5b72f 33/84: Add compat-declare-version to compat-29.el, ELPA Syncer, 2023/01/03
- [elpa] externals/compat fdae099b00 34/84: Move if-let and related function from subr-x to subr, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 6ac6ed2a99 36/84: Use make-symbol instead of gensym in function-alias-p tests, ELPA Syncer, 2023/01/03
- [elpa] externals/compat ef5246cf55 38/84: Fix issues related to 'expect' tests, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 0a84a7c219 48/84: Add add-display-text-property from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat e6d279af18 14/84: Extend byte-compile-docstring-max-column to 100, ELPA Syncer, 2023/01/03
- [elpa] externals/compat c177ff5e83 17/84: Reuse ntake in take definition, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 0de389aca6 19/84: Add string-equal-ignore-case from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat ff331f6c29 22/84: Add prefixed plist-put from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 9aac0f55d1 23/84: Add prefixed plist-member from Emacs 29,
ELPA Syncer <=
- [elpa] externals/compat 9ab3081959 26/84: Add string-pixel-width from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat d375504e3c 27/84: Add with-buffer-unmodified-if-unchanged from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat ded0f01036 40/84: Revert "Fix gv-expander for compat-alist-get", ELPA Syncer, 2023/01/03
- [elpa] externals/compat 878221eabd 44/84: Update the commentary section for compat-29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 4a56adbcdf 42/84: Remove references to the deleted "Emacs 24.5" node, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 0c14c42bc1 50/84: Copy edebug specifications instead of referencing, ELPA Syncer, 2023/01/03
- [elpa] externals/compat b888c2fb49 53/84: Replace when-let with expansions in compat-29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 59cd42a912 60/84: Generate test names without double-dashes, ELPA Syncer, 2023/01/03
- [elpa] externals/compat b0f8f6eaac 61/84: Remove realname for ntake, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 45028d9fa7 64/84: Merge branch 'master' into emacs-29.1, ELPA Syncer, 2023/01/03