]> git.eshelyaron.com Git - emacs.git/commitdiff
(read-number): New function.
authorRichard M. Stallman <rms@gnu.org>
Mon, 30 Jan 1995 00:34:44 +0000 (00:34 +0000)
committerRichard M. Stallman <rms@gnu.org>
Mon, 30 Jan 1995 00:34:44 +0000 (00:34 +0000)
lisp/emacs-lisp/lucid.el

index c248348d954f0adc0d81ad88e31b290b4391a98c..d32ec9de75ec703dbeebaa4b6a5ee382b26e53a5 100644 (file)
@@ -99,6 +99,27 @@ type that you get.  That will work in both versions of Emacs."
                (setq i (1- i))))))
       (setq keymap (cdr keymap)))))
 
+(defun read-number (prompt &optional integers-only)
+  "Read a number from the minibuffer.
+Keep reentering the minibuffer until we get suitable input.
+If optional argument INTEGERS-ONLY is non-nil, insist on an integer."
+  (interactive)
+  (let (success
+       (number nil)
+       (predicate (if integers-only 'integerp 'numberp)))
+    (while (not success)
+      (let ((input-string (read-string prompt)))
+       (condition-case ()
+           (setq number (read input-string))
+         (error))
+       (if (funcall predicate number)
+           (setq success t)
+         (let ((cursor-in-echo-area t))
+           (message "Please type %s"
+                    (if integers-only "an integer" "a number"))
+           (sit-for 1)))))
+    number))
+
 (defun real-path-name (name &optional default)
   (file-truename (expand-file-name name default)))