From 3d433fac1162f1544fbcfc7e4a8675a258764f34 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 | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/lisp/ob-python.el b/lisp/ob-python.el index 8c51679..170b6cd 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")) @@ -363,6 +364,19 @@ (defun org-babel-python--indented-p (input) (goto-char (point-min)) (re-search-forward "^\\s-" nil t))) +(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." + (with-temp-buffer + (insert string) + (goto-char (point-min)) + (when (looking-at "\\s-*\n\\(\\(>>> \\)\\|\\(\\.\\.\\. \\)\\)*") + (delete-region (match-beginning 0) (match-end 0))) + (buffer-string))) + (provide 'ob-python) -- 2.3.1