From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: elisp: can a function/defun return two strings..? prompt for two strings?? Date: Sun, 27 Feb 2011 12:07:48 +0100 Organization: Informatimago Message-ID: <87hbbp20sb.fsf@kuiper.lan.informatimago.com> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1298806846 7481 80.91.229.12 (27 Feb 2011 11:40:46 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 27 Feb 2011 11:40:46 +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 12:40:41 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 1PtezL-0002yg-RR for geh-help-gnu-emacs@m.gmane.org; Sun, 27 Feb 2011 12:40:36 +0100 Original-Received: from localhost ([127.0.0.1]:44111 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PtezL-0002Rn-As for geh-help-gnu-emacs@m.gmane.org; Sun, 27 Feb 2011 06:40:35 -0500 Original-Path: usenet.stanford.edu!news-transit.tcx.org.uk!news.netcologne.de!newsfeed-fusi2.netcologne.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 89 Original-X-Trace: individual.net eDkakYC3wB5qdnMNmRIyNgwpF61ZUPXPiZUU/HCn3Bndn5zIZ5 Cancel-Lock: sha1:ZTgyNGM1MGNlYTdmN2E1N2MyMDMzNWI0ZjM1ZTkzYjZmOWI1OTA2Yw== sha1:3NsM7GCbCFtObWqP6k9dSDd3n7k= Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en X-Disabled: X-No-Archive: no User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) Original-Xref: usenet.stanford.edu gnu.emacs.help:185368 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:79525 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: (defun pseudo-code () > ;; search buffer for line of interest. (let ((line-of-interest (search-buffer-for-it))) > ;; if the line exists (if (line-exists-p line-of-interest) (list > ;; does it specify str1? (if (line-specify-str1-p line-of-interest) > ;; if it does, grab that str1, hold it for eventual return (grab-str1 line-of-interest) > ;; if it doesn't, prompt user for it, and hold it for eventual > return. (read-from-minibuffer "prompt for str1")) > ;; does the same line specify str2? (if (line-specify-str2-p line-of-interest) > ;; if it does, grab that str2, hold it for eventual return (grab-str2 line-of-interest) > ;; if it doesn't, prompt user for it, and hold it for eventual > return. (read-from-minibuffer "prompt for str2"))) > ;; if the line doesn't exist, > ;; prompt user for str1 and str2 (let ((str1 (read-from-minibuffer "prompt for str1")) (str2 (read-from-minibuffer "prompt for str2"))) (insert "%s %s\n" str1 str2) (list str1 str2))))) > ;; create/insert new line in buffer, inserting str1 & str2 into it. > ;; return str1 and str2 to calling function Now you just need to implement the missing functions used above... > Most of the coding for the above will busy itself with finding the line > of interest-- or determining that it doesn't exist. I doubt so. Clearly, the coding above busies itself with something else, as the pseudo code clearly indicates. > 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. What are you talking about??? > 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.) You cannot return variables, only values, resulting from the evaluation of expressions. -- __Pascal Bourguignon__ http://www.informatimago.com/ A bad day in () is better than a good day in {}.