From: Stefan Monnier <monnier@iro.umontreal.ca>
To: Alexander Adolf <alexander.adolf@condition-alpha.com>
Cc: emacs-devel@gnu.org
Subject: Re: Thoughts on Refactoring In-Buffer Completion In message.el
Date: Tue, 19 Jul 2022 18:13:14 -0400 [thread overview]
Message-ID: <jwvtu7c93mx.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <82e662dc46347e410c0b1d871e998b00@condition-alpha.com> (Alexander Adolf's message of "Tue, 19 Jul 2022 23:41:33 +0200")
Hi, thanks,
I think this is looking pretty good.
Here are my comments to your patch.
> @@ -8244,14 +8243,51 @@ message-email-recipient-header-regexp
> :type 'regexp)
>
> (defcustom message-completion-alist
> - `((,message-newgroups-header-regexp . ,#'message-expand-group)
> - (,message-email-recipient-header-regexp . ,#'message-expand-name))
> - "Alist of (RE . FUN). Use FUN for completion on header lines matching RE.
> -FUN should be a function that obeys the same rules as those
> -of `completion-at-point-functions'."
> - :version "27.1"
> + `((,message-newgroups-header-regexp . (:category group
> + :styles (substring partial-completion)
> + :completions ,#'message-expand-group))
> + (,message-email-recipient-header-regexp . (:category email
> + :styles (substring partial-completion)
> + :completions ,#'message-expand-name)))
`group` is too generic a name (remember that those category names are
"global" so they should be meaning in any other context than
message.el).
`newsgroup` maybe?
> +:completions
> +
> + The function that provides completions, and that obeys the
> + same rules as those of `completion-at-point-functions'.
> + In-buffer completion will be performed as if
> + `completion-at-point-functions' had been set to this value."
I think this should be a completion table, not a CAPF function.
> + (_
> + (let* ((recipe (alist-get message-email-recipient-header-regexp
> + message-completion-alist))
> + (completions-function (plist-get recipe :completions)))
> + (funcall completions-function))))))))
Hmm... `recipe` should be (car alist), rather than this
weird (alist-get ...), no?
And then we should do the (skip-chars-forw/backward "^, \t\n") dance
here, as well as the metadata dance to add the `category` if specified
by `recipe`.
> +;; set completion category defaults for newsgroup names based the on
> +;; settings in `message-completion-alist'
> +(let ((recipe (alist-get message-newgroups-header-regexp
> + message-completion-alist)))
> + (pcase recipe
> + ((pred functionp)
> + (add-to-list 'completion-category-defaults
> + '(group (styles substring partial-completion))))
> + (_
> + (add-to-list 'completion-category-defaults
> + `(,(plist-get recipe :category)
> + (styles ,@(plist-get recipe :styles)))))))
I'd expect something like a `dolist` loop through
`message-completion-alist` rather than this weird (alist-get ...).
What am I missing?
Also, maybe rather than do this at top level, maybe we could add/set
`completion-category-defaults` directly from
`message-completion-function`, so it's done "more lazily" and so it
dynamically adapts to changes to `message-completion-alist`.
Tho, now that I think about it, having those styles in
`message-completion-alist` is weird: that var is a `defcustom`, hence
a user setting, yet we put it into `completion-category-defaults` which
is not meant to contain user settings (that's what
`completion-category-overrides` is for).
So maybe we should just hardcode
(add-to-list 'completion-category-defaults
'(newsgroup (styles substring partial-completion))))
(add-to-list 'completion-category-defaults
'(email (styles substring partial-completion))))
and remove the `:styles` from `message-completion-alist` since the user
should set `completion-category-overrides` instead.
[ It will also remove the problematic situation where
`message-completion-alist` contains two entries with the same
`:category` but with different `:styles`. ]
> @@ -8402,7 +8474,12 @@ message--name-table
> bbdb-responses)
> (lambda (string pred action)
> (pcase action
> - ('metadata '(metadata (category . email)))
> + ('metadata (let* ((recipe (alist-get message-email-recipient-header-regexp
> + message-completion-alist))
> + (cat (plist-get recipe :category)))
> + (pcase recipe
> + ((pred functionp) '(metadata (category . email)))
> + (_ (when cat `(metadata (category . ,cat)))))))
I think we should do this metadata dance in
`message-completion-function` (where we already have the `recipe` at
hand). Otherwise the `message-completion-alist` would be weird since
the `:category` entry would only be obeyed by those `:completions`
functions which happen to decide to obey it.
Stefan
next prev parent reply other threads:[~2022-07-19 22:13 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-23 15:26 Thoughts on Refactoring In-Buffer Completion In message.el Alexander Adolf
2022-06-25 4:35 ` Thomas Fitzsimmons
2022-06-27 15:48 ` Alexander Adolf
2022-06-25 8:22 ` Stefan Monnier
2022-06-27 16:37 ` Alexander Adolf
2022-06-28 15:49 ` Stefan Monnier
2022-07-19 21:41 ` Alexander Adolf
2022-07-19 22:13 ` Stefan Monnier [this message]
2022-07-20 20:59 ` Alexander Adolf
2022-07-20 23:59 ` Stefan Monnier
2022-07-22 13:20 ` Alexander Adolf
2022-07-22 13:58 ` Alexander Adolf
2022-07-27 21:16 ` Alexander Adolf
2022-08-17 2:45 ` Stefan Monnier
-- strict thread matches above, loose matches on Subject: below --
2022-08-13 13:11 Alexander Adolf
2022-08-17 1:54 ` Stefan Monnier
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=jwvtu7c93mx.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).