emacs-devel
[Top][All Lists]
Advanced

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

Re: Simplification of `affixation-function`


From: Daniel Mendler
Subject: Re: Simplification of `affixation-function`
Date: Tue, 27 Apr 2021 20:40:40 +0200

On 4/27/21 8:11 PM, Juri Linkov wrote:
> affixation-function is called immediately after sorting candidates.
> format-function could be called immediately before inserting candidates
> only when they are displayed.

I don't see why using the affixation function is not possible for the
transformation. The affixation function is basically just called right
before insertion, right before the candidates are passed to
`display-completion-list`. I don't see the need for an additional format
function here.

>> why not change the affixation function then such that it only returns a
>> single string? We could do that but I think it is valuable to separate
>> prefix/candidate/suffix for display in a tablist.
> 
> Because completion--insert-strings needs to highlight the untransformed
> candidate with mouse-face=highlight.

Yes, that's right. `choose-completion` uses the mouse highlight to
locate the candidate. But this trick must be relaxed as soon as you
bring transformed candidates into the game. In my `group-function` patch
I am attaching the untransformed candidate to the property
`completion--string`, which is then read by `choose-completion`. Note
that the highlighting is still preserved, if no grouping/transformation
is used. In that case the highlighting still reflects the untransformed
candidate. As such the change is backward compatible as long as
grouping/transformation is guarded behind a feature flag.
>> The group function candidate transformation is also to be distinguished
>> from a potential transformation performed by a
>> format/affixation-function, since the group transformation should be
>> only applied when grouping is active. It is therefore better to keep the
>> transformations separate.
> 
> API would be more clear when transformation is separated from grouping.
> So if there is no need to transform group candidates, only group-function
> is provided.  When group candidates need transformation, then additionally
> format/affixation-function can be provided as well.

I considered exactly this, but it is problematic. The idea of grouping
is that you can optionally turn it on or optionally support it in the
UI. The grouping transformation should only be applied when grouping is
enabled. This is important since the grouping candidate transformation
may remove some redundant part of the candidate which is then displayed
in the group title. This means we cannot conflate the grouping candidate
transformation with the `affixation/format-function`.

We can either go with two functions
`group-sort-function+group-transform-function`, where
`group-transform-function` is optional or with the boolean `transform`
argument I am having now in the patch. I think it is easier to have a
single `group-function` instead of splitting this small feature into two
functions.

Daniel



reply via email to

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