unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Kevin Rodgers <ihs_4664@yahoo.com>
Subject: Re: [elisp]How to ask and provide a Default value?
Date: Thu, 04 Mar 2004 08:54:31 -0700	[thread overview]
Message-ID: <40475137.5080409@yahoo.com> (raw)
In-Reply-To: uwu61hzlf.fsf@163.cn.comp.os.linuxcom

FKtPp@Office ;) wrote:
 >    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: ")

OK, so you're using just `r' for the beginning and end args and `n' for
each of the base, step, and column args.  `r' doesn't prompt the user
for input, but provides the current region bounds automatically.  And
here's a simple way to test the `n' character code:

(defun foo (number)
   (interactive "nNumber: ")
   (message "number=%d" number))

When I type `M-x foo RET RET' on Emacs 19.34, I get an "End of file
during parsing" error.  When I type that on Emacs 21.3, I get a
transient "Please enter a number." Message, then the prompt is
redisplayed.  So evidently Emacs does not provide a default for the `n'
character code.

 >   (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))))

You are confused here: the `n' characters codes in the interactive form
will cause base, step, and column to be bound to numbers, not strings.

 >     (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))))

When the save-excursion form returns, it will restore the previous
narrowing (if any), so you should not explicitly call widen there.

-- 
Kevin Rodgers

  reply	other threads:[~2004-03-04 15:54 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-04  6:54 [elisp]How to ask and provide a Default value? FKtPp@Office ;)
2004-03-04 15:54 ` Kevin Rodgers [this message]
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
  -- strict thread matches above, loose matches on Subject: below --
2004-03-05  7:45 Joakim Hove
2004-03-05  8:04 ` Joakim Hove
2004-03-06  7:52 ` FKtPp@Office ;)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=40475137.5080409@yahoo.com \
    --to=ihs_4664@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).