From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Rodgers Newsgroups: gmane.emacs.help Subject: Re: [elisp]How to ask and provide a Default value? Date: Thu, 04 Mar 2004 08:54:31 -0700 Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <40475137.5080409@yahoo.com> References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1078689277 14018 80.91.224.253 (7 Mar 2004 19:54:37 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 7 Mar 2004 19:54:37 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Mar 07 20:54:34 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1B04M5-0000P5-00 for ; Sun, 07 Mar 2004 20:54:33 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1B04LT-0003tu-Nb for geh-help-gnu-emacs@m.gmane.org; Sun, 07 Mar 2004 14:53:55 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!170.207.51.80!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 73 Original-NNTP-Posting-Host: 170.207.51.80 Original-X-Trace: news.uni-berlin.de 1078415663 57571099 I 170.207.51.80 ([82742]) User-Agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:0.9.4.1) Gecko/20020406 Netscape6/6.2.2 X-Accept-Language: en-us Original-Xref: shelby.stanford.edu gnu.emacs.help:121466 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:17447 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:17447 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