[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: result of completing-read contradicting require-match
From: |
carlmarcos |
Subject: |
Re: result of completing-read contradicting require-match |
Date: |
Sat, 2 Jul 2022 23:13:38 +0200 (CEST) |
Jul 2, 2022, 19:20 by bugs@gnu.support:
> * carlmarcos--- via Users list for the GNU Emacs text editor
> <help-gnu-emacs@gnu.org> [2022-07-02 21:59]:
>
>> I am using completing-read that uses require-match, without initial-input
>> and withoutdef.
>>
>> If I press return so that the input is neither "name" or "name-mode", it
>> seems that an empty
>> string is returned. The result seems to contradict require-match being `t'.
>>
>
> (let* ((cseq '("name" "name-mode"))
> (csel (completing-read "Type: " cseq nil t nil)))
> csel) ⇒ then after pressing ENTER I get: ""
>
>
> REQUIRE-MATCH can take the following values:
> - t means that the user is not allowed to exit unless the input is (or
> completes to) an element of COLLECTION or is null.
> - nil means that the user can exit with any input.
> - ‘confirm’ means that the user can exit with any input, but she needs
> to confirm her choice if the input is not an element of COLLECTION.
> - ‘confirm-after-completion’ means that the user can exit with any
> input, but she needs to confirm her choice if she called
> ‘minibuffer-complete’ right before ‘minibuffer-complete-and-exit’
> and the input is not an element of COLLECTION.
> - a function, which will be called with the input as the parameter.
> If it returns a non-nil value, the minibuffer is exited with that value.
> - anything else behaves like t except that typing RET does not exit if it
> does non-null completion.
>
Have been playing with REQUIRE-MATCH being 'confirm, but there is not
information
what to do if yao want to confirm.
> I guess that simple pressing of ENTER means "null" in this case.
> But if anything is chosen, then it must be an element of the
> collection.
>
> If you then add default, then it would get the first value:
>
> (let* ((cseq '("name" "name-mode"))
> (csel (completing-read "Type: " cseq nil t nil nil (car cseq))))
> csel) ⇒ then after pressing ENTER I get: "name"
>
> other way to persist asking until you get the true result is here:
>
> (defun rcd-repeat-until-not-empty-string (function &rest args)
> "Repeat FUNCTION with optional ARGS until result is not empty string."
> (let ((result))
> (while (string-empty-p (setq result (apply function args))))
> result))
>
> (defun my-fun ()
> (let* ((cseq '("name" "name-mode"))
> (csel (completing-read "Type: " cseq nil t nil nil nil)))
> csel))
>
> In this case it will keep asking you until you enter something.
>
> (rcd-repeat-until-not-empty-string 'my-fun) ⇒ "name-mode"
>
>
> --
> Jean
>
> Take action in Free Software Foundation campaigns:
> https://www.fsf.org/campaigns
>
> In support of Richard M. Stallman
> https://stallmansupport.org/
>
Re: result of completing-read contradicting require-match,
carlmarcos <=