From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: HOW TO GIVE A DEFAULT TO A TRULY INTERACTIVE FUNCTION Date: Fri, 18 Oct 2002 11:05:02 -0600 Sender: help-gnu-emacs-admin@gnu.org Message-ID: <3DB03F3E.1070604@ihs.com> References: <878z0wgr7j.fsf@fbigm.here> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: main.gmane.org 1034999049 30373 80.91.224.249 (19 Oct 2002 03:44:09 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Sat, 19 Oct 2002 03:44:09 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 182kX1-0007td-00 for ; Sat, 19 Oct 2002 05:44:07 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 182aZn-0006Tr-00; Fri, 18 Oct 2002 13:06:19 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!170.207.51.80!not-for-mail Original-Newsgroups: gnu.emacs.help,comp.emacs Original-Lines: 53 Original-NNTP-Posting-Host: 170.207.51.80 Original-X-Trace: fu-berlin.de 1034960689 25971936 170.207.51.80 (16 [82742]) User-Agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:0.9.4.1) Gecko/20020406 Netscape6/6.2.2 X-Accept-Language: en-us Original-Xref: shelby.stanford.edu gnu.emacs.help:106177 comp.emacs:75352 Original-To: help-gnu-emacs@gnu.org Errors-To: help-gnu-emacs-admin@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.help:2730 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:2730 Friedrich Dominicus wrote: > Counterintuitive is (prin1-to-string) I would qualify it as a bug and > suggest following patch: ... > patched > (defun read-number (prompt &optional integers-only default-value) > "Read a number from the minibuffer, prompting with PROMPT. > If optional second argument INTEGERS-ONLY is non-nil, accept > only integer input. > If DEFAULT-VALUE is non-nil, return that if user enters an empty > line." > (let ((pred (if integers-only 'integerp 'numberp)) > num) > (while (not (funcall pred num)) > (setq num (condition-case () > (let ((minibuffer-completion-table nil)) > (read-from-minibuffer > prompt (if num (prin1-to-string num)) nil t > nil nil (if (numberp default-value) > (prin1-to-string default-value) > default-value))) > (input-error nil) > (invalid-read-syntax nil) > (end-of-file nil))) > (or (funcall pred num) (beep))) > num)) > > To the regulars here. Would you think I should file a bug report and > send that patch to the maintainers? Yes. (But send it as a diff.) > Now it get's clear: > (defun demo (&optional num) > (interactive > (let* ((defaultval 5) > (prompt (format "Give me a number (default %d): " defaultval))) > (list (read-number prompt t defaultval)))) > (insert (format "got %d" num))) > > Well read-number should read a number therefor it does it is logical > to have defaultval which is a number too. With the provided patch this > will do. Exactly. -- Kevin Rodgers