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: Yuri Khan
Subject: Re: How to read an integer from the minibuffer
Date: Tue, 16 Nov 2021 18:52:57 +0700

On Tue, 16 Nov 2021 at 18:37, Emanuel Berg via Users list for the GNU
Emacs text editor <help-gnu-emacs@gnu.org> wrote:

> > Depending on circumstances, you might want to refine the
> > regexp to disallow leading zeros unless it is the only digit
> > in the integer part; and/or allow exponential format.

> As for disallowing leading zeroes I think it should be as
> close to Emacs as possible, eval 00 for example.

This is because I said “depending on circumstances”. You may want to
allow leading zeros and treat the number as decimal anyway, or you
might want to allow leading zeros and treat the number as octal, or
disallow leading zeros. It is application-specific.

> > It might also be a good idea to wrap all that in
> > a ‘save-match-data’.)
>
> What/how do you mean?

Suppose we put that function in a library and document it as “it
parses decimal numbers, checking that it is actually a decimal
number”.

A user tries to use the function between a (string-match …) and a
subsequent (match-beginning), (match-end), (match-string) or
(match-substitute-replacement). But our function itself uses
(string-match) so we trash the user’s match result.

(It is said somewhere that, generally, it is the caller’s
responsibility to preserve the match data across a function call that
might trash it, though. Maybe because this way yields better
performance when nobody actually cares about the last match data.)



reply via email to

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