emacs-devel
[Top][All Lists]
Advanced

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

Re: Updating *Completions* as you type


From: Juri Linkov
Subject: Re: Updating *Completions* as you type
Date: Wed, 22 Nov 2023 09:51:44 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu)

>>> - Again, the user is still able to configure the display-sort-function
>>>   by configuring the individual completion table.
>>
>> Does this mean that every individual completion table should have
>> a separate user option?
>
> No: only the completion tables which specify a display-sort-function in
> their metadata.  All such completion tables should have a user option to
> configure that display-sort-function.

How then users could change the sorting order for individual tables
that don't specify a display-sort-function to use an order different
from completions-sort?

> Well, yes.  So then we agree that a user option for an individual
> completion table, if it exists, should take precedence over
> completion-category-overrides?

The problem is that we can't distinguish two cases:

1. when display-sort-function is hard-coded in metadata
   by the author of the completion table;
2. when display-sort-function in metadata
   gets the value from the user option.

Since we can't distinguish these cases, then it makes more sense
when completion-category-overrides overrides everything:

  (alist-get 'display-sort-function (alist-get category 
completion-category-overrides))
  (alist-get 'display-sort-function metadata) ;; metadata with/out individual 
options
  (alist-get 'display-sort-function (alist-get category 
completion-category-defaults))

There is no problem with this because completion-category-overrides
is a user option as well, so everything still is under user control.

> So then we're only disagreeing over whether such options should exist?

Yes, I think we should add individual options only in exceptional cases.

> These individual options would also provide a natural place to document
> behavior like "if you configure the display-sort-function for buffer
> completion to 'identity, then the buffer sort order will match
> (buffer-list)".  But the user could still make use of that information
> by configuring the category.

I agree that an option with documentation could help in such cases
when a non-trivial sorting function is provided for a completion table.

>> I see no need to add individual options as all.  Every completion table
>> that significantly differs from other tables so that it needs a separate
>> display-sort-function, could provide a separate category.  For example,
>> there is a category 'buffer'.  If 'switch-to-buffer' needs another
>> display-sort-function it could provide a category 'buffer-for-switching'.
>
> That won't work with the scenario I described before with sorting
> file-name completion by mtime, where changing the sorting requires also
> changing the completion table.

I agree that individual options are required in such rare cases when
their values affect the completion table and its formatting.

> Also, this would require adding a category for essentially every
> completion table.  For example, I see that read-from-kill-ring specifies
> a display-sort-function, currently set to 'identity.

It's much simpler to add an extra line with a category.

> If we wanted to make that configurable, it seems much easier to just do
>
>           (if (eq action 'metadata)
>               ;; Keep sorted by recency
> -             '(metadata (display-sort-function . identity))
> +             `(metadata (display-sort-function . ,read-from-kill-ring-sort))
>             (complete-with-action action completions string pred)))

This is an incomplete patch, there should be also a dozen of lines
with defcustom, its docstring, the version number and a list
of choices, etc.  And all this for a very small percent of users
who would like to change this order.  This is too wasteful.
It would be much more efficient to allow doing the same
by customizing completion-category-overrides.



reply via email to

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