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 20:45:05 +0000 (UTC) Message-ID: References: <87k4chwgpa.fsf@gmail.com> <23747.1308539849@alphaville.dokosmarshall.org> <87ei2ouwxk.fsf@gmail.com> 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]:46422) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QYlLW-0005E4-SL for emacs-orgmode@gnu.org; Mon, 20 Jun 2011 16:45:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QYlLU-0002uP-TV for emacs-orgmode@gnu.org; Mon, 20 Jun 2011 16:45:22 -0400 Received: from lo.gmane.org ([80.91.229.12]:39809) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QYlLU-0002u9-6V for emacs-orgmode@gnu.org; Mon, 20 Jun 2011 16:45:20 -0400 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QYlLQ-0004YG-VP for emacs-orgmode@gnu.org; Mon, 20 Jun 2011 22:45:17 +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 22:45:16 +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 22:45:16 +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 Eric Schulte gmail.com> writes: > I've changed the python session evaluation so that it explicitly sends a > RET to the inferior Python process after every line of input. The > attached patch makes this change. > I can confirm that this fixes the > problem in your example (when an empty line is placed between the block > and the subsequent print statement) Eric -- I did confirm that the patch works with this block: ------------------------------------------------ #+begin_src python :results output :session mypy x = 1 for i in range(1,5): x = x + i print x print "Did it work?" #+end_src ------------------------------------------------ But it doesn't work with the block below, which _is_ valid Python code. I'm not sure whether you're aware that it isn't working with the code below (and were thinking that the code below is _not_ valid python), or whether you were going to require the user to input blank lines at appropriate spots: ---------------------------------------------- #+begin_src python :results output :session mypy x = 1 for i in range(1,5): x = x + i print x print "Did it work?" #+end_src ------------------------------------------- The above block is valid Python, it's just because of the quirk of the interactive python shell that it has to have a blank line inserted before the [print "Did it work?"] line. The locations where the blank lines would need to be inserted in code are wherever the line indent goes from >0 back to 0. A user could be required to insert these, of course, but since it's valid python to leave them out it seems like something org-babel should do behind the scenes. The '0 indent' for purposes of python execution is the smallest indent in the org-babel source. So even though all source code lines are indented in above org block, the line 'x=1' has zero indent for python eval purposes. The relevance of this is just to show that extra lines for shell/babel evaluation are necessary only when code indent goes back to zero, not when indent merely becomes smaller. So the code below works fine, even though indent shrinks after 'print y' and 'print z' statements:: ------------------------------ #+begin_src python :results output :session mypy x = 1 y = 1 z = 1 for i in range(1,5): x = x + i print x for y in range(10,15): print y for z in range(20,25): print z print "Did it work?" #+end_src ------------------------------------ Like the simpler example, though, it doesn't work with with the blank line omitted, which it should. I hope I'm not confusing things. The patch does help, but doesn't address the extra-line insertion issue. -- Herb