aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/subr.el
diff options
context:
space:
mode:
authorStefan Monnier <[email protected]>2004-03-26 14:49:12 +0000
committerStefan Monnier <[email protected]>2004-03-26 14:49:12 +0000
commit9bf2aa6a719f09761aa93e6365e17af751469045 (patch)
tree2e597f46bdf4d5931f54e8de4f8ff6e659ceebe3 /lisp/subr.el
parent7c7085c0524295f052b16e703b075f9a24e6e160 (diff)
(read-number): New function.
Diffstat (limited to 'lisp/subr.el')
-rw-r--r--lisp/subr.el23
1 files changed, 22 insertions, 1 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index 0b3c3df4e8..2c39a8447c 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -1,6 +1,6 @@
;;; subr.el --- basic lisp subroutines for Emacs
-;; Copyright (C) 1985, 86, 92, 94, 95, 99, 2000, 2001, 2002, 2003
+;; Copyright (C) 1985, 86, 92, 94, 95, 99, 2000, 2001, 2002, 03, 2004
;; Free Software Foundation, Inc.
;; Maintainer: FSF
@@ -1307,6 +1307,27 @@ Optional DEFAULT is a default password to use instead of empty input."
(setq pass new-pass))))))
(message nil)
(or pass default ""))))
+
+;; This should be used by `call-interactively' for `n' specs.
+(defun read-number (prompt &optional default)
+ (let ((n nil))
+ (when default
+ (setq prompt
+ (if (string-match "\\(\\):[^:]*" prompt)
+ (replace-match (format " [%s]" default) t t prompt 1)
+ (concat prompt (format " [%s] " default)))))
+ (while
+ (progn
+ (let ((str (read-from-minibuffer prompt nil nil nil nil
+ (number-to-string default))))
+ (setq n (cond
+ ((zerop (length str)) default)
+ ((stringp str) (read str)))))
+ (unless (numberp n)
+ (message "Please enter a number.")
+ (sit-for 1)
+ t)))
+ n))
;;; Atomic change groups.