all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Batch execution and --script
@ 2012-08-29 15:47 Marcelo de Moraes Serpa
  2012-08-29 16:42 ` Nick Daly
  0 siblings, 1 reply; 10+ messages in thread
From: Marcelo de Moraes Serpa @ 2012-08-29 15:47 UTC (permalink / raw)
  To: Org Mode

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

Hey guys,

Regarding this: http://orgmode.org/manual/Batch-execution.html

I also had success using --script, as in:

#!/Applications/Emacs.app/Contents/MacOS/Emacs --script

In the top of a .el file. You can then chmod it to be executable and run it.

Just thought I'd share, as an alternative, but I'm not sure if there are
any subtle differences, though.

Cheers,

- Marcelo.

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

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

* Re: Batch execution and --script
  2012-08-29 15:47 Batch execution and --script Marcelo de Moraes Serpa
@ 2012-08-29 16:42 ` Nick Daly
  2012-08-29 17:50   ` Marcelo de Moraes Serpa
  2012-08-29 18:29   ` Nick Dokos
  0 siblings, 2 replies; 10+ messages in thread
From: Nick Daly @ 2012-08-29 16:42 UTC (permalink / raw)
  To: Marcelo de Moraes Serpa; +Cc: Org Mode

On Wed, Aug 29, 2012 at 10:47 AM, Marcelo de Moraes Serpa
<celoserpa@gmail.com> wrote:
> Hey guys,
>
> Regarding this: http://orgmode.org/manual/Batch-execution.html
>
> I also had success using --script, as in:
>
> #!/Applications/Emacs.app/Contents/MacOS/Emacs --script
>
> In the top of a .el file. You can then chmod it to be executable and run it.

Would you mind sharing a simple .el file you'd use that way?  The
site's example is a bash script, and I wonder how much cleaner a .el
file would be.

Nick

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

* Re: Batch execution and --script
  2012-08-29 16:42 ` Nick Daly
@ 2012-08-29 17:50   ` Marcelo de Moraes Serpa
  2012-08-30  5:34     ` Bastien
  2012-08-29 18:29   ` Nick Dokos
  1 sibling, 1 reply; 10+ messages in thread
From: Marcelo de Moraes Serpa @ 2012-08-29 17:50 UTC (permalink / raw)
  To: Nick Daly; +Cc: Org Mode

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

Sure!

Bear in mind I'm not an elisp expert, and I got it working after a lot of
trial and error. I'm using this script as part of a quickblogging engine
I'm writing for org (still testing, will share once it works as expected)
so that I can blog from directly from my journal org file to a jekyll blog.

I also created a new function based off org-export-generic called
org-export-generic-markdown which can be called in a non-interactive way,
so that it could work from the script.

The script basically exports a specific org file to markdown (in the same
dir the org file is located). Now I want to make it accept command-line
arguments. I will check it out tonight.

Here it goes:

http://pastie.org/4611632

This is pretty powerful, as you can also return data from the script by
using princ. I can imagine millions of ways this could be used to integrate
org with other apps/languages.

- Marcelo.


On Wed, Aug 29, 2012 at 11:42 AM, Nick Daly <nick.m.daly@gmail.com> wrote:

> On Wed, Aug 29, 2012 at 10:47 AM, Marcelo de Moraes Serpa
> <celoserpa@gmail.com> wrote:
> > Hey guys,
> >
> > Regarding this: http://orgmode.org/manual/Batch-execution.html
> >
> > I also had success using --script, as in:
> >
> > #!/Applications/Emacs.app/Contents/MacOS/Emacs --script
> >
> > In the top of a .el file. You can then chmod it to be executable and run
> it.
>
> Would you mind sharing a simple .el file you'd use that way?  The
> site's example is a bash script, and I wonder how much cleaner a .el
> file would be.
>
> Nick
>

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

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

* Re: Batch execution and --script
  2012-08-29 16:42 ` Nick Daly
  2012-08-29 17:50   ` Marcelo de Moraes Serpa
@ 2012-08-29 18:29   ` Nick Dokos
  2012-08-29 18:35     ` Marcelo de Moraes Serpa
  1 sibling, 1 reply; 10+ messages in thread
From: Nick Dokos @ 2012-08-29 18:29 UTC (permalink / raw)
  To: Nick Daly; +Cc: Org Mode, Marcelo de Moraes Serpa

Nick Daly <nick.m.daly@gmail.com> wrote:

> On Wed, Aug 29, 2012 at 10:47 AM, Marcelo de Moraes Serpa
> <celoserpa@gmail.com> wrote:
> > Hey guys,
> >
> > Regarding this: http://orgmode.org/manual/Batch-execution.html
> >
> > I also had success using --script, as in:
> >
> > #!/Applications/Emacs.app/Contents/MacOS/Emacs --script
> >
> > In the top of a .el file. You can then chmod it to be executable and run it.
> 
> Would you mind sharing a simple .el file you'd use that way?  The
> site's example is a bash script, and I wonder how much cleaner a .el
> file would be.
> 

