Article View: comp.emacs
Article #9565Re: Need read-number function
From: reingold
Date: Fri, 09 Feb 1990 17:37
Date: Fri, 09 Feb 1990 17:37
21 lines
1299 bytes
1299 bytes
Here's the way I've written the general form. Now that I've got it, I
can't figure out how I managed without it!
(defun read-object (prompt acceptable &optional initial-contents)
"Return an object read from the minibuffer.
Prompt with the string PROMPT and use the function ACCEPTABLE to decide if
entered item is acceptable. If non-nil, optional third arg INITIAL-CONTENTS
is a string to insert in the minibuffer before reading."
(let ((value (read-minibuffer prompt initial-contents)))
(while (not (funcall acceptable value))
(setq value (read-minibuffer prompt initial-contents)))
value))
For example, to read a month, defaulting to current-month, use
(read-object
"Enter month (1-12): "
'(lambda (x) (and (integerp x) (<= 1 x) (<= x 12)))
(int-to-string current-month))
Technical Details
Message-ID:
<4300070@m.cs.uiuc.edu>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!deimos!ux1.cso.uiuc.edu!ux1.cso.uiuc.edu!m.cs.uiuc.edu!reingoldReferences:
<4300068@m.cs.uiuc.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uunet!deimos!ux1.cso.uiuc.edu!ux1.cso.uiuc.edu!m.cs.uiuc.edu!reingold From: reingold@m.cs.uiuc.edu Newsgroups: comp.emacs Subject: Re: Need read-number function Message-ID: <4300070@m.cs.uiuc.edu> Date: 9 Feb 90 17:37:46 GMT References: <4300068@m.cs.uiuc.edu> Lines: 21 Nf-ID: #R:m.cs.uiuc.edu:4300068:m.cs.uiuc.edu:4300070:000:820 Nf-From: m.cs.uiuc.edu!reingold Feb 8 19:19:00 1990