From: Juri Linkov <juri@linkov.net>
To: Daniel Mendler <mail@daniel-mendler.de>
Cc: 68214@debbugs.gnu.org
Subject: bug#68214: Completion sorting customization by category
Date: Wed, 03 Jan 2024 18:07:50 +0200 [thread overview]
Message-ID: <868r5630ft.fsf@mail.linkov.net> (raw)
In-Reply-To: <ab10a89f-4223-415b-8949-57b1b7a0b444@daniel-mendler.de> (Daniel Mendler's message of "Wed, 3 Jan 2024 08:20:37 +0100")
[-- Attachment #1: Type: text/plain, Size: 1591 bytes --]
> Would it make sense to define a general
> `completion-metadata-override-get` function instead of
> `completion--display-sort-function`?
Thanks for the suggestion, Daniel. This is used now in a new patch below.
> This function could be used to look up the other meta data
> functions too, `display-sort-function`, `annotation-function`,
> `affixation-function`, `group-function`, etc.
All these meta data functions could be added later to
completion-category-overrides after pushing the current patch.
> (defun completion-metadata-override-get (metadata prop)
> (if-let ((cat (completion-metadata-get metadata 'category))
> (over (completion--category-override cat prop)))
> (cdr over)
> (completion-metadata-get metadata prop)))
>
> I suggest to use `if-let` instead of `let*`, such that an override is
> not retrieved if the category is nil.
Maybe customization of completion-category-overrides could support
a catch-all category `nil` for completions without metadata, like
e.g. `nil` can be used in .dir-locals.el as a catch-all for all modes.
But I'm not sure how useful this would be.
> Besides that, in the `completion-category-overrides`, you use
> `completion--sorting-type` for the `display-sort-function`, while it
> should just be `function`.
A new patch doesn't use anymore `completion--sorting-type`
since there is a small difference between customization choices
in `completions-sort` and `completion-category-overrides`:
`completion-category-overrides` needs the value `identity`
that prevents a fallback to `completions-sort` as `nil` does.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: completion-metadata-override-get.patch --]
[-- Type: text/x-diff, Size: 2964 bytes --]
diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index fa2dcb4f698..ac07b92acb8 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -1148,10 +1153,16 @@ completion-category-defaults
(defcustom completion-category-overrides nil
"List of category-specific user overrides for completion styles.
+
Each override has the shape (CATEGORY . ALIST) where ALIST is
an association list that can specify properties such as:
- `styles': the list of `completion-styles' to use for that category.
- `cycle': the `completion-cycle-threshold' to use for that category.
+- `display-sort-function': where `nil' means to use either the sorting
+function from metadata or if it's nil then fall back to `completions-sort';
+`identity' means to not use any sorting to keep the original order;
+and other values are the same as in `completions-sort'.
+
Categories are symbols such as `buffer' and `file', used when
completing buffer and file names, respectively.
@@ -1171,12 +1182,26 @@ completion-category-overrides
,completion--styles-type)
(cons :tag "Completion Cycling"
(const :tag "Select one value from the menu." cycle)
- ,completion--cycling-threshold-type))))
+ ,completion--cycling-threshold-type)
+ (cons :tag "Completion Sorting"
+ (const :tag "Select one value from the menu."
+ display-sort-function)
+ (choice (const :tag "Use default" nil)
+ (const :tag "No sorting" identity)
+ (const :tag "Alphabetical sorting" alphabetical)
+ (const :tag "Historical sorting" historical)
+ (function :tag "Custom function"))))))
(defun completion--category-override (category tag)
(or (assq tag (cdr (assq category completion-category-overrides)))
(assq tag (cdr (assq category completion-category-defaults)))))
+(defun completion-metadata-override-get (metadata prop)
+ (if-let ((cat (completion-metadata-get metadata 'category))
+ (over (completion--category-override cat prop)))
+ (cdr over)
+ (completion-metadata-get metadata prop)))
+
(defun completion--styles (metadata)
(let* ((cat (completion-metadata-get metadata 'category))
(over (completion--category-override cat 'styles)))
@@ -2522,7 +2547,7 @@ minibuffer-completion-help
(aff-fun (or (completion-metadata-get all-md 'affixation-function)
(plist-get completion-extra-properties
:affixation-function)))
- (sort-fun (completion-metadata-get all-md 'display-sort-function))
+ (sort-fun (completion-metadata-override-get all-md 'display-sort-function))
(group-fun (completion-metadata-get all-md 'group-function))
(mainbuf (current-buffer))
;; If the *Completions* buffer is shown in a new
next prev parent reply other threads:[~2024-01-03 16:07 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-02 17:07 bug#68214: Completion sorting customization by category Juri Linkov
2024-01-03 7:20 ` Daniel Mendler
2024-01-03 16:07 ` Juri Linkov [this message]
2024-01-03 17:12 ` Daniel Mendler
2024-01-04 17:21 ` Juri Linkov
2024-01-05 7:59 ` Juri Linkov
2024-01-05 8:33 ` Daniel Mendler
2024-01-06 17:33 ` Juri Linkov
2024-01-06 17:59 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-07 18:05 ` Juri Linkov
2024-01-07 18:37 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-09 17:59 ` Juri Linkov
2024-01-09 18:14 ` Juri Linkov
2024-01-09 18:31 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-10 7:35 ` Juri Linkov
2024-01-10 8:53 ` Daniel Mendler via Bug reports for GNU Emacs, the Swiss army knife of text editors
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=868r5630ft.fsf@mail.linkov.net \
--to=juri@linkov.net \
--cc=68214@debbugs.gnu.org \
--cc=mail@daniel-mendler.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).