Marcelo posted a larger example, but maybe a very small example might be
helpful. Put the following in some file (I called it hello.el but the
name does not really matter):

--8<---------------cut here---------------start------------->8---
#! /usr/local/bin/emacs --script

(message "Hello World!")
--8<---------------cut here---------------end--------------->8---

Make it executable:

  chmod +x hello.el

and run it:

  ./hello.el

Nick

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

* Re: Batch execution and --script
  2012-08-29 18:29   ` Nick Dokos
@ 2012-08-29 18:35     ` Marcelo de Moraes Serpa
  2012-08-29 18:59       ` Thorsten Jolitz
  2012-08-29 19:13       ` Nick Dokos
  0 siblings, 2 replies; 10+ messages in thread
From: Marcelo de Moraes Serpa @ 2012-08-29 18:35 UTC (permalink / raw)
  To: nicholas.dokos; +Cc: Org Mode, Nick Daly

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

Hi Nick,

Thanks for turning it into a concise example :)

Is that somewhere in the manual or Worg? Perhaps it should be added. I
never contributed to Worg, I will look into how tonight.

This is a subject that should be explored more. I see a lot of potential in
having CLI .el scripts (i.e taking the emacs GUI out of the equation).

- Marcelo.


On Wed, Aug 29, 2012 at 1:29 PM, Nick Dokos <nicholas.dokos@hp.com> wrote:

> Nick Daly <nick.m.daly@gmail.com> wrote:
>
> > On Wed, Aug 29, 2012 at 10:47 AM, Marcelo de Moraes Serpa
> > <celoserpa@gmail.com> wrote:
> > > Hey guys,
> > >
> > > Regarding this: http://orgmode.org/manual/Batch-execution.html
> > >
> > > I also had success using --script, as in:
> > >
> > > #!/Applications/Emacs.app/Contents/MacOS/Emacs --script
> > >
> > > In the top of a .el file. You can then chmod it to be executable and
> run it.
> >
> > Would you mind sharing a simple .el file you'd use that way?  The
> > site's example is a bash script, and I wonder how much cleaner a .el
> > file would be.
> >
>
> Marcelo posted a larger example, but maybe a very small example might be
> helpful. Put the following in some file (I called it hello.el but the
> name does not really matter):
>
> --8<---------------cut here---------------start------------->8---
> #! /usr/local/bin/emacs --script
>
> (message "Hello World!")
> --8<---------------cut here---------------end--------------->8---
>
> Make it executable:
>
>   chmod +x hello.el
>
> and run it:
>
>   ./hello.el
>
> Nick
>
>

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

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

* Re: Batch execution and --script
  2012-08-29 18:35     ` Marcelo de Moraes Serpa
@ 2012-08-29 18:59       ` Thorsten Jolitz
  2012-08-29 19:13       ` Nick Dokos
  1 sibling, 0 replies; 10+ messages in thread
From: Thorsten Jolitz @ 2012-08-29 18:59 UTC (permalink / raw)
  To: emacs-orgmode

Marcelo de Moraes Serpa <celoserpa@gmail.com> writes:

Hi Marcelo,

> This is a subject that should be explored more. I see a lot of
> potential in having CLI .el scripts (i.e taking the emacs GUI out of
> the equation).

I once asked a related question on stackoverflow, and recieved this
answer that shows how to 
- become more independent of the location of the emacs executable
- pass more than one argument on the shebang line
at the same time: 

,-----------------------------------------------------------------------------
|      Many unix variants only allow a single argument to the program on      
|      the shebang line. Sad, but true. If you use #!/usr/bin/env emacs so    
|      as not to depend on the location of the emacs executable, you can't    
|      pass an argument at all.                                               
|                                                                             
|      Chaining scripts is a possibility on some systems, but that too is     
|      not supported everywhere.                                              
|                                                                             
|      You can go the time-honored route of writing a script that is both     
|      a shell script and an Emacs Lisp script (like Perl's if                
|      $running_under_some_shell, for example). It sure looks hackish, but    
|      it works.                                                              
|                                                                             
|      Elisp comments begin with ;, which in the shell separates two          
| up   commands. So we can use a ; followed by a shell instruction to         
| vote switch over to Emacs, with the actual Lisp code beginning on the       
| 21   next line. Shells don't like an empty command though, so we need to    
| down find something that both the shell and Emacs treat as a no-op, so      
| vote put before the ;. The shell no-op command is :; you can write it       
|      ":" as far as the shell is concerned, and Emacs parses that as a       
|      constant at top level which is also a no-op.                           
|                                                                             
|      #! /bin/sh                                                             
|      ":"; exec emacs --no-site-file --script "$0" -- "$@" # -*-emacs-lisp-*-
|      (print (+ 2 2))                                                        
`-----------------------------------------------------------------------------


