unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Daniel Mendler <mail@daniel-mendler.de>
Cc: joaotavora@gmail.com, dgutov@yandex.ru, monnier@iro.umontreal.ca,
	48841@debbugs.gnu.org, 47711@debbugs.gnu.org
Subject: bug#47711: bug#48841: [PATCH] Add new `completion-filter-completions` API and deferred highlighting
Date: Thu, 12 Aug 2021 11:00:11 +0300	[thread overview]
Message-ID: <837dgrdrec.fsf@gnu.org> (raw)
In-Reply-To: <aa52bb9b-2adb-e579-6da1-d784e57e3c68@daniel-mendler.de> (message from Daniel Mendler on Wed, 11 Aug 2021 16:16:57 +0200)

[I removed emacs-devel from the CC list, please don't cross-post to
both emacs-devel and the bug tracker.]

> From: Daniel Mendler <mail@daniel-mendler.de>
> Date: Wed, 11 Aug 2021 16:16:57 +0200
> Cc: 48841@debbugs.gnu.org, Dmitry Gutov <dgutov@yandex.ru>,
>  João Távora <joaotavora@gmail.com>,
>  Stefan Monnier <monnier@iro.umontreal.ca>, 47711@debbugs.gnu.org
> 
> I prepared a patch which provides the API
> `completion-filter-completions`. This function supports deferred
> highlighting and returns additional data with the list of matching
> completion candidates. The API supersedes the existing function
> `completion-all-completions`.

Thanks.  The discussion of this is still going on, and I don't
consider myself an expert in this area of Emacs, so below please find
only comments for minor formatting and documentation aspects.

> Add a new `completion-filter-completions` API, which supersedes
> `completion-all-completions`.  The new API returns the matching
> completion candidates and additional data.  The return value is an
> alist, with the keys `completions`, `base`, `end` and `highlight`.
> The API can be extended in a backward compatible way later on thanks
> to the use of an alist as return value.

Please don't use Markdown-style quoting `like this` in our comments
and log messages.  We quote 'like this' in these places.

> The `completions` value is the list of completion strings *without*
> applied highlighting.  The completion strings are returned unmodified,
> which avoids allocations and results in performance gains for

This is unclear: how can you return a list of strings which you
produce without allocating the strings?

>         The value `base` is the base position of the completion.

"Base position" where, or relative to what object?

> Correspondingly the value `end` specifies the end position of the
> completion counted from the beginning of the input strng.

So the base position is also relative to the beginning of the input
string?  If so, please say so explicitly.

>                                                    Finally the
> `highlight` value is a function taking a list of completion strings
> and returns a new list of new strings with highlighting applied.

If you say "taking a list...", then for consistent style please also
say "...and returning a new list...".

> A continously updating UI can use the highlighting function to apply
> highlighting only to the visible completions.

Not, "visible", but "displayed", right?  So I'd rephrase

  ...to apply highlighting only to the completions that are actually
  displayed.

> (completion-basic-all-completions,
> completion-emacs21-all-completions,
> completion-emacs22-all-completions): Use it.

That's incorrect format, I guess you did it by hand rather than
letting change-log-mode do it for you?  The correct format looks like
this:

  (completion-basic-all-completions)
  (completion-emacs21-all-completions)
  (completion-emacs22-all-completions): use it.

IOW, each line ends with a closing parentheses, not a comma.

