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: [External] : Re: result of completing-read contradicting require-match Date: Sun, 10 Jul 2022 20:56:45 +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="14153"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mutt/+ () (2022-06-11) Cc: Yuri Khan , "carlmarcos@tutanota.com" , Help Gnu Emacs To: Drew Adams Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jul 10 20:12:51 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 1oAbQH-0003Ot-AW for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 10 Jul 2022 20:12:49 +0200 Original-Received: from localhost ([::1]:49458 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oAbQG-0006t3-5P for geh-help-gnu-emacs@m.gmane-mx.org; Sun, 10 Jul 2022 14:12:48 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36026) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oAbPJ-0006sf-94 for help-gnu-emacs@gnu.org; Sun, 10 Jul 2022 14:11:49 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:51205) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oAbPH-0002v8-88 for help-gnu-emacs@gnu.org; Sun, 10 Jul 2022 14:11:48 -0400 Original-Received: from localhost ([::ffff:102.87.129.133]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 00000000000A3E16.0000000062CB165F.000011D7; Sun, 10 Jul 2022 11:11:41 -0700 Mail-Followup-To: Drew Adams , Yuri Khan , "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:138413 Archived-At: * Drew Adams [2022-07-10 17:36]: > > I would like to merge these two functions and use each of them > > sometimes singly. The third merged one would check for both values. > > I'm not following this thread. Just happened to > read your initial statement, which sounds like > you want to repeat invoking a function until it > returns nil or non-nil. > > If so, Emacs already gives you that: > `run-hook-with-args-until-failure' > (`*-success' is similar). > > https://www.gnu.org/software/emacs/manual/html_node/elisp/Running-Hooks.html Looks similar, but not that it works straight how I think it should. It runs the hook until NIL or non-NIL, and there is no reliability what it will return. It also has purpose to run eventually many functions, not just one. It is not same as what I use. These functions will return the value from function that is invoked repeatedly until it gives some value. I define "nothing" as non-empty string and not null (defun rcd-is-nothing-p (thing) "Return TRUE if THING is nothing." (cond ((and (stringp thing) (seq-empty-p thing)) t) ((null thing) t) (t nil))) (defun rcd-repeat-until-something (function &rest args) "Repeat FUNCTION with optional ARGS until result is something. Result shall be non empty string or number." (let ((result)) (while (rcd-is-nothing-p (setq result (apply function args)))) result)) I use it when for example, I do not want an empty string: (read-from-minibuffer "Tell me: ") ⇒ "" What I do not want is empty string, I want to make sure there is some input, so it would keep asking me until I get selection. (rcd-repeat-until-something 'read-from-minibuffer "Tell me: ") ⇒ "OK" Then I have for example country selection: (rcd-repeat-until-something 'cf-country-select) ⇒ 228 - at this moment I can choose among many countries, I could type "UNITED STAT-" and get value 228 - but I cannot continue with ENTER in no way. And I do not need any defaults. That spares me programming time and evaluating values, it is less error prone for user. Instead of: (let ((country (cf-country-select))) (when country (do something))) or instead of: (let ((country (cf-country-select))) (if country (do something) (error "You did not select country"))) it is more convient to simply demand that selection is made and be sure of it: (let ((country (rcd-repeat-until-something 'cf-country-select))) (do something with country)) thus I am sparing many `when' and `if' clauses, as it ensures that function returns "something". -- Jean Take action in Free Software Foundation campaigns: https://www.fsf.org/campaigns In support of Richard M. Stallman https://stallmansupport.org/