From 32a6bae7c0ff83ec0f30e7c89886701dfa3f015b Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Tue, 30 Oct 2012 18:04:41 -0600 Subject: [PATCH] better hline and None translations in ob-python * lisp/ob-python.el (org-babel-python-hline-to): Customize hline conversion to python. (org-babel-python-None-to): Customize none conversion from python. (org-babel-python-var-to-python): Use new variable. (org-babel-python-table-or-string): Use new variable. --- lisp/ob-python.el | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lisp/ob-python.el b/lisp/ob-python.el index 71adf7307..041f4b540 100644 --- a/lisp/ob-python.el +++ b/lisp/ob-python.el @@ -52,6 +52,12 @@ This will typically be either 'python or 'python-mode.") (defvar org-src-preserve-indentation) +(defcustom org-babel-python-hline-to "None" + "Replace hlines in incoming tables with this when translating to python.") + +(defcustom org-babel-python-None-to 'hline + "Replace 'None' in python tables with this before returning.") + (defun org-babel-execute:python (body params) "Execute a block of Python code with Babel. This function is called by `org-babel-execute-src-block'." @@ -114,7 +120,7 @@ specifying a variable of the same value." (if (listp var) (concat "[" (mapconcat #'org-babel-python-var-to-python var ", ") "]") (if (equal var 'hline) - "None" + org-babel-python-hline-to (format (if (and (stringp var) (string-match "[\n\r]" var)) "\"\"%S\"\"" "%S") var)))) @@ -123,7 +129,13 @@ specifying a variable of the same value." "Convert RESULTS into an appropriate elisp value. If the results look like a list or tuple, then convert them into an Emacs-lisp table, otherwise return the results as a string." - (org-babel-script-escape results)) + ((lambda (res) + (if (listp res) + (mapcar (lambda (el) (if (equal el 'None) + org-babel-python-None-to el)) + res) + res)) + (org-babel-script-escape results))) (defvar org-babel-python-buffers '((:default . nil))) -- 2.11.4.GIT