unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Re: [elisp]How to ask and provide a Default value?
@ 2004-03-05  7:45 Joakim Hove
  2004-03-05  8:04 ` Joakim Hove
  2004-03-06  7:52 ` FKtPp@Office ;)
  0 siblings, 2 replies; 9+ messages in thread
From: Joakim Hove @ 2004-03-05  7:45 UTC (permalink / raw)



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     /
  \--------------------------------------------------------------------/

^ permalink raw reply	[flat|nested] 9+ messages in thread
* [elisp]How to ask and provide a Default value?
@ 2004-03-04  6:54 FKtPp@Office ;)
  2004-03-04 15:54 ` Kevin Rodgers
  0 siblings, 1 reply; 9+ messages in thread
From: FKtPp@Office ;) @ 2004-03-04  6:54 UTC (permalink / raw)


hi all,
   I wrote a simple function like:

(defun sleeve-step-region (beginning end base step column)
  "Insert a column of increasing numbers in the region.
"

;; And here, I want it ask some parameters when invoked. Now the
;; problem is: I want it provide a *Default* value, but don't know how
;; to write the character descriptions -_-!! In "(elisp) Interactive
;; Codes"
;; I find this:
;; 
;; ,----
;; |  Default
;; |      A default value of some sort is used if the user enters no text in
;; |      the minibuffer.  The default depends on the code character.
;; `----
;;
;; Can anyone give me some sample to use this "Default" character
;; description?
;;
;; Somebody have suggested  me to use "Lisp expression" in the
;; interactive special form. But I still want to know how to use the
;; character descriptions :P

  (interactive "r\nnTell me the base Number: \nnTell me the Step: \nnWhich column: ")
  (let ((step-number (if (numberp step)
		  step
		(string-to-number step)))
	(base-number (if (numberp base)
			 base
		       (string-to-number base)))
	(column-number (if (numberp column)
			   column
			 (string-to-number column))))
    (save-excursion 
      (narrow-to-region beginning end)
      (goto-char (point-min))
      (beginning-of-line)
      (while (< (point) (point-max))
	(goto-char (+ (point) column-number))
	(insert (number-to-string base-number))
	(setq base-number (+ base-number step-number))
	(forward-line))
      (widen))))

best wishes and thanks for any suggestions!! :)
yours FKtPp 

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2004-03-08 18:46 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-03-05  7:45 [elisp]How to ask and provide a Default value? Joakim Hove
2004-03-05  8:04 ` Joakim Hove
2004-03-06  7:52 ` FKtPp@Office ;)
  -- strict thread matches above, loose matches on Subject: below --
2004-03-04  6:54 FKtPp@Office ;)
2004-03-04 15:54 ` Kevin Rodgers
2004-03-05  1:02   ` FKtPp@Office ;)
2004-03-05 18:16     ` Kevin Rodgers
2004-03-06  7:56       ` FKtPp@Office ;)
2004-03-08 18:46         ` Kevin Rodgers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).