emacs-devel
[Top][All Lists]
Advanced

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

Re: Turning completion table lambdas into symbols


From: Juri Linkov
Subject: Re: Turning completion table lambdas into symbols
Date: Wed, 29 Nov 2023 09:18:46 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/30.0.50 (x86_64-pc-linux-gnu)

>>>> display-buffer has a similar problem, but the difference is that
>>>> it's possible to identify a buffer by its name and use a regexp
>>>> to match buffer names.  Whereas for completing-read it's not easy
>>>> to identify a completion table.  A category matches a set of
>>>> completion tables, so maybe we need another identification
>>>> for individual tables?
>>>
>>> True, that would help.  Maybe the function symbol for the completion
>>> table?  Tables are usually lambdas today, but maybe we could make it
>>> easy to use a defun'd function instead, which would be very good for
>>> comprehensibility in general IMO.
>>
>> Turning lambdas into symbols looks good, this is like the existing
>> 'help--symbol-completion-table'.
>
> Like 'help--symbol-completion-table' in what way?

Just an example where minibuffer-completion-table is a symbol.

> One thing that requires a lambda is when the table is over some custom
> data.  But that can sometimes be avoided by moving the logic into the
> table, like this for example:
>
> +(defun project--project-dir-completion-table (string pred action)
> +  (cond
> +   ((eq action 'metadata)
> +    '(metadata . ((category . project-dir))))
> +   (t
> +    (complete-with-action action (cons "... (choose a dir)" project--list) 
> string pred))))
> ...
> -              (completing-read "Select project: " choices nil t nil 
> 'project--dir-history))))
> +              (completing-read "Select project: " 
> #'project--project-dir-completion-table
> +                               nil t nil 'project--dir-history))))

> If there was a canonical way for a completion table to maintain some
> state which *doesn't* require the completion table to be a lambda, I
> think most completion tables could become defuns instead of lambdas.
> (And then they could be customized based on the function symbol)

Or they could be customized based on a new symbol for table identification
without turning lambdas into defuns:

  (completing-read "Select project: "
                   (lambda (string pred action)
                     (cond
                      ((eq action 'metadata)
                       '(metadata
                         . ((category . project-dir)
                            (table . project-dir-completion-table))))
                      (t
                       (complete-with-action action choices string pred))))
                   nil t nil 'project--dir-history)



reply via email to

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