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 8BWFOK0ee19gdAAA0tVLHw (envelope-from ) for ; Mon, 05 Oct 2020 13:25:01 +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 gDhANK0ee1/KcgAAB5/wlQ (envelope-from ) for ; Mon, 05 Oct 2020 13:25:01 +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 A76AE940215 for ; Mon, 5 Oct 2020 13:25:00 +0000 (UTC) Received: from localhost ([::1]:33868 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kPQU6-0003AC-Vn for larch@yhetil.org; Mon, 05 Oct 2020 09:24:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46680) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kPQT7-00036E-Qx for emacs-orgmode@gnu.org; Mon, 05 Oct 2020 09:23:58 -0400 Received: from mail-lj1-f169.google.com ([209.85.208.169]:41480) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kPQT4-0004MH-La for emacs-orgmode@gnu.org; Mon, 05 Oct 2020 09:23:57 -0400 Received: by mail-lj1-f169.google.com with SMTP id p15so3074050ljj.8 for ; Mon, 05 Oct 2020 06:23:54 -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; bh=t+n57bDtN9CpcXwjAAhQn1jyprNnMas4deR0k8EBWQw=; b=Ct9HtoaGe446KEyeIig98zZfJVwGracOVEuQi8TZtxzWGU6nqFYv0MptDAYxgPLX9B K7KlzA+P5oC873Yl3C4ZEk34GRcCoRnKag/fz71/lrGgxz+QqONXIC1iGcY912bNTOE0 H3pMPMSOp08o03EEiUhEbnYs2R1FlY8va1t9GT0f9oCHzHUK9Ym2sqVXn5k53Urk2F06 SgAY73q0C60yXkm/zpxkB74JYM7N+TGwjxX5Z/FWQu9dPTsdT1/4+vTwYr3eyDkUNMEs geWYZFszb/GyFRtU1SyA7XRe/GgPjQZiBLv/A0kh6ki6nxsRvQ37TsP1StgnEcBj+rJU VZkw== X-Gm-Message-State: AOAM531P/fe/hMzIcS/1UnZltKi+Ng94cAjCV3bZuO+0j5XF3O79NGFB gbCdAG0/bVDyIOSTOM1PFNFnUQyiACIz+209j7o7fdE/6Rk5VA== X-Google-Smtp-Source: ABdhPJygr/0N9vkFM2zchAsOTx19dImh38VVwQzIJwLvsvi6hF3SBbhgHkRwMz6Z8YmRjrSJ0+TKNqROg2d8eBWtt1I= X-Received: by 2002:a2e:8841:: with SMTP id z1mr4432059ljj.292.1601904232447; Mon, 05 Oct 2020 06:23:52 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: ian martins Date: Mon, 5 Oct 2020 09:23:41 -0400 Message-ID: Subject: Re: [PATCH] ob-java To: Org-Mode mailing list Content-Type: multipart/alternative; boundary="000000000000bd425b05b0ec644e" Received-SPF: pass client-ip=209.85.208.169; envelope-from=ianxm1@gmail.com; helo=mail-lj1-f169.google.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/05 09:23:53 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -11 X-Spam_score: -1.2 X-Spam_bar: - X-Spam_report: (-1.2 / 5.0 requ) BAYES_00=-1.9, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FORGED_FROMDOMAIN=0.248, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, 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: , 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: dJF+JrClKIRV --000000000000bd425b05b0ec644e Content-Type: text/plain; charset="UTF-8" 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 > --000000000000bd425b05b0ec644e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
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 ex= port resulted in source block headers being lost.=C2=A0 Here is the same wi= thout 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~ head= er
- work with tramp

* Examples
** Example 1
This outputs &= quot;hello." =C2=A0If class and main definitions aren't given the<= br>code block will be wrapped in generic ones.

#+begin_src java :res= ults output silent
=C2=A0 System.out.print("hello");
#+end_= src

This is exactly equivalent:

#+begin_src java :results out= put silent
=C2=A0 public class Main {
=C2=A0 =C2=A0 =C2=A0 public sta= tic void main(String[] args) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 System= .out.print("hello");
=C2=A0 =C2=A0 =C2=A0 }
=C2=A0 }
#+e= nd_src

** Example 2
This also outputs "hello."

#= +begin_src java :results value silent
=C2=A0 return "hello";#+end_src

** Example 3
This generates the class "Example&q= uot; in the package "org.orgmode" in the
current directory.
#+begin_src java :results output silent :classname org.orgmode.Example= :dir .
=C2=A0 System.out.print("hello, org-mode");
#+end_s= rc

** Example 4
The "Hey" class defines a static method= but no main. C-c C-c on the
"Hey" source block will write &qu= ot;./org/orgmode/Hey.java" and compile it.

The "Main"= class calls the "Hey" class. C-c C-c on the "Main" sou= rce
block will write "./org/orgmode/Main.java" and compile and= run it.

#+begin_src java :results output silent :dir .
=C2=A0 pa= ckage org.orgmode;

=C2=A0 public class Hey {
=C2=A0 =C2=A0 =C2=A0= public static String say() {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 return = "hey";
=C2=A0 =C2=A0 =C2=A0 }
=C2=A0 }
#+end_src

= #+begin_src java :results output silent :dir .
=C2=A0 package org.orgmod= e;

