From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xend Newsgroups: gmane.emacs.help Subject: Re: interact with user Date: Thu, 27 Nov 2008 18:23:18 -0800 (PST) Organization: http://groups.google.com Message-ID: <82fd15a5-e04a-42ec-af77-7250e82f9238@c36g2000prc.googlegroups.com> References: <5e7d7456-b98e-4750-8f46-f05568f1db0c@a29g2000pra.googlegroups.com> <5672ef09-72a1-4df4-851c-a416d05cb9c0@s1g2000prg.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1227840133 7939 80.91.229.12 (28 Nov 2008 02:42:13 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 28 Nov 2008 02:42:13 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Nov 28 03:43:16 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1L5tK7-0007Co-QE for geh-help-gnu-emacs@m.gmane.org; Fri, 28 Nov 2008 03:43:16 +0100 Original-Received: from localhost ([127.0.0.1]:43076 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L5tIy-0005sx-4C for geh-help-gnu-emacs@m.gmane.org; Thu, 27 Nov 2008 21:42:04 -0500 Original-Path: news.stanford.edu!newsfeed.stanford.edu!postnews.google.com!c36g2000prc.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 109 Original-NNTP-Posting-Host: 123.149.26.168 Original-X-Trace: posting.google.com 1227838999 22886 127.0.0.1 (28 Nov 2008 02:23:19 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Fri, 28 Nov 2008 02:23:19 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: c36g2000prc.googlegroups.com; posting-host=123.149.26.168; posting-account=o4YrVwoAAAAAIOu9uBqaRT4EH9JiGtz4 User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092416 Firefox/3.0.3,gzip(gfe),gzip(gfe) Original-Xref: news.stanford.edu gnu.emacs.help:164848 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:60175 Archived-At: On Nov 26, 9:46=C2=A0pm, Xah Lee wrote: > On Nov 26, 5:39 am, Xend wrote: > > > how can i get input from user (interact with user)in function with GNU/ > > emacs,the function interactive only work to parse arguments. are there > > bulitin emacs function or i should programming to do it? > > btw, The =E2=80=9Cinteractive=E2=80=9D function has a general form like t= his: > =E2=80=9C(interactive lispExp)=E2=80=9D, where in the lispExp is any lisp= code, among > which you can use any lisp function that query user. The return value > of lispExp becomes the argument of your command. > > more answer here: > > =E2=80=A2 Emacs Lisp Idioms > =C2=A0http://xahlee.org/emacs/elisp_idioms.html > > here's relevant excerpt: > > ---------------------------------------- > Prompting User for Input > Get User Input as Arguments > > Idiom for promping user for input as the argument to your command. > > Use this code =E2=80=9C(interactive "=E2=80=B9code=E2=80=BA=E2=80=B9promp= string=E2=80=BA")=E2=80=9D. Example: > > (defun query-friends-phone (name) > =C2=A0 "..." > =C2=A0 (interactive "sEnter friend's name: ") > =C2=A0 (message "Name: %s" name) > ) > > What the =E2=80=9C(interactive "sEnter friend's name:")=E2=80=9D does is = that it will > ask user to input something, taken as string, and becomes the value of > your command's parameter. > > The =E2=80=9Cinteractive=E2=80=9D can be used to get other types of input= . Here are > some basic examples of using =E2=80=9Cinteractive=E2=80=9D. > > =C2=A0 =C2=A0 * =E2=80=9C(interactive)=E2=80=9D makes the function availa= ble thru interactive > use, where user can call it with execute-extended-command (M-x). > =C2=A0 =C2=A0 * =E2=80=9C(interactive "s")=E2=80=9D will prompt user for = input, taken as string, > as argument to the function. > =C2=A0 =C2=A0 * =E2=80=9C(interactive "n")=E2=80=9D will prompt user for = input, taken as number, > as argument to the function. > > The prompt text can follow the single-letter code string. > > If your function takes multiple inputs, you can promp user multiple > times, using a single call =E2=80=9Cinteractive=E2=80=9D, by joining the = promp code > string with =E2=80=9C\n=E2=80=9D in between, like this: > > (defun query-friends-phone (name age) > =C2=A0 "..." > =C2=A0 (interactive "sEnter friend's name: \nnEnter friend's age: ") > =C2=A0 (message "Name: %s, Age: %d" name age) > ) > > (info "(elisp)Defining Commands") > Query For User Input > > The =E2=80=9C(interactive ...)=E2=80=9D clause is useful for filling para= meters of > your command. But sometimes you need to promp user in the middle of a > program. For example: =E2=80=9CMake change to this file?=E2=80=9D. You ca= n use =E2=80=9Cy-or-n- > p=E2=80=9D function. Like this: > > (if (y-or-n-p "Do it?") > =C2=A0 =C2=A0 (progn > =C2=A0 =C2=A0 =C2=A0 ;; code to do something here > =C2=A0 =C2=A0 ) > =C2=A0 (progn > =C2=A0 =C2=A0 ;; code if user answered no. > =C2=A0 ) > ) > > The y-or-n-p will ask the user to type a =E2=80=9Cy=E2=80=9D or =E2=80=9C= n=E2=80=9D character. You can > also use =E2=80=9Cyes-and-no-p=E2=80=9D, which forces user to type full = =E2=80=9Cyes=E2=80=9D and =E2=80=9Cno=E2=80=9D > to answer. This can be used for example when you want to confirm > deleting files. > > Yes-or-No-Queries > > If you need more general mechanism for getting user input, you'll need > to use =E2=80=9Cread-from-minibuffer=E2=80=9D. This can be useful for exa= mple, when > you want use features like keyword completion or input history. > > (info "(elisp)Text from Minibuffer") > > =C2=A0 Xah > =E2=88=91http://xahlee.org/ > > =E2=98=84 thanks for your help.men