Path: utzoo!attcan!uunet!talos!kjones From: kjones@talos.uu.net (Kyle Jones) Newsgroups: comp.emacs Subject: Re: Need read-number function Message-ID: <1990Feb8.132524.1694@talos.uu.net> Date: 8 Feb 90 13:25:24 GMT References: <4300068@m.cs.uiuc.edu> Reply-To: kyle@xanth.cs.odu.edu Lines: 24 reingold@m.cs.uiuc.edu writes: > I need a function read-number that would behave like (interactive "n"); > that is, it would keep trying until a numeric value was typed. [ Assuming GNU emacs here... ] Yah, I had to code this one myself. I don't know if a function like this should be standard in the distribution or not. Common Lisp's elephantiasis is largely due to adopting functions from everyone's toolbox. Anyway, here's the function. (defun read-number (prompt &optional initial-input) "Read a number from the minibuffer prompting with PROMPT. If non-nil, the optional second argument INITIAL-INPUT should be a string to insert into the minibuffer before reading." (let (result) (while (null result) (setq result (read-string prompt initial-input)) (if (string-match "^ *-?[0-9]+" result) (setq result (string-to-int result)) (setq result nil))) result ))