[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [elisp]How to ask and provide a Default value?
From: |
Joakim Hove |
Subject: |
Re: [elisp]How to ask and provide a Default value? |
Date: |
Fri, 05 Mar 2004 08:45:45 +0100 |
User-agent: |
Gnus/5.1003 (Gnus v5.10.3) Emacs/21.3.50 (gnu/linux) |
Hello,
maybe you can use this little function:
(defun read-number-with-default (prompt &optional default)
(let ((default-string (if default (number-to-string default) "")))
(string-to-number (read-from-minibuffer prompt default-string))))
Observe two things:
1. The default value is presented to the read routine as
"INITIAL-CONTENTS", and *not* "DEFAULT-VALUE".
2. The routine does not check the number format, and
(string-to-number ) seemingly eats anything with digits in it.
In case you want to use this function you would typically read the
input in the body of the function, i.e. something like:
(defun sleeve-step-region (beginning end base step column)
"Insert a column of increasing numbers in the region."
(let* ((beginning (read-number-with-default "Beginning: " 100))
(end (read-number-with-default "End: " (+ beginning 10)))
...
HTH - Joakim
--
/--------------------------------------------------------------------\
/ Joakim Hove / hove@bccs.no / (55 5) 84076 | \
| Unifob AS, Avdeling for Beregningsvitenskap (BCCS) | Stabburveien 18 |
| CMU | 5231 Paradis |
\ Thormøhlensgt.55, 5020 Bergen. | 55 91 28 18 /
\--------------------------------------------------------------------/
- Re: [elisp]How to ask and provide a Default value?,
Joakim Hove <=