Procházet zdrojové kódy

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.
Eric Schulte před 12 roky
rodič
revize
32a6bae7c0
1 změnil soubory, kde provedl 14 přidání a 2 odebrání
  1. 14 2
      lisp/ob-python.el

+ 14 - 2
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)))