emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* ob-java compile only
@ 2020-09-27 21:19 John Herrlin
  2020-09-28  1:53 ` ian martins
  0 siblings, 1 reply; 5+ messages in thread
From: John Herrlin @ 2020-09-27 21:19 UTC (permalink / raw)
  To: ian martins; +Cc: Org-Mode mailing list

[-- Attachment #1: Type: text/plain, Size: 697 bytes --]


Hey Ian!

Happy to see you as the maintainer of the ob-java!

I would like to propose a feature to ob-java. The feature allows a
source code block to write and compile only, without executing.

Here is a common use case for me.

Class without a entry point have an :compile-only header.

   #+HEADER: :classname se/my_test_package/Hey
   #+HEADER: :dir src
   #+HEADER: :compile-only t
   #+HEADER: :results none
   #+BEGIN_SRC java
     package se.my_test_package;

     public class Hey {
         public static String hey(String name) {
             return "Hey " + name;
         }
     }
   #+END_SRC

The provided diff works for my small use case. What do you think?

--
Best regards
John


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ob-java-compile-only-header.diff --]
[-- Type: text/x-patch, Size: 2145 bytes --]

diff --git a/lisp/ob-java.el b/lisp/ob-java.el
index fee695bb9..5c98a0417 100644
--- a/lisp/ob-java.el
+++ b/lisp/ob-java.el
@@ -60,6 +60,7 @@ parameters may be used, like javac -verbose"
 	 (cmpflag (or (cdr (assq :cmpflag params)) ""))
 	 (cmdline (or (cdr (assq :cmdline params)) ""))
 	 (cmdargs (or (cdr (assq :cmdargs params)) ""))
+	 (compile-only (assq :compile-only params))
 	 (full-body (org-babel-expand-body:generic body params)))
     ;; created package-name directories if missing
     (unless (or (not packagename) (file-exists-p packagename))
@@ -67,18 +68,19 @@ parameters may be used, like javac -verbose"
     (with-temp-file src-file (insert full-body))
     (org-babel-eval
      (concat org-babel-java-compiler " " cmpflag " " src-file) "")
-    (let ((results (org-babel-eval (concat org-babel-java-command
-                                           " " cmdline " " classname " " cmdargs) "")))
-      (org-babel-reassemble-table
-       (org-babel-result-cond (cdr (assq :result-params params))
-	 (org-babel-read results t)
-         (let ((tmp-file (org-babel-temp-file "c-")))
-           (with-temp-file tmp-file (insert results))
-           (org-babel-import-elisp-from-file tmp-file)))
-       (org-babel-pick-name
-        (cdr (assq :colname-names params)) (cdr (assq :colnames params)))
-       (org-babel-pick-name
-        (cdr (assq :rowname-names params)) (cdr (assq :rownames params)))))))
+    (unless compile-only
+      (let ((results (org-babel-eval (concat org-babel-java-command
+                                             " " cmdline " " classname " " cmdargs) "")))
+	(org-babel-reassemble-table
+	 (org-babel-result-cond (cdr (assq :result-params params))
+	   (org-babel-read results t)
+           (let ((tmp-file (org-babel-temp-file "c-")))
+             (with-temp-file tmp-file (insert results))
+             (org-babel-import-elisp-from-file tmp-file)))
+	 (org-babel-pick-name
+          (cdr (assq :colname-names params)) (cdr (assq :colnames params)))
+	 (org-babel-pick-name
+          (cdr (assq :rowname-names params)) (cdr (assq :rownames params))))))))
 
 (provide 'ob-java)
 

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: ob-java compile only
  2020-09-27 21:19 ob-java compile only John Herrlin
@ 2020-09-28  1:53 ` ian martins
  2020-09-28  8:11   ` John Herrlin
  0 siblings, 1 reply; 5+ messages in thread
From: ian martins @ 2020-09-28  1:53 UTC (permalink / raw)
  To: John Herrlin; +Cc: Org-Mode mailing list

[-- Attachment #1: Type: text/plain, Size: 1779 bytes --]

Hi John,

Thanks for the suggestion and patch. Is the reason for this so that you can
have classes without needing dummy "main" methods?

Did you consider using org-babel-tangle to generate the source files? This
works for me:

Steps:
1. put javatangle.org (below) on your local.
2. create "pkg" directory where javatangle.org is
3. run org-babel-tangle on javatangle.org (this writes two source files to
the pkg dir)
4. run C-c C-c on the top source block (this compiles both source files and
runs main)

----- javatangle.org -----

#+begin_src java :results output :classname pkg/Main :tangle pkg/Main.java
  package pkg;

  public class Main {
      public static void main(String[] args) {
          System.out.println(Hey.hey());
      }
  }
#+end_src

#+begin_src java :results output :classname pkg/Hey :tangle pkg/Hey.java
  package pkg;

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



On Sun, Sep 27, 2020 at 5:19 PM John Herrlin <jherrlin@gmail.com> wrote:

>
> Hey Ian!
>
> Happy to see you as the maintainer of the ob-java!
>
> I would like to propose a feature to ob-java. The feature allows a
> source code block to write and compile only, without executing.
>
> Here is a common use case for me.
>
> Class without a entry point have an :compile-only header.
>
>    #+HEADER: :classname se/my_test_package/Hey
>    #+HEADER: :dir src
>    #+HEADER: :compile-only t
>    #+HEADER: :results none
>    #+BEGIN_SRC java
>      package se.my_test_package;
>
>      public class Hey {
>          public static String hey(String name) {
>              return "Hey " + name;
>          }
>      }
>    #+END_SRC
>
> The provided diff works for my small use case. What do you think?
>
> --
> Best regards
> John
>
>

[-- Attachment #2: Type: text/html, Size: 2711 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ob-java compile only
  2020-09-28  1:53 ` ian martins
