[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Better alternative to completing-read-multiple
From: |
Thierry Volpiatto |
Subject: |
Re: Better alternative to completing-read-multiple |
Date: |
Sat, 20 Apr 2024 06:16:57 +0000 |
Ilya Chernyshov <ichernyshovvv@gmail.com> writes:
> Hello
>
> In completing-read-multiple, the resulting list of chosen strings is made
> by splitting the input string with crm-separator regular expression variable.
>
> This approach is not suitable for a list of candidates where a candidate
> string might contain a character that is currently treated as a
> separator. Imagine a situation where you read a list of Org headings
> from user. In an Org heading you can have any character including the
> default separator ",". Changing the value of crm-separator locally is
> not a solution here.
>
> A much better solution could be a completion command where a chosen
> candidate is appended to a list (displayed in the prompt) when a user
> presses RET and then returned when a user presses something like
> C-RET. Already chosen candidates could be erased via C-<backspace>
You can provide this feature to Helm users:
--8<---------------cut here---------------start------------->8---
(defvar helm-comp-read-use-marked)
(let ((lst '(a b c d e)))
(if (boundp 'helm-comp-read-use-marked)
(let ((helm-comp-read-use-marked t))
(completing-read "test: " lst))
(completing-read-multiple "test: " lst)))
--8<---------------cut here---------------end--------------->8---
The completing-read will return a list of marked candidates, if Helm is
not available fallback to CRM.
> This functionality definitely could be helpful at least in org, org-ql
> packages
> (for completion over org headings).
>
> I am not an Elisp expert, but here's some drafts. If you are interested,
> please comment.
>
> Test the function:
>
> (ic-completing-read-multiple "Prompt: " '("first" "second" "third"))
>
>
--
Thierry