emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] How-to evaluate Java-snippets in org-mode/org-babel?


From: Eric Schulte
Subject: Re: [O] How-to evaluate Java-snippets in org-mode/org-babel?
Date: Thu, 28 Jul 2011 18:06:06 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

Torsten Wagner <address@hidden> writes:

> Hi Eric,
>
> some feedback of first testing weeks....
> It works well on my desktop machine, I tried to do the same on my
> laptop. However, I faced the problem that java did not find the files.
> I tried everything. Made sure using the same java and emacs version
> (same linux distro, same test file). Copied over .emacs config files,
> compared the versions of ob-java.el on both machines. I couldn't
> figure out why it works with one and does not work on the other
> machine.
> Somehow the classpath seems to differ buy I do not see where to change
> it in the correct way.
>
> I hacked a bit into ob-java.el file. I noticed that you call the
> generated class file by creating the string
>
> java packagename/classname
>
> whereas packagename/classname is coming from the classname variable
> set at the source-code block.
>
> In the earlier attempt we used
>
> java -cp . packagename.classname
>
> which makes sure the classpath is set to the local directory.
>
> I hacked this into your code and now it works on the laptop too (to
> say this modification works on both desktop and laptop). It might be
> worse to add, since the classpath seems to be set depending on many
> parameters (distro, other java ides, local user settings, etc.). Thus,
> many might observe problems at this point.
>
> Please find a patch attached.
>
> Even better would be to add an option to set the classpath but my
> elisp skills are to poor for that.... but would like to see how to do
> it ;)
> #+BABEL: :classpath "."
> where it might be the local directory by default?!
>

I've just pushed up a slightly different solution which involves two new
header arguments
- :cmpflag can be used to pass flags to the java compiler (e.g., "cp .")
- :cmdline can be used to pass flags to the java executable (e.g., "cp .")

So, the following could be used to get the behavior resulting from your
patch using these flags.

#+begin_src emacs-lisp
(setq org-babel-default-header-args:java '((:cmpflag "-cp .") (:cmdline "-cp 
.")))
#+end_src

This solution somehow seems more flexible in that it won't force a
classpath value on users and will allow for passing other flags to the
java runtime.

>
> Beside of that I noticed that there might be a need for a plain-text
> mode.. sounds funny, but maybe sometimes someone need auxiliary files
> which are not executed by themselves. Sure I could use simply a shell
> session and echo into a file, or tangle it,  but I guess it might be
> more elegant to have a, "only-paste-this-into-this-file-execute"
>
> #+BEGIN_SRC: plain :filename folder/folder/testdata.csv
> 1, 2
> 2, 4
> 3, 8
> #+END_SRC
> to generate /folder/folder/testdata.csv which contains the data in the
> block.
>

This is currently possible with tangling, e.g.,

#+begin_src text :tangle somewhere.txt
  This will still tangle out to a file, and it opens in text mode, which
  may be nice.  
#+end_src

Thanks for the feedback and the patch -- Eric

>
> Because sometimes, one might need to call external programs or
> programs in code-blocks are supposed to read data from files instead
> from within org-babel.
>
> In general this could be the standard feature for all unrecognised
> languages. Probably with a warning that the required
> compiler/interpreter is not configured. However, this would allow
> people at least to get the source files which they could use
> externally. The difference to tangle would be that one can decide
> block by block what to execute. E.g., I could have several of the
> above "testdata" blocks and simply executing one of them would change
> the input for later code blocks.
>
> Totti
>
>
>
>

-- 
Eric Schulte
http://cs.unm.edu/~eschulte/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]