From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Bingham, Jay" Newsgroups: gmane.emacs.help Subject: RE: HOW TO GIVE A DEFAULT TO A TRULY INTERACTIVE FUNCTION Date: Mon, 14 Oct 2002 13:27:42 -0500 Sender: help-gnu-emacs-admin@gnu.org Message-ID: <72A87F7160C0994D8C5A36E2FDC227F5035E77F8@txnexc01.americas.cpqcorp.net> NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Trace: main.gmane.org 1034620070 4290 127.0.0.1 (14 Oct 2002 18:27:50 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 14 Oct 2002 18:27:50 +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 1819wR-00016v-00 for ; Mon, 14 Oct 2002 20:27:48 +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 1819wu-00044F-00; Mon, 14 Oct 2002 14:28:16 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 1819wX-0003yb-00 for help-gnu-emacs@gnu.org; Mon, 14 Oct 2002 14:27:53 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 1819wV-0003yH-00 for help-gnu-emacs@gnu.org; Mon, 14 Oct 2002 14:27:52 -0400 Original-Received: from zcamail04.zca.compaq.com ([161.114.32.104]) by monty-python.gnu.org with esmtp (Exim 4.10) id 1819wU-0003yA-00 for help-gnu-emacs@gnu.org; Mon, 14 Oct 2002 14:27:50 -0400 Original-Received: from cacexg12.americas.cpqcorp.net (cacexg12.americas.cpqcorp.net [16.105.250.119]) by zcamail04.zca.compaq.com (Postfix) with ESMTP id 16FCB1016 for ; Mon, 14 Oct 2002 11:27:50 -0700 (PDT) Original-Received: from txnexc01.americas.cpqcorp.net ([16.74.7.244]) by cacexg12.americas.cpqcorp.net with Microsoft SMTPSVC(5.0.2195.2966); Mon, 14 Oct 2002 11:27:44 -0700 X-MimeOLE: Produced By Microsoft Exchange V6.0.6249.0 content-class: urn:content-classes:message X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: HOW TO GIVE A DEFAULT TO A TRULY INTERACTIVE FUNCTION Thread-Index: AcJzm7sCRNRjtYnuSHOERHWETEWDBgAA9jXg Original-To: X-OriginalArrivalTime: 14 Oct 2002 18:27:44.0377 (UTC) FILETIME=[63641690:01C273AF] 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:2597 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:2597 The reason that this function does not do what you want it to is that = the interactive code, "n", in the string type arg-descriptor specifies = that the interactive value must be a number, emacs will not let you = enter a non-numeric value which is what just typing return at the prompt = amounts to. So emacs tells you to enter a number and redisplays the = prompt. Using a string type arg-descriptor the only way that you can set up a = function to allow you to enter a number or nothing is to use the "s" = interactive code character (which does not provide any number = validation) If you are using emacs 21 the easiest way to do number = validation is to use the string-match function with the [:alpha:] = character class as the regexp. Also when the argument is a string the "if (null number)" construct = cannot be used, use "if (string=3D "" number)" instead. Here is your function using a string arg-descriptor, that does some very = crude numeric validation and inserts a 5 when nothing is entered at the = prompt. (defun demo (&optional number) "Demo of an optional argument of the function." (interactive "sEnter a numeric value:") (setq defaultval "5") (if (string=3D "" number) (setq number defaultval)) (if (not (string-match "[:alpha:]" number)) (insert (format "%s" number)) (message "non-numeric value entered, please re-enter")) ) If you want a function that prompts for a number until one is entered = you will have to use an elisp expression type arg-descriptor and do your = own number validation. I used to have a function that did its own = number validation but I lost it when I left my last employer, so I can't = send you an example without going to a lot of work. As I recall the = lisp expression prompted for the number, did the validation and = re-issued the prompt if the string entered was not numeric. There may = be some examples in the emacs lisp reference manual (see: = http://www.gnu.org/manual/elisp-manual-21-2.8). -_ J_) C_)ingham . HP - NonStop Austin Software & Services - Software Product = Assurance . Austin, TX . Language is the apparel in which your thoughts parade in public. . Never clothe them in vulgar and shoddy attire. -Dr. George W. = Crane- -----Original Message----- From: gnuist006 [mailto:gnuist006@hotmail.com]=20 Sent: Monday, October 14, 2002 11:02 AM To: help-gnu-emacs@gnu.org Subject: HOW TO GIVE A DEFAULT TO A TRULY INTERACTIVE FUNCTION (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) =20 ; 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? _______________________________________________ Help-gnu-emacs mailing list Help-gnu-emacs@gnu.org http://mail.gnu.org/mailman/listinfo/help-gnu-emacs