help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: result of completing-read contradicting require-match


From: Yuri Khan
Subject: Re: result of completing-read contradicting require-match
Date: Sun, 3 Jul 2022 03:38:31 +0700

On Sun, 3 Jul 2022 at 03:07, Jean Louis <bugs@gnu.support> wrote:

> > Based on the quoted part of the docstring, you could probably pass a
> > function that returns t for an allowed value, and nil for disallowed
> > values, including an empty string or nil.
>
> Do you mean from `completing-read':
>
> "- 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."

I do.

> Do you mean this:
>
> (let* ((cseq '("name" "name-mode"))
>        (csel (completing-read "Type: " cseq nil FUNCTION-HERE? nil )))
>   csel)

I do.

> and what would be value name for function to check it?

I meant a closure over the list of valid strings, something like this:

    (let* ((choices '("name" "name-mode"))
           (is-valid (lambda (s) (member s choices)))
           (choice (completing-read "Type: " choices nil is-valid)))
      choice)

I took the liberty to give variables sane names.
I did not test this as my currently installed Emacs does not accept
functions as the REQUIRE-MATCH argument. (Or, rather, it does but
treats them as the “anything else” case.)



reply via email to

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