[Top][All Lists]

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

Re: How to read an integer from the minibuffer

From: Jean Louis
Subject: Re: How to read an integer from the minibuffer
Date: Fri, 12 Nov 2021 22:05:54 +0300
User-agent: Mutt/2.0.7+183 (3d24855) (2021-05-28)

* Emanuel Berg via Users list for the GNU Emacs text editor 
<> [2021-11-12 03:58]:
> Gregory Heytings wrote:
> >>> Apparently it doesn't do what I want here, namely
> >>> converting "[0-9]" into "0123456789", "[0-9a-f]" into
> >>> "0123456789abcdef", and so forth.
> >>
> >> I think it can!
> >
> > Please show me how...
> First here is another version of "read-integer" ...
> We see a problem BTW that `string-to-number' returns 0
> on error!

That problem I have solved in rcd-utilities.el with:

(defun string-is-number-p (s)
  "Return number only if string is pure number, otherwise NIL."
  (let ((s (string-trim s)))
    (cond ((seq-empty-p s) nil)
          ((string-match "[^0123456789\\.]" s) nil)
          ((numberp (string-to-number s)) (string-to-number s)))))


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]