diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2025-05-12 23:58:22 +0200 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2025-05-13 00:03:17 +0200 |
| commit | cfe89a74a63e8205782b7217ae01145b54a27fcc (patch) | |
| tree | 45ad4c05cf9d1d0de1e60d59a96bcb59d9cf34f1 | |
| parent | 7d6be88c8664de35f506aac960a6c11225599b6b (diff) | |
compat-31: New function hash-table-contains-p
| -rw-r--r-- | NEWS.org | 1 | ||||
| -rw-r--r-- | compat-31.el | 6 | ||||
| -rw-r--r-- | compat-tests.el | 8 | ||||
| -rw-r--r-- | compat.texi | 5 |
4 files changed, 20 insertions, 0 deletions
@@ -15,6 +15,7 @@ - compat-31: New macro =with-work-buffer=. - compat-31: New function =unbuttonize-region=. - compat-31: New extended function =seconds-to-string=. +- compat-31: New function =hash-table-contains-p=. - Drop support for Emacs 24.x. Emacs 25.1 is required now. In case Emacs 24.x support is still needed, Compat 30 can be used. diff --git a/compat-31.el b/compat-31.el index b6aa5e3..e27ef0f 100644 --- a/compat-31.el +++ b/compat-31.el @@ -29,6 +29,12 @@ ;;;; Defined in subr.el +(compat-defun hash-table-contains-p (key table) ;; <compat-tests:hash-table-contains-p> + "Return non-nil if TABLE has an element with KEY." + (declare (side-effect-free t)) + (let ((missing '#:missing)) + (not (eq (gethash key table missing) missing)))) + (compat-defmacro static-when (condition &rest body) ;; <compat-tests:static-when> "A conditional compilation macro. Evaluate CONDITION at macro-expansion time. If it is non-nil, diff --git a/compat-tests.el b/compat-tests.el index 5d70ac5..8bfc502 100644 --- a/compat-tests.el +++ b/compat-tests.el @@ -3012,6 +3012,14 @@ (with-temp-buffer (should-equal (take 3 (widget-create 'key)) '(key :value "")))) +(ert-deftest compat-hash-table-contains-p () + (let ((h (make-hash-table :test #'equal))) + (puthash :foo t h) + (should (hash-table-contains-p :foo h)) + (should-not (hash-table-contains-p :bar h)) + (should-not (hash-table-contains-p 'missing h)) + (should-not (hash-table-contains-p '#:missing h)))) + (ert-deftest compat-copy-tree () ;; Adapted from Emacs /test/lisp/subr-tests.el ;; Check that values other than conses, vectors and records are diff --git a/compat.texi b/compat.texi index 2b81e7e..d9f9358 100644 --- a/compat.texi +++ b/compat.texi @@ -3452,6 +3452,11 @@ older than 31.1. 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 +@defmac hash-table-contains-p key table +Return non-nil if @var{table} has an element with @var{key}. +@end defmac + @c copied from lispref/control.texi @defmac static-when condition body... Test @var{condition} at macro-expansion time. If its value is |
