emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Batch mode evaluation of source code?
@ 2011-06-17 21:14 Herbert Sitz
  2011-06-17 21:47 ` Eric Schulte
  0 siblings, 1 reply; 9+ messages in thread
From: Herbert Sitz @ 2011-06-17 21:14 UTC (permalink / raw)
  To: emacs-orgmode

The Org manual gives an example of a batch mode --eval that runs code to tangle
code from Org files.  I assume there's also a way to simply run a source code
block and get its output in the terminal but I can't see how to do it.

To give a concrete example, the Org manual uses this Python source block as
example illustrating the difference between :session and non-session results
output.  How would I evaluate it from the command line and get the results
output back in the terminal?:

-------------------------
#+begin_src python  :results output
print "hello"
2
print "bye"
#+end_src
------------------------

-- Herb

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

* Re: Batch mode evaluation of source code?
  2011-06-17 21:14 Batch mode evaluation of source code? Herbert Sitz
@ 2011-06-17 21:47 ` Eric Schulte
  2011-06-17 22:45   ` Herbert Sitz
  0 siblings, 1 reply; 9+ messages in thread
From: Eric Schulte @ 2011-06-17 21:47 UTC (permalink / raw)
  To: Herbert Sitz; +Cc: emacs-orgmode

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

Hi Herb,

The following org-mode file and minimal elisp file can be used to print
the results of evaluating a code block from a batch Emacs session (note
this is using Emacs24, so Org-mode/Babel do not need to be explicitly
loaded).

I used the following command line
: emacs --batch -l run-code.el 2> /dev/null

And the following two files.

[-- Attachment #2: run-code.el --]
[-- Type: application/emacs-lisp, Size: 242 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: short-code.org --]
[-- Type: text/x-org, Size: 134 bytes --]

#+Title: short code buffer

#+begin_src python :results output
  print "hello"
  2
  print "bye"
#+end_src

#+results:
: hello
: bye


[-- Attachment #4: Type: text/plain, Size: 767 bytes --]


Cheers -- Eric

Herbert Sitz <hsitz@nwlink.com> writes:

> The Org manual gives an example of a batch mode --eval that runs code to tangle
> code from Org files.  I assume there's also a way to simply run a source code
> block and get its output in the terminal but I can't see how to do it.
>
> To give a concrete example, the Org manual uses this Python source block as
> example illustrating the difference between :session and non-session results
> output.  How would I evaluate it from the command line and get the results
> output back in the terminal?:
>
> -------------------------
> #+begin_src python  :results output
> print "hello"
> 2
> print "bye"
> #+end_src
> ------------------------
>
> -- Herb
>
>
>

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

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

* Re: Batch mode evaluation of source code?
  2011-06-17 21:47 ` Eric Schulte
@ 2011-06-17 22:45   ` Herbert Sitz
  2011-06-17 22:55     ` Herbert Sitz
                       ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Herbert Sitz @ 2011-06-17 22:45 UTC (permalink / raw)
  To: emacs-orgmode

Eric Schulte <schulte.eric <at> gmail.com> writes:

>  
> The following org-mode file and minimal elisp file can be used 
> to print
> the results of evaluating a code block from a batch Emacs 
> session 
> (note
> this is using Emacs24, so Org-mode/Babel do not need to be 
> explicitly
> loaded).
> 
> I used the following command line
> : emacs --batch -l run-code.el 2> /dev/null
> 

Eric -- Thanks, very cool.  I'm toying around with this approach to do dynamic
code-block evaluation in the Org-mode clone I'm making in Vim. No problem with
on-export-evaluation, since the vim-org-clone just saves the file and issues a
batch mode org-export or org-publish command to emacs, which takes over from
there.

I think this dynamic evaluation could be useful, but it also seems like a new
server is getting called for each emacs --batch mode call.  That's cumbersome
for this dynamic-evaluation stuff because of start-up overhead for emacs on 
each call.  Is that the way its supposed to work?  

