summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2025-03-06 18:21:55 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2025-03-06 18:21:55 +0100
commitc833f2edcb68466bef53a6ea104371a26d6bc0c8 (patch)
treeb76475aa20ea2e908f7c8f32d33751b988c95ead
parentbdae1151e87cb877abf4bdf81ec8dd441187a5f8 (diff)
compat-31: New function completion-table-with-metadata
-rw-r--r--NEWS.org1
-rw-r--r--compat-31.el11
-rw-r--r--compat-tests.el7
3 files changed, 19 insertions, 0 deletions
diff --git a/NEWS.org b/NEWS.org
index 6145d6b..31b180e 100644
--- a/NEWS.org
+++ b/NEWS.org
@@ -8,6 +8,7 @@
- compat-31: New functions =minusp= and =plusp=.
- compat-31: New macros =incf= and =decf=.
- compat-31: New function =color-blend=.
+- compat-31: New function =completion-table-with-metadata=.
- 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 84ff7bf..59ea412 100644
--- a/compat-31.el
+++ b/compat-31.el
@@ -83,5 +83,16 @@ For instance:
(push (+ (* (nth i a) alpha) (* (nth i b) (- 1 alpha))) blend))
(nreverse blend)))
+;;;; Defined in minibuffer.el
+
+(compat-defun completion-table-with-metadata (table metadata) ;; <compat-tests:completion-table-with-metadata>
+ "Return new completion TABLE with METADATA.
+METADATA should be an alist of completion metadata. See
+`completion-metadata' for a list of supported metadata."
+ (lambda (string pred action)
+ (if (eq action 'metadata)
+ `(metadata . ,metadata)
+ (complete-with-action action table string pred))))
+
(provide 'compat-31)
;;; compat-31.el ends here
diff --git a/compat-tests.el b/compat-tests.el
index fedbda2..5b12baf 100644
--- a/compat-tests.el
+++ b/compat-tests.el
@@ -3055,6 +3055,13 @@
(let ((completion-category-overrides '((compat-test (a . 10)))))
(should-equal 10 (compat-call completion-metadata-get md 'a))))))
+(ert-deftest compat-completion-table-with-metadata ()
+ (let* ((md '((category . text)))
+ (table (completion-table-with-metadata '("word") md))
+ (md2 (completion-metadata "" table nil)))
+ (should-equal (car md2) 'metadata)
+ (should (eq (cdr md2) md))))
+
(ert-deftest compat-untrusted-content ()
(should (local-variable-if-set-p 'untrusted-content)))