@ 2020-09-28  8:11   ` John Herrlin
  2020-09-29  2:18     ` ian martins
  0 siblings, 1 reply; 5+ messages in thread
From: John Herrlin @ 2020-09-28  8:11 UTC (permalink / raw)
  To: ian martins; +Cc: Org-Mode mailing list


Hey Ian,

Thank you for the quick feedback!

That workflow seems to work perfectly if it's Java all the way. Then it
compiles all the related files. I am mostly working with the classes
from Clojure.

Here is an example:

   #+HEADER: :classname se/my_test_package/Hey
   #+HEADER: :compile-only t
   #+HEADER: :results none
   #+HEADER: :dir src
   #+BEGIN_SRC java
     package se.my_test_package;

     public class Hey {
         public static String hey(String name) {
             return "Hey " + name;
         }
     }
   #+END_SRC

   #+BEGIN_SRC clojure :results output code
     (import [se.my_test_package Hey])

     (Hey/hey "John")
   #+END_SRC


Best regards



ian martins <ianxm@jhu.edu> writes:

> Hi John,
>
> Thanks for the suggestion and patch. Is the reason for this so that you can
> have classes without needing dummy "main" methods?
>
> Did you consider using org-babel-tangle to generate the source files? This
> works for me:
>
> Steps:
> 1. put javatangle.org (below) on your local.
> 2. create "pkg" directory where javatangle.org is
> 3. run org-babel-tangle on javatangle.org (this writes two source files to
> the pkg dir)
> 4. run C-c C-c on the top source block (this compiles both source files and
> runs main)
>
> ----- javatangle.org -----
>
> #+begin_src java :results output :classname pkg/Main :tangle pkg/Main.java
>   package pkg;
>
>   public class Main {
>       public static void main(String[] args) {
>           System.out.println(Hey.hey());
>       }
>   }
> #+end_src
>
> #+begin_src java :results output :classname pkg/Hey :tangle pkg/Hey.java
>   package pkg;
>
>   public class Hey {
>       public static String hey() {
>           return "hey";
>       }
>   }
> #+end_src
>
>
>
> On Sun, Sep 27, 2020 at 5:19 PM John Herrlin <jherrlin@gmail.com> wrote:
>
>>
>> Hey Ian!
>>
>> Happy to see you as the maintainer of the ob-java!
>>
>> I would like to propose a feature to ob-java. The feature allows a
>> source code block to write and compile only, without executing.
>>
>> Here is a common use case for me.
>>
>> Class without a entry point have an :compile-only header.
>>
>>    #+HEADER: :classname se/my_test_package/Hey
>>    #+HEADER: :dir src
>>    #+HEADER: :compile-only t
>>    #+HEADER: :results none
>>    #+BEGIN_SRC java
>>      package se.my_test_package;
>>
>>      public class Hey {
>>          public static String hey(String name) {
>>              return "Hey " + name;
>>          }
>>      }
>>    #+END_SRC
>>
>> The provided diff works for my small use case. What do you think?
>>
>> --
>> Best regards
>> John
>>
>>


