From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tim X Newsgroups: gmane.emacs.help Subject: Re: elisp: can a function/defun return two strings..? prompt for two strings?? Date: Mon, 28 Feb 2011 08:10:49 +1100 Organization: Unlimited download news at news.astraweb.com Message-ID: <87lj1118va.fsf@puma.rapttech.com.au> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1298843890 29462 80.91.229.12 (27 Feb 2011 21:58:10 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 27 Feb 2011 21:58:10 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Feb 27 22:58:06 2011 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.69) (envelope-from ) id 1Ptocv-0002px-G0 for geh-help-gnu-emacs@m.gmane.org; Sun, 27 Feb 2011 22:58:05 +0100 Original-Received: from localhost ([127.0.0.1]:35598 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PtoRO-0005vx-D2 for geh-help-gnu-emacs@m.gmane.org; Sun, 27 Feb 2011 16:46:10 -0500 Original-Path: usenet.stanford.edu!news.glorb.com!news2.glorb.com!news.glorb.com!news-xfer.nntp.sonic.net!news.astraweb.com!border5.newsrouter.astraweb.com!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) Cancel-Lock: sha1:oYsiJ/VasKP2gCrIN+ne2RKLv18= Original-Lines: 45 Original-NNTP-Posting-Host: 5f2e2b90.news.astraweb.com Original-X-Trace: DXC=>gJRo<_`IS6J5c6\GR85Z>L?0kYOcDh@:W\:Hm@YlDb:^D8U\dF3`\49:BodX0GDT=5jLnYO4HRI< Original-Xref: usenet.stanford.edu gnu.emacs.help:185389 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:79544 Archived-At: ken writes: > In one line of a file/buffer (which might exist or might not) will be > two strings, both of which must be fetched and returned to the calling > function. I was going to write two separate functions, one for each > string, but since both strings are in the same line, it seemed highly > inefficient to search for the same line of text twice... made more sense > to search for it once, and get both strings in the same function. > > Here's pseudo-code: > > ;; search buffer for line of interest. > ;; if the line exists > ;; does it specify str1? > ;; if it does, grab that str1, hold it for eventual return > ;; if it doesn't, prompt user for it, and hold it for eventual return. > ;; does the same line specify str2? > ;; if it does, grab that str2, hold it for eventual return > ;; if it doesn't, prompt user for it, and hold it for eventual return. > ;; if the line doesn't exist, > ;; prompt user for str1 and str2 > ;; create/insert new line in buffer, inserting str1 & str2 into it. > ;; return str1 and str2 to calling function > > Most of the coding for the above will busy itself with finding the line > of interest-- or determining that it doesn't exist. So why should I do > that twice, once for each string? Sure, I could save to a variable the > location of the line of interest to avoid having to search for it again, > but then I'm back to working with two variables, the location and just > one string. So that's a non-solution. > > So how to "return" two variables to a calling function, possibly have to > prompt for one or both of them? (I can think of a half dozen ways to do > this in C, but this is elisp.) > > Just return the strings as a list of two strings i.e. (list str1 str2) Tim -- tcross (at) rapttech dot com dot au