I'm working on Windows7 and have an Emacs client running when I issue the 
batch command, which I assumed also means there is a running emacs server.  
Is the
call getting made to the running emacs server?  If so, is there some way to
avoid the startup overhead (which seems to come from 'Adding c:/program files
(x86)/emacs/EmacsW32/lisp/ to load path.').  Or, if my batch call is _not_
making use of the running Emacs server is there some way to get it to use that
server?

Thanks again,

Herb

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

* Re: Batch mode evaluation of source code?
  2011-06-17 22:45   ` Herbert Sitz
@ 2011-06-17 22:55     ` Herbert Sitz
  2011-06-17 23:02       ` Nick Dokos
  2011-06-17 23:05     ` Eric Schulte
  2011-06-18  7:32     ` Achim Gratz
  2 siblings, 1 reply; 9+ messages in thread
From: Herbert Sitz @ 2011-06-17 22:55 UTC (permalink / raw)
  To: emacs-orgmode

Herbert Sitz <hsitz <at> nwlink.com> writes:

> I'm working on Windows7 and have an Emacs client running when I issue the 
> batch command, which I assumed also means there is a running emacs server.  
> Is the
> call getting made to the running emacs server?  If so, is there some way to
> avoid the startup overhead (which seems to come from 'Adding c:/program files
> (x86)/emacs/EmacsW32/lisp/ to load path.').  Or, if my batch call is _not_
> making use of the running Emacs server is there some way to get it to use that
> server?
> 
> Herb
> 

I can confirm that a new emacs process is getting created to run each batch mode
command.  I don't really understand the emacs-client/emacs-server setup is
supposed to work.  So I guess my question is whether my batch-mode command can
be made as a client of the existing emacs-server.  I'm guessing the answer is
'No', but if so maybe there's some other way to speed up creation of the new
emacs process when it's used solely to process an Org source-code-block?  

-- Herb

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

* Re: Batch mode evaluation of source code?
  2011-06-17 22:55     ` Herbert Sitz
@ 2011-06-17 23:02       ` Nick Dokos
  2011-06-17 23:10         ` Herbert Sitz
  0 siblings, 1 reply; 9+ messages in thread
From: Nick Dokos @ 2011-06-17 23:02 UTC (permalink / raw)
  To: Herbert Sitz; +Cc: nicholas.dokos, emacs-orgmode

Herbert Sitz <hsitz@nwlink.com> wrote:

> Herbert Sitz <hsitz <at> nwlink.com> writes:
> 
> > I'm working on Windows7 and have an Emacs client running when I issue the 
> > batch command, which I assumed also means there is a running emacs server.  
> > Is the
> > call getting made to the running emacs server?  If so, is there some way to
> > avoid the startup overhead (which seems to come from 'Adding c:/program files
> > (x86)/emacs/EmacsW32/lisp/ to load path.').  Or, if my batch call is _not_
> > making use of the running Emacs server is there some way to get it to use that
> > server?
> > 
> > Herb
> > 
> 
> I can confirm that a new emacs process is getting created to run each batch mode
> command.  I don't really understand the emacs-client/emacs-server setup is
> supposed to work.  So I guess my question is whether my batch-mode command can
> be made as a client of the existing emacs-server.  I'm guessing the answer is
> 'No', but if so maybe there's some other way to speed up creation of the new
> emacs process when it's used solely to process an Org source-code-block?  
> 

You do M-x server-start on the running emacs to start the server
part. Then you invoke emacsclient from the command line to connect to
it - check the manpage of emacsclient for details: you might be able to
arrange something with the --eval argument.

Nick

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

* Re: Batch mode evaluation of source code?
  2011-06-17 22:45   ` Herbert Sitz
  2011-06-17 22:55     ` Herbert Sitz
@ 2011-06-17 23:05     ` Eric Schulte
  2011-06-18  0:17       ` Herbert Sitz
  2011-06-18  7:32     ` Achim Gratz
  2 siblings, 1 reply; 9+ messages in thread
From: Eric Schulte @ 2011-06-17 23:05 UTC (permalink / raw)
  To: Herbert Sitz; +Cc: emacs-orgmode

Herbert Sitz <hsitz@nwlink.com> writes:

> Eric Schulte <schulte.eric <at> gmail.com> writes:
>
>>  
>> The following org-mode file and minimal elisp file can be used 
>> to print
>> the results of evaluating a code block from a batch Emacs 
>> session 
>> (note
>> this is using Emacs24, so Org-mode/Babel do not need to be 
>> explicitly
>> loaded).
>> 
>> I used the following command line
>> : emacs --batch -l run-code.el 2> /dev/null
>> 
>
> Eric -- Thanks, very cool.  I'm toying around with this approach to do dynamic
> code-block evaluation in the Org-mode clone I'm making in Vim. No problem with
> on-export-evaluation, since the vim-org-clone just saves the file and issues a
> batch mode org-export or org-publish command to emacs, which takes over from
> there.
>
> I think this dynamic evaluation could be useful, but it also seems like a new
> server is getting called for each emacs --batch mode call.  That's cumbersome
> for this dynamic-evaluation stuff because of start-up overhead for emacs on 
> each call.  Is that the way its supposed to work?  
>
> I'm working on Windows7 and have an Emacs client running when I issue
> the batch command, which I assumed also means there is a running emacs
> server.  Is the call getting made to the running emacs server?  If so,
> is there some way to avoid the startup overhead (which seems to come
> from 'Adding c:/program files (x86)/emacs/EmacsW32/lisp/ to load
> path.').  Or, if my batch call is _not_ making use of the running
> Emacs server is there some way to get it to use that server?
>
> Thanks again,
>

The example I attached using "--batch" *does* startup a new Emacs
instance on every execution.  You should be able to replace the "emacs"
command with "emacsclient" (or some windows equivalent) command to
connect to a running server, rather than having to create a new
connection on every evaluation.

By connecting to a persistent Emacs instance much of the .el script I
attached could be removed assuming Babel has already been configured in
the running Emacs server.

Hope this helps -- Eric

>
> Herb
>
>
>

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

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

* Re: Batch mode evaluation of source code?
  2011-06-17 23:02       ` Nick Dokos
@ 2011-06-17 23:10         ` Herbert Sitz
  0 siblings, 0 replies; 9+ messages in thread
From: Herbert Sitz @ 2011-06-17 23:10 UTC (permalink / raw)
  To: emacs-orgmode

Nick Dokos <nicholas.dokos <at> hp.com> writes:

> > 
> You do M-x server-start on the running emacs to start the server
> part. Then you invoke emacsclient from the command line to connect to
> it - check the manpage of emacsclient for details: you might be able to
> arrange something with the --eval argument.
> 
> Nick
> 
> 

Nick -- Thanks, also found a previous newsgroup post on same subject here:

http://www.mail-archive.com/emacs-orgmode@gnu.org/msg19489.html

I'll toy around and see what I can get working.  Seems like if I can
get the quoting in Windows shell for the eval segment then I should
be able to get result I want. . . 

-- Herb

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

* Re: Batch mode evaluation of source code?
  2011-06-17 23:05     ` Eric Schulte
@ 2011-06-18  0:17       ` Herbert Sitz
  0 siblings, 0 replies; 9+ messages in thread
From: Herbert Sitz @ 2011-06-18  0:17 UTC (permalink / raw)
  To: emacs-orgmode

Eric Schulte <schulte.eric <at> gmail.com> writes:
> 
> By connecting to a persistent Emacs instance much of the .el script I
> attached could be removed assuming Babel has already been configured in
> the running Emacs server.
> 
> Hope this helps -- Eric
> 

Eric, Nick:

Thanks, yes it does.  Using also Nick's tip about using --eval (batch doesn't
seem to work when calling a client process) I've got things working at least
part of the way.

I can do the following command in the terminal:

>  "c:\program files (x86)\emacs\emacs\bin\emacsclientw.exe" --eval ^"(progn (let
((org-confirm-babel-evaluate nil)) (find-file \^"short-code.org\^")
(org-babel-next-src-block) (print (org-babel-execute-src-block))))

This gets processed properly by the running client, but print command output
goes into the *message* buffer rather than to the terminal used to enter the
command.

Any tips on how to redirect the output to my terminal?  If not, saving to a file
is a decent alternative (though I don't know how to do that either, lol).

-- Herb

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

* Re: Batch mode evaluation of source code?
  2011-06-17 22:45   ` Herbert Sitz
  2011-06-17 22:55     ` Herbert Sitz
  2011-06-17 23:05     ` Eric Schulte
@ 2011-06-18  7:32     ` Achim Gratz
  2 siblings, 0 replies; 9+ messages in thread
From: Achim Gratz @ 2011-06-18  7:32 UTC (permalink / raw)
  To: emacs-orgmode

Herbert Sitz <hsitz@nwlink.com> writes:
> I'm working on Windows7 and have an Emacs client running when I issue the 
> batch command, which I assumed also means there is a running emacs server.  

You need to always call emacsclient, not emacs.  As server you can
either have a running Emacs which has started a server (manually or via
invocation on the command line) or an Emacs that has been started
headless in daemon mode.  A little used (but very nice) feature of
emacsclient is the alternate editor argument: if you set that to the
empty string, it will start an Emacs in daemon mode if it didn't find an
already running server and then connect to it.


Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Waldorf MIDI Implementation & additional documentation:
http://Synth.Stromeko.net/Downloads.html#WaldorfDocs

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

end of thread, other threads:[~2011-06-18  7:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-17 21:14 Batch mode evaluation of source code? Herbert Sitz
2011-06-17 21:47 ` Eric Schulte
2011-06-17 22:45   ` Herbert Sitz
2011-06-17 22:55     ` Herbert Sitz
2011-06-17 23:02       ` Nick Dokos
2011-06-17 23:10         ` Herbert Sitz
2011-06-17 23:05     ` Eric Schulte
2011-06-18  0:17       ` Herbert Sitz
2011-06-18  7:32     ` Achim Gratz

Code repositories for project(s) associated with this 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).