Maybe thats interesting for you. The full question is here: 
http://stackoverflow.com/questions/6238331/emacs-shell-scripts-how-to-put-initial-options-into-the-script

-- 
cheers,
Thorsten

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

* Re: Batch execution and --script
  2012-08-29 18:35     ` Marcelo de Moraes Serpa
  2012-08-29 18:59       ` Thorsten Jolitz
@ 2012-08-29 19:13       ` Nick Dokos
  1 sibling, 0 replies; 10+ messages in thread
From: Nick Dokos @ 2012-08-29 19:13 UTC (permalink / raw)
  To: Marcelo de Moraes Serpa; +Cc: Org Mode, Nick Daly

Marcelo de Moraes Serpa <celoserpa@gmail.com> wrote:

> Is that somewhere in the manual or Worg? Perhaps it should be added. I
> never contributed to Worg, I will look into how tonight.

The --script is described in the emacs manual, but no example is
provided.  Adding it to Worg (maybe with a two-stage explanation:
trivial "Hello World" example, followed by an org-specific example)
is a good idea.

For contributing to Worg, see the "Maintenance of Worg" section:

    http://orgmode.org/worg/#sec-4

> This is a subject that should be explored more. I see a lot of
> potential in having CLI .el scripts (i.e taking the emacs GUI out of
> the equation).

Note that you could do this even before --script was invented:

  emacs --batch -l /path/to/somefile.el

is exactly equivalent to the --script invocation of somefile.el, which
in turn is more or less[fn:1] equivalent to stuffing the above command
line into a bash script file, making *that* executable and running it.
The --script method is a bit more convenient but it is just "syntactic
sugar".

Nick

Footnotes:

[fn:1] There is an extra fork/exec of bash in this method, but that's about it.

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

* Re: Batch execution and --script
  2012-08-29 17:50   ` Marcelo de Moraes Serpa
@ 2012-08-30  5:34     ` Bastien
  2012-11-28  2:18       ` Bernt Hansen
  0 siblings, 1 reply; 10+ messages in thread
From: Bastien @ 2012-08-30  5:34 UTC (permalink / raw)
  To: Marcelo de Moraes Serpa; +Cc: Org Mode, Nick Daly

Hi Marcelo,

Marcelo de Moraes Serpa <celoserpa@gmail.com> writes:

> I also created a new function based off org-export-generic called
> org-export-generic-markdown which can be called in a non-interactive
> way, so that it could work from the script.

NB: While org-export-generic.el was handy for a while, developers should
not rely on it write new code.  It is obsoleted by org-export.el.

-- 
 Bastien

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

* Re: Batch execution and --script
  2012-08-30  5:34     ` Bastien
@ 2012-11-28  2:18       ` Bernt Hansen
  2012-12-04 14:25         ` Bastien
  0 siblings, 1 reply; 10+ messages in thread
From: Bernt Hansen @ 2012-11-28  2:18 UTC (permalink / raw)
  To: Bastien; +Cc: Org Mode, Nick Daly, Marcelo de Moraes Serpa

Bastien <bzg@altern.org> writes:

> Hi Marcelo,
>
> Marcelo de Moraes Serpa <celoserpa@gmail.com> writes:
>
>> I also created a new function based off org-export-generic called
>> org-export-generic-markdown which can be called in a non-interactive
>> way, so that it could work from the script.
>
> NB: While org-export-generic.el was handy for a while, developers should
> not rely on it write new code.  It is obsoleted by org-export.el.

Hi Bastien,

I suggest you put a notice at the top of org-export-generic.el with this
notice and suggest future developers use org-export.el instead.

Regards,
Bernt

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

* Re: Batch execution and --script
  2012-11-28  2:18       ` Bernt Hansen
@ 2012-12-04 14:25         ` Bastien
  0 siblings, 0 replies; 10+ messages in thread
From: Bastien @ 2012-12-04 14:25 UTC (permalink / raw)
  To: Bernt Hansen; +Cc: Org Mode, Marcelo de Moraes Serpa, Nick Daly

Hi Bernt,

Bernt Hansen <bernt@norang.ca> writes:

> I suggest you put a notice at the top of org-export-generic.el with this
> notice and suggest future developers use org-export.el instead.

Good idea -- done.

Thanks,

-- 
 Bastien

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

end of thread, other threads:[~2012-12-04 14:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-29 15:47 Batch execution and --script Marcelo de Moraes Serpa
2012-08-29 16:42 ` Nick Daly
2012-08-29 17:50   ` Marcelo de Moraes Serpa
2012-08-30  5:34     ` Bastien
2012-11-28  2:18       ` Bernt Hansen
2012-12-04 14:25         ` Bastien
2012-08-29 18:29   ` Nick Dokos
2012-08-29 18:35     ` Marcelo de Moraes Serpa
2012-08-29 18:59       ` Thorsten Jolitz
2012-08-29 19:13       ` Nick Dokos

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.