]> git.eshelyaron.com Git - emacs.git/commitdiff
Support more metadata properties in completion-extra-properties (bug#68214)
authorJuri Linkov <juri@linkov.net>
Tue, 9 Jan 2024 17:57:50 +0000 (19:57 +0200)
committerJuri Linkov <juri@linkov.net>
Tue, 9 Jan 2024 17:57:50 +0000 (19:57 +0200)
* doc/lispref/minibuf.texi (Completion Variables): Add
to the table of completion-extra-properties new items:
`group-function', `display-sort-function', `cycle-sort-function'.

* lisp/icomplete.el (icomplete--augment): Remove unnecessary
plist-get from completion-extra-properties since now
completion-metadata-get does this.

* lisp/minibuffer.el (completion-metadata-get): Use plist-get to
get prop from completion-extra-properties and cache the keyword.
Thanks to Daniel Mendler <mail@daniel-mendler.de>.
(completion-extra-properties): Mention new properties in docstring.
(minibuffer-completion-help): Remove unnecessary
plist-get from completion-extra-properties since now
completion-metadata-get does this.

* lisp/net/eww.el (eww-switch-to-buffer):
* test/lisp/minibuffer-tests.el (completions-affixation-navigation-test):
Unquote lambda in completion-extra-properties.

doc/lispref/minibuf.texi
etc/NEWS
lisp/icomplete.el
lisp/minibuffer.el
lisp/net/eww.el
test/lisp/minibuffer-tests.el

index 8d25a53161ed15f8365a0abe75a0adfa95d5ed6b..18df44256a8e5cfac83fd59a035dccf3cdfb15e7 100644 (file)
@@ -1928,6 +1928,15 @@ element of the returned list must be a three-element list, the
 completion, a prefix string, and a suffix string.  This function takes
 priority over @code{:annotation-function}.
 
+@item :group-function
+The function to group completions.
+
+@item :display-sort-function
+The function to sort entries in the @file{*Completions*} buffer.
+
+@item :cycle-sort-function
+The function to sort entries when cycling.
+
 @item :exit-function
 The value should be a function to run after performing completion.
 The function should accept two arguments, @var{string} and
index f4d008ee2d6d2f1d73a0383e1649c82655bb1d41..fcec2ca715a45dd03c8dd1bb34d234d5baf754b2 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -752,6 +752,11 @@ The new supported completion properties are 'cycle-sort-function',
 'completion-category-overrides' that will override the properties
 defined in completion metadata.
 
++++
+*** 'completion-extra-properties' supports more metadata.
+The new supported completion properties are 'group-function',
+'display-sort-function', 'cycle-sort-function'.
+
 ** Pcomplete
 
 ---
index d49714f320445f86d8738fe8c3b6ea4508b5633f..aa3c5680a7e1c69f102c3495e307df96d84f5a53 100644 (file)
@@ -789,10 +789,8 @@ and SUFFIX, if non-nil, are obtained from `affixation-function' or
 `group-function'.  Consecutive `equal' sections are avoided.
 COMP is the element in PROSPECTS or a transformation also given
 by `group-function''s second \"transformation\" protocol."
-  (let* ((aff-fun (or (completion-metadata-get md 'affixation-function)
-                      (plist-get completion-extra-properties :affixation-function)))
-         (ann-fun (or (completion-metadata-get md 'annotation-function)
-                      (plist-get completion-extra-properties :annotation-function)))
+  (let* ((aff-fun (completion-metadata-get md 'affixation-function))
+         (ann-fun (completion-metadata-get md 'annotation-function))
          (grp-fun (and completions-group
                        (completion-metadata-get md 'group-function)))
          (annotated
index 04b36f03d1172c2fd105a1eb5d95a31a095a04ae..42d04e0ff9671ea033f1091f8392f7760d13ee39 100644 (file)
@@ -151,15 +151,25 @@ The metadata of a completion table should be constant between two boundaries."
                        minibuffer-completion-predicate))
 
 (defun completion-metadata-get (metadata prop)
-  "Get PROP from completion METADATA.
+  "Get property PROP from completion METADATA.
 If the metadata specifies a completion category, the variables
 `completion-category-overrides' and
-`completion-category-defaults' take precedence."
+`completion-category-defaults' take precedence for
+category-specific overrides.  If the completion metadata does not
+specify the property, the `completion-extra-properties' plist is
+consulted.  Note that the keys of the
+`completion-extra-properties' plist are keyword symbols, not
+plain symbols."
   (if-let (((not (eq prop 'category)))
            (cat (alist-get 'category metadata))
            (over (completion--category-override cat prop)))
       (cdr over)
-    (alist-get prop metadata)))
+    (or (alist-get prop metadata)
+        (plist-get completion-extra-properties
+                   ;; Cache the keyword
+                   (or (get prop 'completion-extra-properties--keyword)
+                       (put prop 'completion-extra-properties--keyword
+                            (intern (concat ":" (symbol-name prop)))))))))
 
 (defun complete-with-action (action collection string predicate)
   "Perform completion according to ACTION.
@@ -2447,6 +2457,15 @@ These include:
    `:annotation-function' when both are provided, so only this
    function is used.
 
+`:group-function': Function for grouping the completion candidates.
+
+`:display-sort-function': Function to sort entries in *Completions*.
+
+`:cycle-sort-function': Function to sort entries when cycling.
+
+See more information about these functions above
+in `completion-metadata'.
+
 `:exit-function': Function to run after completion is performed.
 
    The function must accept two arguments, STRING and STATUS.
@@ -2569,12 +2588,8 @@ The candidate will still be chosen by `choose-completion' unless
                                            base-size md
                                            minibuffer-completion-table
                                            minibuffer-completion-predicate))
-             (ann-fun (or (completion-metadata-get all-md 'annotation-function)
-                          (plist-get completion-extra-properties
-                                     :annotation-function)))
-             (aff-fun (or (completion-metadata-get all-md 'affixation-function)
-                          (plist-get completion-extra-properties
-                                     :affixation-function)))
+             (ann-fun (completion-metadata-get all-md 'annotation-function))
+             (aff-fun (completion-metadata-get all-md 'affixation-function))
              (sort-fun (completion-metadata-get all-md 'display-sort-function))
              (group-fun (completion-metadata-get all-md 'group-function))
              (mainbuf (current-buffer))
index 22f07cbc5b4b71092025fb2c5ed30d281c8bcf67..6c46ef0fedb0dfb68a54b90f47174371c64f13cc 100644 (file)
@@ -2064,9 +2064,10 @@ If CHARSET is nil then use UTF-8."
   "Prompt for an EWW buffer to display in the selected window."
   (interactive nil eww-mode)
   (let ((completion-extra-properties
-         '(:annotation-function (lambda (buf)
-                                  (with-current-buffer buf
-                                    (format " %s" (eww-current-url))))))
+         `(:annotation-function
+           ,(lambda (buf)
+              (with-current-buffer buf
+                (format " %s" (eww-current-url))))))
         (curbuf (current-buffer)))
     (pop-to-buffer-same-window
      (read-buffer "Switch to EWW buffer: "
index 6dc15d0801f61900dc2daf3f39b8fa6e9f9631a9..c1fe3032cb5e1380c135eaa8019616b43b7ce95a 100644 (file)
 
 (ert-deftest completions-affixation-navigation-test ()
   (let ((completion-extra-properties
-         '(:affixation-function
-           (lambda (completions)
-             (mapcar (lambda (c)
-                       (list c "prefix " " suffix"))
-                     completions)))))
+         `(:affixation-function
+           ,(lambda (completions)
+              (mapcar (lambda (c)
+                        (list c "prefix " " suffix"))
+                      completions)))))
     (completing-read-with-minibuffer-setup
         '("aa" "ab" "ac")
       (insert "a")