From c833f2edcb68466bef53a6ea104371a26d6bc0c8 Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Thu, 6 Mar 2025 18:21:55 +0100 Subject: compat-31: New function completion-table-with-metadata --- NEWS.org | 1 + compat-31.el | 11 +++++++++++ compat-tests.el | 7 +++++++ 3 files changed, 19 insertions(+) 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) ;; + "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))) -- cgit v1.0