From mboxrd@z Thu Jan 1 00:00:00 1970 From: dieter@schoen.or.at Subject: ob-lua.el Date: Tue, 6 May 2014 22:34:59 +0000 (GMT) Message-ID: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="--=_NextPart_ce4d942d051ba54e4f7e48418aaf019a" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55416) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Whnx7-0001KM-Kr for emacs-orgmode@gnu.org; Tue, 06 May 2014 18:35:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Whnx0-0003yK-5x for emacs-orgmode@gnu.org; Tue, 06 May 2014 18:35:09 -0400 Received: from postrelay205.edis.at ([91.227.204.205]:55228) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Whnwz-0003wV-VT for emacs-orgmode@gnu.org; Tue, 06 May 2014 18:35:02 -0400 Received: from mailrelay.edis.at (postrelay205.edis.at [91.227.204.205]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by postrelay205.edis.at (Postfix) with ESMTPS id 69D2C200216A for ; Wed, 7 May 2014 00:35:00 +0200 (CEST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org ----=_NextPart_ce4d942d051ba54e4f7e48418aaf019a Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: Quoted-Printable hi all, for a project I need to tangle lua files (including parameters and table= s), and there seems to be no ob-lua.el (yet). so I shamelessly copied ob-python.el and adapted it to my needs. right now it can tangle lua, also with simple or table parameters. if anybody is interested, I can upload it. before that, it should maybe be completed, and also pass some generic tangle test, I think. I have shortly looked at testing/examples/ob-shell-test.org. Is a test l= ike this suitable? kind regards, dieter ----=_NextPart_ce4d942d051ba54e4f7e48418aaf019a Content-Type: text/html; charset="utf-8" Content-Transfer-Encoding: Quoted-Printable hi all,

for a project I need to tangle l= ua files (including parameters and tables),
and there seems to= be no ob-lua.el (yet).

so I shamelessly copied= ob-python.el and adapted it to my needs.
right now it can tan= gle lua, also with simple or table parameters.

= if anybody is interested, I can upload it.
before that, it sho= uld maybe be completed, and also pass some generic tangle test, I think.=
I have shortly looked at testing/examples/ob-shell-test.org. = Is a test like this suitable?

kind regards,
dieter
----=_NextPart_ce4d942d051ba54e4f7e48418aaf019a-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bastien Subject: Re: ob-lua.el Date: Wed, 07 May 2014 00:46:03 +0200 Message-ID: <871tw64jbo.fsf@bzg.ath.cx> References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:59022) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Who7r-0003de-Ki for emacs-orgmode@gnu.org; Tue, 06 May 2014 18:46:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Who7k-0008Lz-GM for emacs-orgmode@gnu.org; Tue, 06 May 2014 18:46:15 -0400 Received: from mail-s76.mailgun.info ([184.173.153.204]:45566) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Who7k-0008Lu-Cv for emacs-orgmode@gnu.org; Tue, 06 May 2014 18:46:08 -0400 In-Reply-To: (dieter@schoen.or.at's message of "Tue, 6 May 2014 22:34:59 +0000 (GMT)") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: dieter@schoen.or.at Cc: emacs-orgmode@gnu.org Hi Dieter, dieter@schoen.or.at writes: > for a project I need to tangle lua files (including parameters and > tables), > and there seems to be no ob-lua.el (yet). > > so I shamelessly copied ob-python.el and adapted it to my needs. > right now it can tangle lua, also with simple or table parameters. > > if anybody is interested, I can upload it. Yes, please do! > before that, it should maybe be completed, and also pass some generic > tangle test, I think. > I have shortly looked at testing/examples/ob-shell-test.org. Is a > test like this suitable? I suggest to look at testing/lisp/test-ob-shell.el. HTH, -- Bastien From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Busch Subject: Re: ob-lua.el Date: Tue, 6 May 2014 23:25:31 +0000 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:53620) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhpGf-0006ph-9g for emacs-orgmode@gnu.org; Tue, 06 May 2014 19:59:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WhpGa-0000jn-8D for emacs-orgmode@gnu.org; Tue, 06 May 2014 19:59:25 -0400 Received: from mail-by2lp0236.outbound.protection.outlook.com ([207.46.163.236]:22004 helo=na01-by2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WhpGa-0000ja-12 for emacs-orgmode@gnu.org; Tue, 06 May 2014 19:59:20 -0400 In-Reply-To: Content-Language: en-US List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: "emacs-orgmode@gnu.org" I'm VERY interested! Regards, John V. Busch ________________________________________ From: emacs-orgmode-bounces+jbusch=3Ddataverve.com@gnu.org [emacs-orgmode-b= ounces+jbusch=3Ddataverve.com@gnu.org] on behalf of dieter@schoen.or.at [di= eter@schoen.or.at] Sent: Tuesday, May 6, 2014 6:34 PM To: emacs-orgmode@gnu.org Subject: [O] ob-lua.el hi all, for a project I need to tangle lua files (including parameters and tables), and there seems to be no ob-lua.el (yet). so I shamelessly copied ob-python.el and adapted it to my needs. right now it can tangle lua, also with simple or table parameters. if anybody is interested, I can upload it. before that, it should maybe be completed, and also pass some generic tangl= e test, I think. I have shortly looked at testing/examples/ob-shell-test.org. Is a test like= this suitable? kind regards, dieter From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dieter Schoen Subject: Re: ob-lua.el Date: Fri, 09 May 2014 22:23:04 +0200 Message-ID: <87y4yau2fr.wl%dieter@schoen.or.at> References: <871tw64jbo.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54582) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WirK5-0002mv-Oq for emacs-orgmode@gnu.org; Fri, 09 May 2014 16:23:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WirK0-0000Br-Eq for emacs-orgmode@gnu.org; Fri, 09 May 2014 16:23:13 -0400 Received: from postrelay210.edis.at ([91.227.204.210]:38008) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WirK0-0000Bh-8c for emacs-orgmode@gnu.org; Fri, 09 May 2014 16:23:08 -0400 Received: from mailrelay.edis.at (postrelay210.edis.at [91.227.204.210]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by postrelay210.edis.at (Postfix) with ESMTPS id 2100720020FB for ; Fri, 9 May 2014 22:23:06 +0200 (CEST) In-Reply-To: <871tw64jbo.fsf@bzg.ath.cx> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org At Wed, 07 May 2014 00:46:03 +0200, Bastien wrote: > > Hi Dieter, > > dieter@schoen.or.at writes: > > > for a project I need to tangle lua files (including parameters and > > tables), > > and there seems to be no ob-lua.el (yet). > > > > so I shamelessly copied ob-python.el and adapted it to my needs. > > right now it can tangle lua, also with simple or table parameters. > > > > if anybody is interested, I can upload it. > > Yes, please do! > > > before that, it should maybe be completed, and also pass some generic > > tangle test, I think. > > I have shortly looked at testing/examples/ob-shell-test.org. Is a > > test like this suitable? > > I suggest to look at testing/lisp/test-ob-shell.el. > sorry for the delay, I had to fix some quoting.. here is what i have already. it is not yet ERT tested, only manually. ob-lua.el is capable to tangle code which uses tables with one, two or many columns. i have not yet done any code executing tests. first, here is my test harness: #+NAME: simple-table | simple one | | two | | three | is converted into sim={{"simple one"}, {"two"}, {"three"}} #+NAME: assoc-table | name | value | |---------+-------| | colour | blue | | weather | fine | this is converted into mapv={{"colour", "blue"}, {"weather", "fine"}} i copied this behaviour (an associative map) from ob-shell.el #+NAME: big-table | name | value | remark | |-------------+--------+--------| | tool | emacs | cool | | environment | debian | fair | and finally, big={{"tool", "emacs", "cool"}, {"environment", "debian", "fair"}} <#part type="text/x-org" filename="/home/dieter/git/org/code-exporter.org" disposition=attachment> <#/part> and ob-lua.el <#part type="application/emacs-lisp" filename="/home/dieter/.emacs.d/elpa/org-20140505/ob-lua.el" disposition=attachment> <#/part> as i am quite new to emacs/org, i will be thankful for any feedback. kind regards, dieter From mboxrd@z Thu Jan 1 00:00:00 1970 From: dieter@schoen.or.at Subject: Re: ob-lua.el Date: Fri, 9 May 2014 20:26:49 +0000 (GMT) Message-ID: <10493aa.dd867f2eeab70f315adbc3ac0113988b@afterlogic.edis.at> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=_mailrelay-6023-1399667210-0001-2" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:55397) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WirNh-0004EU-3V for emacs-orgmode@gnu.org; Fri, 09 May 2014 16:27:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WirNb-0001RN-Lu for emacs-orgmode@gnu.org; Fri, 09 May 2014 16:26:57 -0400 Received: from postrelay205.edis.at ([91.227.204.205]:33949) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WirNb-0001RF-30 for emacs-orgmode@gnu.org; Fri, 09 May 2014 16:26:51 -0400 Received: from mailrelay.edis.at (postrelay205.edis.at [91.227.204.205]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by postrelay205.edis.at (Postfix) with ESMTPS id 5E28D2002076 for ; Fri, 9 May 2014 22:26:50 +0200 (CEST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org This is a MIME-formatted message. If you see this text it means that your E-mail software does not support MIME-formatted messages. --=_mailrelay-6023-1399667210-0001-2 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable now with attachments, i hope.... >---- Original Message ---- >From: Dieter Schoen >To: emacs-orgmode@gnu.org >Sent: Fri, May 9, 2014, 10:23 PM >Subject: Re: [O] ob-lua.el > >At Wed, 07 May 2014 00:46:03 +0200, >Bastien wrote: >> >> Hi Dieter, >> >> dieter@schoen.or.at writes: >> >> > for a project I need to tangle lua files (including parameters and >> > tables), >> > and there seems to be no ob-lua.el (yet). >> > >> > so I shamelessly copied ob-python.el and adapted it to my needs. >> > right now it can tangle lua, also with simple or table parameters. >> > >> > if anybody is interested, I can upload it. >> >> Yes, please do! >> >> > before that, it should maybe be completed, and also pass some gener= ic >> > tangle test, I think. >> > I have shortly looked at testing/examples/ob-shell-test.org. Is a >> > test like this suitable? >> >> I suggest to look at testing/lisp/test-ob-shell.el. >> > >sorry for the delay, I had to fix some quoting.. > >here is what i have already. it is not yet ERT tested, only manually. >ob-lua.el is capable to tangle code which uses tables with one, two or= many >columns. >i have not yet done any code executing tests. > >first, here is my test harness: > >#+NAME: simple-table >| simple one | >| two | >| three | > >is converted into > > sim=3D{{"simple one"}, {"two"}, {"three"}} > > >#+NAME: assoc-table >| name | value | >|---------+-------| >| colour | blue | >| weather | fine | > >this is converted into > > mapv=3D{{"colour", "blue"}, {"weather", "fine"}} > >i copied this behaviour (an associative map) from ob-shell.el > >#+NAME: big-table >| name | value | remark | >|-------------+--------+--------| >| tool | emacs | cool | >| environment | debian | fair | > >and finally, > > big=3D{{"tool", "emacs", "cool"}, {"environment", "debian", "fair"}= } > > ><#part type=3D"text/x-org" filename=3D"/home/dieter/git/org/code-export= er.org" disposition=3Dattachment> ><#/part> > >and ob-lua.el > ><#part type=3D"application/emacs-lisp" filename=3D"/home/dieter/.emacs.= d/elpa/org-20140505/ob-lua.el" disposition=3Dattachment> ><#/part> > >as i am quite new to emacs/org, i will be thankful for any feedback. > >kind regards, >dieter --=_mailrelay-6023-1399667210-0001-2 Content-Type: application/octet-stream; name="code-exporter.org" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="code-exporter.org" KiBzaGVsbCBzY3JpcHQKCiMrTkFNRTogc2ltcGxlLXRhYmxlCnwgc2ltcGxlIG9uZSB8Cnwg dHdvICAgICAgICB8CnwgdGhyZWUgICAgICB8CgoKCiMrTkFNRTogYXNzb2MtdGFibGUKfCBu YW1lICAgIHwgdmFsdWUgfAp8LS0tLS0tLS0tKy0tLS0tLS18CnwgY29sb3VyICB8IGJsdWUg IHwKfCB3ZWF0aGVyIHwgZmluZSAgfAoKIytOQU1FOiBiaWctdGFibGUKfCBuYW1lICAgICAg ICB8IHZhbHVlICB8IHJlbWFyayB8CnwtLS0tLS0tLS0tLS0tKy0tLS0tLS0tKy0tLS0tLS0t fAp8IHRvb2wgICAgICAgIHwgZW1hY3MgIHwgY29vbCAgIHwKf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M CgogIHByaW50ICJzaW1wbGUiLCBzaW0KICBwcmludCAibWFwdiAgIiwgbWFwdgogIHByaW50 ICJiaWcgICAiLCBiaWcKCiMrRU5EX1NSQwoKCg== --=_mailrelay-6023-1399667210-0001-2 Content-Type: application/octet-stream; name="ob-lua.el" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="ob-lua.el" Ozs7IG9iLWx1YS5lbCAtLS0gb3JnLWJhYmVsIGZ1bmN0aW9ucyBmb3IgbHVhIGV2YWx1YXRp b24KCjs7IENvcHlyaWdodCAoQykgMjAwOS0yMDE0IEZyZWUgU29mdHdhcmUgRm91bmRhdGlv biwgSW5jLgoKOzsgQXV0aG9yczogRXJpYyBTY2h1bHRlCjs7CSBEYW4gRGF2aXNvbgo7OyBL ZXl3b3JkczogbGl0ZXJhdGUgcHJvZ3JhbW1pbmcsIHJlcHJvZHVjaWJsZSByZXNlYXJjaAo7 OyBIb21lcGFnZTogaHR0cDovL29yZ21vZGUub3JnCgo7OyBUaGlzIGZpbGUgaXMgcGFydCBv ZiBHTlUgRW1hY3MuCgo7OyBHTlUgRW1hY3MgaXMgZnJlZSBzb2Z0d2FyZTogeW91IGNhbiBy ZWRpc3RyaWJ1dGUgaXQgYW5kL29yIG1vZGlmeQo7OyBpdCB1bmRlciB0aGUgdGVybXMgb2Yg dGhlIEdOVSBHZW5lcmFsIFB1YmxpYyBMaWNlbnNlIGFzIHB1Ymxpc2hlZCBieQo7OyB0aGUg RnJlZSBTb2Z0d2FyZSBGb3VuZGF0aW9uLCBlaXRoZXIgdmVyc2lvbiAzIG9mIHRoZSBMaWNl bnNlLCBvcgo7OyAoYXQgeW91ciBvcHRpb24pIGFueSBsYXRlciB2ZXJzaW9uLgoKOzsgR05V IEVtYWNzIGlzIGRpc3RyaWJ1dGVkIGluIHRoZSBob3BlIHRoYXQgaXQgd2lsbCBiZSB1c2Vm dWwsCjs7IGJ1dCBXSVRIT1VUIEFOWSBXQVJSQU5UWTsgd2l0aG91dCBldmVuI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IG9mIHRoZSBzYW1lIHZhbHVlLiIK ICAoaWYgKGxpc3RwIHZhcikKICAgICAgKGlmIChhbmQgKD0gMSAobGVuZ3RoIHZhcikpIChu b3QgKGxpc3RwIChjYXIgdmFyKSkpKQogICAgICAgICAgKG9yZy1iYWJlbC1sdWEtdmFyLXRv LWx1YSAoY2FyIHZhcikpCiAgICAgICAgKGlmIChhbmQKICAgICAgICAgICAgICg9IDIgKGxl bmd0aCB2YXIpKQogICAgICAgICAgICAgKG5vdCAobGlzdHAgKGNhciB2YXIpKSkpCiAgICAg ICAgICAgIChjb25jYXQKICAgICAgICAgICAgIChzdWJzdHJpbmctbm8tcHJvcGVydGllcyAo Y2FyIHZhcikpCiAgICAgICAgICAgICAiPSIKICAgICAgICAgICAgIChvcmctYmFiZWwtbHVh LXZhci10by1sdWEgKGNkciB2YXIpKSkKICAgICAgICAgIChjb25jYXQgInsiIChtYXBjb25j YXQgIydvcmctYmFiZWwtbHVhLXZhci10by1sdWEgdmFyICIsICIpICJ9IikpKQogICAgKGlm IChlcXVhbCB2YXIgJ2hsaW5lKQogICAgICAgIG9yZy1iYWJlbC1sdWEtaGxpbmUtdG8KICAg ICAgKGZvcm1hdAogICAgICAgKGlmIChhbmQgKHN0cmluZ3AgdmFyKSAoc3RyaW5nLW1hdGNo ICJbXG5ccl0iIHZhcikpICJcIlwiJVNcIlwiIiAiJVMiKQogICAgICAgKGlmIChzdHJpbmdw IHZhcikgKHN1YnN0cmluZy1uby1wcm9wZXJ0aWVzIHZhcikgdmFyKSkpKSkKCihkZWZ1biBv cmctYmFiZWwtbHVhLXRhYmxlLW9yLXN0cmluZyAocmVzdWx0cykKICAiQ29udmVydCBSRVNV TFRTIGludG8gYW4gYXBwcm9wcmlhdGUgZWxpc3AgdmFsdWUuCklmIHRoZSByZXN1bHRzIGxv b2sgbGlrZSBhIGxpc3Qgb3IgdHVwbGUsIHRoZW4gY29udmVydCB0aGVtIGludG8gYW4KRW1h Y3MtbGlzcCB0YWJsZSw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ZiB0aGUKbGFzdCBz dGF0ZW1lbnQgaW4gQk9EWSwgYXMgZWxpc3AuIgogIChsZXQgKChyYXcKICAgICAgICAgKGNh c2UgcmVzdWx0LXR5cGUKICAgICAgICAgICAob3V0cHV0IChvcmctYmFiZWwtZXZhbCBvcmct YmFiZWwtbHVhLWNvbW1hbmQKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAo Y29uY2F0IChpZiBwcmVhbWJsZSAoY29uY2F0IHByZWFtYmxlICJcbiIpKQogICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgYm9keSkpKQogICAgICAgICAgICh2 YWx1ZSAobGV0ICgodG1wLWZpbGUgKG9yZy1iYWJlbC10ZW1wLWZpbGUgImx1YS0iKSkpCiAg ICAgICAgICAgICAgICAgICAgKG9yZy1iYWJlbC1ldmFsCiAgICAgICAgICAgICAgICAgICAg IG9yZy1iYWJlbC1sdWEtY29tbWFuZAogICAgICAgICAgICAgICAgICAgICAoY29uY2F0CiAg ICAgICAgICAgICAgICAgICAgICAoaWYgcHJlYW1ibGUgKGNvbmNhdCBwcmVhbWJsZSAiXG4i KSAiIikKICAgICAgICAgICAgICAgICAgICAgIChmb3JtYXQKICAgICAgICAgICAgICAgICAg ICAgICAoaWYgKG1lbWJlciAicHAiIHJlc3VsdC1wYXJhbXMpCiAgICAgICAgICAgICAgICAg ICAgICAgICAgIG9yZy1iYWJlbC1sdWEtcHAtd3JhcHBlci1tZXRob2QKICAgICAgICAgICAg ICAgICAgICAgICAgIG9yZy1iYWJlbC1sdWEtd3JhcHBlci1tZXRob2QpCiAgICAgICAgICAg ICAgICAgICAgICAgKG1hcGNvbmNhdAogICAgICAgICAgICAgICAgICAgICAgICAobGFtYmRh IChsaW5lKSAoZm9ybWF0ICJcdCVzIiBsaW5lKSkKICAgICAgICAgICAgICAgICAgICAgICAg KHNwbGl0LXN0cmluZwogICAgICAgICAgICAgICAgICAgICAgICAgKG9yZy1yZW1vdmUtaW5k ZW50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GVtZW50KSAoZnVuY2FsbCBzZW5kLXdhaXQpKQoJICAgICAoaWYgcHAK CQkgKGxpc3QKCQkgICJpbXBvcnQgcHByaW50IgoJCSAgKGZvcm1hdCAib3BlbignJXMnLCAn dycpLndyaXRlKHBwcmludC5wZm9ybWF0KF8pKSIKCQkJICAob3JnLWJhYmVsLXByb2Nlc3Mt ZmlsZS1uYW1lIHRtcC1maWxlICdub3F1b3RlKSkpCgkgICAgICAgKGxpc3QgKGZvcm1hdCAi b3BlbignJXMnLCAndycpLndyaXRlKHN0cihfKSkiCgkJCSAgICAgKG9yZy1iYWJlbC1wcm9j ZXNzLWZpbGUtbmFtZSB0bXAtZmlsZQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgJ25vcXVvdGUpKSkpKSkpCgkgKGlucHV0LWJv ZHkgKGxhbWJkYSAoYm9keSkKCQkgICAgICAgKG1hcGMgKGxhbWJkYSAobGluZSkgKGluc2Vy dCBsaW5lKSAoZnVuY2FsbCBzZW5kLXdhaXQpKQoJCQkgICAgIChzcGxpdC1zdHJpbmcgYm9k eSAiW1xyXG5dIikpCgkJICAgICAgIChmdW5jYWxsIHNlbmQtd2FpdCkpKQogICAgICAgICAo cmVzdWx0cwogICAgICAgICAgKGNhc2UgcmVzdWx0LXR5cGUKICAgICAgICAgICAgKG91dHB1 dAogICAgICAgICAgICAgKG1hcGNvbmNhdAogICAgICAgICAgICAgICMnb3JnLWJhYmVsLXRy aW0KICAgICAgICAgICAgICAoYnV0bGFzdAogICAgICAgICAgICAgICAob3JnLWJhYmVsLWNv bWludC13aXRoLW91dHB1dAogICAgICAgICAgICAgICAgICAgKHNlc3Npb24gb3JnLWJhYmVs LWx1YS1lb2UtaW5kaWNhdG9yIHQgYm9keSkKICAgICAgICAgICAgICAgICAoZnVuY2FsbCBp bnB1dC1ib2R5IGJvZHkpCiAgICAgICAgICAgICAgICAgKGZ1bmNhbGwgc2VuZC13YWl0KSAo ZnVuY2FsbCBzZW5kLXdhaXQpCiAgICAgICAgICAgICAgICAgKGluc2VydCBvcmctYmFiZWwt bHVhLWVvZS1pbmRpY2F0b3IpCiAgICAgICAgICAgICAgICAgKGZ1bmNhbGwgc2VuZC13YWl0 KSkKICAgICAgICAgICAgICAgMikgIlxuIikpCiAgICAgICAgICAgICh2YWx1ZQogICAgICAg ICAgICAgKGxldCAoKHRtcC1maWxlIChvcmctYmFiZWwtdGVtcC1maWxlICJsdWEtIikpKQog ICAgICAgICAgICAgICAob3JnLWJhYmVsLWNvbWludC13aXRoLW91dHB1dAogICAgICAgICAg ICAgICAgICAgKHNlc3Npb24gb3JnLWJhYmVsLWx1YS1lb2UtaW5kaWNhdG9yIG5pbCBib2R5 KQogICAgICAgICAgICAgICAgIChsZXQgKChjb21pbnQtcHJvY2Vzcy1lY2hvZXMgbmlsKSkK ICAgICAgICAgICAgICAgICAgIChmdW5jYWxsIGlucHV0LWJvZHkgYm9keSkKICAgICAgICAg ICAgICAgICAgIChmdW5jYWxsIGR1bXAtbGFzdC12YWx1ZSB0bXAtZmlsZQogICAgICAgICAg ICAgICAgICAgICAgICAgICAgKG1lbWJlciAicHAiIHJlc3VsdC1wYXJhbXMpKQogICAgICAg ICAgICAgICAgICAgKGZ1bmNhbGwgc2VuZC13YWl0KSAoZnVuY2FsbCBzZW5kLXdhaXQpCiAg ICAgICAgICAgICAgICAgICAoaW5zZXJ0IG9yZy1iYWJlbC1sdWEtZW9lLWluZGljYXRvcikK ICAgICAgICAgICAgICAgICAgIChmdW5jYWxsIHNlbmQtd2FpdCkpKQogICAgICAgICAgICAg ICAob3JnLWJhYmVsLWV2YWwtcmVhZC1maWxlIHRtcC1maWxlKSkpKSkpCiAgICAodW5sZXNz IChzdHJpbmc9IChzdWJzdHJpbmcgb3JnLWJhYmVsLWx1YS1lb2UtaW5kaWNhdG9yIDEgLTEp IHJlc3VsdHMpCiAgICAgIChvcmctYmFiZWwtcmVzdWx0LWNvbmQgcmVzdWx0LXBhcmFtcwoJ cmVzdWx0cwogICAgICAgIChvcmctYmFiZWwtbHVhLXRhYmxlLW9yLXN0cmluZyByZXN1bHRz KSkpKSkKCihkZWZ1biBvcmctYmFiZWwtbHVhLXJlYWQtc3RyaW5nIChzdHJpbmcpCiAgIlN0 cmlwICdzIGZyb20gYXJvdW5kIEx1YSBzdHJpbmcuIgogIChpZiAoc3RyaW5nLW1hdGNoICJe J1xcKFteXDAwMF0rXFwpJyQiIHN0cmluZykKICAgICAgKG1hdGNoLXN0cmluZyAxIHN0cmlu ZykKICAgIHN0cmluZykpCgoocHJvdmlkZSAnb2ItbHVhKQoKCgo7Ozsgb2ItbHVhLmVsIGVu ZHMgaGVyZQo= --=_mailrelay-6023-1399667210-0001-2-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: ob-lua.el Date: Mon, 12 May 2014 09:26:21 -0600 Message-ID: <87mwenuife.fsf@gmail.com> References: <10493aa.dd867f2eeab70f315adbc3ac0113988b@afterlogic.edis.at> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60766) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wjs8E-0001h6-0W for emacs-orgmode@gnu.org; Mon, 12 May 2014 11:27:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wjs89-0004Gh-W3 for emacs-orgmode@gnu.org; Mon, 12 May 2014 11:27:09 -0400 Received: from mail-pa0-x233.google.com ([2607:f8b0:400e:c03::233]:51500) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wjs89-0004FS-KN for emacs-orgmode@gnu.org; Mon, 12 May 2014 11:27:05 -0400 Received: by mail-pa0-f51.google.com with SMTP id kq14so8754121pab.38 for ; Mon, 12 May 2014 08:27:04 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: dieter@schoen.or.at Cc: emacs-orgmode@gnu.org This looks good so far. Does code execution work but it is untested, or has it not been implemented? Would you suggest adding this now or waiting for code execution? I don't see you listed on the contributors page, would you be willing to do FSF copyright assignment? http://orgmode.org/worg/org-contribute.html Thanks! Eric dieter@schoen.or.at writes: > now with attachments, i hope.... > > > >>---- Original Message ---- >>From: Dieter Schoen >>To: emacs-orgmode@gnu.org >>Sent: Fri, May 9, 2014, 10:23 PM >>Subject: Re: [O] ob-lua.el >> >>At Wed, 07 May 2014 00:46:03 +0200, >>Bastien wrote: >>> >>> Hi Dieter, >>> >>> dieter@schoen.or.at writes: >>> >>> > for a project I need to tangle lua files (including parameters and >>> > tables), >>> > and there seems to be no ob-lua.el (yet). >>> > >>> > so I shamelessly copied ob-python.el and adapted it to my needs. >>> > right now it can tangle lua, also with simple or table parameters. >>> > >>> > if anybody is interested, I can upload it. >>> >>> Yes, please do! >>> >>> > before that, it should maybe be completed, and also pass some generic >>> > tangle test, I think. >>> > I have shortly looked at testing/examples/ob-shell-test.org. Is a >>> > test like this suitable? >>> >>> I suggest to look at testing/lisp/test-ob-shell.el. >>> >> >>sorry for the delay, I had to fix some quoting.. >> >>here is what i have already. it is not yet ERT tested, only manually. >>ob-lua.el is capable to tangle code which uses tables with one, two or many >>columns. >>i have not yet done any code executing tests. >> >>first, here is my test harness: >> >>#+NAME: simple-table >>| simple one | >>| two | >>| three | >> >>is converted into >> >> sim={{"simple one"}, {"two"}, {"three"}} >> >> >>#+NAME: assoc-table >>| name | value | >>|---------+-------| >>| colour | blue | >>| weather | fine | >> >>this is converted into >> >> mapv={{"colour", "blue"}, {"weather", "fine"}} >> >>i copied this behaviour (an associative map) from ob-shell.el >> >>#+NAME: big-table >>| name | value | remark | >>|-------------+--------+--------| >>| tool | emacs | cool | >>| environment | debian | fair | >> >>and finally, >> >> big={{"tool", "emacs", "cool"}, {"environment", "debian", "fair"}} >> >> >><#part type="text/x-org" filename="/home/dieter/git/org/code-exporter.org" disposition=attachment> >><#/part> >> >>and ob-lua.el >> >><#part type="application/emacs-lisp" filename="/home/dieter/.emacs.d/elpa/org-20140505/ob-lua.el" disposition=attachment> >><#/part> >> >>as i am quite new to emacs/org, i will be thankful for any feedback. >> >>kind regards, >>dieter > > > ;;; ob-lua.el --- org-babel functions for lua evaluation > > ;; Copyright (C) 2009-2014 Free Software Foundation, Inc. > > ;; Authors: Eric Schulte > ;; Dan Davison > ;; Keywords: literate programming, reproducible research > ;; Homepage: http://orgmode.org > > ;; This file is part of GNU Emacs. > > ;; GNU Emacs is free software: you can redistribute it and/or modify > ;; it under the terms of the GNU General Public License as published by > ;; the Free Software Foundation, either version 3 of the License, or > ;; (at your option) any later version. > > ;; GNU Emacs is distributed in the hope that it will be useful, > ;; but WITHOUT ANY WARRANTY; without even the implied warranty of > ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > ;; GNU General Public License for more details. > > ;; You should have received a copy of the GNU General Public License > ;; along with GNU Emacs. If not, see . > > ;;; Commentary: > > ;; Org-Babel support for evaluating lua source code. > > ;;; Code: > (require 'ob) > (eval-when-compile (require 'cl)) > > (declare-function org-remove-indentation "org" ) > (declare-function lua-shell "ext:lua-mode" (&optional argprompt)) > (declare-function lua-toggle-shells "ext:lua-mode" (arg)) > (declare-function run-lua "ext:lua" (cmd &optional dedicated show)) > > (defvar org-babel-tangle-lang-exts) > (add-to-list 'org-babel-tangle-lang-exts '("lua" . "lua")) > > (defvar org-babel-default-header-args:lua '()) > > (defcustom org-babel-lua-command "lua" > "Name of the command for executing Lua code." > :version "24.4" > :package-version '(Org . "8.0") > :group 'org-babel > :type 'string) > > (defcustom org-babel-lua-mode > (if (or (featurep 'xemacs) (featurep 'lua-mode)) 'lua-mode 'lua) > "Preferred lua mode for use in running lua interactively. > This will typically be either 'lua or 'lua-mode." > :group 'org-babel > :version "24.4" > :package-version '(Org . "8.0") > :type 'symbol) > > (defvar org-src-preserve-indentation) > > (defcustom org-babel-lua-hline-to "None" > "Replace hlines in incoming tables with this when translating to lua." > :group 'org-babel > :version "24.4" > :package-version '(Org . "8.0") > :type 'string) > > (defcustom org-babel-lua-None-to 'hline > "Replace 'None' in lua tables with this before returning." > :group 'org-babel > :version "24.4" > :package-version '(Org . "8.0") > :type 'symbol) > > (defun org-babel-execute:lua (body params) > "Execute a block of Lua code with Babel. > This function is called by `org-babel-execute-src-block'." > (let* ((session (org-babel-lua-initiate-session > (cdr (assoc :session params)))) > (result-params (cdr (assoc :result-params params))) > (result-type (cdr (assoc :result-type params))) > (return-val (when (and (eq result-type 'value) (not session)) > (cdr (assoc :return params)))) > (preamble (cdr (assoc :preamble params))) > (full-body > (org-babel-expand-body:generic > (concat body (if return-val (format "\nreturn %s" return-val) "")) > params (org-babel-variable-assignments:lua params))) > (result (org-babel-lua-evaluate > session full-body result-type result-params preamble))) > (org-babel-reassemble-table > result > (org-babel-pick-name (cdr (assoc :colname-names params)) > (cdr (assoc :colnames params))) > (org-babel-pick-name (cdr (assoc :rowname-names params)) > (cdr (assoc :rownames params)))))) > > (defun org-babel-prep-session:lua (session params) > "Prepare SESSION according to the header arguments in PARAMS. > VARS contains resolved variable references" > (let* ((session (org-babel-lua-initiate-session session)) > (var-lines > (org-babel-variable-assignments:lua params))) > (org-babel-comint-in-buffer session > (mapc (lambda (var) > (end-of-line 1) (insert var) (comint-send-input) > (org-babel-comint-wait-for-output session)) var-lines)) > session)) > > (defun org-babel-load-session:lua (session body params) > "Load BODY into SESSION." > (save-window-excursion > (let ((buffer (org-babel-prep-session:lua session params))) > (with-current-buffer buffer > (goto-char (process-mark (get-buffer-process (current-buffer)))) > (insert (org-babel-chomp body))) > buffer))) > > ;; helper functions > > (defun org-babel-variable-assignments:lua (params) > "Return a list of Lua statements assigning the block's variables." > (mapcar > (lambda (pair) > (format "%s=%s" > (car pair) > (org-babel-lua-var-to-lua (cdr pair)))) > (mapcar #'cdr (org-babel-get-header params :var)))) > > (defun org-babel-lua-var-to-lua (var) > "Convert an elisp value to a lua variable. > Convert an elisp value, VAR, into a string of lua source code > specifying a variable of the same value." > (if (listp var) > (if (and (= 1 (length var)) (not (listp (car var)))) > (org-babel-lua-var-to-lua (car var)) > (if (and > (= 2 (length var)) > (not (listp (car var)))) > (concat > (substring-no-properties (car var)) > "=" > (org-babel-lua-var-to-lua (cdr var))) > (concat "{" (mapconcat #'org-babel-lua-var-to-lua var ", ") "}"))) > (if (equal var 'hline) > org-babel-lua-hline-to > (format > (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) > "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." > (let ((res (org-babel-script-escape results))) > (if (listp res) > (mapcar (lambda (el) (if (equal el 'None) > org-babel-lua-None-to el)) > res) > res))) > > (defvar org-babel-lua-buffers '((:default . "*Lua*"))) > > (defun org-babel-lua-session-buffer (session) > "Return the buffer associated with SESSION." > (cdr (assoc session org-babel-lua-buffers))) > > (defun org-babel-lua-with-earmuffs (session) > (let ((name (if (stringp session) session (format "%s" session)))) > (if (and (string= "*" (substring name 0 1)) > (string= "*" (substring name (- (length name) 1)))) > name > (format "*%s*" name)))) > > (defun org-babel-lua-without-earmuffs (session) > (let ((name (if (stringp session) session (format "%s" session)))) > (if (and (string= "*" (substring name 0 1)) > (string= "*" (substring name (- (length name) 1)))) > (substring name 1 (- (length name) 1)) > name))) > > (defvar lua-default-interpreter) > (defvar lua-which-bufname) > (defvar lua-shell-buffer-name) > (defun org-babel-lua-initiate-session-by-key (&optional session) > "Initiate a lua session. > If there is not a current inferior-process-buffer in SESSION > then create. Return the initialized session." > (require org-babel-lua-mode) > (save-window-excursion > (let* ((session (if session (intern session) :default)) > (lua-buffer (org-babel-lua-session-buffer session)) > (cmd (if (member system-type '(cygwin windows-nt ms-dos)) > (concat org-babel-lua-command " -i") > org-babel-lua-command))) > (cond > ((and (eq 'lua org-babel-lua-mode) > (fboundp 'run-lua)) ; lua.el > (if (not (version< "24.1" emacs-version)) > (run-lua cmd) > (unless lua-buffer > (setq lua-buffer (org-babel-lua-with-earmuffs session))) > (let ((lua-shell-buffer-name > (org-babel-lua-without-earmuffs lua-buffer))) > (run-lua cmd)))) > ((and (eq 'lua-mode org-babel-lua-mode) > (fboundp 'lua-shell)) ; lua-mode.el > ;; Make sure that lua-which-bufname is initialized, as otherwise > ;; it will be overwritten the first time a Lua buffer is > ;; created. > (lua-toggle-shells lua-default-interpreter) > ;; `lua-shell' creates a buffer whose name is the value of > ;; `lua-which-bufname' with '*'s at the beginning and end > (let* ((bufname (if (and lua-buffer (buffer-live-p lua-buffer)) > (replace-regexp-in-string ;; zap surrounding * > "^\\*\\([^*]+\\)\\*$" "\\1" lua-buffer) > (concat "Lua-" (symbol-name session)))) > (lua-which-bufname bufname)) > (lua-shell) > (setq lua-buffer (org-babel-lua-with-earmuffs bufname)))) > (t > (error "No function available for running an inferior Lua"))) > (setq org-babel-lua-buffers > (cons (cons session lua-buffer) > (assq-delete-all session org-babel-lua-buffers))) > session))) > > (defun org-babel-lua-initiate-session (&optional session params) > "Create a session named SESSION according to PARAMS." > (unless (string= session "none") > (org-babel-lua-session-buffer > (org-babel-lua-initiate-session-by-key session)))) > > (defvar org-babel-lua-eoe-indicator "'org_babel_lua_eoe'" > "A string to indicate that evaluation has completed.") > (defvar org-babel-lua-wrapper-method > " > def main(): > %s > > open('%s', 'w').write( str(main()) )") > (defvar org-babel-lua-pp-wrapper-method > " > import pprint > def main(): > %s > > open('%s', 'w').write( pprint.pformat(main()) )") > > (defun org-babel-lua-evaluate > (session body &optional result-type result-params preamble) > "Evaluate BODY as Lua code." > (if session > (org-babel-lua-evaluate-session > session body result-type result-params) > (org-babel-lua-evaluate-external-process > body result-type result-params preamble))) > > (defun org-babel-lua-evaluate-external-process > (body &optional result-type result-params preamble) > "Evaluate BODY in external lua process. > If RESULT-TYPE equals 'output then return standard output as a > string. If RESULT-TYPE equals 'value then return the value of the > last statement in BODY, as elisp." > (let ((raw > (case result-type > (output (org-babel-eval org-babel-lua-command > (concat (if preamble (concat preamble "\n")) > body))) > (value (let ((tmp-file (org-babel-temp-file "lua-"))) > (org-babel-eval > org-babel-lua-command > (concat > (if preamble (concat preamble "\n") "") > (format > (if (member "pp" result-params) > org-babel-lua-pp-wrapper-method > org-babel-lua-wrapper-method) > (mapconcat > (lambda (line) (format "\t%s" line)) > (split-string > (org-remove-indentation > (org-babel-trim body)) > "[\r\n]") "\n") > (org-babel-process-file-name tmp-file 'noquote)))) > (org-babel-eval-read-file tmp-file)))))) > (org-babel-result-cond result-params > raw > (org-babel-lua-table-or-string (org-babel-trim raw))))) > > (defun org-babel-lua-evaluate-session > (session body &optional result-type result-params) > "Pass BODY to the Lua process in SESSION. > If RESULT-TYPE equals 'output then return standard output as a > string. If RESULT-TYPE equals 'value then return the value of the > last statement in BODY, as elisp." > (let* ((send-wait (lambda () (comint-send-input nil t) (sleep-for 0 5))) > (dump-last-value > (lambda > (tmp-file pp) > (mapc > (lambda (statement) (insert statement) (funcall send-wait)) > (if pp > (list > "import pprint" > (format "open('%s', 'w').write(pprint.pformat(_))" > (org-babel-process-file-name tmp-file 'noquote))) > (list (format "open('%s', 'w').write(str(_))" > (org-babel-process-file-name tmp-file > 'noquote))))))) > (input-body (lambda (body) > (mapc (lambda (line) (insert line) (funcall send-wait)) > (split-string body "[\r\n]")) > (funcall send-wait))) > (results > (case result-type > (output > (mapconcat > #'org-babel-trim > (butlast > (org-babel-comint-with-output > (session org-babel-lua-eoe-indicator t body) > (funcall input-body body) > (funcall send-wait) (funcall send-wait) > (insert org-babel-lua-eoe-indicator) > (funcall send-wait)) > 2) "\n")) > (value > (let ((tmp-file (org-babel-temp-file "lua-"))) > (org-babel-comint-with-output > (session org-babel-lua-eoe-indicator nil body) > (let ((comint-process-echoes nil)) > (funcall input-body body) > (funcall dump-last-value tmp-file > (member "pp" result-params)) > (funcall send-wait) (funcall send-wait) > (insert org-babel-lua-eoe-indicator) > (funcall send-wait))) > (org-babel-eval-read-file tmp-file)))))) > (unless (string= (substring org-babel-lua-eoe-indicator 1 -1) results) > (org-babel-result-cond result-params > results > (org-babel-lua-table-or-string results))))) > > (defun org-babel-lua-read-string (string) > "Strip 's from around Lua string." > (if (string-match "^'\\([^\000]+\\)'$" string) > (match-string 1 string) > string)) > > (provide 'ob-lua) > > > > ;;; ob-lua.el ends here -- Eric Schulte https://cs.unm.edu/~eschulte PGP: 0x614CA05D From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dieter Schoen Subject: Re: ob-lua.el Date: Tue, 13 May 2014 12:57:23 +0200 Message-ID: <87k39q2bfw.wl%dieter@schoen.or.at> References: <10493aa.dd867f2eeab70f315adbc3ac0113988b@afterlogic.edis.at> <87mwenuife.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43378) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkAOt-0003Uy-Iu for emacs-orgmode@gnu.org; Tue, 13 May 2014 06:57:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WkAOm-000190-Dr for emacs-orgmode@gnu.org; Tue, 13 May 2014 06:57:35 -0400 Received: from postrelay210.edis.at ([91.227.204.210]:41172) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WkAOm-00018s-5k for emacs-orgmode@gnu.org; Tue, 13 May 2014 06:57:28 -0400 Received: from mailrelay.edis.at (postrelay210.edis.at [91.227.204.210]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by postrelay210.edis.at (Postfix) with ESMTPS id 9ACF0200225E for ; Tue, 13 May 2014 12:57:27 +0200 (CEST) In-Reply-To: <87mwenuife.fsf@gmail.com> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Eric Schulte Cc: emacs-orgmode@gnu.org At Mon, 12 May 2014 09:26:21 -0600, Eric Schulte wrote: > > This looks good so far. thank you. it's my first published lisp code (although big parts are stolen..) > Does code execution work but it is untested, or has it not been > implemented? Would you suggest adding this now or waiting for code > execution? i have added a "results: output" and as such perform a limited test now, and that worked fine. so i would say that it's fit for basic usage. in parallel i will continue to learn ERT (emacs regression testing) and write formal tests. > I don't see you listed on the contributors page, would you > be willing to do FSF copyright assignment? > > http://orgmode.org/worg/org-contribute.html i thought that it's not a copyright is not a question since i posted the code here. ;) but formally: yes, i'd like to do a FSF copyright assignment. i have just sent the email to assign@gnu.org to start the process. kind regards, dieter From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bastien Subject: Re: ob-lua.el Date: Wed, 21 May 2014 09:30:44 +0200 Message-ID: <87oayrpp0b.fsf@bzg.ath.cx> References: <10493aa.dd867f2eeab70f315adbc3ac0113988b@afterlogic.edis.at> <87mwenuife.fsf@gmail.com> <87k39q2bfw.wl%dieter@schoen.or.at> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:50842) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wn0zE-0001TD-VM for emacs-orgmode@gnu.org; Wed, 21 May 2014 03:30:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wn0zA-0004GA-Cr for emacs-orgmode@gnu.org; Wed, 21 May 2014 03:30:52 -0400 Received: from mail-wi0-x230.google.com ([2a00:1450:400c:c05::230]:35981) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wn0zA-0004G2-6n for emacs-orgmode@gnu.org; Wed, 21 May 2014 03:30:48 -0400 Received: by mail-wi0-f176.google.com with SMTP id n15so7147520wiw.15 for ; Wed, 21 May 2014 00:30:47 -0700 (PDT) In-Reply-To: <87k39q2bfw.wl%dieter@schoen.or.at> (Dieter Schoen's message of "Tue, 13 May 2014 12:57:23 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Dieter Schoen Cc: emacs-orgmode@gnu.org, Eric Schulte Hi Dieter, Dieter Schoen writes: > i have just sent the email to assign@gnu.org to start the process. Great -- let us know how it goes (can take one month.) In the meantime, you can fix small things like the authors of the package, the owner of the copyright and such. Thanks for this contribution! -- Bastien From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dieter Schoen Subject: Re: ob-lua.el Date: Sat, 24 May 2014 12:55:52 +0200 Message-ID: <871tvjzbrb.wl%dieter@schoen.or.at> References: <10493aa.dd867f2eeab70f315adbc3ac0113988b@afterlogic.edis.at> <87mwenuife.fsf@gmail.com> <87k39q2bfw.wl%dieter@schoen.or.at> <87oayrpp0b.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=_mailrelay-31232-1400928954-0001-2" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:54998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wo9cU-00025q-Sr for emacs-orgmode@gnu.org; Sat, 24 May 2014 06:56:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wo9cQ-0008LZ-1G for emacs-orgmode@gnu.org; Sat, 24 May 2014 06:56:06 -0400 In-Reply-To: <87oayrpp0b.fsf@bzg.ath.cx> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Bastien Cc: emacs-orgmode@gnu.org, Eric Schulte This is a MIME-formatted message. If you see this text it means that your E-mail software does not support MIME-formatted messages. --=_mailrelay-31232-1400928954-0001-2 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit At Wed, 21 May 2014 09:30:44 +0200, Bastien wrote: > > Hi Dieter, > > Dieter Schoen writes: > > > i have just sent the email to assign@gnu.org to start the process. > > Great -- let us know how it goes (can take one month.) As I wrote off-list, I received the signed pdf yesterday. > In the meantime, you can fix small things like the authors of the > package, the owner of the copyright and such. I have my name to the copyright, but left in the name of the authors of ob-python.el, as I used that as a template. Is that ok? Another change to the first version is that it's now also possible to do :results value and :results value pp. (The first version still had python wrapper code in there.) The Lua pretty-printer function is a home-brew, as Lua does not provide much in that direction out of the box, at least to my knowledge. So here it comes: --=_mailrelay-31232-1400928954-0001-2 Content-Type: text/plain; type=emacs-lisp; name="ob-lua.el"; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="ob-lua.el" ;;; ob-lua.el --- org-babel functions for lua evaluation ;; Copyright (C) 2009-2014 Free Software Foundation, Inc. ;; Authors: Eric Schulte ;; Dan Davison ;; Keywords: literate programming, reproducible research ;; Homepage: http://orgmode.org ;; This file is part of GNU Emacs. ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;;; Commentary: ;; Org-Babel support for evaluating lua source code. ;;; Code: (require 'ob) (eval-when-compile (require 'cl)) (declare-function org-remove-indentation "org" ) (declare-function lua-shell "ext:lua-mode" (&optional argprompt)) (declare-function lua-toggle-shells "ext:lua-mode" (arg)) (declare-function run-lua "ext:lua" (cmd &optional dedicated show)) (defvar org-babel-tangle-lang-exts) (add-to-list 'org-babel-tangle-lang-exts '("lua" . "lua")) (defvar org-babel-default-header-args:lua '()) (defcustom org-babel-lua-command "lua" "Name of the command for executing Lua code." :version "24.4" :package-version '(Org . "8.0") :group 'org-babel :type 'string) (defcustom org-babel-lua-mode (if (or (featurep 'xemacs) (featurep 'lua-mode)) 'lua-mode 'lua) "Preferred lua mode for use in running lua interactively. This will typically be either 'lua or 'lua-mode." :group 'org-babel :version "24.4" :package-version '(Org . "8.0") :type 'symbol) (defvar org-src-preserve-indentation) (defcustom org-babel-lua-hline-to "None" "Replace hlines in incoming tables with this when translating to lua." :group 'org-babel :version "24.4" :package-version '(Org . "8.0") :type 'string) (defcustom org-babel-lua-None-to 'hline "Replace 'None' in lua tables with this before returning." :group 'org-babel :version "24.4" :package-version '(Org . "8.0") :type 'symbol) (defun org-babel-execute:lua (body params) "Execute a block of Lua code with Babel. This function is called by `org-babel-execute-src-block'." (let* ((session (org-babel-lua-initiate-session (cdr (assoc :session params)))) (result-params (cdr (assoc :result-params params))) (result-type (cdr (assoc :result-type params))) (return-val (when (and (eq result-type 'value) (not session)) (cdr (assoc :return params)))) (preamble (cdr (assoc :preamble params))) (full-body (org-babel-expand-body:generic (concat body (if return-val (format "\nreturn %s" return-val) "")) params (org-babel-variable-assignments:lua params))) (result (org-babel-lua-evaluate session full-body result-type result-params preamble))) (org-babel-reassemble-table result (org-babel-pick-name (cdr (assoc :colname-names params)) (cdr (assoc :colnames params))) (org-babel-pick-name (cdr (assoc :rowname-names params)) (cdr (assoc :rownames params)))))) (defun org-babel-prep-session:lua (session params) "Prepare SESSION according to the header arguments in PARAMS. VARS contains resolved variable references" (let* ((session (org-babel-lua-initiate-session session)) (var-lines (org-babel-variable-assignments:lua params))) (org-babel-comint-in-buffer session (mapc (lambda (var) (end-of-line 1) (insert var) (comint-send-input) (org-babel-comint-wait-for-output session)) var-lines)) session)) (defun org-babel-load-session:lua (session body params) "Load BODY into SESSION." (save-window-excursion (let ((buffer (org-babel-prep-session:lua session params))) (with-current-buffer buffer (goto-char (process-mark (get-buffer-process (current-buffer)))) (insert (org-babel-chomp body))) buffer))) ;; helper functions (defun org-babel-variable-assignments:lua (params) "Return a list of Lua statements assigning the block's variables." (mapcar (lambda (pair) (format "%s=%s" (car pair) (org-babel-lua-var-to-lua (cdr pair)))) (mapcar #'cdr (org-babel-get-header params :var)))) (defun org-babel-lua-var-to-lua (var) "Convert an elisp value to a lua variable. Convert an elisp value, VAR, into a string of lua source code specifying a variable of the same value." (if (listp var) (if (and (= 1 (length var)) (not (listp (car var)))) (org-babel-lua-var-to-lua (car var)) (if (and (= 2 (length var)) (not (listp (car var)))) (concat (substring-no-properties (car var)) "=" (org-babel-lua-var-to-lua (cdr var))) (concat "{" (mapconcat #'org-babel-lua-var-to-lua var ", ") "}"))) (if (equal var 'hline) org-babel-lua-hline-to (format (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) "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." (let ((res (org-babel-script-escape results))) (if (listp res) (mapcar (lambda (el) (if (equal el 'None) org-babel-lua-None-to el)) res) res))) (defvar org-babel-lua-buffers '((:default . "*Lua*"))) (defun org-babel-lua-session-buffer (session) "Return the buffer associated with SESSION." (cdr (assoc session org-babel-lua-buffers))) (defun org-babel-lua-with-earmuffs (session) (let ((name (if (stringp session) session (format "%s" session)))) (if (and (string= "*" (substring name 0 1)) (string= "*" (substring name (- (length name) 1)))) name (format "*%s*" name)))) (defun org-babel-lua-without-earmuffs (session) (let ((name (if (stringp session) session (format "%s" session)))) (if (and (string= "*" (substring name 0 1)) (string= "*" (substring name (- (length name) 1)))) (substring name 1 (- (length name) 1)) name))) (defvar lua-default-interpreter) (defvar lua-which-bufname) (defvar lua-shell-buffer-name) (defun org-babel-lua-initiate-session-by-key (&optional session) "Initiate a lua session. If there is not a current inferior-process-buffer in SESSION then create. Return the initialized session." (require org-babel-lua-mode) (save-window-excursion (let* ((session (if session (intern session) :default)) (lua-buffer (org-babel-lua-session-buffer session)) (cmd (if (member system-type '(cygwin windows-nt ms-dos)) (concat org-babel-lua-command " -i") org-babel-lua-command))) (cond ((and (eq 'lua org-babel-lua-mode) (fboundp 'run-lua)) ; lua.el (if (not (version< "24.1" emacs-version)) (run-lua cmd) (unless lua-buffer (setq lua-buffer (org-babel-lua-with-earmuffs session))) (let ((lua-shell-buffer-name (org-babel-lua-without-earmuffs lua-buffer))) (run-lua cmd)))) ((and (eq 'lua-mode org-babel-lua-mode) (fboundp 'lua-shell)) ; lua-mode.el ;; Make sure that lua-which-bufname is initialized, as otherwise ;; it will be overwritten the first time a Lua buffer is ;; created. (lua-toggle-shells lua-default-interpreter) ;; `lua-shell' creates a buffer whose name is the value of ;; `lua-which-bufname' with '*'s at the beginning and end (let* ((bufname (if (and lua-buffer (buffer-live-p lua-buffer)) (replace-regexp-in-string ;; zap surrounding * "^\\*\\([^*]+\\)\\*$" "\\1" lua-buffer) (concat "Lua-" (symbol-name session)))) (lua-which-bufname bufname)) (lua-shell) (setq lua-buffer (org-babel-lua-with-earmuffs bufname)))) (t (error "No function available for running an inferior Lua"))) (setq org-babel-lua-buffers (cons (cons session lua-buffer) (assq-delete-all session org-babel-lua-buffers))) session))) (defun org-babel-lua-initiate-session (&optional session params) "Create a session named SESSION according to PARAMS." (unless (string= session "none") (org-babel-lua-session-buffer (org-babel-lua-initiate-session-by-key session)))) (defvar org-babel-lua-eoe-indicator "'org_babel_lua_eoe'" "A string to indicate that evaluation has completed.") (defvar org-babel-lua-wrapper-method " function main() %s end fd=io.open(\"%s\", \"w\") fd:write( main() ) fd:close()") (defvar org-babel-lua-pp-wrapper-method " -- table to string function t2s(t, indent) if indent == nil then indent = \"\" end if type(t) == \"table\" then ts = \"\" for k,v in pairs(t) do if type(v) == \"table\" then ts = ts .. indent .. t2s(k,indent .. \" \") .. \" = \\n\" .. t2s(v, indent .. \" \") else ts = ts .. indent .. t2s(k,indent .. \" \") .. \" = \" .. t2s(v, indent .. \" \") .. \"\\n\" end end return ts else return tostring(t) end end function main() %s end fd=io.open(\"%s\", \"w\") fd:write(t2s(main())) fd:close()") (defun org-babel-lua-evaluate (session body &optional result-type result-params preamble) "Evaluate BODY as Lua code." (if session (org-babel-lua-evaluate-session session body result-type result-params) (org-babel-lua-evaluate-external-process body result-type result-params preamble))) (defun org-babel-lua-evaluate-external-process (body &optional result-type result-params preamble) "Evaluate BODY in external lua process. If RESULT-TYPE equals 'output then return standard output as a string. If RESULT-TYPE equals 'value then return the value of the last statement in BODY, as elisp." (let ((raw (case result-type (output (org-babel-eval org-babel-lua-command (concat (if preamble (concat preamble "\n")) body))) (value (let ((tmp-file (org-babel-temp-file "lua-"))) (org-babel-eval org-babel-lua-command (concat (if preamble (concat preamble "\n") "") (format (if (member "pp" result-params) org-babel-lua-pp-wrapper-method org-babel-lua-wrapper-method) (mapconcat (lambda (line) (format "\t%s" line)) (split-string (org-remove-indentation (org-babel-trim body)) "[\r\n]") "\n") (org-babel-process-file-name tmp-file 'noquote)))) (org-babel-eval-read-file tmp-file)))))) (org-babel-result-cond result-params raw (org-babel-lua-table-or-string (org-babel-trim raw))))) (defun org-babel-lua-evaluate-session (session body &optional result-type result-params) "Pass BODY to the Lua process in SESSION. If RESULT-TYPE equals 'output then return standard output as a string. If RESULT-TYPE equals 'value then return the value of the last statement in BODY, as elisp." (let* ((send-wait (lambda () (comint-send-input nil t) (sleep-for 0 5))) (dump-last-value (lambda (tmp-file pp) (mapc (lambda (statement) (insert statement) (funcall send-wait)) (if pp (list "import pprint" (format "open('%s', 'w').write(pprint.pformat(_))" (org-babel-process-file-name tmp-file 'noquote))) (list (format "open('%s', 'w').write(str(_))" (org-babel-process-file-name tmp-file 'noquote))))))) (input-body (lambda (body) (mapc (lambda (line) (insert line) (funcall send-wait)) (split-string body "[\r\n]")) (funcall send-wait))) (results (case result-type (output (mapconcat #'org-babel-trim (butlast (org-babel-comint-with-output (session org-babel-lua-eoe-indicator t body) (funcall input-body body) (funcall send-wait) (funcall send-wait) (insert org-babel-lua-eoe-indicator) (funcall send-wait)) 2) "\n")) (value (let ((tmp-file (org-babel-temp-file "lua-"))) (org-babel-comint-with-output (session org-babel-lua-eoe-indicator nil body) (let ((comint-process-echoes nil)) (funcall input-body body) (funcall dump-last-value tmp-file (member "pp" result-params)) (funcall send-wait) (funcall send-wait) (insert org-babel-lua-eoe-indicator) (funcall send-wait))) (org-babel-eval-read-file tmp-file)))))) (unless (string= (substring org-babel-lua-eoe-indicator 1 -1) results) (org-babel-result-cond result-params results (org-babel-lua-table-or-string results))))) (defun org-babel-lua-read-string (string) "Strip 's from around Lua string." (if (string-match "^'\\([^\000]+\\)'$" string) (match-string 1 string) string)) (provide 'ob-lua) ;;; ob-lua.el ends here --=_mailrelay-31232-1400928954-0001-2-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bastien Subject: Re: ob-lua.el Date: Sat, 24 May 2014 14:25:05 +0200 Message-ID: <87y4xrxt26.fsf@bzg.ath.cx> References: <10493aa.dd867f2eeab70f315adbc3ac0113988b@afterlogic.edis.at> <87mwenuife.fsf@gmail.com> <87k39q2bfw.wl%dieter@schoen.or.at> <87oayrpp0b.fsf@bzg.ath.cx> <871tvjzbrb.wl%dieter@schoen.or.at> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40893) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WoB0k-0000zc-TN for emacs-orgmode@gnu.org; Sat, 24 May 2014 08:25:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WoB0f-0001hq-GL for emacs-orgmode@gnu.org; Sat, 24 May 2014 08:25:14 -0400 Received: from mail-we0-x22b.google.com ([2a00:1450:400c:c03::22b]:53172) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WoB0f-0001gU-AC for emacs-orgmode@gnu.org; Sat, 24 May 2014 08:25:09 -0400 Received: by mail-we0-f171.google.com with SMTP id w62so6070987wes.30 for ; Sat, 24 May 2014 05:25:08 -0700 (PDT) In-Reply-To: <871tvjzbrb.wl%dieter@schoen.or.at> (Dieter Schoen's message of "Sat, 24 May 2014 12:55:52 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Dieter Schoen Cc: emacs-orgmode@gnu.org, Eric Schulte Hi Dieter, Dieter Schoen writes: > I have my name to the copyright, but left in the name of the authors > of ob-python.el, as I used that as a template. > Is that ok? Yes -- but I don't see your name anywhere in the file. > Another change to the first version is that it's now also possible > to do :results value and :results value pp. > (The first version still had python wrapper code in there.) Great! > The Lua pretty-printer function is a home-brew, as Lua does not provide > much in that direction out of the box, at least to my knowledge. What ob-lua.el depends on? You declare functions that suggests there is both lua-mode.el and lua.el* -- I think this is a leftover from ob-pyhton.el. Can you double-check this? Also, there should be a note explaining how to install lua-mode.el, since it is not part of Emacs. * See (defcustom org-babel-lua-mode ... Also, there is (defvar org-src-preserve-indentation) which is not used. Let's do some more cleaning and then apply this to master. Thanks! -- Bastien From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dieter Schoen Subject: Re: ob-lua.el Date: Sat, 24 May 2014 23:17:53 +0200 Message-ID: <87oaymvptq.wl%dieter@schoen.or.at> References: <10493aa.dd867f2eeab70f315adbc3ac0113988b@afterlogic.edis.at> <87mwenuife.fsf@gmail.com> <87k39q2bfw.wl%dieter@schoen.or.at> <87oayrpp0b.fsf@bzg.ath.cx> <871tvjzbrb.wl%dieter@schoen.or.at> <87y4xrxt26.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=_mailrelay-22442-1400966276-0001-2" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:34831) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WoJKV-0002HE-Qb for emacs-orgmode@gnu.org; Sat, 24 May 2014 17:18:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WoJKQ-0001CK-Td for emacs-orgmode@gnu.org; Sat, 24 May 2014 17:18:11 -0400 In-Reply-To: <87y4xrxt26.fsf@bzg.ath.cx> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Bastien Cc: emacs-orgmode@gnu.org, Eric Schulte This is a MIME-formatted message. If you see this text it means that your E-mail software does not support MIME-formatted messages. --=_mailrelay-22442-1400966276-0001-2 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit At Sat, 24 May 2014 14:25:05 +0200, Bastien wrote: > > Hi Dieter, > > Dieter Schoen writes: > > > I have my name to the copyright, but left in the name of the authors > > of ob-python.el, as I used that as a template. > > Is that ok? > > Yes -- but I don't see your name anywhere in the file. madre-de-dios. i should not try to work when my boys are around. > What ob-lua.el depends on? > > You declare functions that suggests there is both lua-mode.el and > lua.el* -- I think this is a leftover from ob-pyhton.el. Can you > double-check this? Also, there should be a note explaining how to > install lua-mode.el, since it is not part of Emacs. Yes, that was a copy/paste relict from ob-python, I removed the latter mode reference. > * See (defcustom org-babel-lua-mode ... As far as I understand the code, lua-mode would only be used for the session support, to have an inferior process as receiver for code blocks. I could not yet get the session support to work, there is a bit more work involved than simple s/py/lua/. I'll continue to work in that area. > Also, there is (defvar org-src-preserve-indentation) which is not > used. removed. > Let's do some more cleaning and then apply this to master. regards, dieter ------------ --=_mailrelay-22442-1400966276-0001-2 Content-Type: text/plain; type=emacs-lisp; name="ob-lua.el"; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="ob-lua.el" ;;; ob-lua.el --- org-babel functions for lua evaluation ;; Copyright (C) 2009-2014 Free Software Foundation, Inc. ;; Authors: Dieter Schoen ;; Eric Schulte, Dan Davison ;; Keywords: literate programming, reproducible research ;; Homepage: http://orgmode.org ;; This file is part of GNU Emacs. ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;; Requirements: ;; for session support, lua-mode is needed. ;; lua-mode is not part of GNU Emacs/orgmode, but can be obtained ;; from marmalade or melpa. ;; However, sessions are not yet working. ;; Org-Babel support for evaluating lua source code. ;;; Code: (require 'ob) (eval-when-compile (require 'cl)) (declare-function org-remove-indentation "org" ) (declare-function lua-shell "ext:lua-mode" (&optional argprompt)) (declare-function lua-toggle-shells "ext:lua-mode" (arg)) (declare-function run-lua "ext:lua" (cmd &optional dedicated show)) (defvar org-babel-tangle-lang-exts) (add-to-list 'org-babel-tangle-lang-exts '("lua" . "lua")) (defvar org-babel-default-header-args:lua '()) (defcustom org-babel-lua-command "lua" "Name of the command for executing Lua code." :version "24.4" :package-version '(Org . "8.0") :group 'org-babel :type 'string) (defcustom org-babel-lua-mode (if (or (featurep 'xemacs) (featurep 'lua-mode)) 'lua-mode) "Preferred lua mode for use in running lua interactively. This will typically be 'lua-mode." :group 'org-babel :version "24.4" :package-version '(Org . "8.0") :type 'symbol) (defcustom org-babel-lua-hline-to "None" "Replace hlines in incoming tables with this when translating to lua." :group 'org-babel :version "24.4" :package-version '(Org . "8.0") :type 'string) (defcustom org-babel-lua-None-to 'hline "Replace 'None' in lua tables with this before returning." :group 'org-babel :version "24.4" :package-version '(Org . "8.0") :type 'symbol) (defun org-babel-execute:lua (body params) "Execute a block of Lua code with Babel. This function is called by `org-babel-execute-src-block'." (let* ((session (org-babel-lua-initiate-session (cdr (assoc :session params)))) (result-params (cdr (assoc :result-params params))) (result-type (cdr (assoc :result-type params))) (return-val (when (and (eq result-type 'value) (not session)) (cdr (assoc :return params)))) (preamble (cdr (assoc :preamble params))) (full-body (org-babel-expand-body:generic (concat body (if return-val (format "\nreturn %s" return-val) "")) params (org-babel-variable-assignments:lua params))) (result (org-babel-lua-evaluate session full-body result-type result-params preamble))) (org-babel-reassemble-table result (org-babel-pick-name (cdr (assoc :colname-names params)) (cdr (assoc :colnames params))) (org-babel-pick-name (cdr (assoc :rowname-names params)) (cdr (assoc :rownames params)))))) (defun org-babel-prep-session:lua (session params) "Prepare SESSION according to the header arguments in PARAMS. VARS contains resolved variable references" (let* ((session (org-babel-lua-initiate-session session)) (var-lines (org-babel-variable-assignments:lua params))) (org-babel-comint-in-buffer session (mapc (lambda (var) (end-of-line 1) (insert var) (comint-send-input) (org-babel-comint-wait-for-output session)) var-lines)) session)) (defun org-babel-load-session:lua (session body params) "Load BODY into SESSION." (save-window-excursion (let ((buffer (org-babel-prep-session:lua session params))) (with-current-buffer buffer (goto-char (process-mark (get-buffer-process (current-buffer)))) (insert (org-babel-chomp body))) buffer))) ;; helper functions (defun org-babel-variable-assignments:lua (params) "Return a list of Lua statements assigning the block's variables." (mapcar (lambda (pair) (format "%s=%s" (car pair) (org-babel-lua-var-to-lua (cdr pair)))) (mapcar #'cdr (org-babel-get-header params :var)))) (defun org-babel-lua-var-to-lua (var) "Convert an elisp value to a lua variable. Convert an elisp value, VAR, into a string of lua source code specifying a variable of the same value." (if (listp var) (if (and (= 1 (length var)) (not (listp (car var)))) (org-babel-lua-var-to-lua (car var)) (if (and (= 2 (length var)) (not (listp (car var)))) (concat (substring-no-properties (car var)) "=" (org-babel-lua-var-to-lua (cdr var))) (concat "{" (mapconcat #'org-babel-lua-var-to-lua var ", ") "}"))) (if (equal var 'hline) org-babel-lua-hline-to (format (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) "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." (let ((res (org-babel-script-escape results))) (if (listp res) (mapcar (lambda (el) (if (equal el 'None) org-babel-lua-None-to el)) res) res))) (defvar org-babel-lua-buffers '((:default . "*Lua*"))) (defun org-babel-lua-session-buffer (session) "Return the buffer associated with SESSION." (cdr (assoc session org-babel-lua-buffers))) (defun org-babel-lua-with-earmuffs (session) (let ((name (if (stringp session) session (format "%s" session)))) (if (and (string= "*" (substring name 0 1)) (string= "*" (substring name (- (length name) 1)))) name (format "*%s*" name)))) (defun org-babel-lua-without-earmuffs (session) (let ((name (if (stringp session) session (format "%s" session)))) (if (and (string= "*" (substring name 0 1)) (string= "*" (substring name (- (length name) 1)))) (substring name 1 (- (length name) 1)) name))) (defvar lua-default-interpreter) (defvar lua-which-bufname) (defvar lua-shell-buffer-name) (defun org-babel-lua-initiate-session-by-key (&optional session) "Initiate a lua session. If there is not a current inferior-process-buffer in SESSION then create. Return the initialized session." (require org-babel-lua-mode) (save-window-excursion (let* ((session (if session (intern session) :default)) (lua-buffer (org-babel-lua-session-buffer session)) (cmd (if (member system-type '(cygwin windows-nt ms-dos)) (concat org-babel-lua-command " -i") org-babel-lua-command))) (cond ((and (eq 'lua-mode org-babel-lua-mode) (fboundp 'lua-start-process)) ; lua-mode.el ;; Make sure that lua-which-bufname is initialized, as otherwise ;; it will be overwritten the first time a Lua buffer is ;; created. ;;(lua-toggle-shells lua-default-interpreter) ;; `lua-shell' creates a buffer whose name is the value of ;; `lua-which-bufname' with '*'s at the beginning and end (let* ((bufname (if (and lua-process-buffer (buffer-live-p lua-process-buffer)) (replace-regexp-in-string ;; zap surrounding * "^\\*\\([^*]+\\)\\*$" "\\1" (buffer-name lua-process-buffer)) (concat "Lua-" (symbol-name session)))) (lua-which-bufname bufname)) (lua-start-process) (setq lua-buffer (org-babel-lua-with-earmuffs bufname)))) (t (error "No function available for running an inferior Lua"))) (setq org-babel-lua-buffers (cons (cons session lua-process-buffer) (assq-delete-all session org-babel-lua-buffers))) session))) (defun org-babel-lua-initiate-session (&optional session params) "Create a session named SESSION according to PARAMS." (unless (string= session "none") (org-babel-lua-session-buffer (org-babel-lua-initiate-session-by-key session)))) (defvar org-babel-lua-eoe-indicator "\"org_babel_lua_eoe\"" "A string to indicate that evaluation has completed.") (defvar org-babel-lua-wrapper-method " function main() %s end fd=io.open(\"%s\", \"w\") fd:write( main() ) fd:close()") (defvar org-babel-lua-pp-wrapper-method " -- table to string function t2s(t, indent) if indent == nil then indent = \"\" end if type(t) == \"table\" then ts = \"\" for k,v in pairs(t) do if type(v) == \"table\" then ts = ts .. indent .. t2s(k,indent .. \" \") .. \" = \\n\" .. t2s(v, indent .. \" \") else ts = ts .. indent .. t2s(k,indent .. \" \") .. \" = \" .. t2s(v, indent .. \" \") .. \"\\n\" end end return ts else return tostring(t) end end function main() %s end fd=io.open(\"%s\", \"w\") fd:write(t2s(main())) fd:close()") (defun org-babel-lua-evaluate (session body &optional result-type result-params preamble) "Evaluate BODY as Lua code." (if session (org-babel-lua-evaluate-session session body result-type result-params) (org-babel-lua-evaluate-external-process body result-type result-params preamble))) (defun org-babel-lua-evaluate-external-process (body &optional result-type result-params preamble) "Evaluate BODY in external lua process. If RESULT-TYPE equals 'output then return standard output as a string. If RESULT-TYPE equals 'value then return the value of the last statement in BODY, as elisp." (let ((raw (case result-type (output (org-babel-eval org-babel-lua-command (concat (if preamble (concat preamble "\n")) body))) (value (let ((tmp-file (org-babel-temp-file "lua-"))) (org-babel-eval org-babel-lua-command (concat (if preamble (concat preamble "\n") "") (format (if (member "pp" result-params) org-babel-lua-pp-wrapper-method org-babel-lua-wrapper-method) (mapconcat (lambda (line) (format "\t%s" line)) (split-string (org-remove-indentation (org-babel-trim body)) "[\r\n]") "\n") (org-babel-process-file-name tmp-file 'noquote)))) (org-babel-eval-read-file tmp-file)))))) (org-babel-result-cond result-params raw (org-babel-lua-table-or-string (org-babel-trim raw))))) (defun org-babel-lua-evaluate-session (session body &optional result-type result-params) "Pass BODY to the Lua process in SESSION. If RESULT-TYPE equals 'output then return standard output as a string. If RESULT-TYPE equals 'value then return the value of the last statement in BODY, as elisp." (let* ((send-wait (lambda () (comint-send-input nil t) (sleep-for 0 5))) (dump-last-value (lambda (tmp-file pp) (mapc (lambda (statement) (insert statement) (funcall send-wait)) (if pp (list "-- table to string function t2s(t, indent) if indent == nil then indent = \"\" end if type(t) == \"table\" then ts = \"\" for k,v in pairs(t) do if type(v) == \"table\" then ts = ts .. indent .. t2s(k,indent .. \" \") .. \" = \\n\" .. t2s(v, indent .. \" \") else ts = ts .. indent .. t2s(k,indent .. \" \") .. \" = \" .. t2s(v, indent .. \" \") .. \"\\n\" end end return ts else return tostring(t) end end " (format "fd:write(_)) fd:close()" (org-babel-process-file-name tmp-file 'noquote))) (list (format "fd=io.open(\"%s\", \"w\") fd:write( _ ) fd:close()" (org-babel-process-file-name tmp-file 'noquote))))))) (input-body (lambda (body) (mapc (lambda (line) (insert line) (funcall send-wait)) (split-string body "[\r\n]")) (funcall send-wait))) (results (case result-type (output (mapconcat #'org-babel-trim (butlast (org-babel-comint-with-output (session org-babel-lua-eoe-indicator t body) (funcall input-body body) (funcall send-wait) (funcall send-wait) (insert org-babel-lua-eoe-indicator) (funcall send-wait)) 2) "\n")) (value (let ((tmp-file (org-babel-temp-file "lua-"))) (org-babel-comint-with-output (session org-babel-lua-eoe-indicator nil body) (let ((comint-process-echoes nil)) (funcall input-body body) (funcall dump-last-value tmp-file (member "pp" result-params)) (funcall send-wait) (funcall send-wait) (insert org-babel-lua-eoe-indicator) (funcall send-wait))) (org-babel-eval-read-file tmp-file)))))) (unless (string= (substring org-babel-lua-eoe-indicator 1 -1) results) (org-babel-result-cond result-params results (org-babel-lua-table-or-string results))))) (defun org-babel-lua-read-string (string) "Strip 's from around Lua string." (if (string-match "^'\\([^\000]+\\)'$" string) (match-string 1 string) string)) (provide 'ob-lua) ;;; ob-lua.el ends here --=_mailrelay-22442-1400966276-0001-2-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bastien Subject: Re: ob-lua.el Date: Sun, 25 May 2014 07:24:07 +0200 Message-ID: <87zji6toqw.fsf@bzg.ath.cx> References: <10493aa.dd867f2eeab70f315adbc3ac0113988b@afterlogic.edis.at> <87mwenuife.fsf@gmail.com> <87k39q2bfw.wl%dieter@schoen.or.at> <87oayrpp0b.fsf@bzg.ath.cx> <871tvjzbrb.wl%dieter@schoen.or.at> <87y4xrxt26.fsf@bzg.ath.cx> <87oaymvptq.wl%dieter@schoen.or.at> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:52226) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WoQuu-0008V8-S7 for emacs-orgmode@gnu.org; Sun, 25 May 2014 01:24:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WoQup-00065W-3m for emacs-orgmode@gnu.org; Sun, 25 May 2014 01:24:16 -0400 Received: from mail-we0-x234.google.com ([2a00:1450:400c:c03::234]:63648) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WoQuo-00065R-TM for emacs-orgmode@gnu.org; Sun, 25 May 2014 01:24:11 -0400 Received: by mail-we0-f180.google.com with SMTP id t61so6706293wes.11 for ; Sat, 24 May 2014 22:24:10 -0700 (PDT) In-Reply-To: <87oaymvptq.wl%dieter@schoen.or.at> (Dieter Schoen's message of "Sat, 24 May 2014 23:17:53 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Dieter Schoen Cc: emacs-orgmode@gnu.org, Eric Schulte Hi Dieter, Dieter Schoen writes: > Yes, that was a copy/paste relict from ob-python, I removed the latter > mode reference. OK -- I see there are still references to both lua-mode.el and lua.el (which does not exist) and you need to add a link to the lua-mode.el github repository. >> * See (defcustom org-babel-lua-mode ... > > As far as I understand the code, lua-mode would only be used for the session > support, to have an inferior process as receiver for code blocks. > I could not yet get the session support to work, there is a bit more work > involved than simple s/py/lua/. > I'll continue to work in that area. Okay. Another thing: :version "24.4" :package-version '(Org . "8.0") needs to be :version "24.5" :package-version '(Org . "8.3") to be accurate. Thanks for the ongoing work, keep us posted and we can put this in master when you get the confirmation from the FSF for the copyright assignment. Thanks! -- Bastien From mboxrd@z Thu Jan 1 00:00:00 1970 From: Dieter Schoen Subject: Re: ob-lua.el Date: Mon, 26 May 2014 22:57:41 +0200 Message-ID: <87a9a4i7ga.wl%dieter@schoen.or.at> References: <10493aa.dd867f2eeab70f315adbc3ac0113988b@afterlogic.edis.at> <87mwenuife.fsf@gmail.com> <87k39q2bfw.wl%dieter@schoen.or.at> <87oayrpp0b.fsf@bzg.ath.cx> <871tvjzbrb.wl%dieter@schoen.or.at> <87y4xrxt26.fsf@bzg.ath.cx> <87oaymvptq.wl%dieter@schoen.or.at> <87zji6toqw.fsf@bzg.ath.cx> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=_mailrelay-12904-1401137864-0001-2" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35167) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wp1y2-00081x-85 for emacs-orgmode@gnu.org; Mon, 26 May 2014 16:58:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wp1xx-0001Hc-BF for emacs-orgmode@gnu.org; Mon, 26 May 2014 16:57:58 -0400 In-Reply-To: <87zji6toqw.fsf@bzg.ath.cx> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Bastien Cc: emacs-orgmode@gnu.org This is a MIME-formatted message. If you see this text it means that your E-mail software does not support MIME-formatted messages. --=_mailrelay-12904-1401137864-0001-2 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit At Sun, 25 May 2014 07:24:07 +0200, Bastien wrote: > > OK -- I see there are still references to both lua-mode.el and lua.el > (which does not exist) and you need to add a link to the lua-mode.el > github repository. The reference to lua.el should be gone now. Link added. > Okay. Another thing: > > :version "24.4" > :package-version '(Org . "8.0") > > needs to be > > :version "24.5" > :package-version '(Org . "8.3") > > to be accurate. Fixed. One problem which I am currently working on is session mode. This is not yet working. Therefore I have put an (error "..") in org-babel-lua-initiate-session. > Thanks for the ongoing work, keep us posted and we can put this in > master when you get the confirmation from the FSF for the copyright > assignment. I already received the confirmation from FSF (the signed PDF), and I have seen that I have been added to the contributors of org-mode. Kind regards, Dieter --=_mailrelay-12904-1401137864-0001-2 Content-Type: text/plain; type=emacs-lisp; name="ob-lua.el"; charset=us-ascii Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="ob-lua.el" ;;; ob-lua.el --- org-babel functions for lua evaluation ;; Copyright (C) 2009-2014 Free Software Foundation, Inc. ;; Authors: Dieter Schoen ;; Eric Schulte, Dan Davison ;; Keywords: literate programming, reproducible research ;; Homepage: http://orgmode.org ;; This file is part of GNU Emacs. ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;; Requirements: ;; for session support, lua-mode is needed. ;; lua-mode is not part of GNU Emacs/orgmode, but can be obtained ;; from marmalade or melpa. ;; The source respository is here: ;; https://github.com/immerrr/lua-mode ;; However, sessions are not yet working. ;; Org-Babel support for evaluating lua source code. ;;; Code: (require 'ob) (eval-when-compile (require 'cl)) (declare-function org-remove-indentation "org" ) (declare-function lua-shell "ext:lua-mode" (&optional argprompt)) (declare-function lua-toggle-shells "ext:lua-mode" (arg)) (declare-function run-lua "ext:lua" (cmd &optional dedicated show)) (defvar org-babel-tangle-lang-exts) (add-to-list 'org-babel-tangle-lang-exts '("lua" . "lua")) (defvar org-babel-default-header-args:lua '()) (defcustom org-babel-lua-command "lua" "Name of the command for executing Lua code." :version "24.5" :package-version '(Org . "8.3") :group 'org-babel :type 'string) (defcustom org-babel-lua-mode 'lua-mode "Preferred lua mode for use in running lua interactively. This will typically be 'lua-mode." :group 'org-babel :version "24.5" :package-version '(Org . "8.3") :type 'symbol) (defcustom org-babel-lua-hline-to "None" "Replace hlines in incoming tables with this when translating to lua." :group 'org-babel :version "24.5" :package-version '(Org . "8.3") :type 'string) (defcustom org-babel-lua-None-to 'hline "Replace 'None' in lua tables with this before returning." :group 'org-babel :version "24.5" :package-version '(Org . "8.3") :type 'symbol) (defun org-babel-execute:lua (body params) "Execute a block of Lua code with Babel. This function is called by `org-babel-execute-src-block'." (let* ((session (org-babel-lua-initiate-session (cdr (assoc :session params)))) (result-params (cdr (assoc :result-params params))) (result-type (cdr (assoc :result-type params))) (return-val (when (and (eq result-type 'value) (not session)) (cdr (assoc :return params)))) (preamble (cdr (assoc :preamble params))) (full-body (org-babel-expand-body:generic (concat body (if return-val (format "\nreturn %s" return-val) "")) params (org-babel-variable-assignments:lua params))) (result (org-babel-lua-evaluate session full-body result-type result-params preamble))) (org-babel-reassemble-table result (org-babel-pick-name (cdr (assoc :colname-names params)) (cdr (assoc :colnames params))) (org-babel-pick-name (cdr (assoc :rowname-names params)) (cdr (assoc :rownames params)))))) (defun org-babel-prep-session:lua (session params) "Prepare SESSION according to the header arguments in PARAMS. VARS contains resolved variable references" (let* ((session (org-babel-lua-initiate-session session)) (var-lines (org-babel-variable-assignments:lua params))) (org-babel-comint-in-buffer session (mapc (lambda (var) (end-of-line 1) (insert var) (comint-send-input) (org-babel-comint-wait-for-output session)) var-lines)) session)) (defun org-babel-load-session:lua (session body params) "Load BODY into SESSION." (save-window-excursion (let ((buffer (org-babel-prep-session:lua session params))) (with-current-buffer buffer (goto-char (process-mark (get-buffer-process (current-buffer)))) (insert (org-babel-chomp body))) buffer))) ;; helper functions (defun org-babel-variable-assignments:lua (params) "Return a list of Lua statements assigning the block's variables." (mapcar (lambda (pair) (format "%s=%s" (car pair) (org-babel-lua-var-to-lua (cdr pair)))) (mapcar #'cdr (org-babel-get-header params :var)))) (defun org-babel-lua-var-to-lua (var) "Convert an elisp value to a lua variable. Convert an elisp value, VAR, into a string of lua source code specifying a variable of the same value." (if (listp var) (if (and (= 1 (length var)) (not (listp (car var)))) (org-babel-lua-var-to-lua (car var)) (if (and (= 2 (length var)) (not (listp (car var)))) (concat (substring-no-properties (car var)) "=" (org-babel-lua-var-to-lua (cdr var))) (concat "{" (mapconcat #'org-babel-lua-var-to-lua var ", ") "}"))) (if (equal var 'hline) org-babel-lua-hline-to (format (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) "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." (let ((res (org-babel-script-escape results))) (if (listp res) (mapcar (lambda (el) (if (equal el 'None) org-babel-lua-None-to el)) res) res))) (defvar org-babel-lua-buffers '((:default . "*Lua*"))) (defun org-babel-lua-session-buffer (session) "Return the buffer associated with SESSION." (cdr (assoc session org-babel-lua-buffers))) (defun org-babel-lua-with-earmuffs (session) (let ((name (if (stringp session) session (format "%s" session)))) (if (and (string= "*" (substring name 0 1)) (string= "*" (substring name (- (length name) 1)))) name (format "*%s*" name)))) (defun org-babel-lua-without-earmuffs (session) (let ((name (if (stringp session) session (format "%s" session)))) (if (and (string= "*" (substring name 0 1)) (string= "*" (substring name (- (length name) 1)))) (substring name 1 (- (length name) 1)) name))) (defvar lua-default-interpreter) (defvar lua-which-bufname) (defvar lua-shell-buffer-name) (defun org-babel-lua-initiate-session-by-key (&optional session) "Initiate a lua session. If there is not a current inferior-process-buffer in SESSION then create. Return the initialized session." (require org-babel-lua-mode) (save-window-excursion (let* ((session (if session (intern session) :default)) (lua-buffer (org-babel-lua-session-buffer session)) (cmd (if (member system-type '(cygwin windows-nt ms-dos)) (concat org-babel-lua-command " -i") org-babel-lua-command))) (cond ((and (eq 'lua-mode org-babel-lua-mode) (fboundp 'lua-start-process)) ; lua-mode.el ;; Make sure that lua-which-bufname is initialized, as otherwise ;; it will be overwritten the first time a Lua buffer is ;; created. ;;(lua-toggle-shells lua-default-interpreter) ;; `lua-shell' creates a buffer whose name is the value of ;; `lua-which-bufname' with '*'s at the beginning and end (let* ((bufname (if (and lua-process-buffer (buffer-live-p lua-process-buffer)) (replace-regexp-in-string ;; zap surrounding * "^\\*\\([^*]+\\)\\*$" "\\1" (buffer-name lua-process-buffer)) (concat "Lua-" (symbol-name session)))) (lua-which-bufname bufname)) (lua-start-process) (setq lua-buffer (org-babel-lua-with-earmuffs bufname)))) (t (error "No function available for running an inferior Lua"))) (setq org-babel-lua-buffers (cons (cons session lua-process-buffer) (assq-delete-all session org-babel-lua-buffers))) session))) (defun org-babel-lua-initiate-session (&optional session params) "Create a session named SESSION according to PARAMS." (unless (string= session "none") (error "Sessions currently not supported, work in progress") (org-babel-lua-session-buffer (org-babel-lua-initiate-session-by-key session)))) (defvar org-babel-lua-eoe-indicator "--eoe" "A string to indicate that evaluation has completed.") (defvar org-babel-lua-wrapper-method " function main() %s end fd=io.open(\"%s\", \"w\") fd:write( main() ) fd:close()") (defvar org-babel-lua-pp-wrapper-method " -- table to string function t2s(t, indent) if indent == nil then indent = \"\" end if type(t) == \"table\" then ts = \"\" for k,v in pairs(t) do if type(v) == \"table\" then ts = ts .. indent .. t2s(k,indent .. \" \") .. \" = \\n\" .. t2s(v, indent .. \" \") else ts = ts .. indent .. t2s(k,indent .. \" \") .. \" = \" .. t2s(v, indent .. \" \") .. \"\\n\" end end return ts else return tostring(t) end end function main() %s end fd=io.open(\"%s\", \"w\") fd:write(t2s(main())) fd:close()") (defun org-babel-lua-evaluate (session body &optional result-type result-params preamble) "Evaluate BODY as Lua code." (if session (org-babel-lua-evaluate-session session body result-type result-params) (org-babel-lua-evaluate-external-process body result-type result-params preamble))) (defun org-babel-lua-evaluate-external-process (body &optional result-type result-params preamble) "Evaluate BODY in external lua process. If RESULT-TYPE equals 'output then return standard output as a string. If RESULT-TYPE equals 'value then return the value of the last statement in BODY, as elisp." (let ((raw (case result-type (output (org-babel-eval org-babel-lua-command (concat (if preamble (concat preamble "\n")) body))) (value (let ((tmp-file (org-babel-temp-file "lua-"))) (org-babel-eval org-babel-lua-command (concat (if preamble (concat preamble "\n") "") (format (if (member "pp" result-params) org-babel-lua-pp-wrapper-method org-babel-lua-wrapper-method) (mapconcat (lambda (line) (format "\t%s" line)) (split-string (org-remove-indentation (org-babel-trim body)) "[\r\n]") "\n") (org-babel-process-file-name tmp-file 'noquote)))) (org-babel-eval-read-file tmp-file)))))) (org-babel-result-cond result-params raw (org-babel-lua-table-or-string (org-babel-trim raw))))) (defun org-babel-lua-evaluate-session (session body &optional result-type result-params) "Pass BODY to the Lua process in SESSION. If RESULT-TYPE equals 'output then return standard output as a string. If RESULT-TYPE equals 'value then return the value of the last statement in BODY, as elisp." (let* ((send-wait (lambda () (comint-send-input nil t) (sleep-for 0 5))) (dump-last-value (lambda (tmp-file pp) (mapc (lambda (statement) (insert statement) (funcall send-wait)) (if pp (list "-- table to string function t2s(t, indent) if indent == nil then indent = \"\" end if type(t) == \"table\" then ts = \"\" for k,v in pairs(t) do if type(v) == \"table\" then ts = ts .. indent .. t2s(k,indent .. \" \") .. \" = \\n\" .. t2s(v, indent .. \" \") else ts = ts .. indent .. t2s(k,indent .. \" \") .. \" = \" .. t2s(v, indent .. \" \") .. \"\\n\" end end return ts else return tostring(t) end end " (format "fd:write(_)) fd:close()" (org-babel-process-file-name tmp-file 'noquote))) (list (format "fd=io.open(\"%s\", \"w\") fd:write( _ ) fd:close()" (org-babel-process-file-name tmp-file 'noquote))))))) (input-body (lambda (body) (mapc (lambda (line) (insert line) (funcall send-wait)) (split-string body "[\r\n]")) (funcall send-wait))) (results (case result-type (output (mapconcat #'org-babel-trim (butlast (org-babel-comint-with-output (session org-babel-lua-eoe-indicator t body) (funcall input-body body) (funcall send-wait) (funcall send-wait) (insert org-babel-lua-eoe-indicator) (funcall send-wait)) 2) "\n")) (value (let ((tmp-file (org-babel-temp-file "lua-"))) (org-babel-comint-with-output (session org-babel-lua-eoe-indicator nil body) (let ((comint-process-echoes nil)) (funcall input-body body) (funcall dump-last-value tmp-file (member "pp" result-params)) (funcall send-wait) (funcall send-wait) (insert org-babel-lua-eoe-indicator) (funcall send-wait))) (org-babel-eval-read-file tmp-file)))))) (unless (string= (substring org-babel-lua-eoe-indicator 1 -1) results) (org-babel-result-cond result-params results (org-babel-lua-table-or-string results))))) (defun org-babel-lua-read-string (string) "Strip 's from around Lua string." (if (string-match "^'\\([^\000]+\\)'$" string) (match-string 1 string) string)) (provide 'ob-lua) ;;; ob-lua.el ends here --=_mailrelay-12904-1401137864-0001-2-- From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bastien Subject: Re: ob-lua.el Date: Thu, 29 May 2014 19:57:24 +0200 Message-ID: <87a9a0tqm3.fsf@bzg.ath.cx> References: <10493aa.dd867f2eeab70f315adbc3ac0113988b@afterlogic.edis.at> <87mwenuife.fsf@gmail.com> <87k39q2bfw.wl%dieter@schoen.or.at> <87oayrpp0b.fsf@bzg.ath.cx> <871tvjzbrb.wl%dieter@schoen.or.at> <87y4xrxt26.fsf@bzg.ath.cx> <87oaymvptq.wl%dieter@schoen.or.at> <87zji6toqw.fsf@bzg.ath.cx> <87a9a4i7ga.wl%dieter@schoen.or.at> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:36570) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wq4a5-00077u-3h for emacs-orgmode@gnu.org; Thu, 29 May 2014 13:57:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wq4Zz-00088n-Mx for emacs-orgmode@gnu.org; Thu, 29 May 2014 13:57:33 -0400 Received: from mail-we0-x22c.google.com ([2a00:1450:400c:c03::22c]:43144) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wq4Zz-00088g-Fz for emacs-orgmode@gnu.org; Thu, 29 May 2014 13:57:27 -0400 Received: by mail-we0-f172.google.com with SMTP id k48so815639wev.3 for ; Thu, 29 May 2014 10:57:26 -0700 (PDT) In-Reply-To: <87a9a4i7ga.wl%dieter@schoen.or.at> (Dieter Schoen's message of "Mon, 26 May 2014 22:57:41 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Dieter Schoen Cc: emacs-orgmode@gnu.org Hi Dieter, Dieter Schoen writes: > I already received the confirmation from FSF (the signed PDF), and I have seen > that I have been added to the contributors of org-mode. Please send me your public key and I'll give you access to the repository. When you're done fixing `org-babel-lua-initiate-session' and other stuff, please commit ob-lua.el to the lisp/ directory. If you are unsure about the commit message, please post the patch to the list first and we'll see. Thanks! -- Bastien