From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: Re: result of completing-read contradicting require-match Date: Sat, 2 Jul 2022 22:20:29 +0300 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="19341"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/+ () (2022-05-21) Cc: Help Gnu Emacs To: carlmarcos@tutanota.com Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jul 02 21:29:35 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o7ioA-0004s0-9w for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 02 Jul 2022 21:29:34 +0200 Original-Received: from localhost ([::1]:43744 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o7io8-0005td-R8 for geh-help-gnu-emacs@m.gmane-mx.org; Sat, 02 Jul 2022 15:29:32 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36470) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7imG-0005CZ-CB for help-gnu-emacs@gnu.org; Sat, 02 Jul 2022 15:27:36 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:41201) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o7imE-0008Qp-Dd for help-gnu-emacs@gnu.org; Sat, 02 Jul 2022 15:27:35 -0400 Original-Received: from localhost ([::ffff:102.87.29.106]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 0000000000087C50.0000000062C09C1E.00007BDF; Sat, 02 Jul 2022 12:27:25 -0700 Mail-Followup-To: carlmarcos@tutanota.com, Help Gnu Emacs Content-Disposition: inline In-Reply-To: Received-SPF: pass client-ip=217.170.207.13; envelope-from=bugs@gnu.support; helo=stw1.rcdrun.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:138263 Archived-At: * carlmarcos--- via Users list for the GNU Emacs text editor [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/