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: Emanuel Berg
Subject: Re: How to read an integer from the minibuffer
Date: Tue, 16 Nov 2021 13:00:14 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

Yuri Khan 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.)

OK ... nothing that clearly and instantly will improve
it, maybe.

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

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