From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Edi Weitz Newsgroups: gmane.emacs.help Subject: Re: HOW TO GIVE A DEFAULT TO A TRULY INTERACTIVE FUNCTION Date: 14 Oct 2002 22:07:03 +0200 Sender: help-gnu-emacs-admin@gnu.org Message-ID: <8765w4yec8.fsf@bird.agharta.de> References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1034626451 1945 80.91.224.249 (14 Oct 2002 20:14:11 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 14 Oct 2002 20:14:11 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 181BbO-0000VE-00 for ; Mon, 14 Oct 2002 22:14:10 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 181BYm-0005G7-00; Mon, 14 Oct 2002 16:11:28 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!130.133.1.3!fu-berlin.de!uni-berlin.de!trane.agharta.DE!not-for-mail Original-Newsgroups: gnu.emacs.help,comp.emacs Original-Lines: 57 Original-NNTP-Posting-Host: trane.agharta.de (62.159.208.82) Original-X-Trace: fu-berlin.de 1034626022 22216076 62.159.208.82 (16 [15706]) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Original-Xref: shelby.stanford.edu gnu.emacs.help:106058 comp.emacs:75287 Original-To: help-gnu-emacs@gnu.org Errors-To: help-gnu-emacs-admin@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.help:2605 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:2605 gnuist006@hotmail.com (gnuist006) writes: > (defun demo (&optional number) > "Demo of an optional argument of the function." > (interactive "nEnter a number:") > (setq defaultval 5) > (if (null number) (setq number defaultval)) > (insert (format "%s" number)) > ) (demo) > ; works due to optional argument > > I want the default to work on the command line also. > They say emacs is customizable. OK it is if you only want to do what > it > can do, and never try to do what you want to do. > > I want to invoke it on command line ie M-x demo > It comes and says > Enter a number:_ > > I prefer it display the default 5 in the message and there is > SINGLE instance of 5 in the function. ie using defaultval. > > If this cannot do this and you were all lying to yourself that > emacs is customizable, infinitely extensible, then I atleast want > quick fix for this. > > When I hit RTN after it begs for number once, it go away and use > defaultval and stop buggin me. > > At present it does not stap and keeps bugging till I enter 5. > Why do I have to remember the default when I am giving it that much > money? This guy is obviously a troll who doesn't deserve an answer but for the sake of others who might read this: (require 'cl) (defun* bar (&optional (default 5)) (let* ((default-string (format "%s" default)) (string (read-string "Number: " default-string nil default-string))) ;; needs check for wrong input (list (string-to-number string)))) (defun foo (n) (interactive (bar 42)) (insert (format "%s" (* 3 n)))) I'm sure the real Emacs experts know better ways to do this, I just wanted to show that it's doable. Edi.