emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [babel] Calling source blocks with arguments
@ 2011-03-23 21:56 Philipp Haselwarter
  2011-03-28 15:19 ` Philipp Haselwarter
  2011-03-29 13:59 ` Eric Schulte
  0 siblings, 2 replies; 5+ messages in thread
From: Philipp Haselwarter @ 2011-03-23 21:56 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

Is there a way to call a source-block with (positional) arguments, like
one would do on the command line?

I want to include some shell scripts in a paper and would prefer not
having to introduce some kind of artificial variables.

So I could just write my scripts inline, like

#+srcname: script.sh
#+begin_src sh
  #!/bin/sh
  echo $0: $@
#+end_src

and demonstrate their output by calling them

#+call: script.sh("arg1", "arg2") :results output

would produce something like

#+results:
: script.sh: arg1 arg2


Can this be done?

PS:
Is there a way to set «:results output» for the whole file?

thanks,

-- 
Philipp Haselwarter

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

* Re: [babel] Calling source blocks with arguments
  2011-03-23 21:56 [babel] Calling source blocks with arguments Philipp Haselwarter
@ 2011-03-28 15:19 ` Philipp Haselwarter
  2011-03-28 15:27   ` Rainer M Krug
  2011-03-28 15:37   ` Eric S Fraga
  2011-03-29 13:59 ` Eric Schulte
  1 sibling, 2 replies; 5+ messages in thread
From: Philipp Haselwarter @ 2011-03-28 15:19 UTC (permalink / raw)
  To: emacs-orgmode

Do you guys really just go and change all your variables in your
scripts?


-- 
Philipp Haselwarter

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

* Re: Re: [babel] Calling source blocks with arguments
  2011-03-28 15:19 ` Philipp Haselwarter
@ 2011-03-28 15:27   ` Rainer M Krug
  2011-03-28 15:37   ` Eric S Fraga
  1 sibling, 0 replies; 5+ messages in thread
From: Rainer M Krug @ 2011-03-28 15:27 UTC (permalink / raw)
  To: Philipp Haselwarter; +Cc: emacs-orgmode

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 28/03/11 17:19, Philipp Haselwarter wrote:
> Do you guys really just go and change all your variables in your
> scripts?
> 
> 
No.

See org manual, section 14.5, "Evaluating code blocks"

#+function: <name>(<arguments>) <header arguments>

Rainer

- -- 
Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
Biology, UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Tel:        +33 - (0)9 53 10 27 44
Cell:       +27 - (0)8 39 47 90 42
Fax (SA):   +27 - (0)8 65 16 27 82
Fax (D) :   +49 - (0)3 21 21 25 22 44
Fax (FR):   +33 - (0)9 58 10 27 44
email:      Rainer@krugs.de

Skype:      RMkrug
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk2QqOAACgkQoYgNqgF2egrlsQCfQnenn3xgg1GV2mTBveMV2n6R
AxEAmwWTVC154zWL3mI5GN8yzZVhOBzf
=/2tq
-----END PGP SIGNATURE-----

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

* Re: Re: [babel] Calling source blocks with arguments
  2011-03-28 15:19 ` Philipp Haselwarter
  2011-03-28 15:27   ` Rainer M Krug
@ 2011-03-28 15:37   ` Eric S Fraga
  1 sibling, 0 replies; 5+ messages in thread
From: Eric S Fraga @ 2011-03-28 15:37 UTC (permalink / raw)
  To: Philipp Haselwarter; +Cc: emacs-orgmode

Philipp Haselwarter <philipp.haselwarter@gmx.de> writes:

> Do you guys really just go and change all your variables in your
> scripts?

I guess... but, in answer to your original question, I would simply pass
all arguments as one "org" variable (eg. :var cmdline="one two three")
and then have the shell script break these up as desired.  I know that's
not what you wanted, mind you... :(

-- 
: Eric S Fraga (GnuPG: 0xC89193D8FFFCF67D) in Emacs 24.0.50.1
: using Org-mode version 7.5 (release_7.5.115.g00134.dirty)

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

* Re: [babel] Calling source blocks with arguments
  2011-03-23 21:56 [babel] Calling source blocks with arguments Philipp Haselwarter
  2011-03-28 15:19 ` Philipp Haselwarter
@ 2011-03-29 13:59 ` Eric Schulte
  1 sibling, 0 replies; 5+ messages in thread
From: Eric Schulte @ 2011-03-29 13:59 UTC (permalink / raw)
  To: Philipp Haselwarter; +Cc: emacs-orgmode

Philipp Haselwarter <philipp.haselwarter@gmx.de> writes:

> Hi,
>
> Is there a way to call a source-block with (positional) arguments, like
> one would do on the command line?
>
> I want to include some shell scripts in a paper and would prefer not
> having to introduce some kind of artificial variables.
>
> So I could just write my scripts inline, like
>
> #+srcname: script.sh
> #+begin_src sh
>   #!/bin/sh
>   echo $0: $@
> #+end_src
>
> and demonstrate their output by calling them
>
> #+call: script.sh("arg1", "arg2") :results output
>
> would produce something like
>
> #+results:
> : script.sh: arg1 arg2
>

This wouldn't work under the current setup, for example, we don't even
write the contents of the sh code block to a temporary file, so $0
wouldn't really mean anything... or actually, this would just return the
file-name of the shell used to evaluate the code block, e.g.,

#+begin_src sh
  echo $0
#+end_src

#+results:
: sh

>
>
> Can this be done?
>

Not currently, however if there is enough interest, it wouldn't be too
hard to add a :cmdline header argument to shell scripts, which would
result in the code block body being written to a temporary file, then
called with the supplied :cmdline arguments.

>
> PS:
> Is there a way to set «:results output» for the whole file?
>

Yes, see http://orgmode.org/manual/Buffer_002dwide-header-arguments.html

Cheers -- Eric

>
> thanks,

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

end of thread, other threads:[~2011-03-29 14:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-23 21:56 [babel] Calling source blocks with arguments Philipp Haselwarter
2011-03-28 15:19 ` Philipp Haselwarter
2011-03-28 15:27   ` Rainer M Krug
2011-03-28 15:37   ` Eric S Fraga
2011-03-29 13:59 ` Eric Schulte

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