emacs-devel
[Top][All Lists]
Advanced

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

Re: [ELPA] New package: company-eudc


From: Stefan Monnier
Subject: Re: [ELPA] New package: company-eudc
Date: Wed, 05 May 2021 16:36:03 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> EUDC does not contain any adapters/back-ends for other packages. And it
> would have seemed odd to me, if a basic package contained code to adapt
> itself to another package, which builds on top of itself.

The "completion backends" used to be distributed with the Company
package, because that's what you need to do to get things started, but
fundamentally Company is a piece of infrastructure, and every backend
belongs with the package for which it provides completions rather than
with Company.

>>>> - Why make it a Company backend instead of a CAPF function (since
>>>>   Company knows how to use CAPF functions as well)?
>>>> [...]
>>> That's one of the next things on my to-do list. ;-)
>> I think it would make a lot of sense to add such a CAPF directly to
>> `eudc.el`, and then to hook it into `message.el`.
> Agreed; that's the plan (adding a new function to EUDC, which in turn
> can be added to `completion-at-point-functions`).

See below for a 100% untested first step.

>> I must admit, I don't know where `company-eudc-expand-inline` would end
>> up in that scenario, tho :-(
>> [...]
>
> Indeed; `company-eudc-expand-inline` is to cater for the particularity
> of EUDC queries potentially taking very long. I have yet to research
> whether CAPF has a similar function to start completion with a single,
> specific back-end only, and which can be bound to a key.

CAPF is only a backend, whereas "start completion" presumes a command
and that would inevitably be part of the UI.

> A `let` statement shadowing `completion-at-point-functions` could be
> a (slightly hacky though) way of achieving this.

Yes, that would be the natural way to do that, but the question is what
to put within this let-binding: you can either call
`company-begin-backend` or `completion-at-point`, or `corfu-<something>`,
or `auto-complete-<something>`, depending on the favorite UI of this user.

> Another issue to solve (showing off my lack of knowledge of CAPF here)
> is providing the EUDC suggestions in suitable message header fields
> only.

I think the patch below shows how this is done (I don't have an EUDC
setup here to test the code, sorry).

Should we add the company-specific code for now in `eudc.el` and then
work to replace it with a CAPF backend (bringing it to feature-parity
with the Company code will probably take some time and potentially
changes elsewhere, which is why I suggest to install the Company code
now even though the intention is to make it redundant).


        Stefan


diff --git a/company-eudc.el b/company-eudc.el
index 52dd21ce08..f89626225c 100644
--- a/company-eudc.el
+++ b/company-eudc.el
@@ -102,6 +102,36 @@ For the semantics of COMMAND, ARG, and IGNORED see 
`company-backends'."
     (`sorted t)
     (`ignore-case t)))
 
+(defvar eudc-completion-table
+  ;; FIXME: This belongs in `eudc.el'.
+  (completion-table-dynamic
+   (lambda (prefix)
+     ;; FIXME: completion tables can only do "prefix completion" so the
+     ;; `split-string' below won't give the intended result.
+     ;; The intended behavior is normally instead provided by
+     ;; a `completion-style' such as `orderless' which would call this
+     ;; completion tables several times (once per "word").
+     ;; A possible other solution is to use the "backend" (aka "passthrough")
+     ;; completion style which lets the completion table provide its own
+     ;; completion style.
+     (eudc-query-with-words (split-string prefix "[ \t]+")))))
+
+(defun message-eudc-capf ()
+  ;; FIXME: This belongs in `message.el' and is probably redundant there
+  ;; because there's already code doing that for other
+  ;; completion tables (bbdb, ecomplete, ...).
+  (let ((end (point))
+       (start (save-excursion
+                (if (re-search-backward "\\([:,]\\|^\\)[ \t]*"
+                                        (point-at-bol) 'move)
+                    (goto-char (match-end 0)))
+                (point))))
+    (when (let ((case-fold-search t))
+           (looking-back
+            "^\\([^ :]*-\\)?\\(To\\|B?Cc\\|From\\|Reply-to\\):.*? 
*\\([^,;]*\\)"
+            (line-beginning-position)))
+      (list start end eudc-completion-table))))
+
 ;;;###autoload
 (defun company-eudc-activate-autocomplete ()
   "Provide `company-eudc' completions under company mode control.




reply via email to

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