--
Mvh John


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ob-java compile only
  2020-09-28  8:11   ` John Herrlin
@ 2020-09-29  2:18     ` ian martins
  2020-09-29 19:22       ` John Herrlin
  0 siblings, 1 reply; 5+ messages in thread
From: ian martins @ 2020-09-29  2:18 UTC (permalink / raw)
  To: John Herrlin; +Cc: Org-Mode mailing list

[-- Attachment #1: Type: text/plain, Size: 3954 bytes --]

Thanks for explaining. That makes sense.

I'm hesitant to add the compile-only header for a couple reasons. Generally
C-c C-c on a source block means "run this" but with compile-only it'll mean
"run this but don't run it." It's semantically inconsistent. Also I want to
bring more feature parity to ob-java, so that there's more consistency
across babel. I'm reluctant to add headers not found elsewhere.

Consider some alternatives:
1. one option is to add a dummy main to every class. it could do nothing or
run unit tests. it's not a bad place to kick off unit tests, but I don't
think you should have to.
2. you could use org-babel-tangle to write out the source files, and
compile from an emacs compile buffer. this might be more convenient than
compiling from babel since recompiles are a single keystroke.
3. a future version of ob-java will know if a class has a "public static
void main." at that point it'll be easy to automatically skip execution of
the class if it doesn't define a main, without the need for a new header.

On Mon, Sep 28, 2020 at 4:11 AM John Herrlin <jherrlin@gmail.com> wrote:

>
> Hey Ian,
>
> Thank you for the quick feedback!
>
> That workflow seems to work perfectly if it's Java all the way. Then it
> compiles all the related files. I am mostly working with the classes
> from Clojure.
>
> Here is an example:
>
>    #+HEADER: :classname se/my_test_package/Hey
>    #+HEADER: :compile-only t
>    #+HEADER: :results none
>    #+HEADER: :dir src
>    #+BEGIN_SRC java
>      package se.my_test_package;
>
>      public class Hey {
>          public static String hey(String name) {
>              return "Hey " + name;
>          }
>      }
>    #+END_SRC
>
>    #+BEGIN_SRC clojure :results output code
>      (import [se.my_test_package Hey])
>
>      (Hey/hey "John")
>    #+END_SRC
>
>
> Best regards
>
>
>
> ian martins <ianxm@jhu.edu> writes:
>
> > Hi John,
> >
> > Thanks for the suggestion and patch. Is the reason for this so that you
> can
> > have classes without needing dummy "main" methods?
> >
> > Did you consider using org-babel-tangle to generate the source files?
> This
> > works for me:
> >
> > Steps:
> > 1. put javatangle.org (below) on your local.
> > 2. create "pkg" directory where javatangle.org is
> > 3. run org-babel-tangle on javatangle.org (this writes two source files
> to
> > the pkg dir)
> > 4. run C-c C-c on the top source block (this compiles both source files
> and
> > runs main)
> >
> > ----- javatangle.org -----
> >
> > #+begin_src java :results output :classname pkg/Main :tangle
> pkg/Main.java
> >   package pkg;
> >
> >   public class Main {
> >       public static void main(String[] args) {
> >           System.out.println(Hey.hey());
> >       }
> >   }
> > #+end_src
> >
> > #+begin_src java :results output :classname pkg/Hey :tangle pkg/Hey.java
> >   package pkg;
> >
> >   public class Hey {
> >       public static String hey() {
> >           return "hey";
> >       }
> >   }
> > #+end_src
> >
> >
> >
> > On Sun, Sep 27, 2020 at 5:19 PM John Herrlin <jherrlin@gmail.com> wrote:
> >
> >>
> >> Hey Ian!
> >>
> >> Happy to see you as the maintainer of the ob-java!
> >>
> >> I would like to propose a feature to ob-java. The feature allows a
> >> source code block to write and compile only, without executing.
> >>
> >> Here is a common use case for me.
> >>
> >> Class without a entry point have an :compile-only header.
> >>
> >>    #+HEADER: :classname se/my_test_package/Hey
> >>    #+HEADER: :dir src
> >>    #+HEADER: :compile-only t
> >>    #+HEADER: :results none
> >>    #+BEGIN_SRC java
> >>      package se.my_test_package;
> >>
> >>      public class Hey {
> >>          public static String hey(String name) {
> >>              return "Hey " + name;
> >>          }
> >>      }
> >>    #+END_SRC
> >>
> >> The provided diff works for my small use case. What do you think?
> >>
> >> --
> >> Best regards
> >> John
> >>
> >>
>
>
> --
> Mvh John
>

[-- Attachment #2: Type: text/html, Size: 5667 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: ob-java compile only
  2020-09-29  2:18     ` ian martins
