From 06056792c96c4c5996db5dd13e857658e6d4a573 Mon Sep 17 00:00:00 2001 From: Achim Gratz Date: Sun, 12 May 2013 20:36:51 +0200 Subject: [PATCH] ob-sh: detect tables correctly, add :hlines processing and :hline-string header arg * lisp/ob-sh.el (org-babel-variable-assignments:sh): Check for ":hlines yes" and use header arg :hlines-string if defined (default to "hline") and add this to the call of `org-babel-sh-var-to-sh'. (org-babel-sh-var-to-sh, org-babel-sh-var-to-string): Add additional optional string argument `hline' and use it for the :hline parameter in the call to `orgtbl-to-generic'. Thanks to Paul Stansell for pointing out the error. --- lisp/ob-sh.el | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lisp/ob-sh.el b/lisp/ob-sh.el index f11b799..72f3c19 100644 --- a/lisp/ob-sh.el +++ b/lisp/ob-sh.el @@ -88,26 +88,31 @@ (defun org-babel-load-session:sh (session body params) (defun org-babel-variable-assignments:sh (params) "Return list of shell statements assigning the block's variables." - (let ((sep (cdr (assoc :separator params)))) + (let ((sep (cdr (assoc :separator params))) + (hline (when (string= "yes" (cdr (assoc :hlines params))) + (or (cdr (assoc :hline-string params)) + "hline")))) (mapcar (lambda (pair) (format "%s=%s" (car pair) - (org-babel-sh-var-to-sh (cdr pair) sep))) + (org-babel-sh-var-to-sh (cdr pair) sep hline))) (mapcar #'cdr (org-babel-get-header params :var))))) -(defun org-babel-sh-var-to-sh (var &optional sep) +(defun org-babel-sh-var-to-sh (var &optional sep hlines) "Convert an elisp value to a shell variable. Convert an elisp var into a string of shell commands specifying a var of the same value." - (format org-babel-sh-var-quote-fmt (org-babel-sh-var-to-string var sep))) + (format org-babel-sh-var-quote-fmt (org-babel-sh-var-to-string var sep hline))) -(defun org-babel-sh-var-to-string (var &optional sep) +(defun org-babel-sh-var-to-string (var &optional sep hline) "Convert an elisp value to a string." (let ((echo-var (lambda (v) (if (stringp v) v (format "%S" v))))) (cond - ((and (listp var) (listp (car var))) - (orgtbl-to-generic var (list :sep (or sep "\t") :fmt echo-var))) + ((and (listp var) (or (listp (car var)) 'hline)) + (orgtbl-to-generic var (list :sep (or sep "\t") + :fmt echo-var + :hline hline))) ((listp var) (mapconcat echo-var var "\n")) (t (funcall echo-var var))))) -- 1.8.2.2