From: ian martins <ianxm@jhu.edu>
To: Org-Mode mailing list <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] ob-java
Date: Mon, 5 Oct 2020 09:23:41 -0400 [thread overview]
Message-ID: <CAC=rjb5py_-uNBikLNZarYfTSXMxaOBeJsF8LW+C-3KX6cA5mg@mail.gmail.com> (raw)
In-Reply-To: <CAC=rjb6FMM=5nMKZJhdQkUiXHnnoNOfVvHUgCpw84feinOcwzQ@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 5418 bytes --]
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 <ianxm@jhu.edu> 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
>
[-- Attachment #2: Type: text/html, Size: 6832 bytes --]
next prev parent reply other threads:[~2020-10-05 13:25 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-05 12:35 [PATCH] ob-java ian martins
2020-10-05 13:23 ` ian martins [this message]
2020-10-09 11:15 ` ian martins
2020-10-20 18:28 ` John Herrlin
2020-10-20 19:17 ` John Herrlin
2020-10-21 2:37 ` ian martins
2020-10-21 5:59 ` John Herrlin
2020-10-21 12:47 ` ian martins
2020-10-21 13:54 ` John Herrlin
2020-10-22 12:23 ` ian martins
2020-10-22 12:56 ` John Herrlin
2020-10-24 17:05 ` Kyle Meyer
2020-10-25 2:10 ` ian martins
2020-10-25 2:40 ` Kyle Meyer
2020-10-25 19:36 ` ian martins
2020-11-05 16:29 ` Jarmo Hurri
2020-11-05 17:10 ` ian martins
2020-11-06 5:21 ` Jarmo Hurri
2020-11-06 23:00 ` ian martins
2020-11-09 14:06 ` Jarmo Hurri
2020-11-10 13:14 ` ian martins
2020-11-10 6:29 ` Jarmo Hurri
2020-11-14 11:47 ` Jarmo Hurri
2020-11-14 15:46 ` ian martins
2020-11-15 4:36 ` Jarmo Hurri
2020-11-17 12:07 ` ian martins
2020-12-14 5:55 ` Bastien
2020-11-11 7:45 ` Bastien
2020-10-24 11:58 ` Bastien
2020-10-25 0:30 ` ian martins
2020-10-28 9:13 ` Bastien
2020-10-31 11:03 ` ian martins
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAC=rjb5py_-uNBikLNZarYfTSXMxaOBeJsF8LW+C-3KX6cA5mg@mail.gmail.com' \
--to=ianxm@jhu.edu \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).