=C2=A0 public class Main {
=C2=A0 =C2=A0 =C2=A0 public static = void main(String[] args) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 System.out= .print(Hey.say());
=C2=A0 =C2=A0 =C2=A0 }
=C2=A0 }
#+end_src
Instead of C-c C-c, we could have added tangle headers and written thesource files out by tangling.

** Example 5
This prints the varia= ble from the header

#+begin_src java :var msg=3D"hello, org-mod= e" :results output silent
=C2=A0 System.out.print(msg);
#+end_sr= c

** Example 6
This prints "hello, org-mode." The table= is provided to the method as a list of lists.

#+name: table
| me= ssage | hello, org-mode =C2=A0|

#+begin_src java :var tbl=3Dtable :r= esults output silent
=C2=A0 System.out.print(tbl.get(0).get(1));
#+en= d_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
=C2=A0 im= port java.util.Arrays;

=C2=A0 return Arrays.asList("message&quo= t;, "hello, org-mode");
#+end_src

#+RESULTS:
| messa= ge | 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 - support for functional mode (`:= results value')
=C2=A0 - accept variables
=C2=A0 - don't requ= ire package, class, and main definitions
=C2=A0 - write source and resul= t tempfiles to
=C2=A0 =C2=A0 `org-babel-temporary-directory', but re= spects the `:dir' header
=C2=A0 - work with tramp


2 Examp= les
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Some examples follow.=C2=A0 S= ee the tests for more examples.=C2=A0 I'll write proper docs after revi= ew.

2.1 Example 1
~~~~~~~~~~~~~

=C2=A0 Th= is outputs "hello." =C2=A0If class and main definitions aren'= t given the
=C2=A0 code block will be wrapped in generic ones.

= =C2=A0 ,----
=C2=A0 | System.out.print("hello");
=C2=A0 `--= --

=C2=A0 This is exactly equivalent:

=C2=A0 ,----
=C2=A0 = | public class Main {
=C2=A0 | =C2=A0 =C2=A0 public static void main(Str= ing[] args) {
=C2=A0 | =C2=A0 =C2=A0 =C2=A0 =C2=A0 System.out.print(&quo= t;hello");
=C2=A0 | =C2=A0 =C2=A0 }
=C2=A0 | }
=C2=A0 `----

2.2 Example 2
~~~~~~~~~~~~~

=C2=A0 This also outputs &q= uot;hello."

=C2=A0 ,----
=C2=A0 | return "hello";<= br>=C2=A0 `----


2.3 Example 3
~~~~~~~~~~~~~

=C2=A0 Thi= s generates the class "Example" in the package "org.orgmode&= quot; in the
=C2=A0 current directory.

=C2=A0 ,----
=C2=A0 | S= ystem.out.print("hello, org-mode");
=C2=A0 `----


2.= 4 Example 4
~~~~~~~~~~~~~

=C2=A0 The "Hey" class define= s a static method but no main. C-c C-c on the
=C2=A0 "Hey" sou= rce block will write "./org/orgmode/Hey.java" and compile it.
=
=C2=A0 The "Main" class calls the "Hey" class. C-c = C-c on the "Main" source
=C2=A0 block will write "./org/o= rgmode/Main.java" and compile and run it.

=C2=A0 ,----
=C2= =A0 | package org.orgmode;
=C2=A0 |
=C2=A0 | public class Hey {
= =C2=A0 | =C2=A0 =C2=A0 public static String say() {
=C2=A0 | =C2=A0 =C2= =A0 =C2=A0 =C2=A0 return "hey";
=C2=A0 | =C2=A0 =C2=A0 }
= =C2=A0 | }
=C2=A0 `----

=C2=A0 ,----
=C2=A0 | package org.orgm= ode;
=C2=A0 |
=C2=A0 | public class Main {
=C2=A0 | =C2=A0 =C2=A0= public static void main(String[] args) {
=C2=A0 | =C2=A0 =C2=A0 =C2=A0 = =C2=A0 System.out.print(Hey.say());
=C2=A0 | =C2=A0 =C2=A0 }
=C2=A0 |= }
=C2=A0 `----

=C2=A0 Instead of C-c C-c, we could have added ta= ngle headers and written the
=C2=A0 source files out by tangling.

2.5 Example 5
~~~~~~~~~~~~~

=C2=A0 This prints the variable = from the header

=C2=A0 ,----
=C2=A0 | System.out.print(msg);
= =C2=A0 `----


2.6 Example 6
~~~~~~~~~~~~~

=C2=A0 This p= rints "hello, org-mode." The table is provided to the method as=C2=A0 a list of lists.

=C2=A0 =C2=A0message =C2=A0hello, org-mode=

=C2=A0 ,----
=C2=A0 | System.out.print(tbl.get(0).get(1));
= =C2=A0 `----


2.7 Example 7
~~~~~~~~~~~~~

=C2=A0 This e= xample returns a list.

=C2=A0 Note that you're allowed to specif= y imports without defining the class
=C2=A0 or main methods.

=C2= =A0 ,----
=C2=A0 | import java.util.Arrays;
=C2=A0 |
=C2=A0 | ret= urn Arrays.asList("message", "hello, org-mode");
=C2= =A0 `----

=C2=A0 =C2=A0message =C2=A0hello, org-mode
--000000000000bd425b05b0ec644e--