Eric Schulte writes:
> This does look like a bug to me.  Can you isolate "where" the value of
> data in your example is first assigned the wrong value?

The error lies in how ob-sh tries to determine if it needs to process a
table or a vector and then forgets to check for 'hline, thus ending up
in the vector branch with the table data.

> Thanks for reporting.  I will save your example for when I next have
> development time.

Here's a suggestion for a quick fix.  I've also implemented :hlines
processing for ob-sh (it was ignoring that header arg unconditionally)
and added an experimental header arg :hline-string to control how hlines
get actually exported.  BTW, trailing blank lines in the output get
swallowed when re-importing to Org, I'm not sure if that is supposed to
happen or not.

>From 06056792c96c4c5996db5dd13e857658e6d4a573 Mon Sep 17 00:00:00 2001
From: Achim Gratz <strom...@stromeko.de>
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

Giving ob-gnuplot (and possible ob-awk, which also uses
orgtbl-to-generic) a similar treatment would allow to do this directly
without going through ob.sh of course.


Regards,
Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Factory and User Sound Singles for Waldorf Q+, Q and microQ:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds

Reply via email to