emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] a small bug in ob-lua.el


From: Brad Knotwell
Subject: [O] a small bug in ob-lua.el
Date: Sat, 29 Dec 2018 17:48:34 +0000 (UTC)

Hello all--

I've been using the babel integration with Lua and it has a bug worth noting--multi-line header argument variables that are tangled to a file will be tangled in a way lua doesn't interpret correctly.  To use a specific example:

#+NAME: csvdata
#+BEGIN_EXAMPLE
x,y,z,zz
1,2,3,"hi"
4,5,6,"hi,hi"
7,8,9,"hi,hi,hi"
#+END_EXAMPLE

#+BEGIN_SRC lua :var csv=csvdata :tangle test.lua

print(csv)
#+END_SRC

tangles to the (python default?) following:

csv="""x,y,z,zz

1,2,3,\"hi\"

4,5,6,\"hi,hi\"

7,8,9,\"hi,hi,hi\"

"""


print(csv)

which Lua won't parse.  It would parse the following however:

csv=[=[x,y,z,zz

1,2,3,\"hi\"

4,5,6,\"hi,hi\"

7,8,9,\"hi,hi,hi\"

]=]


print(csv)

Furthermore, it will also remove the need to escape the internal double quote characters so you could have even cleaner output:

csv=[=[x,y,z,zz

1,2,3,"hi"

4,5,6,"hi,hi"

7,8,9,"hi,hi,hi"

]=]


The following trivial patch resolves it and tangles to a file that Lua can evaluate:

csv=[=[x,y,z,zz

1,2,3,"hi"

4,5,6,"hi,hig"

7,8,9,"hi,hi,hi"

]=]


print(csv)



diff --git a/lisp/ob-lua.el b/lisp/ob-lua.el
index 442ea568b..4625b3202 100644
--- a/lisp/ob-lua.el
+++ b/lisp/ob-lua.el
@@ -148,7 +148,7 @@ specifying a variable of the same value."
     (if (eq var 'hline)
         org-babel-lua-hline-to
       (format
-       (if (and (stringp var) (string-match "[\n\r]" var)) "\"\"%S\"\"" "%S")
+       (if (and (stringp var) (string-match "[\n\r]" var)) "[=[%s]=]" "%S")
        (if (stringp var) (substring-no-properties var) var)))))
 
 (defun org-babel-lua-table-or-string (results)

Thx.

--Brad

reply via email to

[Prev in Thread] Current Thread [Next in Thread]