emacs-devel
[Top][All Lists]
Advanced

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

Re: Allowing completion sources to customize completion display


From: Eshel Yaron
Subject: Re: Allowing completion sources to customize completion display
Date: Thu, 23 Nov 2023 09:25:19 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Spencer Baugh <sbaugh@janestreet.com> writes:

> If I have multiple sources for completion active at once, I might prefer
> different completion sources to be displayed differently.
>
> ...
>
> But the same completion-in-region-function and UI has to be used
> regardless of whether I'm getting symbol-completion or block-completion
> - I don't see a way to change completion-in-region-function based on the
> source.
>
> Maybe we should add one?

FWIW I had similar thoughts just the other day.  Allowing capfs to
request a certain selection UI makes sense in some situations, because
sometimes the most appropriate UI may depend on the results of a
specific capf.  For example, say we have a legacy completion command,
e.g. `ispell-complete-word`, that we want to port to a capf.  But the
legacy completion command comes with its bespoke completion selection
UI, so it might be desirable to have the new capf mimic the legacy UI
during the transition phase, without affecting other capfs, so other
capfs still use the regular UI when they take effect.

OTOH, IMO it's better to keep the UI as consistent and predictable as
possible, so I would avoid using such a capability too liberally.

> Some possibilities:
> - Maybe completion table metadata could just include a
>   completion-in-region-function to use?
>
> - Maybe completion-category-overrides could change
>   completion-in-region-function based on the category?
>
> - Maybe something else entirely?

How about something like the following?  That seems simple enough and
gives individual capfs full discretion to specify their selection UI.

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 5c12d9fc914..ff5472040d3 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -2823,7 +2823,10 @@ completion-at-point
                (lambda ()
                  ;; We're still in the same completion field.
                  (let ((newstart (car-safe (funcall hookfun))))
-                   (and newstart (= newstart start))))))
+                   (and newstart (= newstart start)))))
+              (completion-in-region-function
+               (or (plist-get plist :completion-in-region-function)
+                   completion-in-region-function)))
          (completion-in-region start end collection
                                (plist-get plist :predicate))))
       ;; Maybe completion already happened and the function returned t.




reply via email to

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