* [babel] - Support for Groovy
@ 2010-03-19 17:46 Nathan Neff
2010-03-19 18:50 ` Dan Davison
0 siblings, 1 reply; 4+ messages in thread
From: Nathan Neff @ 2010-03-19 17:46 UTC (permalink / raw)
To: emacs-orgmode
[-- Attachment #1.1: Type: text/plain, Size: 902 bytes --]
Hello,
I'm trying to write an org-babel-groovy.el file, and have read through the
org-babel-template.el and org-babel-template.org files.
Eventually, I decided to just copy the org-babel-perl.el file to
org-babel-groovy and
replace 'perl' with 'groovy' where appropriate :-/
I'm able to get Groovy to run from an org-babel file with this code:
#+begin_src groovy :results output
println "bar";
#+end_src
However, the program doesn't run -- all I get is the "usage" output from
Groovy:
(Ex: usage: groovy <file> blah blah blah)
I suspect that this is because I don't have a major-mode for Groovy
installed.
I'd really just like for a Groovy script to be run from org-babel, and for
the output
to be inserted into an org-babel file.
Can anyone help? I have the source code here:
http://github.com/NathanNeff/org-mode/blob/nate/contrib/babel/lisp/langs/org-babel-groovy.el
Thanks,
--Nate
[-- Attachment #1.2: Type: text/html, Size: 1210 bytes --]
[-- Attachment #2: Type: text/plain, Size: 201 bytes --]
_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [babel] - Support for Groovy
2010-03-19 17:46 [babel] - Support for Groovy Nathan Neff
@ 2010-03-19 18:50 ` Dan Davison
2010-03-19 18:55 ` Eric S Fraga
0 siblings, 1 reply; 4+ messages in thread
From: Dan Davison @ 2010-03-19 18:50 UTC (permalink / raw)
To: Nathan Neff; +Cc: emacs-orgmode
Nathan Neff <nathan.neff@gmail.com> writes:
> Hello,
>
> I'm trying to write an org-babel-groovy.el file, and have read through the
> org-babel-template.el and org-babel-template.org files.
>
> Eventually, I decided to just copy the org-babel-perl.el file to
> org-babel-groovy and
> replace 'perl' with 'groovy' where appropriate :-/
>
> I'm able to get Groovy to run from an org-babel file with this code:
>
> #+begin_src groovy :results output
> println "bar";
> #+end_src
>
> However, the program doesn't run -- all I get is the "usage" output from
> Groovy:
> (Ex: usage: groovy <file> blah blah blah)
>
Hi Nate,
> I suspect that this is because I don't have a major-mode for Groovy installed.
No, that's not the problem. This should be easy to fix... we just need
to know how to get groovy to read commands from standard input. I.e. how
do we do the groovy equivalent of this:
~> echo 'print "bar\n"' | perl
bar
I haven't figured it out yet. Typically one would use a '-' to represent
stdin on the command line. My most promising attempt was this
~> echo 'println "bar";' | groovy -e -
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, script_from_command_line: 1: unexpected token: @ line 1, column 2.
1 error
'script_from_command_line' sounded good there.
These don't work
~> echo 'println "bar";' | groovy
error: neither -e or filename provided
[usage message follows]
~> echo 'println "bar";' | groovy -
error: neither -e or filename provided
[usage message follows]
So if you work out how to do that, then on line 96 of
org-babel-groovy.el
(org-babel-shell-command-on-region (point-min) (point-max) "groovy" 'current-buffer 'replace)
change "groovy" to whatever the correct shell invocation for reading
commands from stdin is. There are other solutions (e.g. writing the
commands to file, or writing a wrapper script) but it would be
preferable not to have to take those routes.
Dan
>
> I'd really just like for a Groovy script to be run from org-babel, and for the
> output
> to be inserted into an org-babel file.
>
> Can anyone help? I have the source code here:
>
> http://github.com/NathanNeff/org-mode/blob/nate/contrib/babel/lisp/langs/
> org-babel-groovy.el
>
> Thanks,
> --Nate
> _______________________________________________
> Emacs-orgmode mailing list
> Please use `Reply All' to send replies to the list.
> Emacs-orgmode@gnu.org
> http://lists.gnu.org/mailman/listinfo/emacs-orgmode
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [babel] - Support for Groovy
2010-03-19 18:50 ` Dan Davison
@ 2010-03-19 18:55 ` Eric S Fraga
2010-03-19 19:29 ` Dan Davison
0 siblings, 1 reply; 4+ messages in thread
From: Eric S Fraga @ 2010-03-19 18:55 UTC (permalink / raw)
To: Dan Davison; +Cc: emacs-orgmode
On Fri, 19 Mar 2010 14:50:09 -0400, Dan Davison <davison@stats.ox.ac.uk> wrote:
>
> Nathan Neff <nathan.neff@gmail.com> writes:
>
> > I'm trying to write an org-babel-groovy.el file, and have read through the
> > org-babel-template.el and org-babel-template.org files.
[...]
> > (Ex: usage: groovy <file> blah blah blah)
> >
>
> Hi Nate,
>
> > I suspect that this is because I don't have a major-mode for Groovy installed.
>
> No, that's not the problem. This should be easy to fix... we just need
> to know how to get groovy to read commands from standard input. I.e. how
> do we do the groovy equivalent of this:
Can you not simply put the commands into a file and then run groovy on
that given that groovy obviously expects a file (see usage above)? I
believe that's what you have done with some of the other babel
languages? It's what I did for my own very clumsy and limited maxima
and octave interfaces...
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [babel] - Support for Groovy
2010-03-19 18:55 ` Eric S Fraga
@ 2010-03-19 19:29 ` Dan Davison
0 siblings, 0 replies; 4+ messages in thread
From: Dan Davison @ 2010-03-19 19:29 UTC (permalink / raw)
To: e.fraga; +Cc: emacs-orgmode
Eric S Fraga <ucecesf@ucl.ac.uk> writes:
> On Fri, 19 Mar 2010 14:50:09 -0400, Dan Davison <davison@stats.ox.ac.uk> wrote:
>>
>> Nathan Neff <nathan.neff@gmail.com> writes:
>>
>> > I'm trying to write an org-babel-groovy.el file, and have read through the
>> > org-babel-template.el and org-babel-template.org files.
>
> [...]
>
>> > (Ex: usage: groovy <file> blah blah blah)
>> >
>>
>> Hi Nate,
>>
>> > I suspect that this is because I don't have a major-mode for Groovy installed.
>>
>> No, that's not the problem. This should be easy to fix... we just need
>> to know how to get groovy to read commands from standard input. I.e. how
>> do we do the groovy equivalent of this:
>
> Can you not simply put the commands into a file and then run groovy on
> that given that groovy obviously expects a file (see usage above)? I
> believe that's what you have done with some of the other babel
> languages? It's what I did for my own very clumsy and limited maxima
> and octave interfaces...
We could, but I had recently settled on a consistent approach using
shell-command-on-region across languages. The main thing is that this
works straightforwardly with tramp when code is executing on a remote
machine, plus we have a consistent way of dealing with stderr and
stdout. But then, isn't there something about consistency and hobgoblins
and small minds. So yes, if groovy can't take commands on stdin then
this seems to work:
(defun org-babel-groovy-evaluate (session body &optional result-type)
"Evaluate groovy code in BODY"
;; external process evaluation
(let ((infile (make-temp-file "org_babel_groovy_input_")))
(save-excursion
(with-temp-buffer
(with-temp-file infile (insert body))
;; (message "buffer=%s" (buffer-string)) ;; debugging
(shell-command (format "groovy %s" infile) (current-buffer))
(buffer-string)))))
Nate -- if you haven't then could you sign FSF copyright papers for
Emacs, so we can add your module?
Eric -- would you your maxima (and jython) code to go in org-babel? (We'd
like it)
Dan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-03-19 19:29 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-19 17:46 [babel] - Support for Groovy Nathan Neff
2010-03-19 18:50 ` Dan Davison
2010-03-19 18:55 ` Eric S Fraga
2010-03-19 19:29 ` Dan Davison
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.