|
From: | Kevin Rodgers |
Subject: | Re: HOW TO GIVE A DEFAULT TO A TRULY INTERACTIVE FUNCTION |
Date: | Fri, 18 Oct 2002 11:05:02 -0600 |
User-agent: | Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:0.9.4.1) Gecko/20020406 Netscape6/6.2.2 |
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 tnil 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. -- <a href="mailto:<kevinr@ihs.com>">Kevin Rodgers</a>
[Prev in Thread] | Current Thread | [Next in Thread] |