From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id UKg7KywukF9kPwAA0tVLHw (envelope-from ) for ; Wed, 21 Oct 2020 12:48:44 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id IGwLJywukF++eQAAB5/wlQ (envelope-from ) for ; Wed, 21 Oct 2020 12:48:44 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 43AFC9403A0 for ; Wed, 21 Oct 2020 12:48:42 +0000 (UTC) Received: from localhost ([::1]:34286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kVDXk-0006d2-Uv for larch@yhetil.org; Wed, 21 Oct 2020 08:48:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48478) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kVDWv-0006c0-Fd for emacs-orgmode@gnu.org; Wed, 21 Oct 2020 08:47:49 -0400 Received: from mail-ej1-f47.google.com ([209.85.218.47]:35624) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kVDWr-00073P-Pp for emacs-orgmode@gnu.org; Wed, 21 Oct 2020 08:47:49 -0400 Received: by mail-ej1-f47.google.com with SMTP id p5so3055760ejj.2 for ; Wed, 21 Oct 2020 05:47:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=FEaE1byP/GUwmX1y6g7mP7xWDthoRqTa3dIy+UcrYRE=; b=Mr6f+A8giu8o4FcNGgrrHdoJySpeMPTimONY664H49Idobxwa4uksW1uq4h47ftPVz VK4V/Zg9bQac1E01Td0yXG70MROUyO8OyQDVDUd1bCbx+SvY4Sj3ZjrSLKG85iiWC/gQ lEKx+lyOZ+MBOacVHyIL0nrKQYUCxzId8eNWVgXlGLDJ91rsHfOUvaA5F+sEYkGYRywf +tJ1hD3BoMpgT2dI/+jiVIFjXLZa5DfEYoSuobRsD6V/cjqaXEM7MFuNqG8MdyUWR8k5 hPj/+y43Pmy4ap4qhAphNl8q1Wock0qIuIJlfiLIAjohj0qcHGljFDxFuUMVNb2W2wb7 Q7Mg== X-Gm-Message-State: AOAM531HICHBeK4lfmO1qO6tYZl+nxKkwyUrP+PD2JMioKdnZzubLe3m HKVwnwjZs/lAvCxzTIZeDrJlsXWSK6gLTYMeIE8= X-Google-Smtp-Source: ABdhPJysaZXjC27DMjzxGLTQwMRwCpTxeZYltajb+cTOjTRdyb8CzTwLnbE/zMY41k38Jwp4Hal7BBocskph1cQadII= X-Received: by 2002:a17:906:660f:: with SMTP id b15mr3458739ejp.333.1603284464126; Wed, 21 Oct 2020 05:47:44 -0700 (PDT) MIME-Version: 1.0 References: <87h7qohfm8.fsf@gmail.com> <87d01cglvm.fsf@gmail.com> In-Reply-To: <87d01cglvm.fsf@gmail.com> From: ian martins Date: Wed, 21 Oct 2020 08:47:32 -0400 Message-ID: Subject: Re: [PATCH] ob-java To: John Herrlin Content-Type: multipart/alternative; boundary="000000000000f54ea705b22dc030" Received-SPF: pass client-ip=209.85.218.47; envelope-from=ianxm1@gmail.com; helo=mail-ej1-f47.google.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/21 08:47:44 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FORGED_FROMDOMAIN=0.25, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.25, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-orgmode@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Org-Mode mailing list Errors-To: emacs-orgmode-bounces+larch=yhetil.org@gnu.org Sender: "Emacs-orgmode" X-Scanner: scn0 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=jhu.edu (policy=none); spf=pass (aspmx1.migadu.com: domain of emacs-orgmode-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=emacs-orgmode-bounces@gnu.org X-Spam-Score: -0.91 X-TUID: b5+4g1l+lZHt --000000000000f54ea705b22dc030 Content-Type: text/plain; charset="UTF-8" > > What do you think about having a configurable list where the user can > add =org-babel-java--import-maybe=? In my current use case I could then > add RxJava imports to that list and the imports could be removed from > the source code block. I think this can already be done. imports can be added to the headers, and babel allows file-wide headers, so you could add a =#+HEADER: :import rx.Observable= line to the file and all source blocks would get it. it's slightly different in that =org-babel-java--import-maybe= skips imports that it thinks aren't needed. also if there are any non-java source blocks in the same file, these imports could be added to them which would be bad, so when mixing multiple languages in the same file this wouldn't be an option. NIT > Some spacing when writing =public static...= > Thanks for fixing the spacing. I don't think I can give you credit for the patch, though, without leaving it out until ob-java is accepted. On Wed, Oct 21, 2020 at 1:59 AM John Herrlin wrote: > > I did and it looks really good. The difference in this example: > > #+BEGIN_SRC java > import rx.Observable; > > Observable.range(5, 3) > .subscribe((Integer i) -> { System.out.println("Got: " + i); }, > (Throwable t) -> { t.printStackTrace();}, > () -> { System.out.println("Ending > stream"); }); > #+END_SRC > > from the ones I posted yesterday is tremendous! > > I am not very experienced with Emacs lisp but I think it's pretty easy > to understand how things works and follow the code. The comments are > also of good help. I really appreciate the work you have done! > > > What do you think about having a configurable list where the user can > add =org-babel-java--import-maybe=? In my current use case I could then > add RxJava imports to that list and the imports could be removed from > the source code block. > > > NIT > > Some spacing when writing =public static...= > > #+BEGIN_SRC diff > diff --git a/lisp/ob-java.el b/lisp/ob-java.el > index 94c3f69cf..4f3904871 100644 > --- a/lisp/ob-java.el > +++ b/lisp/ob-java.el > @@ -220,7 +220,7 @@ RESULT-FILE is the temp file to write the result." > (org-babel-java--move-past org-babel-java--class-re) > (insert "\n public static void main(String[] args) { > System.out.print(\"success\"); > -}\n\n")) > + }\n\n")) > > ;; special handling to return value > (when (eq result-type 'value) > #+END_SRC > > > > ian martins writes: > > > Thanks for testing, and thanks for pointing that out. I will fix it so > that > > `public` is optional. > > > > btw, in your example you didn't have to specify `:classname` since you > > defined the class name in the source block. > > > > btw2, did you notice that you can C-c C-c on source blocks that don't > have > > main methods and it'll compile without error? > > > > On Tue, Oct 20, 2020 at 3:17 PM John Herrlin wrote: > > > >> > >> Hey, > >> > >> Did some debugging and found out that my class didn't contained =public= > >> and the patch requires it to be. > >> > >> This works fine: > >> > >> #+HEADER: :classname Main > >> #+HEADER: :dir src > >> #+HEADER: :cmdline -classpath ./rxjava-1.3.8.jar:. > >> #+HEADER: :cmpflag -classpath ./rxjava-1.3.8.jar > >> #+BEGIN_SRC java :results output code > >> import rx.Observable; > >> public class Main { > >> public static void main(String[] args) { > >> Observable.range(5, 5) > >> .subscribe(System.out::println); > >> } > >> } > >> #+END_SRC > >> > >> > >> > >> > >> ian martins writes: > >> > >> > I noticed that the tests didn't run with "make test." This updates the > >> > patch so that they can. I didn't add java to the list of default > >> languages > >> > because the java tests are slow. > >> > > >> > On Mon, Oct 5, 2020 at 9:23 AM ian martins wrote: > >> > > >> >> I wrote those examples in an org file so I could test as I wrote > them, > >> and > >> >> then exported it to make it more readable, but the export resulted in > >> >> source block headers being lost. Here is the same without export: > >> >> ---- > >> >> * Changes > >> >> > >> >> - support for functional mode (~:results value~) > >> >> - accept variables > >> >> - don't require package, class, and main definitions > >> >> - write source and result tempfiles to > ~org-babel-temporary-directory~, > >> >> but respects the ~:dir~ header > >> >> - work with tramp > >> >> > >> >> * Examples > >> >> ** Example 1 > >> >> This outputs "hello." If class and main definitions aren't given the > >> >> code block will be wrapped in generic ones. > >> >> > >> >> #+begin_src java :results output silent > >> >> System.out.print("hello"); > >> >> #+end_src > >> >> > >> >> This is exactly equivalent: > >> >> > >> >> #+begin_src java :results output silent > >> >> public class Main { > >> >> public static void main(String[] args) { > >> >> System.out.print("hello"); > >> >> } > >> >> } > >> >> #+end_src > >> >> > >> >> ** Example 2 > >> >> This also outputs "hello." > >> >> > >> >> #+begin_src java :results value silent > >> >> return "hello"; > >> >> #+end_src > >> >> > >> >> ** Example 3 > >> >> This generates the class "Example" in the package "org.orgmode" in > the > >> >> current directory. > >> >> > >> >> #+begin_src java :results output silent :classname > org.orgmode.Example > >> >> :dir . > >> >> System.out.print("hello, org-mode"); > >> >> #+end_src > >> >> > >> >> ** Example 4 > >> >> The "Hey" class defines a static method but no main. C-c C-c on the > >> >> "Hey" source block will write "./org/orgmode/Hey.java" and compile > it. > >> >> > >> >> The "Main" class calls the "Hey" class. C-c C-c on the "Main" source > >> >> block will write "./org/orgmode/Main.java" and compile and run it. > >> >> > >> >> #+begin_src java :results output silent :dir . > >> >> package org.orgmode; > >> >> > >> >> public class Hey { > >> >> public static String say() { > >> >> return "hey"; > >> >> } > >> >> } > >> >> #+end_src > >> >> > >> >> #+begin_src java :results output silent :dir . > >> >> package org.orgmode; > >> >> > >> >> public class Main { > >> >> public static void main(String[] args) { > >> >> System.out.print(Hey.say()); > >> >> } > >> >> } > >> >> #+end_src > >> >> > >> >> Instead of C-c C-c, we could have added tangle headers and written > the > >> >> source files out by tangling. > >> >> > >> >> ** Example 5 > >> >> This prints the variable from the header > >> >> > >> >> #+begin_src java :var msg="hello, org-mode" :results output silent > >> >> System.out.print(msg); > >> >> #+end_src > >> >> > >> >> ** Example 6 > >> >> This prints "hello, org-mode." The table is provided to the method > as a > >> >> list of lists. > >> >> > >> >> #+name: table > >> >> | message | hello, org-mode | > >> >> > >> >> #+begin_src java :var tbl=table :results output silent > >> >> System.out.print(tbl.get(0).get(1)); > >> >> #+end_src > >> >> > >> >> ** Example 7 > >> >> This example returns a list. > >> >> > >> >> Note that you're allowed to specify imports without defining the > class > >> >> or main methods. > >> >> > >> >> #+begin_src java :results value :exports both > >> >> import java.util.Arrays; > >> >> > >> >> return Arrays.asList("message", "hello, org-mode"); > >> >> #+end_src > >> >> > >> >> #+RESULTS: > >> >> | message | hello, org-mode | > >> >> > >> >> On Mon, Oct 5, 2020 at 8:35 AM ian martins wrote: > >> >> > >> >>> 1 Changes > >> >>> ========= > >> >>> > >> >>> - support for functional mode (`:results value') > >> >>> - accept variables > >> >>> - don't require package, class, and main definitions > >> >>> - write source and result tempfiles to > >> >>> `org-babel-temporary-directory', but respects the `:dir' header > >> >>> - work with tramp > >> >>> > >> >>> > >> >>> 2 Examples > >> >>> ========== > >> >>> Some examples follow. See the tests for more examples. I'll write > >> >>> proper docs after review. > >> >>> > >> >>> 2.1 Example 1 > >> >>> ~~~~~~~~~~~~~ > >> >>> > >> >>> This outputs "hello." If class and main definitions aren't given > the > >> >>> code block will be wrapped in generic ones. > >> >>> > >> >>> ,---- > >> >>> | System.out.print("hello"); > >> >>> `---- > >> >>> > >> >>> This is exactly equivalent: > >> >>> > >> >>> ,---- > >> >>> | public class Main { > >> >>> | public static void main(String[] args) { > >> >>> | System.out.print("hello"); > >> >>> | } > >> >>> | } > >> >>> `---- > >> >>> > >> >>> > >> >>> 2.2 Example 2 > >> >>> ~~~~~~~~~~~~~ > >> >>> > >> >>> This also outputs "hello." > >> >>> > >> >>> ,---- > >> >>> | return "hello"; > >> >>> `---- > >> >>> > >> >>> > >> >>> 2.3 Example 3 > >> >>> ~~~~~~~~~~~~~ > >> >>> > >> >>> This generates the class "Example" in the package "org.orgmode" in > >> the > >> >>> current directory. > >> >>> > >> >>> ,---- > >> >>> | System.out.print("hello, org-mode"); > >> >>> `---- > >> >>> > >> >>> > >> >>> 2.4 Example 4 > >> >>> ~~~~~~~~~~~~~ > >> >>> > >> >>> The "Hey" class defines a static method but no main. C-c C-c on > the > >> >>> "Hey" source block will write "./org/orgmode/Hey.java" and compile > >> it. > >> >>> > >> >>> The "Main" class calls the "Hey" class. C-c C-c on the "Main" > source > >> >>> block will write "./org/orgmode/Main.java" and compile and run it. > >> >>> > >> >>> ,---- > >> >>> | package org.orgmode; > >> >>> | > >> >>> | public class Hey { > >> >>> | public static String say() { > >> >>> | return "hey"; > >> >>> | } > >> >>> | } > >> >>> `---- > >> >>> > >> >>> ,---- > >> >>> | package org.orgmode; > >> >>> | > >> >>> | public class Main { > >> >>> | public static void main(String[] args) { > >> >>> | System.out.print(Hey.say()); > >> >>> | } > >> >>> | } > >> >>> `---- > >> >>> > >> >>> Instead of C-c C-c, we could have added tangle headers and written > >> the > >> >>> source files out by tangling. > >> >>> > >> >>> > >> >>> 2.5 Example 5 > >> >>> ~~~~~~~~~~~~~ > >> >>> > >> >>> This prints the variable from the header > >> >>> > >> >>> ,---- > >> >>> | System.out.print(msg); > >> >>> `---- > >> >>> > >> >>> > >> >>> 2.6 Example 6 > >> >>> ~~~~~~~~~~~~~ > >> >>> > >> >>> This prints "hello, org-mode." The table is provided to the > method as > >> >>> a list of lists. > >> >>> > >> >>> message hello, org-mode > >> >>> > >> >>> ,---- > >> >>> | System.out.print(tbl.get(0).get(1)); > >> >>> `---- > >> >>> > >> >>> > >> >>> 2.7 Example 7 > >> >>> ~~~~~~~~~~~~~ > >> >>> > >> >>> This example returns a list. > >> >>> > >> >>> Note that you're allowed to specify imports without defining the > >> class > >> >>> or main methods. > >> >>> > >> >>> ,---- > >> >>> | import java.util.Arrays; > >> >>> | > >> >>> | return Arrays.asList("message", "hello, org-mode"); > >> >>> `---- > >> >>> > >> >>> message hello, org-mode > >> >>> > >> >> > >> > --000000000000f54ea705b22dc030 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
What do = you think about having a configurable list where the user can
add =3Dorg-babel-java--import-maybe=3D? In my current use case I could then=
add RxJava imports to that list and the imports could be removed from
the source code block.
=C2=A0
I think this can a= lready be done. imports can be added to the headers, and babel allows file-= wide headers, so you could add a =3D#+HEADER: :import rx.Observable=3D line= to the file and all source blocks would get it.=C2=A0 it's slightly di= fferent in that =3Dorg-babel-java--import-maybe=3D skips imports that it th= inks aren't needed. also if there are any non-java source blocks in the= same file, these imports could be added to them which would be bad, so whe= n mixing multiple languages in the same file this wouldn't be an option= .

NIT
Some spacing when writing =3Dpublic static...=3D
=C2= =A0
Thanks for fixing the spacing. I don't think I can give y= ou credit for the patch, though, without leaving it out until ob-java is ac= cepted.

On Wed, Oct 21, 2020 at 1:59 AM John Herrlin <jherrlin@gmail.com> wrote:
<= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">
I did and it looks really good. The difference in this example:

=C2=A0 =C2=A0 #+BEGIN_SRC java
=C2=A0 =C2=A0 =C2=A0 import rx.Observable;

=C2=A0 =C2=A0 =C2=A0 Observable.range(5, 3)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .subscribe((Integer i) ->=C2=A0 =C2= =A0{ System.out.println("Got: " + i); },
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0(Throwable t) -> { t.printStackTrace();},
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0() ->=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 { System.out.println(&= quot;Ending stream"); });
=C2=A0 =C2=A0 #+END_SRC

from the ones I posted yesterday is tremendous!

I am not very experienced with Emacs lisp but I think it's pretty easy<= br> to understand how things works and follow the code. The comments are
also of good help. I really appreciate the work you have done!


What do you think about having a configurable list where the user can
add =3Dorg-babel-java--import-maybe=3D? In my current use case I could then=
add RxJava imports to that list and the imports could be removed from
the source code block.


NIT

Some spacing when writing =3Dpublic static...=3D

=C2=A0 =C2=A0#+BEGIN_SRC diff
=C2=A0 =C2=A0 =C2=A0diff --git a/lisp/ob-java.el b/lisp/ob-java.el
=C2=A0 =C2=A0 =C2=A0index 94c3f69cf..4f3904871 100644
=C2=A0 =C2=A0 =C2=A0--- a/lisp/ob-java.el
=C2=A0 =C2=A0 =C2=A0+++ b/lisp/ob-java.el
=C2=A0 =C2=A0 =C2=A0@@ -220,7 +220,7 @@ RESULT-FILE is the temp file to wri= te the result."
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (org-babel-java--move-past org-ba= bel-java--class-re)
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (insert "\n=C2=A0 =C2=A0 pub= lic static void main(String[] args) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 System.out.print(\"su= ccess\");
=C2=A0 =C2=A0 =C2=A0-}\n\n"))
=C2=A0 =C2=A0 =C2=A0+=C2=A0 =C2=A0 }\n\n"))

=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ;; special handling to return value
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (when (eq result-type 'value)
=C2=A0 =C2=A0#+END_SRC



ian martins <ianxm@jh= u.edu> writes:

> Thanks for testing, and thanks for pointing that out. I will fix it so= that
> `public` is optional.
>
> btw, in your example you didn't have to specify `:classname` since= you
> defined the class name in the source block.
>
> btw2, did you notice that you can C-c C-c on source blocks that don= 9;t have
> main methods and it'll compile without error?
>
> On Tue, Oct 20, 2020 at 3:17 PM John Herrlin <jherrlin@gmail.com> wrote:
>
>>
>> Hey,
>>
>> Did some debugging and found out that my class didn't containe= d =3Dpublic=3D
>> and the patch requires it to be.
>>
>> This works fine:
>>
>>=C2=A0 =C2=A0 #+HEADER: :classname Main
>>=C2=A0 =C2=A0 #+HEADER: :dir src
>>=C2=A0 =C2=A0 #+HEADER: :cmdline -classpath ./rxjava-1.3.8.jar:. >>=C2=A0 =C2=A0 #+HEADER: :cmpflag -classpath ./rxjava-1.3.8.jar
>>=C2=A0 =C2=A0 #+BEGIN_SRC java :results output code
>>=C2=A0 =C2=A0 =C2=A0 import rx.Observable;
>>=C2=A0 =C2=A0 =C2=A0 public class Main {
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 public static void main(String[]= args) {
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 Observable.range(5= , 5)
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 .sub= scribe(System.out::println);
>>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 }
>>=C2=A0 =C2=A0 =C2=A0 }
>>=C2=A0 =C2=A0 #+END_SRC
>>
>>
>>
>>
>> ian martins <ianxm@jhu.edu> writes:
>>
>> > I noticed that the tests didn't run with "make test.= " This updates the
>> > patch so that they can. I didn't add java to the list of = default
>> languages
>> > because the java tests are slow.
>> >
>> > On Mon, Oct 5, 2020 at 9:23 AM ian martins <ianxm@jhu.edu> wrote:
>> >
>> >> I wrote those examples in an org file so I could test as = I wrote them,
>> and
>> >> then exported it to make it more readable, but the export= resulted in
>> >> source block headers being lost.=C2=A0 Here is the same w= ithout export:
>> >> ----
>> >> * Changes
>> >>
>> >> - support for functional mode (~:results value~)
>> >> - accept variables
>> >> - don't require package, class, and main definitions<= br> >> >> - write source and result tempfiles to ~org-babel-tempora= ry-directory~,
>> >> but respects the ~:dir~ header
>> >> - work with tramp
>> >>
>> >> * Examples
>> >> ** Example 1
>> >> This outputs "hello."=C2=A0 If class and main d= efinitions aren't given the
>> >> code block will be wrapped in generic ones.
>> >>
>> >> #+begin_src java :results output silent
>> >>=C2=A0 =C2=A0System.out.print("hello");
>> >> #+end_src
>> >>
>> >> This is exactly equivalent:
>> >>
>> >> #+begin_src java :results output silent
>> >>=C2=A0 =C2=A0public class Main {
>> >>=C2=A0 =C2=A0 =C2=A0 =C2=A0public static void main(String[= ] args) {
>> >>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0System.out.print(= "hello");
>> >>=C2=A0 =C2=A0 =C2=A0 =C2=A0}
>> >>=C2=A0 =C2=A0}
>> >> #+end_src
>> >>
>> >> ** Example 2
>> >> This also outputs "hello."
>> >>
>> >> #+begin_src java :results value silent
>> >>=C2=A0 =C2=A0return "hello";
>> >> #+end_src
>> >>
>> >> ** Example 3
>> >> This generates the class "Example" in the packa= ge "org.orgmode" in the
>> >> current directory.
>> >>
>> >> #+begin_src java :results output silent :classname org.or= gmode.Example
>> >> :dir .
>> >>=C2=A0 =C2=A0System.out.print("hello, org-mode")= ;
>> >> #+end_src
>> >>
>> >> ** Example 4
>> >> The "Hey" class defines a static method but no = main. C-c C-c on the
>> >> "Hey" source block will write "./org/orgmo= de/Hey.java" and compile it.
>> >>
>> >> The "Main" class calls the "Hey" clas= s. C-c C-c on the "Main" source
>> >> block will write "./org/orgmode/Main.java" and = compile and run it.
>> >>
>> >> #+begin_src java :results output silent :dir .
>> >>=C2=A0 =C2=A0package org.orgmode;
>> >>
>> >>=C2=A0 =C2=A0public class Hey {
>> >>=C2=A0 =C2=A0 =C2=A0 =C2=A0public static String say() { >> >>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return "hey&= quot;;
>> >>=C2=A0 =C2=A0 =C2=A0 =C2=A0}
>> >>=C2=A0 =C2=A0}
>> >> #+end_src
>> >>
>> >> #+begin_src java :results output silent :dir .
>> >>=C2=A0 =C2=A0package org.orgmode;
>> >>
>> >>=C2=A0 =C2=A0public class Main {
>> >>=C2=A0 =C2=A0 =C2=A0 =C2=A0public static void main(String[= ] args) {
>> >>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0System.out.print(= Hey.say());
>> >>=C2=A0 =C2=A0 =C2=A0 =C2=A0}
>> >>=C2=A0 =C2=A0}
>> >> #+end_src
>> >>
>> >> Instead of C-c C-c, we could have added tangle headers an= d written the
>> >> source files out by tangling.
>> >>
>> >> ** Example 5
>> >> This prints the variable from the header
>> >>
>> >> #+begin_src java :var msg=3D"hello, org-mode" := results output silent
>> >>=C2=A0 =C2=A0System.out.print(msg);
>> >> #+end_src
>> >>
>> >> ** Example 6
>> >> This prints "hello, org-mode." The table is pro= vided to the method as a
>> >> list of lists.
>> >>
>> >> #+name: table
>> >> | message | hello, org-mode=C2=A0 |
>> >>
>> >> #+begin_src java :var tbl=3Dtable :results output silent<= br> >> >>=C2=A0 =C2=A0System.out.print(tbl.get(0).get(1));
>> >> #+end_src
>> >>
>> >> ** Example 7
>> >> This example returns a list.
>> >>
>> >> Note that you're allowed to specify imports without d= efining the class
>> >> or main methods.
>> >>
>> >> #+begin_src java :results value :exports both
>> >>=C2=A0 =C2=A0import java.util.Arrays;
>> >>
>> >>=C2=A0 =C2=A0return Arrays.asList("message", &qu= ot;hello, org-mode");
>> >> #+end_src
>> >>
>> >> #+RESULTS:
>> >> | message | hello, org-mode |
>> >>
>> >> On Mon, Oct 5, 2020 at 8:35 AM ian martins <ianxm@jhu.edu> wrote:
>> >>
>> >>> 1 Changes
>> >>> =3D=3D=3D=3D=3D=3D=3D=3D=3D
>> >>>
>> >>>=C2=A0 =C2=A0- support for functional mode (`:results = value')
>> >>>=C2=A0 =C2=A0- accept variables
>> >>>=C2=A0 =C2=A0- don't require package, class, and m= ain definitions
>> >>>=C2=A0 =C2=A0- write source and result tempfiles to >> >>>=C2=A0 =C2=A0 =C2=A0`org-babel-temporary-directory'= ;, but respects the `:dir' header
>> >>>=C2=A0 =C2=A0- work with tramp
>> >>>
>> >>>
>> >>> 2 Examples
>> >>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>> >>> Some examples follow.=C2=A0 See the tests for more ex= amples.=C2=A0 I'll write
>> >>> proper docs after review.
>> >>>
>> >>> 2.1 Example 1
>> >>> ~~~~~~~~~~~~~
>> >>>
>> >>>=C2=A0 =C2=A0This outputs "hello."=C2=A0 If = class and main definitions aren't given the
>> >>>=C2=A0 =C2=A0code block will be wrapped in generic one= s.
>> >>>
>> >>>=C2=A0 =C2=A0,----
>> >>>=C2=A0 =C2=A0| System.out.print("hello"); >> >>>=C2=A0 =C2=A0`----
>> >>>
>> >>>=C2=A0 =C2=A0This is exactly equivalent:
>> >>>
>> >>>=C2=A0 =C2=A0,----
>> >>>=C2=A0 =C2=A0| public class Main {
>> >>>=C2=A0 =C2=A0|=C2=A0 =C2=A0 =C2=A0public static void m= ain(String[] args) {
>> >>>=C2=A0 =C2=A0|=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0System= .out.print("hello");
>> >>>=C2=A0 =C2=A0|=C2=A0 =C2=A0 =C2=A0}
>> >>>=C2=A0 =C2=A0| }
>> >>>=C2=A0 =C2=A0`----
>> >>>
>> >>>
>> >>> 2.2 Example 2
>> >>> ~~~~~~~~~~~~~
>> >>>
>> >>>=C2=A0 =C2=A0This also outputs "hello."
>> >>>
>> >>>=C2=A0 =C2=A0,----
>> >>>=C2=A0 =C2=A0| return "hello";
>> >>>=C2=A0 =C2=A0`----
>> >>>
>> >>>
>> >>> 2.3 Example 3
>> >>> ~~~~~~~~~~~~~
>> >>>
>> >>>=C2=A0 =C2=A0This generates the class "Example&qu= ot; in the package "org.orgmode" in
>> the
>> >>>=C2=A0 =C2=A0current directory.
>> >>>
>> >>>=C2=A0 =C2=A0,----
>> >>>=C2=A0 =C2=A0| System.out.print("hello, org-mode&= quot;);
>> >>>=C2=A0 =C2=A0`----
>> >>>
>> >>>
>> >>> 2.4 Example 4
>> >>> ~~~~~~~~~~~~~
>> >>>
>> >>>=C2=A0 =C2=A0The "Hey" class defines a stati= c method but no main. C-c C-c on the
>> >>>=C2=A0 =C2=A0"Hey" source block will write &= quot;./org/orgmode/Hey.java" and compile
>> it.
>> >>>
>> >>>=C2=A0 =C2=A0The "Main" class calls the &quo= t;Hey" class. C-c C-c on the "Main" source
>> >>>=C2=A0 =C2=A0block will write "./org/orgmode/Main= .java" and compile and run it.
>> >>>
>> >>>=C2=A0 =C2=A0,----
>> >>>=C2=A0 =C2=A0| package org.orgmode;
>> >>>=C2=A0 =C2=A0|
>> >>>=C2=A0 =C2=A0| public class Hey {
>> >>>=C2=A0 =C2=A0|=C2=A0 =C2=A0 =C2=A0public static String= say() {
>> >>>=C2=A0 =C2=A0|=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return= "hey";
>> >>>=C2=A0 =C2=A0|=C2=A0 =C2=A0 =C2=A0}
>> >>>=C2=A0 =C2=A0| }
>> >>>=C2=A0 =C2=A0`----
>> >>>
>> >>>=C2=A0 =C2=A0,----
>> >>>=C2=A0 =C2=A0| package org.orgmode;
>> >>>=C2=A0 =C2=A0|
>> >>>=C2=A0 =C2=A0| public class Main {
>> >>>=C2=A0 =C2=A0|=C2=A0 =C2=A0 =C2=A0public static void m= ain(String[] args) {
>> >>>=C2=A0 =C2=A0|=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0System= .out.print(Hey.say());
>> >>>=C2=A0 =C2=A0|=C2=A0 =C2=A0 =C2=A0}
>> >>>=C2=A0 =C2=A0| }
>> >>>=C2=A0 =C2=A0`----
>> >>>
>> >>>=C2=A0 =C2=A0Instead of C-c C-c, we could have added t= angle headers and written
>> the
>> >>>=C2=A0 =C2=A0source files out by tangling.
>> >>>
>> >>>
>> >>> 2.5 Example 5
>> >>> ~~~~~~~~~~~~~
>> >>>
>> >>>=C2=A0 =C2=A0This prints the variable from the header<= br> >> >>>
>> >>>=C2=A0 =C2=A0,----
>> >>>=C2=A0 =C2=A0| System.out.print(msg);
>> >>>=C2=A0 =C2=A0`----
>> >>>
>> >>>
>> >>> 2.6 Example 6
>> >>> ~~~~~~~~~~~~~
>> >>>
>> >>>=C2=A0 =C2=A0This prints "hello, org-mode." = The table is provided to the method as
>> >>>=C2=A0 =C2=A0a list of lists.
>> >>>
>> >>>=C2=A0 =C2=A0 message=C2=A0 hello, org-mode
>> >>>
>> >>>=C2=A0 =C2=A0,----
>> >>>=C2=A0 =C2=A0| System.out.print(tbl.get(0).get(1)); >> >>>=C2=A0 =C2=A0`----
>> >>>
>> >>>
>> >>> 2.7 Example 7
>> >>> ~~~~~~~~~~~~~
>> >>>
>> >>>=C2=A0 =C2=A0This example returns a list.
>> >>>
>> >>>=C2=A0 =C2=A0Note that you're allowed to specify i= mports without defining the
>> class
>> >>>=C2=A0 =C2=A0or main methods.
>> >>>
>> >>>=C2=A0 =C2=A0,----
>> >>>=C2=A0 =C2=A0| import java.util.Arrays;
>> >>>=C2=A0 =C2=A0|
>> >>>=C2=A0 =C2=A0| return Arrays.asList("message"= ;, "hello, org-mode");
>> >>>=C2=A0 =C2=A0`----
>> >>>
>> >>>=C2=A0 =C2=A0 message=C2=A0 hello, org-mode
>> >>>
>> >>
>>
--000000000000f54ea705b22dc030--