[Top][All Lists]

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

Re: [External] : Re: result of completing-read contradicting require-mat

From: Jean Louis
Subject: Re: [External] : Re: result of completing-read contradicting require-match
Date: Sun, 10 Jul 2022 20:56:45 +0300
User-agent: Mutt/+ () (2022-06-11)

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

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))))

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

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


Take action in Free Software Foundation campaigns:

In support of Richard M. Stallman

reply via email to

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