Subject: bug#74865: [PATCH] Use `completion-table-with-metadata'

From: Daniel Mendler <[email-masked]>
Date: Mon, 16 Dec 2024 20:26:45 +0100

Juri Linkov <[email-masked]> writes:

>>> Also it could be used in `read-char-by-name' as well.
>>
>> Yes, there are certainly more use cases. I didn't use it for
>> `read-char-by-name' since this would change the caching behavior
>> slightly. The character names would be loaded a little bit earlier,
>> which would slow down the initialization of `read-char-by-name'.
>
> Maybe the caching behavior could be preserved by turning
> `completion-table-with-metadata' into a macro?

Let us please keep `completion-table-with-metadata' a function for
composeability and ease of reasoning. `completion-table-with-metadata'
follows the many already existing `completion-table-with-*' functions in
minibuffer.el.

In order to delay initialization of the completion candidates we can use
the following code:

(completion-table-with-metadata
 (lambda (string pred action)
   (complete-with-action action (ucs-names) string pred))
 metadata)

(completion-table-with-metadata
 (completion-table-dynamic (lambda (_) (ucs-names)))
 metadata)

>>> Maybe `completion-table-with-metadata' should be announced
>>> in the "Lisp Changes" section of etc/NEWS?
>>
>> Yes, please go ahead adding it to the NEWS. I will backport the function
>> also via Compat.
>
> Ok, now added to NEWS.

Thanks.

Daniel