help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [elisp]How to ask and provide a Default value?


From: FKtPp@Office ;)
Subject: Re: [elisp]How to ask and provide a Default value?
Date: Fri, 05 Mar 2004 09:02:04 +0800
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (windows-nt)

Kevin Rodgers <ihs_4664@yahoo.com> writes:


[...]

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

Thank you. I got it too :) 

> So evidently Emacs does not provide a default for the `n' character
> code.

But, I still don't know how to use the default character description
:P Would u please give me a sample?

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

And thank u again. I will take ur advise :P


reply via email to

[Prev in Thread] Current Thread [Next in Thread]