[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/compat 2e206a8304 21/84: Add prefixed plist-get from Em
From: |
ELPA Syncer |
Subject: |
[elpa] externals/compat 2e206a8304 21/84: Add prefixed plist-get from Emacs 29 |
Date: |
Tue, 3 Jan 2023 08:57:32 -0500 (EST) |
branch: externals/compat
commit 2e206a8304b3fcf3e8d855f5c3dc475bd70f5dd8
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>
Add prefixed plist-get from Emacs 29
---
compat-29.el | 19 +++++++++++++++++++
compat-tests.el | 10 ++++++++++
compat.texi | 14 ++++++++++++++
3 files changed, 43 insertions(+)
diff --git a/compat-29.el b/compat-29.el
index af29d96446..3d823ee6aa 100644
--- a/compat-29.el
+++ b/compat-29.el
@@ -107,6 +107,25 @@ 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 plist-get (plist prop &optional predicate)
+ "Extract a value from a property list.
+PLIST is a property list, which is a list of the form
+\(PROP1 VALUE1 PROP2 VALUE2...).
+
+This function returns the value corresponding to the given PROP, or
+nil if PROP is not one of the properties on the list. The comparison
+with PROP is done using PREDICATE, which defaults to `eq'.
+
+This function doesn't signal an error if PLIST is invalid."
+ :prefix t
+ (if (or (null predicate) (eq predicate 'eq))
+ (plist-get plist prop)
+ (catch 'found
+ (while (consp plist)
+ (when (funcall predicate prop (car plist))
+ (throw 'found (cadr 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 4f91473a85..9ad7651534 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -2037,6 +2037,16 @@ being compared against."
(ought t "AAA bbb" "aaa bbb")
(ought t "aaa BBB" "aaa bbb"))
+(compat-deftests compat-plist-get
+ (ought 1 '(:one 1 :two 2 :three 3) :one)
+ (ought 2 '(:one 1 :two 2 :three 3) :two)
+ (ought 3 '(:one 1 :two 2 :three 3) :three)
+ (ought nil '(:one 1 :two 2 :three 3) :four)
+ ;; With a custom predicate
+ (ought :one '(1 :one 2 :two 3 :three) 3 #'>)
+ (ought :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 e82badff2a..c4e8aa710f 100644
--- a/compat.texi
+++ b/compat.texi
@@ -2395,6 +2395,20 @@ differences, like @code{char-equal} when
@code{case-fold-search} is
These functions are prefixed with @code{compat} prefix, and will require
manual loading even after the release of Compat 29.1.0.0:
+@c copied from lispref/lists.texi
+@defun compat-plist-get plist prop &optional predicate
+This returns the value of the @var{property} property stored in the
+property list @var{plist}. Comparisons are done with @var{predicate},
+and defaults to @code{eq}. It accepts a malformed @var{plist}
+argument. If @var{property} is not found in the @var{plist}, it
+returns @code{nil}.
+
+@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 29dd29609a 15/84: Prepare compat.el for testing functions from compat-29, (continued)
- [elpa] externals/compat 29dd29609a 15/84: Prepare compat.el for testing functions from compat-29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 9b8799091c 16/84: Add @subsection headers for Emacs 29.1 node, ELPA Syncer, 2023/01/03
- [elpa] externals/compat db53afa3a7 18/84: Add buffer-text-pixel-size from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat a4036f9b1b 01/84: Prepare Emacs 29.1 compatibility, ELPA Syncer, 2023/01/03
- [elpa] externals/compat f21b114ec7 02/84: Add string-limit, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 9083cfc4f6 05/84: Add get-display-property, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 87da1d984d 11/84: Begin documenting Emacs 29 support, ELPA Syncer, 2023/01/03
- [elpa] externals/compat c81333a6b0 30/84: Merge branch 'master' into emacs-29.1, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 2ee63f46b2 07/84: Make compat-font-lock dependency on compat-macs explicit, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 22b2634ada 06/84: Compile compat-macs before anything else, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 2e206a8304 21/84: Add prefixed plist-get from Emacs 29,
ELPA Syncer <=
- [elpa] externals/compat e13ca90cd7 12/84: Rewrite legacy compat-test definitions, ELPA Syncer, 2023/01/03
- [elpa] externals/compat e370f9b7e7 25/84: Add match-buffers from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 4710da5fa7 28/84: Add file-parent-directory from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat bb86f3aa3b 37/84: Simplify compat--generate-testable, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 282f2dc6a7 41/84: Call install-fn in compat--generate-testable, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 3f3f2e44d5 43/84: Split compat-insert-into-buffer into multiple tests, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 933d6fdf80 24/84: Add buffer-match-p from Emacs 29, ELPA Syncer, 2023/01/03
- [elpa] externals/compat 8d17ffdd88 29/84: Add file-has-changed-p from Emacs 29, ELPA Syncer, 2023/01/03
- [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