[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#56613: 29; minibuffer-complete-history throws an error for minibuffe
From: |
Daniel Mendler |
Subject: |
bug#56613: 29; minibuffer-complete-history throws an error for minibuffer-history-variable=t |
Date: |
Mon, 18 Jul 2022 09:41:09 +0200 |
On 7/18/22 09:24, Juri Linkov wrote:
>> In order to disable sorting from the side of the completion table, it is
>> better to use the completion metadata. This way the sort function will
>> also be picked up by all the alternative completion UIs.
>>
>> (completion-in-region
>> (minibuffer--completion-prompt-end) (point-max)
>> (lambda (str pred action)
>> (if (eq action 'metadata)
>> '(metadata (display-sort-function . identity)
>> (cycle-sort-function . identity))
>> (complete-with-action action completions str pred))))
>
> Thanks for the suggestion, now fixed as well.
Thanks! Since you added this function twice (for history and defaults
completion) you could also introduce a helper function. I use such
helpers in my projects. Maybe such a function would be useful at other
places in the Emacs code base? I haven't grepped but I think this
pattern appears often.
(defun completion-table-presorted (table &rest metadata)
"Disable sorting in the completion UI for TABLE which is already sorted."
(lambda (string pred action)
(if (eq action 'metadata)
`(metadata (display-sort-function . identity)
(cycle-sort-function . identity)
,@metadata)
(complete-with-action action table string pred))))
Or maybe the more general function would be useful too?
(defun completion-table-with-metadata (table &rest metadata)
"Return completion TABLE with METADATA."
(lambda (string pred action)
(if (eq action 'metadata)
`(metadata ,@metadata)
(complete-with-action action table string pred))))
> Stefan added this comment in minibuffer-complete-history:
>
> ;; FIXME: Can we make it work for CRM?
>
> But I can't find a function that would return the
> current completion boundaries to use instead of hard-coding
> minibuffer--completion-prompt-end and point-max. Then
> completing-read-multiple should set locally such a function
> that will use crm-separator and return a cons (BEG . END).
Doesn't it work if you retrieve the boundaries first with
`completion-boundaries` from `minibuffer-completion-table`? In my
Vertico package I use the following code and it works without issues
with CRM. The API requires a little bit of a ceremony.
(let* ((content (minibuffer-contents-no-properties))
(pt (max 0 (- (point) (minibuffer-prompt-end))))
(before (substring content 0 pt))
(after (substring content pt))
(bounds (completion-boundaries
before minibuffer-completion-table
minibuffer-completion-predicate after)))
...)
Daniel
- bug#56613: 29; minibuffer-complete-history throws an error for minibuffer-history-variable=t, Daniel Mendler, 2022/07/17
- bug#56613: 29; minibuffer-complete-history throws an error for minibuffer-history-variable=t, Drew Adams, 2022/07/17
- bug#56613: 29; minibuffer-complete-history throws an error for minibuffer-history-variable=t, Juri Linkov, 2022/07/17
- bug#56613: 29; minibuffer-complete-history throws an error for minibuffer-history-variable=t, Stefan Monnier, 2022/07/18
- bug#56613: 29; minibuffer-complete-history throws an error for minibuffer-history-variable=t, Daniel Mendler, 2022/07/18
- bug#56613: 29; minibuffer-complete-history throws an error for minibuffer-history-variable=t, Stefan Monnier, 2022/07/18
- bug#56613: 29; minibuffer-complete-history throws an error for minibuffer-history-variable=t, Daniel Mendler, 2022/07/18