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 15:05:40 +0700

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

> And they explicitely made it be this way ... weird.

I was going to suggest piggybacking on the JSON parser, but it has the same bug:

M-: (json-read-from-string "123foo")
⇒ 123 (#o173, #x7b, ?\{)

Fortunately, json-read-from-string is simple enough that you can copy
and modify it:

-(defun json-read-from-string (string)
+(defun json-read-from-string-strict (string)
   "Read the JSON object contained in STRING and return it."
   (with-temp-buffer
     (insert string)
     (goto-char (point-min))
-    (json-read)))
+    (prog1 (json-read)
+      (unless (eobp) (error "Trailing garbage")))))

You still get some whitespace skipping though.



reply via email to

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