@ 2020-09-29 19:22       ` John Herrlin
  0 siblings, 0 replies; 5+ messages in thread
From: John Herrlin @ 2020-09-29 19:22 UTC (permalink / raw)
  To: ian martins; +Cc: Org-Mode mailing list


ian martins <ianxm@jhu.edu> writes:

> Thanks for explaining. That makes sense.
>
> I'm hesitant to add the compile-only header for a couple reasons. Generally
> C-c C-c on a source block means "run this" but with compile-only it'll mean
> "run this but don't run it." It's semantically inconsistent. Also I want to
> bring more feature parity to ob-java, so that there's more consistency
> across babel. I'm reluctant to add headers not found elsewhere.

Thank you for the feedback, I am all with you on that and I think
consistency is very important!

>
> Consider some alternatives:
> 1. one option is to add a dummy main to every class. it could do nothing or
> run unit tests. it's not a bad place to kick off unit tests, but I don't
> think you should have to.
> 2. you could use org-babel-tangle to write out the source files, and
> compile from an emacs compile buffer. this might be more convenient than
> compiling from babel since recompiles are a single keystroke.
> 3. a future version of ob-java will know if a class has a "public static
> void main." at that point it'll be easy to automatically skip execution of
> the class if it doesn't define a main, without the need for a new
> header.

The alternatives are nice and I will manage fine!

Looking forward to see what will happen to ob-java!

:)

>
> On Mon, Sep 28, 2020 at 4:11 AM John Herrlin <jherrlin@gmail.com> wrote:
>
>>
>> Hey Ian,
>>
>> Thank you for the quick feedback!
>>
>> That workflow seems to work perfectly if it's Java all the way. Then it
>> compiles all the related files. I am mostly working with the classes
>> from Clojure.
>>
>> Here is an example:
>>
>>    #+HEADER: :classname se/my_test_package/Hey
>>    #+HEADER: :compile-only t
>>    #+HEADER: :results none
>>    #+HEADER: :dir src
>>    #+BEGIN_SRC java
>>      package se.my_test_package;
>>
>>      public class Hey {
>>          public static String hey(String name) {
>>              return "Hey " + name;
>>          }
>>      }
>>    #+END_SRC
>>
>>    #+BEGIN_SRC clojure :results output code
>>      (import [se.my_test_package Hey])
>>
>>      (Hey/hey "John")
>>    #+END_SRC
>>
>>
>> Best regards
>>
>>
>>
>> ian martins <ianxm@jhu.edu> writes:
>>
>> > Hi John,
>> >
>> > Thanks for the suggestion and patch. Is the reason for this so that you
>> can
>> > have classes without needing dummy "main" methods?
>> >
>> > Did you consider using org-babel-tangle to generate the source files?
>> This
>> > works for me:
>> >
>> > Steps:
>> > 1. put javatangle.org (below) on your local.
>> > 2. create "pkg" directory where javatangle.org is
>> > 3. run org-babel-tangle on javatangle.org (this writes two source files
>> to
>> > the pkg dir)
>> > 4. run C-c C-c on the top source block (this compiles both source files
>> and
>> > runs main)
>> >
>> > ----- javatangle.org -----
>> >
>> > #+begin_src java :results output :classname pkg/Main :tangle
>> pkg/Main.java
>> >   package pkg;
>> >
>> >   public class Main {
>> >       public static void main(String[] args) {
>> >           System.out.println(Hey.hey());
>> >       }
>> >   }
>> > #+end_src
>> >
>> > #+begin_src java :results output :classname pkg/Hey :tangle pkg/Hey.java
>> >   package pkg;
>> >
>> >   public class Hey {
>> >       public static String hey() {
>> >           return "hey";
>> >       }
>> >   }
>> > #+end_src
>> >
>> >
>> >
>> > On Sun, Sep 27, 2020 at 5:19 PM John Herrlin <jherrlin@gmail.com> wrote:
>> >
>> >>
>> >> Hey Ian!
>> >>
>> >> Happy to see you as the maintainer of the ob-java!
>> >>
>> >> I would like to propose a feature to ob-java. The feature allows a
>> >> source code block to write and compile only, without executing.
>> >>
>> >> Here is a common use case for me.
>> >>
>> >> Class without a entry point have an :compile-only header.
>> >>
>> >>    #+HEADER: :classname se/my_test_package/Hey
>> >>    #+HEADER: :dir src
>> >>    #+HEADER: :compile-only t
>> >>    #+HEADER: :results none
>> >>    #+BEGIN_SRC java
>> >>      package se.my_test_package;
>> >>
>> >>      public class Hey {
>> >>          public static String hey(String name) {
>> >>              return "Hey " + name;
>> >>          }
>> >>      }
>> >>    #+END_SRC
>> >>
>> >> The provided diff works for my small use case. What do you think?
>> >>
>> >> --
>> >> Best regards
>> >> John
>> >>
>> >>
>>
>>
>> --
>> Mvh John
>>


--
Mvh John


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-09-29 19:46 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-27 21:19 ob-java compile only John Herrlin
2020-09-28  1:53 ` ian martins
2020-09-28  8:11   ` John Herrlin
2020-09-29  2:18     ` ian martins
2020-09-29 19:22       ` John Herrlin

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).