Re: org-babel support for haxe

2020-09-30 Thread ian martins
I wrote the ob-core patch I mentioned before but white writing the commit
message I realized there's probably no need to modify ob-core at all. I was
doing it in order to allow haxe and java to create subdirectories in the
babel temp directory since both languages require class names to match file
names and directory structures to match the class' package (which is like
namespace in C). But for executing babel code blocks from the temp
directory all that is needed is the output; the source file doesn't matter.
I'll try updating the haxe and java patches to build and run directly from
the babel temp directory.

On Thu, Sep 24, 2020 at 5:17 PM ian martins  wrote:

> with ob-java I assumed I shouldn't change ob-core, so I advised/overrode
> ob-core instead of changing it. But it would be much better to change
> ob-core. I'll submit those changes as a separate patch that modifies
> ob-core.
>
> On Sun, Sep 13, 2020 at 4:04 PM Kyle Meyer  wrote:
>
>> ian martins writes:
>>
>> > ob-haxe and ob-java both involve a few changes to ob-core to allow temp
>> > directories instead of just temp files. Should I submit that as a
>> separate
>> > patch?
>>
>> It looks like that change is included with your ob-java patch [0], which
>> will be considered after 9.4 is released [1], so I think it's fine as
>> is.  (In my opinion, splitting up that patch would have been nice, but I
>> don't think it's worth a reroll, at least until some initial comments
>> come in.)
>>
>> [0]
>> https://orgmode.org/list/CAC=rjb7ahmnrq9nc4ao07qk3qzf4lvatmu_r1fwqr+97npn...@mail.gmail.com
>> [1] https://orgmode.org/list/87sgbwgvx6@gnu.org
>>
>


Re: org-babel support for haxe

2020-09-24 Thread ian martins
with ob-java I assumed I shouldn't change ob-core, so I advised/overrode
ob-core instead of changing it. But it would be much better to change
ob-core. I'll submit those changes as a separate patch that modifies
ob-core.

On Sun, Sep 13, 2020 at 4:04 PM Kyle Meyer  wrote:

> ian martins writes:
>
> > ob-haxe and ob-java both involve a few changes to ob-core to allow temp
> > directories instead of just temp files. Should I submit that as a
> separate
> > patch?
>
> It looks like that change is included with your ob-java patch [0], which
> will be considered after 9.4 is released [1], so I think it's fine as
> is.  (In my opinion, splitting up that patch would have been nice, but I
> don't think it's worth a reroll, at least until some initial comments
> come in.)
>
> [0]
> https://orgmode.org/list/CAC=rjb7ahmnrq9nc4ao07qk3qzf4lvatmu_r1fwqr+97npn...@mail.gmail.com
> [1] https://orgmode.org/list/87sgbwgvx6@gnu.org
>


Re: org-babel support for haxe

2020-09-13 Thread Kyle Meyer
ian martins writes:

> ob-haxe and ob-java both involve a few changes to ob-core to allow temp
> directories instead of just temp files. Should I submit that as a separate
> patch?

It looks like that change is included with your ob-java patch [0], which
will be considered after 9.4 is released [1], so I think it's fine as
is.  (In my opinion, splitting up that patch would have been nice, but I
don't think it's worth a reroll, at least until some initial comments
come in.)

[0] 
https://orgmode.org/list/CAC=rjb7ahmnrq9nc4ao07qk3qzf4lvatmu_r1fwqr+97npn...@mail.gmail.com
[1] https://orgmode.org/list/87sgbwgvx6@gnu.org



Re: org-babel support for haxe

2020-09-12 Thread ian martins
Thanks for the feedback. There's no special reason for the external test
data file or repeated executable-find calls. I was following the convention
from ob-C. I'll make those changes.

ob-haxe and ob-java both involve a few changes to ob-core to allow temp
directories instead of just temp files. Should I submit that as a separate
patch?

On Sun, Sep 6, 2020 at 11:24 AM Kyle Meyer  wrote:

