all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jean Louis <bugs@gnu.support>
To: carlmarcos@tutanota.com
Cc: Help Gnu Emacs <help-gnu-emacs@gnu.org>
Subject: Re: result of completing-read contradicting require-match
Date: Sat, 2 Jul 2022 22:20:29 +0300	[thread overview]
Message-ID: <YsCafTaxnxY3rNbw@protected.localdomain> (raw)
In-Reply-To: <N6-GnYu--3-2@tutanota.com>

* 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.

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/



  reply	other threads:[~2022-07-02 19:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-02 18:58 result of completing-read contradicting require-match carlmarcos--- via Users list for the GNU Emacs text editor
2022-07-02 19:20 ` Jean Louis [this message]
2022-07-02 19:54   ` Yuri Khan
2022-07-02 20:07     ` Jean Louis
2022-07-02 20:38       ` Yuri Khan
2022-07-02 21:58         ` Jean Louis
2022-07-09 13:17     ` Jean Louis
2022-07-10 14:36       ` [External] : " Drew Adams
2022-07-10 17:56         ` Jean Louis
2022-07-02 21:13   ` carlmarcos--- via Users list for the GNU Emacs text editor

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YsCafTaxnxY3rNbw@protected.localdomain \
    --to=bugs@gnu.support \
    --cc=carlmarcos@tutanota.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.