From mboxrd@z Thu Jan 1 00:00:00 1970 From: Herbert Sitz Subject: Re: org-babel -- Improper syntax error in session mode? Date: Mon, 20 Jun 2011 03:46:41 +0000 (UTC) Message-ID: References: <87k4chwgpa.fsf@gmail.com> <23747.1308539849@alphaville.dokosmarshall.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([140.186.70.92]:36833) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QYVRz-0005Me-Rf for emacs-orgmode@gnu.org; Sun, 19 Jun 2011 23:47:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QYVRy-0001mH-UB for emacs-orgmode@gnu.org; Sun, 19 Jun 2011 23:46:59 -0400 Received: from lo.gmane.org ([80.91.229.12]:47401) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QYVRy-0001mC-Ih for emacs-orgmode@gnu.org; Sun, 19 Jun 2011 23:46:58 -0400 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QYVRv-0003yj-5N for emacs-orgmode@gnu.org; Mon, 20 Jun 2011 05:46:55 +0200 Received: from c-24-22-131-140.hsd1.wa.comcast.net ([24.22.131.140]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 20 Jun 2011 05:46:55 +0200 Received: from hsitz by c-24-22-131-140.hsd1.wa.comcast.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 20 Jun 2011 05:46:55 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Nick Dokos hp.com> writes: > Having said that, however, I think there *is* a problem: > > If you just start the python interpreter and start typing into it: > > --8<---------------cut here---------------start------------->8--- > x = 1 > for i in range(1,5): > x = x + i > print x > print "Did it work?" > --8<---------------cut here---------------end--------------->8--- > > the problem becomes obvious: the interpreter is still in "indented mode" > and complains about the last print, because it is not "properly" > indented. OTOH, if you exit "indented mode" by pressing another RET > before the final print, the interpreter is happy. This is a kludge used > by the interactive interpreter to accommodate python's reliance on > indentation to delimit block structure. > > That however does not work with babel: even if I leave empty lines > between the print x and the last print, the error persists. Apparently, > babel does not send the empty lines to the interpreter. If there is a > bug in babel, it seems to me this is it. > > Nick > Yep, that's what I was thinking. Experiment a little I found that wrapping it in a function gets around part of the problem. This works fine in the terminal, although it doesn't work from the equivalent Babel source block: --8<---------------cut here---------------start------------->8--- >>> def myfunc(): ... x=1 ... for i in range(1,5): ... x=x+i ... print x ... print "Did it work?" ... >>> myfunc() 2 4 7 11 Did it work? >>> --8<---------------cut here---------------start------------->8--- I don't know whether having Babel feed things in pieces and assemble output is complicated for the general case. It seems to me it wouldn't be that bad, it's only the lines where an indent reverts to zero indent where pieces would need to be broken up. As a partial solution, having Babel insert the requisite blank line after the last line of a function def would be helpful, and I think the output would then all end up in a single block, no need to reassemble (or maybe output reassembly is just simplified a little). -- Herb