emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Herbert Sitz <hsitz@nwlink.com>
To: emacs-orgmode@gnu.org
Subject: Re: org-babel -- Improper syntax error in session mode?
Date: Mon, 20 Jun 2011 03:46:41 +0000 (UTC)	[thread overview]
Message-ID: <loom.20110620T053645-75@post.gmane.org> (raw)
In-Reply-To: 23747.1308539849@alphaville.dokosmarshall.org

Nick Dokos <nicholas.dokos <at> 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
 

  reply	other threads:[~2011-06-20  3:47 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-19 21:54 org-babel -- Improper syntax error in session mode? Herbert Sitz
2011-06-19 23:21 ` Eric Schulte
2011-06-20  1:59   ` Herbert Sitz
2011-06-20  2:12   ` Herbert Sitz
2011-06-20  3:17     ` Nick Dokos
2011-06-20  3:46       ` Herbert Sitz [this message]
2011-06-20 19:23       ` Eric Schulte
2011-06-20 20:45         ` Herbert Sitz
2011-06-20 21:15           ` Eric Schulte
2011-06-20 23:16             ` Herbert Sitz
2011-06-21  0:08               ` Nick Dokos
2011-06-21  0:27                 ` Herbert Sitz
     [not found]                   ` <hesitz@gmail.com>
2011-06-21  1:17                     ` Nick Dokos
2011-06-21  2:19               ` Eric Schulte
2011-06-21  5:13                 ` Herbert Sitz
2011-06-21  7:15                   ` Thomas S. Dye
2011-06-21 15:35                     ` Herbert Sitz
2011-06-21 16:27                       ` Thomas S. Dye
2011-06-21 17:42                         ` Eric Schulte
2011-06-21 17:51                         ` Herbert Sitz
2011-06-21 17:52                       ` Eric Schulte
2011-06-27 18:09                         ` Herbert Sitz
2011-06-21 17:26                   ` Eric Schulte
2011-06-27 18:22                     ` Herbert Sitz
2011-06-20 21:18     ` Jambunathan K

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=loom.20110620T053645-75@post.gmane.org \
    --to=hsitz@nwlink.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).