emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: Kyle Meyer <kyle@kyleam.com>
Cc: Richard Stanton <stanton@haas.berkeley.edu>,
	emacs-orgmode@gnu.org, John Kitchin <jkitchin@andrew.cmu.edu>
Subject: Re: Extraneous output from Python code blocks using :session option
Date: Fri, 13 Mar 2015 09:21:09 +0100	[thread overview]
Message-ID: <87ioe5xq8a.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <87d24dtmck.fsf@kmlap.domain.org> (Kyle Meyer's message of "Fri, 13 Mar 2015 02:58:35 -0400")

Hello,

Kyle Meyer <kyle@kyleam.com> writes:

> I've attached two patches.  The first one is a proposed way to deal with
> the indentation issues in sessions.  It is very similar to what
> python.el does for multiline input (use a temporary file and then
> execute that from the shell).  The second is an update of my previous
> patch to remove shell prompt characters that are leaking into the
> output.

Thank you.

I'll just comment about code, not functionality.

> +(defconst org-babel-python-indented-lines-session-method
> +  (concat "fname= '%s'; fh = open(fname); "
> +	  "exec(compile(fh.read(), fname, 'exec')); "
> +	  "fh.close()")
> +  "Single line to execute indented Python code in session.
> +%s will be formatted with the file name of the file containing
> + the code.")
  ^^^
spurious space

> +(defun org-babel-python--indented-p (input)
> +  "Return true if any line in INPUT is indented."

Non-nil if ...

> +  (with-temp-buffer
> +    (insert input)
> +    (goto-char (point-min))
> +    (re-search-forward "^\\s-" nil t)))

aka

  (org-string-match-p "^[ \t]" input)

> +(defun org-babel-python--strip-session-chars (string)
> +  "Remove leading '>>>' and '...' from Python session output.
> +`org-babel-comint-with-output' splits by
> +`comint-prompt-regexp' (which includes '>>>' and '...'), but, in
> +some situations, these still make it through at the start of the
> +output string."

Argument STRING is not explained in the docstring.

> +  (with-temp-buffer
> +    (insert string)
> +    (goto-char (point-min))
> +    (when (looking-at "\\s-*\n\\(\\(>>> \\)\\|\\(\\.\\.\\. \\)\\)*")
> +      (delete-region (match-beginning 0) (match-end 0)))
> +    (buffer-string)))

aka

  (replace-regexp-in-string "\\`\\s-*\n\\(>>> \\|\\.\\.\\. \\)*" "" string)


Regards,

-- 
Nicolas Goaziou

  reply	other threads:[~2015-03-13  8:20 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-11  3:38 Extraneous output from Python code blocks using :session option Richard Stanton
2015-03-11 18:29 ` Kyle Meyer
2015-03-11 18:54   ` Richard Stanton
2015-03-12 15:17   ` John Kitchin
2015-03-12 15:34     ` Richard Stanton
2015-03-12 21:23       ` Kyle Meyer
2015-03-13  6:58         ` Kyle Meyer
2015-03-13  8:21           ` Nicolas Goaziou [this message]
2015-03-13 14:40             ` Kyle Meyer
2015-03-14  8:26               ` Nicolas Goaziou
2015-03-16  0:40                 ` Kyle Meyer
2015-03-12 21:21     ` Kyle Meyer

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=87ioe5xq8a.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=jkitchin@andrew.cmu.edu \
    --cc=kyle@kyleam.com \
    --cc=stanton@haas.berkeley.edu \
    /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).