comparison lisp/subr.el @ 54570:cf58c77ee000

(read-number): New function.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 26 Mar 2004 14:49:12 +0000
parents 15b3e94eebd4
children 8bcf0c459630
comparison
equal deleted inserted replaced
54569:3a7d16dc72af 54570:cf58c77ee000
1 ;;; subr.el --- basic lisp subroutines for Emacs 1 ;;; subr.el --- basic lisp subroutines for Emacs
2 2
3 ;; Copyright (C) 1985, 86, 92, 94, 95, 99, 2000, 2001, 2002, 2003 3 ;; Copyright (C) 1985, 86, 92, 94, 95, 99, 2000, 2001, 2002, 03, 2004
4 ;; Free Software Foundation, Inc. 4 ;; Free Software Foundation, Inc.
5 5
6 ;; Maintainer: FSF 6 ;; Maintainer: FSF
7 ;; Keywords: internal 7 ;; Keywords: internal
8 8
1305 (let ((new-pass (substring pass 0 -1))) 1305 (let ((new-pass (substring pass 0 -1)))
1306 (and (arrayp pass) (clear-string pass)) 1306 (and (arrayp pass) (clear-string pass))
1307 (setq pass new-pass)))))) 1307 (setq pass new-pass))))))
1308 (message nil) 1308 (message nil)
1309 (or pass default "")))) 1309 (or pass default ""))))
1310
1311 ;; This should be used by `call-interactively' for `n' specs.
1312 (defun read-number (prompt &optional default)
1313 (let ((n nil))
1314 (when default
1315 (setq prompt
1316 (if (string-match "\\(\\):[^:]*" prompt)
1317 (replace-match (format " [%s]" default) t t prompt 1)
1318 (concat prompt (format " [%s] " default)))))
1319 (while
1320 (progn
1321 (let ((str (read-from-minibuffer prompt nil nil nil nil
1322 (number-to-string default))))
1323 (setq n (cond
1324 ((zerop (length str)) default)
1325 ((stringp str) (read str)))))
1326 (unless (numberp n)
1327 (message "Please enter a number.")
1328 (sit-for 1)
1329 t)))
1330 n))
1310 1331
1311 ;;; Atomic change groups. 1332 ;;; Atomic change groups.
1312 1333
1313 (defmacro atomic-change-group (&rest body) 1334 (defmacro atomic-change-group (&rest body)
1314 "Perform BODY as an atomic change group. 1335 "Perform BODY as an atomic change group.