bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#68214: Completion sorting customization by category


From: Daniel Mendler
Subject: bug#68214: Completion sorting customization by category
Date: Tue, 09 Jan 2024 19:31:02 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Juri Linkov <juri@linkov.net> writes:

>> Now I tried to use a more user-friendly let-binding of
>> 'completion-extra-properties' like below, but then discovered
>> that it doesn't work for the category.
>>
>> Maybe 'completion-metadata-get' could try to get a category
>> from 'completion-extra-properties' as well?
>
> Sorry, this was imprecise.  I meant another layer of indirection:
> to get a category from 'completion-extra-properties'
> to be able to get 'display-sort-function' by category.

Indeed. I forgot about this indirection. This should be added as well.
Not sure if there a significantly easier way to write this than as
follows with a separate helper function?

(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
`completion-category-overrides' and
`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 (completion--metadata-get-1 'category metadata))
           (over (completion--category-override cat prop)))
      (cdr over)
    (completion--metadata-get-1 prop metadata)))





reply via email to

[Prev in Thread] Current Thread [Next in Thread]