[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/compat ff331f6c29 22/84: Add prefixed plist-put from Em
From: |
ELPA Syncer |
Subject: |
[elpa] externals/compat ff331f6c29 22/84: Add prefixed plist-put from Emacs 29 |
Date: |
Tue, 3 Jan 2023 08:57:32 -0500 (EST) |
branch: externals/compat
commit ff331f6c2931d88afbcf7af540552d30a76313be
Author: Philip Kaludercic <philipk@posteo.net>
Commit: Philip Kaludercic <philipk@posteo.net>
Add prefixed plist-put from Emacs 29
---
compat-29.el | 23 +++++++++++++++++++++++
compat-tests.el | 30 ++++++++++++++++++++++++++++++
compat.texi | 15 +++++++++++++++
3 files changed, 68 insertions(+)
diff --git a/compat-29.el b/compat-29.el
index 3d823ee6aa..68fd657961 100644
--- a/compat-29.el
+++ b/compat-29.el
@@ -126,6 +126,29 @@ This function doesn't signal an error if PLIST is invalid."
(throw 'found (cadr plist)))
(setq plist (cddr plist))))))
+(compat-defun plist-put (plist prop val &optional predicate)
+ "Change value in PLIST of PROP to VAL.
+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'.
+
+If PROP is already a property on the list, its value is set to VAL,
+otherwise the new PROP VAL pair is added. The new plist is returned;
+use `(setq x (plist-put x prop val))' to be sure to use the new value.
+The PLIST is modified by side effects."
+ :prefix t
+ (if (or (null predicate) (eq predicate 'eq))
+ (plist-put plist prop val)
+ (catch 'found
+ (let ((tail plist))
+ (while (consp tail)
+ (when (funcall predicate prop (car tail))
+ (setcar (cdr tail) val)
+ (throw 'found plist))
+ (setq tail (cddr tail))))
+ (nconc plist (list prop val)))))
+
;;;; Defined in subr.el
(compat-defun function-alias-p (func &optional noerror)
diff --git a/compat-tests.el b/compat-tests.el
index 9ad7651534..76e640e0cf 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -2047,6 +2047,36 @@ being compared against."
(ought :three '(1 :one 2 :two 3 :three) 3 #'<=)
(ought nil '(1 :one 2 :two 3 :three) 4 #'<=))
+(compat-deftests compat-plist-put
+ (ought '(:one -1 :two 2 :three 3)
+ (list :one 1 :two 2 :three 3)
+ :one -1)
+ (ought '(:one -1 :one 2 :one 3)
+ (list :one 1 :one 2 :one 3)
+ :one -1)
+ (ought '(:zero 1 :one -1 :one 3)
+ (list :zero 1 :one 2 :one 3)
+ :one -1)
+ (ought '(:one -1 :two 2 :three 3)
+ (list :one 1 :two 2 :three 3)
+ :one -1)
+ (ought '(:one 1 :two 2 :three 3 :four -1)
+ (list :one 1 :two 2 :three 3)
+ :four -1)
+ ;; With a custom predicate
+ (ought '(1 :eins 2 :two 3 :three)
+ '(1 :one 2 :two 3 :three)
+ 3 :eins #'>)
+ (ought '(1 :one 2 :zwei 3 :three)
+ '(1 :one 2 :two 3 :three)
+ 2 :zwei #'<=)
+ (ought '(1 :one 2 :two 3 :three 4 :vier)
+ '(1 :one 2 :two 3 :three)
+ 4 :vier #'<=)
+ (ought '(1 :vier 2 :two 3 :three)
+ '(1 :one 2 :two 3 :three)
+ 4 :vier #'>))
+
(provide 'compat-tests)
;;; compat-tests.el ends here
diff --git a/compat.texi b/compat.texi
index c4e8aa710f..0fb1ff2438 100644
--- a/compat.texi
+++ b/compat.texi
@@ -2409,6 +2409,21 @@ This compatibility version handles the optional argument
@var{predicate}.
@end defun
+@c copied from lispref/lists.texi
+@defun compat-plist-put plist prop val &optional predicate
+This stores @var{value} as the value of the @var{property} property in
+the property list @var{plist}. Comparisons are done with @var{predicate},
+and defaults to @code{eq}. It may modify @var{plist} destructively,
+or it may construct a new list structure without altering the old. The
+function returns the modified property list, so you can store that back
+in the place where you got @var{plist}.
+
+@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 8d17ffdd88 29/84: Add file-has-changed-p from Emacs 29, (continued)
- [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
- [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 <=
- [elpa] externals/compat 9aac0f55d1 23/84: Add prefixed plist-member from Emacs 29, ELPA Syncer, 2023/01/03
- [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