emacs-devel
[Top][All Lists]
Advanced

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

Re: Possible minibuffer completion enhancements


From: Daniel Mendler
Subject: Re: Possible minibuffer completion enhancements
Date: Tue, 23 Jan 2024 09:08:01 +0100
User-agent: Gnus/5.13 (Gnus v5.13)

Eshel Yaron <me@eshelyaron.com> writes:

> Eshel Yaron <me@eshelyaron.com> writes:
>
>> Daniel Mendler <mail@daniel-mendler.de> writes:
>>
>>> ...the implementation of completion-table-with-metadata I've seen in
>>> Eshel's branch did not seem correct. The function should be simpler:
>>
>> Hmm, define "correct" and "should" :)
>> My implementation is indeed more sophisticated, since it does more.  In
>> particular, it lets you override some metadata while preserving other
>> metadata that come from the original table.  Could you elaborate about
>> how this simplified version is preferable in your opinion?
>>
>>> (defun completion-table-with-metadata (table metadata)
>>>   (lambda (str pred action)
>>>     (if (eq action 'metadata)
>>>         `(metadata ,@metadata
>>>                    ,@(and (functionp table)
>>>                           (cdr (funcall table str pred action))))
>>>       (complete-with-action action table str pred))))
>
> On second thought, your version should indeed work just as well as mine,
> expect that my implementation also allows the extra metadata to be
> computed just in time.  In the common case where the metadata is
> computed ahead of time, both versions basically behave the same, right?

Indeed. Your `completion-table-with-metadata' function allows to compute
the metadata on the fly. Are there use cases for this? From my
experience the completion table metadata is mostly static, except in
cases where completion table boundaries are used. But in that case a
simple helper like `completion-table-with-metadata' seems to too limited
anyway?

The above function can be adapted as follows if a dynamic
recomputation feature is desirable:

(defun completion-table-with-metadata (table metadata)
  (lambda (str pred action)
    (if (eq action 'metadata)
        `(metadata ,@(if (functionp metadata)
                         (funcall metadata str pred)
                       metadata)
                   ,@(and (functionp table)
                          (cdr (funcall table str pred action))))
      (complete-with-action action table str pred))))

Daniel



reply via email to

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