From: Jean Louis <bugs@gnu.support>
To: Drew Adams <drew.adams@oracle.com>
Cc: Yuri Khan <yuri.v.khan@gmail.com>,
"carlmarcos@tutanota.com" <carlmarcos@tutanota.com>,
Help Gnu Emacs <help-gnu-emacs@gnu.org>
Subject: Re: [External] : Re: result of completing-read contradicting require-match
Date: Sun, 10 Jul 2022 20:56:45 +0300 [thread overview]
Message-ID: <YssS3byuG8JIEdEz@protected.localdomain> (raw)
In-Reply-To: <SJ0PR10MB548822896FC10800159E7414F3849@SJ0PR10MB5488.namprd10.prod.outlook.com>
* Drew Adams <drew.adams@oracle.com> [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-<TAB>" 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/
next prev parent reply other threads:[~2022-07-10 17:56 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
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 [this message]
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=YssS3byuG8JIEdEz@protected.localdomain \
--to=bugs@gnu.support \
--cc=carlmarcos@tutanota.com \
--cc=drew.adams@oracle.com \
--cc=help-gnu-emacs@gnu.org \
--cc=yuri.v.khan@gmail.com \
/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.