help-gnu-emacs
[Top][All Lists]
Advanced

[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 
<help-gnu-emacs@gnu.org> [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)))))

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



reply via email to

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