瀏覽代碼

ob-python: Fix discrepancy of single/multi-line code blocks

* lisp/ob-python.el (org-babel-python-evaluate-session): Fix
discrepancy between how single-line and multiline code blocks return
output.

For example, before this commit, the 2 blocks behaved differently:

+begin_src python :session :results output
  pass
  "foo"
+end_src

+RESULTS:

+begin_src python :session :results output
  "foo"
+end_src

+RESULTS:
: 'foo'

But now, they both behave as the former.
Jack Kamm 4 年之前
父節點
當前提交
30a50d1c0f
共有 1 個文件被更改,包括 6 次插入8 次删除
  1. 6 8
      lisp/ob-python.el

+ 6 - 8
lisp/ob-python.el

@@ -330,14 +330,12 @@ last statement in BODY, as elisp."
          (results
           (pcase result-type
             (`output
-	     (let ((body (if (string-match-p ".\n+." body) ; Multiline
-			     (let ((tmp-src-file (org-babel-temp-file
-						  "python-")))
-			       (with-temp-file tmp-src-file (insert body))
-			       (format org-babel-python--exec-tmpfile
-				       (org-babel-process-file-name
-					tmp-src-file 'noquote)))
-			   body)))
+	     (let ((body (let ((tmp-src-file (org-babel-temp-file
+					      "python-")))
+			   (with-temp-file tmp-src-file (insert body))
+			   (format org-babel-python--exec-tmpfile
+				   (org-babel-process-file-name
+				    tmp-src-file 'noquote)))))
 	       (mapconcat
 		#'org-trim
 		(butlast