]> git.eshelyaron.com Git - emacs.git/commitdiff
Support :category in completion-extra-properties (bug#68214)
authorJuri Linkov <juri@linkov.net>
Wed, 10 Jan 2024 07:34:47 +0000 (09:34 +0200)
committerEshel Yaron <me@eshelyaron.com>
Wed, 10 Jan 2024 19:10:18 +0000 (20:10 +0100)
* doc/lispref/minibuf.texi (Completion Variables): Add :category
to the table of completion-extra-properties.

* lisp/minibuffer.el (completion--metadata-get-1): New internal function.
(completion-metadata-get): Use 'completion--metadata-get-1'.
Thanks to Daniel Mendler <mail@daniel-mendler.de>.
(completion-extra-properties): Mention :category in the docstring.

* lisp/calendar/calendar.el (calendar-read-date): Use more
user-friendly let-binding of completion-extra-properties
with :category.

(cherry picked from commit 7755f7172748b2d337fa53434c1f678269cc5c45)

doc/lispref/minibuf.texi
etc/NEWS
lisp/calendar/calendar.el
lisp/minibuffer.el

index 296fa90b0afc910ff9dfc4f075d4c5ece4428b6b..2e77f252362aaabcb05e5f17e5e7571757f7d0c3 100644 (file)
@@ -2038,6 +2038,12 @@ completion commands.  Its value should be a list of property and value
 pairs.  The following properties are supported:
 
 @table @code
+@item :category
+The value should be a symbol describing what kind of text the
+completion function is trying to complete.  If the symbol matches one
+of the keys in @code{completion-category-overrides}, the usual
+completion behavior is overridden.  @xref{Completion Variables}.
+
 @item :annotation-function
 The value should be a function to add annotations in the completions
 buffer.  This function must accept one argument, a completion, and
index 5a7cfefb1002c2385806011edd54d8c219f425bc..3ccb95be0bb8632d09f35250caa8590cd06bb976 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -785,8 +785,8 @@ command, and completion styles in general.
 
 +++
 *** 'completion-extra-properties' supports more metadata.
-The new supported completion properties are 'group-function',
-'display-sort-function', 'cycle-sort-function'.
+The new supported completion properties are 'category',
+'group-function', 'display-sort-function', 'cycle-sort-function'.
 
 ** Pcomplete
 
index e01d5d792a6d8f3986d873cac45695bb79b42139..2c3e7d283012478013ccf10ebe1176198d52791d 100644 (file)
@@ -2337,14 +2337,12 @@ returned is (month year)."
          (defmon (aref month-array (1- (calendar-extract-month default-date))))
          (completion-ignore-case t)
          (month (cdr (assoc-string
-                      (completing-read
-                       (format-prompt "Month name" defmon)
-                       (lambda (string pred action)
-                        (if (eq action 'metadata)
-                            '(metadata (category . calendar-month))
-                          (complete-with-action
-                            action (append month-array nil) string pred)))
-                       nil t nil nil defmon)
+                      (let ((completion-extra-properties
+                             '(:category calendar-month)))
+                        (completing-read
+                         (format-prompt "Month name" defmon)
+                         (append month-array nil)
+                         nil t nil nil defmon))
                       (calendar-make-alist month-array 1) t)))
          (defday (calendar-extract-day default-date))
          (last (calendar-last-day-of-month month year)))
index a90ba93f9ae370d04c66d4913caf8eb7cf89fb0d..d99905c36279d8ab8b0935e72c900df10e6ee167 100644 (file)
@@ -153,6 +153,14 @@ The metadata of a completion table should be constant between two boundaries."
                        minibuffer-completion-table
                        minibuffer-completion-predicate))
 
+(defun completion--metadata-get-1 (metadata prop)
+  (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 completion-metadata-get (metadata prop)
   "Get property PROP from completion METADATA.
 If the metadata specifies a completion category, the variables
@@ -164,15 +172,10 @@ 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))
+           (cat (completion--metadata-get-1 metadata 'category))
            (over (completion--category-override cat prop)))
       (cdr over)
-    (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)))))))))
+    (completion--metadata-get-1 metadata prop)))
 
 (defun complete-with-action (action collection string predicate)
   "Perform completion according to ACTION.
@@ -2549,6 +2552,9 @@ candidates."
   "Property list of extra properties of the current completion job.
 These include:
 
+`:category': the kind of objects returned by `all-completions'.
+   Used by `completion-category-overrides'.
+
 `:annotation-function': Function to annotate the completions buffer.
    The function must accept one argument, a completion string,
    and return either nil or a string which is to be displayed