unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Alexander Adolf <alexander.adolf@condition-alpha.com>
Cc: emacs-devel@gnu.org
Subject: Re: [ELPA] New package: company-eudc
Date: Wed, 05 May 2021 16:36:03 -0400	[thread overview]
Message-ID: <jwvim3xgcxj.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <bc0ee13250b16a17685c45cd5f8e4394@condition-alpha.com> (Alexander Adolf's message of "Wed, 05 May 2021 21:47:49 +0200")

> 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	other threads:[~2021-05-05 20:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-30 14:19 [ELPA] New package: company-eudc Alexander Adolf
2021-04-30 17:30 ` Stefan Monnier
2021-05-03 15:52   ` Alexander Adolf
2021-05-03 23:54     ` Stefan Monnier
2021-05-05 19:47       ` Alexander Adolf
2021-05-05 20:36         ` Stefan Monnier [this message]

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=jwvim3xgcxj.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=alexander.adolf@condition-alpha.com \
    --cc=emacs-devel@gnu.org \
    /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).