[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: |
Sat, 13 Nov 2021 11:44:39 +0300 |
User-agent: |
Mutt/2.0.7+183 (3d24855) (2021-05-28) |
* tomas@tuxteam.de <tomas@tuxteam.de> [2021-11-13 11:18]:
> On Sat, Nov 13, 2021 at 09:36:39AM +0300, Jean Louis wrote:
> > * tomas@tuxteam.de <tomas@tuxteam.de> [2021-11-12 23:25]:
>
> [...]
>
> > > Why not simply numberp?
> > >
> > > (and (numberp s) (string-to-number s))
> >
> > (numberp "123") ⇒ nil
> >
> > It checks if object is number. That is why it is not usable to check
> > if string is actual number.
>
> D'oh, you are right. That'd been too easy ;-)
>
> It seems you'll have to go with a regexp, then do string-to-number.
> Then, again, you'll have to decide: what subset of Emacs's number
> input syntax do you want to implement? Signed/unsigned? Integers?
> Floats? Exponential notation? Bases other than 10?
That helped me realize I have to call function different:
(defun string-is-positive-integer-p (s)
"Return number only if string is positive integer, 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/
- Re: How to read an integer from the minibuffer, (continued)
- Re: How to read an integer from the minibuffer, Jean Louis, 2021/11/12
- Re: How to read an integer from the minibuffer, tomas, 2021/11/12
- Re: How to read an integer from the minibuffer, Emanuel Berg, 2021/11/12
- Re: How to read an integer from the minibuffer, tomas, 2021/11/12
- Re: How to read an integer from the minibuffer, Emanuel Berg, 2021/11/12
- Re: How to read an integer from the minibuffer, Jean Louis, 2021/11/13
- Re: How to read an integer from the minibuffer, tomas, 2021/11/13
- Re: How to read an integer from the minibuffer, Emanuel Berg, 2021/11/16
- Re: How to read an integer from the minibuffer, Jean Louis, 2021/11/13
- Re: How to read an integer from the minibuffer, tomas, 2021/11/13
- Re: How to read an integer from the minibuffer,
Jean Louis <=
- Re: How to read an integer from the minibuffer, Emanuel Berg, 2021/11/16
- Re: How to read an integer from the minibuffer, Emanuel Berg, 2021/11/16
- Re: How to read an integer from the minibuffer, Emanuel Berg, 2021/11/11
- Re: How to read an integer from the minibuffer, Gregory Heytings, 2021/11/11
- Re: How to read an integer from the minibuffer, Emanuel Berg, 2021/11/11
Re: How to read an integer from the minibuffer, Marcin Borkowski, 2021/11/12