From 28b6a003e4ae1dbb1474350203444e76df9e8572 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Fri, 13 Mar 2015 02:46:38 -0400 Subject: [PATCH 2/2] ob-python.el: Strip leading session characters * lisp/ob-python.el (org-babel-python-evaluate-session): Strip extra leading "..." and ">>>" from session output. --- lisp/ob-python.el | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/lisp/ob-python.el b/lisp/ob-python.el index 0dc74ca..e976d9c 100644 --- a/lisp/ob-python.el +++ b/lisp/ob-python.el @@ -321,16 +321,17 @@ (defun org-babel-python-evaluate-session (results (case result-type (output - (mapconcat - #'org-babel-trim - (butlast - (org-babel-comint-with-output - (session org-babel-python-eoe-indicator t body) - (funcall input-body body) - (funcall send-wait) (funcall send-wait) - (insert org-babel-python-eoe-indicator) - (funcall send-wait)) - 2) "\n")) + (org-babel-python--strip-session-chars + (mapconcat + #'org-babel-chomp + (butlast + (org-babel-comint-with-output + (session org-babel-python-eoe-indicator t body) + (funcall input-body body) + (funcall send-wait) (funcall send-wait) + (insert org-babel-python-eoe-indicator) + (funcall send-wait)) + 2) "\n"))) (value (when indented-p (user-error "Value output limited to unindented lines with session")) @@ -356,6 +357,15 @@ (defun org-babel-python-read-string (string) (match-string 1 string) string)) +(defun org-babel-python--strip-session-chars (string) + "Remove leading '>>>' and '...' from STRING. +`org-babel-comint-with-output' splits the Python session output +by `comint-prompt-regexp' (which includes '>>>' and '...'), but, +in some situations, these still make it through at the start of +the output string." + (replace-regexp-in-string "\\`\\s-*\n\\(>>> \\|\\.\\.\\. \\)*" "" + string)) + (provide 'ob-python) -- 2.3.1