> Hi ian,
>
> It looks like this library is instead going to be available through an
> ELPA, but FWIW here are a couple of comments on the tests.
>
> ian martins writes:
>
> > diff --git a/testing/examples/ob-haxe-test.org b/testing/examples/
> ob-haxe-test.org
> > new file mode 100644
> > index 0..ba9119d58
> > --- /dev/null
> > +++ b/testing/examples/ob-haxe-test.org
> > @@ -0,0 +1,247 @@
> > +#+Title: a collection of examples for ob-haxe tests
> > +#+OPTIONS: ^:nil
> > +* Simple
> > +  :PROPERTIES:
> > +  :ID:   966875e9-d10e-406c-9211-449555e3d3b2
> > +  :END:
> > +#+name: simple
> > +#+begin_src haxe :results output silent
> > +  Sys.print(42);
> > +#+end_src
>
> I know some other babel tests use a separate .org file, but I find this
> setup harder to follow compared to having the Org content within the
> test (e.g. using org-test-with-temp-text or
> org-test-with-temp-text-in-file).  Perhaps I'm missing why it's needed
> in this case though.
>
> > diff --git a/testing/lisp/test-ob-haxe.el b/testing/lisp/test-ob-haxe.el
> [...]
> > +;;; Code:
> > +(org-test-for-executable "haxe")
> > +(unless (featurep 'ob-haxe)
> > +  (signal 'missing-test-dependency "Support for haxe code blocks"))
> > +
> > +(ert-deftest ob-haxe/simple ()
> > +  "Hello world program."
> > +  (if (executable-find org-babel-haxe-command)
>
> I think you can avoid the executable-find here and in all the other
> tests because you have (org-test-for-executable "haxe") at the beginning
> of the file.
>


Re: org-babel support for haxe

2020-09-06 Thread Kyle Meyer
Hi ian,

It looks like this library is instead going to be available through an
ELPA, but FWIW here are a couple of comments on the tests.

ian martins writes:

> diff --git a/testing/examples/ob-haxe-test.org 
> b/testing/examples/ob-haxe-test.org
> new file mode 100644
> index 0..ba9119d58
> --- /dev/null
> +++ b/testing/examples/ob-haxe-test.org
> @@ -0,0 +1,247 @@
> +#+Title: a collection of examples for ob-haxe tests
> +#+OPTIONS: ^:nil
> +* Simple
> +  :PROPERTIES:
> +  :ID:   966875e9-d10e-406c-9211-449555e3d3b2
> +  :END:
> +#+name: simple
> +#+begin_src haxe :results output silent
> +  Sys.print(42);
> +#+end_src

I know some other babel tests use a separate .org file, but I find this
setup harder to follow compared to having the Org content within the
test (e.g. using org-test-with-temp-text or
org-test-with-temp-text-in-file).  Perhaps I'm missing why it's needed
in this case though.

> diff --git a/testing/lisp/test-ob-haxe.el b/testing/lisp/test-ob-haxe.el
[...]
> +;;; Code:
> +(org-test-for-executable "haxe")
> +(unless (featurep 'ob-haxe)
> +  (signal 'missing-test-dependency "Support for haxe code blocks"))
> +
> +(ert-deftest ob-haxe/simple ()
> +  "Hello world program."
> +  (if (executable-find org-babel-haxe-command)

I think you can avoid the executable-find here and in all the other
tests because you have (org-test-for-executable "haxe") at the beginning
of the file.



Re: org-babel support for haxe

2020-09-05 Thread ian martins
That makes sense.

It's probably enough to keep the languages page [1] complete and up to
date. External repos should already have docs with the code.

[1] https://orgmode.org/worg/org-contrib/babel/languages.html


On Sat, Sep 5, 2020 at 3:24 AM Bastien  wrote:

> Hi Ian,
>
> ian martins  writes:
>
> > Hello. The included patch adds org-babel support for haxe (https://
> > haxe.org/). It allows main class and function definitions to be
> > optional, accepts variables and supports babel functional mode.
> > Please review.
>
> I'm not an Haxe user, so I cannot review the functionnalities, but
> from a cursory look, it seems fine.
>
> After 9.4, we will probably remove some Babel libraries from Org's
> core: we still need to decide on what criterium, but one candidate
> is to remove a Babel library if the corresponding language is not
> supported within Emacs core itself.
>
> If we go that route, we also need to do a better job at promoting
> external Babel libraries: perhaps a page on https://orgmode.org/worg
> would help.
>
> 2 cents,
>
> --
>  Bastien
>


Re: org-babel support for haxe

2020-09-05 Thread Bastien
Hi Ian,

ian martins  writes:

> Hello. The included patch adds org-babel support for haxe (https://
> haxe.org/). It allows main class and function definitions to be
> optional, accepts variables and supports babel functional mode.
> Please review.

I'm not an Haxe user, so I cannot review the functionnalities, but
from a cursory look, it seems fine.

After 9.4, we will probably remove some Babel libraries from Org's
core: we still need to decide on what criterium, but one candidate
is to remove a Babel library if the corresponding language is not
supported within Emacs core itself.

If we go that route, we also need to do a better job at promoting
external Babel libraries: perhaps a page on https://orgmode.org/worg
would help.

2 cents,

-- 
 Bastien



org-babel support for haxe

2020-06-11 Thread ian martins
Hello. The included patch adds org-babel support for haxe (https://haxe.org/).
It allows main class and function definitions to be optional, accepts
variables and supports babel functional mode. Please review.

I believe the same approach should work for java also. If this is fine I
could try to write an ob-java based on this to give java the same features
listed above.

One thing I would like to change is that this dumps the generated source
files in the current directory instead of burying them in the babel temp
dir (org-babel-temporary-directory). The same applies to the current
ob-java implementation. In order to put the temp source files in the babel
temp dir, there would have to be changes made in ob-core to allow creation
and removal of directories in the babel temp dir. If that seems reasonable
then I could try doing it, but let me know if there are reasons not to or
complications that I haven't thought of.

I've not done the FSF release. If this is acceptable I understand that I'll
have to do that.

-Ian
diff --git a/lisp/ob-haxe.el b/lisp/ob-haxe.el
new file mode 100644
index 0..5b0a42c7a
--- /dev/null
+++ b/lisp/ob-haxe.el
@@ -0,0 +1,260 @@
+;;; ob-haxe.el --- org-babel functions for haxe evaluation
+
+;; Copyright (C) 2020 Free Software Foundation, Inc.
+
+;; Author: Ian Martins
+;; Keywords: literate programming, reproducible research
+;; Homepage: http://orgmode.org
+
+;; This file is not 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 <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Org-Babel support for evaluating haxe source code.
+
+;;; Code:
+(require 'ob)
+
+(defvar org-babel-tangle-lang-exts)
+(add-to-list 'org-babel-tangle-lang-exts '("haxe" . "hx"))
+
+(defvar org-babel-default-header-args:haxe '()
+  "Default header args for haxe source blocks.")
+
+(defconst org-babel-header-args:haxe '((target . '(interp neko hashlink))
+   (imports . :any))
+  "Haxe-specific header arguments.
+org-babel supports three of the platforms the haxe compiler can target.
+
+  `interp' runs the haxe compiler with the `--interp' option.
+  `neko' and `hashlink' compile to bytecode and run the
+  respective VMs.")
+
+(defvar org-babel-haxe-command "haxe"
+  "Name of the haxe command.")
+
+(defcustom org-babel-haxe-hline-to "null"
+  "Replace hlines in incoming tables with this when translating to haxe."
+  :group 'org-babel
+  :version "25.2"
+  :package-version '(Org . "9.3")
+  :type 'string)
+
+(defcustom org-babel-haxe-null-to 'hline
+  "Replace `null' in haxe tables with this before returning."
+  :group 'org-babel
+  :version "25.2"
+  :package-version '(Org . "9.3")
+  :type 'symbol)
+
+(defun org-babel-execute:haxe (body params)
+  "Execute a haxe source block with BODY code and PARAMS params."
+  (let* ((fullclassname (or (cdr (assq :classname params)) ; class and package
+(org-babel-haxe-find-classname body)
+"Main"))
+ (classname (if (seq-contains fullclassname ?.); just class name
+(file-name-extension fullclassname)
+  fullclassname))
+ (packagename (if (seq-contains fullclassname ?.)  ; just package name
+  (file-name-base fullclassname)
+""))
+ (packagedir (if (not (seq-empty-p packagename))   ; package name as a path
+ (replace-regexp-in-string "\\\." "/" packagename)))
+ (src-file (concat (replace-regexp-in-string "\\\." "/" fullclassname) ".hx"))
+ (cmdline (or (cdr (assq :cmdline params)) ""))
+ (target-name (cdr (assq :target params)))
+ (target (cond ((string= target-name "neko") "-neko main.n -cmd \"neko main.n\"")
+   ((string= target-name "hashlink") "-hl main.hl -cmd \"hl main.hl\"")
+   (t "--interp")))
+ (cmd (concat org-babel-haxe-command
+  " " cmdline " -main " fullclassname " " target))
+ (result-type (cdr (assq :result-ty