> +(defvar completion--filter-completions nil
> +  "Enable the new completions return value format.

Using genitive construction should be limited to just 2 words.  Here
you have 4, which produces an awkward, hard to interpret phrase.
Suggest to reword:

  If non-nil, return completions in `completion-filter-completions' format.

Note that I also dropped the "new" part (which generally doesn't stand
the test of time), and instead gave a hint as to what that format is.

Btw, why is this an internal variable?  Shouldn't all completion
styles ideally support it?  If so, it should be a public variable,
documented in the ELisp manual.  And the name should also end with -p,
since it's a boolean.  How about completion-filter-completions-format-p?

> +            New completion style functions may always return their
> +results in the new alist format, since `completion-all-completions'
> +transparently converts back to the old improper list of completions
> +with base size in the last cdr.")

"may" and "always" are a kind of contradiction.

Also, I'd drop the "improper" part, as it sounds like a derogatory
adjective.

>  (defun completion-try-completion (string table pred point &optional metadata)
>    "Try to complete STRING using completion table TABLE.
>  Only the elements of table that satisfy predicate PRED are considered.
> -POINT is the position of point within STRING.
> -The return value can be either nil to indicate that there is no completion,
> -t to indicate that STRING is the only possible completion,
> -or a pair (NEWSTRING . NEWPOINT) of the completed result string together with
> -a new position for point."
> +POINT is the position of point within STRING.  The return value can be
> +either nil to indicate that there is no completion, t to indicate that
> +STRING is the only possible completion, or a pair (NEWSTRING . NEWPOINT)
> +of the completed result string together with a new position for point.
> +The METADATA may be modified by the completion style."

Here you changed whitespace by filling, and that ruined the
intentionally formatted doc string, which made it easy to find the
various forms of the return value and the important parts of the doc
string.  Please keep the original formatting.

>  (defun completion-all-completions (string table pred point &optional metadata)
>    "List the possible completions of STRING in completion table TABLE.
>  Only the elements of table that satisfy predicate PRED are considered.
> -POINT is the position of point within STRING.
> -The return value is a list of completions and may contain the base-size
> -in the last `cdr'."
> -  ;; FIXME: We need to additionally return the info needed for the
> -  ;; second part of completion-base-position.
> -  (completion--nth-completion 2 string table pred point metadata))
> +POINT is the position of point within STRING.  The return value is a
> +list of completions and may contain the base-size in the last `cdr'.
> +The METADATA may be modified by the completion style.  This function
> +has been superseded by `completion-filter-completions', which returns
> +richer information and supports deferred candidate highlighting."

Likewise here.

Also, the "This function has been superseded..." part should be a new
paragraph, so that it stands out.  (And I'm not yet sure we indeed
want to say "superseded" here, but that's part of the on-going
discussion.  maybe use a more neutral language here, like "See also".)

> +    (if (and result (consp (car result)))
> +        ;; Give the completion styles some freedom!
> +        ;; If they are targeting Emacs 28 upwards only, they
> +        ;; may always return a result with deferred
> +        ;; highlighting.  We convert back to the old format
> +        ;; here by applying the highlighting eagerly.

"May always" again.  How about "can always" instead?

> +        (nconc (funcall (cdr (assq 'highlight result))
> +                        (cdr (assq 'completions result)))
> +               (cdr (assq 'base result)))
> +      result)))
> +
> +(defun completion-filter-completions (string table pred point metadata)
> +  "Filter the possible completions of STRING in completion table TABLE.

Is "filter" really the right word here (in the doc string)?  "Filer"
means you take a sequence and produce another sequence with some
members removed.  That's not what this API does, is it?  Suggest to
use a different name, like completion-completions-alist or
completion-all-completions-as-alist.

> +Only the elements of table that satisfy predicate PRED are considered.
> +POINT is the position of point within STRING.  The METADATA may be
> +modified by the completion style.  The return value is a alist with
> +the keys:
> +
> +- base: Base position of the completion (from the start of STRING)

"Base" here means the beginning?  If so, why not call it "beg" or
somesuch?

> +This function supersedes the function `completion-all-completions'."

Again, "supersedes" is too strong, IMO.  I would say "is a variant of"
instead, and explain why this variant could be better suited to some
use cases.  IOW, explain the upsides (and downsides, if any), and let
the programmers decide whether they want this, instead of more-or-less
forcing them to use it.

> +        ;; Deferred highlighting has been requested, but the completion
> +        ;; style returned a non-deferred result. Convert the result to the
                                                  ^^
two spaces between sentences, please.

> +        ;; new alist format.

"New" is not a good word here.

> +      ;; added by the completion machinery.

Please start comments with a capital letter.

> +(defun completion--deferred-hilit (completions prefix-len base end)
> +  "Return completions in old format or new alist format.
> +If `completion--filter-completions' is non-nil use the new format."

Again, please don't use "old" and "new" here, but instead describe
explicitly the differences between them, or provide a hyperlink to
where that is described.

> +                      ;; Apply highlighting

Please end each sentence in a comment with a period.

> +(defun completion-pcm--deferred-hilit (pattern completions base end)
> +  "Return completions in old format or new alist format.
> +If `completion--filter-completions' is non-nil use the new format."

"Old" and "new" again.

>  (defun completion-pcm--hilit-commonality (pattern completions)
>    "Show where and how well PATTERN matches COMPLETIONS.
>  PATTERN, a list of symbols and strings as seen
>  `completion-pcm--merge-completions', is assumed to match every
>  string in COMPLETIONS.  Return a deep copy of COMPLETIONS where
> -each string is propertized with `completion-score', a number
> -between 0 and 1, and with faces `completions-common-part',
> +each string is propertized with faces `completions-common-part',
>  `completions-first-difference' in the relevant segments."

Are we really losing the completion-score property here?  If so, why?

> +           ;; If `pattern' doesn't have an explicit trailing any,

This is confusing: what do you mean by "explicit trailing any" in the
context of patterns?

> +(defun completion--flex-score (pattern completions)
> +  "Compute how well PATTERN matches COMPLETIONS.
> +PATTERN, a list of strings is assumed to match every string in
> +COMPLETIONS.

Is PATTERN really a list?  It would be strange for a list to be called
PATTERN, and how can a list "match every string in COMPLETIONS"?

>               Return a copy of COMPLETIONS where each element is
> +a pair of a score and the completion string.

What is "the completion string" in this case? is it the same string
from COMPLETIONS, or is it something else?  The doc string leaves that
unclear.

>                                                The score lies in
> +the range between -1 and 0, where -1 corresponds to the full
> +match."

What score could a partial match have, and what is the meaning of the
numerical value for a partial match?





  parent reply	other threads:[~2021-08-12  8:00 UTC|newest]

Thread overview: 174+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-05  1:39 bug#48841: fido-mode is slower than ido-mode with similar settings Dmitry Gutov
2021-06-05  9:35 ` João Távora
2021-06-05 23:02   ` Dmitry Gutov
2021-06-05 23:20     ` João Távora
2021-06-05 23:42       ` Dmitry Gutov
2021-06-06  0:25       ` Dmitry Gutov
2021-06-06  6:54         ` João Távora
2021-06-06 22:20           ` Dmitry Gutov
2021-06-06 23:49             ` João Távora
2021-06-07  0:11               ` Dmitry Gutov
2021-06-07  8:52                 ` João Távora
2021-06-11  2:19                   ` Dmitry Gutov
2021-06-11 17:09                     ` João Távora
2021-06-11 22:34                       ` Dmitry Gutov
2021-06-11 22:41                         ` Dmitry Gutov
2021-06-13 14:55                         ` João Távora
2021-06-17  2:36                           ` Dmitry Gutov
2021-06-17 21:21                             ` João Távora
2021-07-04  1:53                               ` Dmitry Gutov
2021-07-07  8:56                                 ` bug#47711: " Daniel Mendler
2021-06-11 23:24                     ` João Távora
2021-06-12  0:43                       ` Dmitry Gutov
2021-06-13 14:29                         ` João Távora
2021-06-14  0:08                           ` Dmitry Gutov
2021-06-14  0:16                             ` João Távora
2021-06-17  2:23                               ` Dmitry Gutov
2021-06-17 21:29                                 ` João Távora
2021-07-04  1:42                                   ` Dmitry Gutov
2021-06-06  2:34       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-06-06  6:59         ` João Távora
2021-06-06 16:54           ` Dmitry Gutov
2021-06-06 18:37             ` João Távora
2021-06-06 22:21               ` Dmitry Gutov
2021-06-06 23:27                 ` João Távora
2021-06-06 17:55           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-06-06 21:33             ` João Távora
2021-08-11 14:16 ` bug#48841: [PATCH] Add new `completion-filter-completions` API and deferred highlighting Daniel Mendler
2021-08-11 16:11   ` Daniel Mendler
2021-08-11 16:17     ` bug#47711: " João Távora
2021-08-12  9:24     ` Daniel Mendler
2021-08-13 10:38       ` bug#48841: [PATCH VERSION 2] " Daniel Mendler
2021-08-13 10:56         ` João Távora
2021-08-13 11:21           ` bug#48841: bug#47711: " Daniel Mendler
2021-08-13 12:05             ` João Távora
2021-08-13 12:22               ` Daniel Mendler
2021-08-13 12:37                 ` bug#48841: " João Távora
2021-08-13 12:56                   ` Daniel Mendler
2021-08-13 13:36                     ` bug#48841: " João Távora
2021-08-13 14:03                       ` Daniel Mendler
2021-08-13 14:11                         ` bug#48841: " João Távora
2021-08-13 14:37                           ` bug#47711: " Daniel Mendler
2021-08-14  2:47                       ` Dmitry Gutov
2021-08-14  7:12                         ` bug#47711: " Eli Zaretskii
2021-08-14 11:22                           ` Dmitry Gutov
2021-08-16  8:48                           ` Daniel Mendler
2021-08-16 11:57                             ` bug#47711: " Eli Zaretskii
2021-08-16 12:02                               ` João Távora
2021-08-16 12:19                                 ` Eli Zaretskii
2021-08-16 12:08                               ` Daniel Mendler
2021-08-14 10:36                         ` João Távora
2021-08-14 11:29                           ` Eli Zaretskii
2021-08-14 12:12                             ` bug#47711: " Lars Ingebrigtsen
2021-08-14 12:39                               ` Eli Zaretskii
2021-08-14 13:29                                 ` Lars Ingebrigtsen
2021-08-16  3:21                               ` Dmitry Gutov
2021-08-16  3:27                                 ` bug#47711: " João Távora
2021-08-16  3:31                                   ` Dmitry Gutov
2021-08-16  3:53                                     ` João Távora
2021-08-16  3:59                                       ` Dmitry Gutov
2021-08-16  4:25                                         ` bug#47711: " João Távora
2021-08-16  9:08                                           ` Daniel Mendler
2021-08-16 10:15                                             ` João Távora
2021-08-16 10:52                                               ` Daniel Mendler
2021-08-16 11:37                                                 ` bug#48841: " João Távora
2021-08-16 12:05                                                   ` Daniel Mendler
2021-08-16 12:17                                                     ` João Távora
2021-08-16 12:43                                                     ` Eli Zaretskii
2021-08-16 14:26                                                   ` bug#48841: " Dmitry Gutov
2021-08-16 14:29                                                     ` João Távora
2021-08-16 12:39                                                 ` Eli Zaretskii
2021-08-16 12:49                                                   ` bug#48841: " Daniel Mendler
2021-08-16 13:21                                                     ` Eli Zaretskii
2021-08-16 14:00                                                       ` Dmitry Gutov
2021-08-16 14:20                                                         ` João Távora
2021-08-16 14:33                                                           ` bug#48841: " Dmitry Gutov
2021-08-16 14:36                                                             ` João Távora
2021-08-16 14:47                                                               ` bug#47711: bug#48841: " Dmitry Gutov
2021-08-16 16:59                                                                 ` João Távora
2021-08-16 18:25                                                             ` João Távora
2021-08-17  2:08                                                               ` Dmitry Gutov
2021-08-17  8:59                                                                 ` João Távora
2021-08-17 11:48                                                                   ` bug#48841: " Eli Zaretskii
2021-08-17 11:52                                                                     ` bug#47711: " João Távora
2021-08-16  3:17                             ` Dmitry Gutov
2021-08-16 11:46                               ` Eli Zaretskii
2021-08-16 13:38                                 ` Dmitry Gutov
2021-08-16 13:41                                   ` João Távora
2021-08-16 14:14                                     ` bug#47711: " Dmitry Gutov
2021-08-15 18:32                           ` bug#48841: [PATCH] Make fido-mode about as fast as ido-mode even with many completions João Távora
2021-08-25 15:42                             ` João Távora
2021-08-14  7:01                     ` bug#48841: bug#47711: [PATCH VERSION 2] Add new `completion-filter-completions` API and deferred highlighting Eli Zaretskii
2021-08-14  9:48                       ` João Távora
2021-08-15  0:03                         ` João Távora
2021-08-16  3:26                       ` Dmitry Gutov
2021-08-16 11:48                         ` bug#48841: " Eli Zaretskii
2021-08-16  8:47                       ` Daniel Mendler
2021-08-14  2:55               ` bug#47711: bug#48841: " Dmitry Gutov
2021-08-14  7:16                 ` bug#48841: " Eli Zaretskii
2023-10-24 22:25                   ` bug#47711: " Dmitry Gutov
2023-10-25 17:52                     ` João Távora
2023-10-25 20:50                       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-25 21:02                         ` João Távora
2023-10-25 22:12                           ` João Távora
2023-10-26 21:49                             ` João Távora
2023-10-26 23:10                               ` Dmitry Gutov
2023-10-26 23:27                                 ` João Távora
2023-10-26 23:35                                   ` Dmitry Gutov
2023-10-26 23:52                                     ` João Távora
2023-10-26 23:25                       ` Dmitry Gutov
2023-10-26 23:44                         ` João Távora
2023-10-27  0:11                           ` Dmitry Gutov
2023-10-27  0:26                             ` João Távora
2023-10-27 13:29                               ` Dmitry Gutov
2023-10-27 13:46                                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-27 15:41                                   ` Dmitry Gutov
2023-10-27 16:19                                     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-27 17:06                                       ` Dmitry Gutov
2023-10-27 18:12                                         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-29  2:07                                           ` Dmitry Gutov
2023-10-29  4:41                                             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-11-03  0:16                                               ` Dmitry Gutov
2023-11-03  3:05                                                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-10-27 17:16                                 ` João Távora
2023-10-28 22:24                                   ` Dmitry Gutov
2023-10-29 23:12                                     ` João Távora
2023-10-31  3:20                                       ` Dmitry Gutov
2023-10-31 10:55                                         ` João Távora
2023-10-31 20:52                                           ` Dmitry Gutov
2023-11-01 18:47                                             ` João Távora
2023-11-01 22:45                                               ` Dmitry Gutov
2023-11-02  9:48                                                 ` João Távora
2023-11-02 10:10                                                   ` Eli Zaretskii
2023-11-02 10:39                                                     ` João Távora
2023-11-02 10:58                                                       ` Eli Zaretskii
2023-11-02 11:12                                                         ` João Távora
2023-11-02 14:40                                                   ` Dmitry Gutov
2023-11-02 15:24                                                     ` João Távora
2023-11-02 15:36                                                       ` Dmitry Gutov
2023-11-02 15:58                                                         ` João Távora
2023-11-02 16:03                                                           ` Dmitry Gutov
2023-11-02 16:09                                                             ` João Távora
2023-11-02 16:15                                                               ` Dmitry Gutov
2021-04-11 20:51                                                                 ` bug#47711: 27.1; Deferred highlighting support in `completion-all-completions', `vertico--all-completions` Daniel Mendler
     [not found]                                                                   ` <handler.47711.B.16181742862702.ack@debbugs.gnu.org>
2021-04-18 21:26                                                                     ` bug#47711: Acknowledgement (27.1; Deferred highlighting support in `completion-all-completions', `vertico--all-completions`) Daniel Mendler
2023-11-04 18:46                                                                   ` bug#47711: bug#48841: bug#47711: bug#48841: bug#47711: [PATCH VERSION 2] Add new `completion-filter-completions` API and deferred highlighting Howard Melman
2024-04-08 17:19                                                                   ` bug#47711: 27.1; Deferred highlighting support in `completion-all-completions', `vertico--all-completions` Dmitry Gutov
2023-11-06 16:20                                                 ` bug#47711: bug#48841: bug#47711: bug#48841: bug#47711: [PATCH VERSION 2] Add new `completion-filter-completions` API and deferred highlighting João Távora
2023-11-06 19:38                                                   ` Dmitry Gutov
2023-11-07 12:13                                                     ` João Távora
2023-11-08  1:06                                                       ` Dmitry Gutov
2023-11-08  1:24                                                         ` João Távora
2023-11-08  1:47                                                           ` Dmitry Gutov
2023-10-27  0:14                           ` João Távora
2021-08-14  8:23                 ` João Távora
2021-08-16  3:48                   ` Dmitry Gutov
2021-08-16  4:20                     ` bug#48841: " João Távora
2021-08-16  8:53                       ` Daniel Mendler
2021-08-14  6:45         ` Eli Zaretskii
2021-08-14  3:11     ` bug#47711: bug#48841: [PATCH] " Dmitry Gutov
2021-08-12  8:00   ` Eli Zaretskii [this message]
2021-08-12  8:47     ` Daniel Mendler
2021-08-14  6:27       ` Eli Zaretskii
2021-08-16  9:42         ` Daniel Mendler
2021-08-16 12:58           ` bug#47711: " Eli Zaretskii

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=837dgrdrec.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=47711@debbugs.gnu.org \
    --cc=48841@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    --cc=joaotavora@gmail.com \
    --cc=mail@daniel-mendler.de \
    --cc=monnier@iro.umontreal.ca \
    /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).