emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Sean O'Halpin" <sean.ohalpin@gmail.com>
To: Michael Baum <maabaum@gmail.com>
Cc: Sebastien Vauban <wxhgmqzgwmuf@spammotel.com>, emacs-orgmode@gnu.org
Subject: Re: How to pass a block of text to a code block as data?
Date: Sat, 9 Feb 2013 18:49:26 +0000	[thread overview]
Message-ID: <CAOXM+eWpMtt90xfa67iNrvTa_NdR=PS61mZwyfobyKFOLosn4Q@mail.gmail.com> (raw)
In-Reply-To: <CA+G3xFhHDz05Muj9Z1TCDCD+5=9NP7B5ZZu4-NMpS4F9s0qVhQ@mail.gmail.com>

On Sat, Feb 9, 2013 at 2:59 AM, Michael Baum <maabaum@gmail.com> wrote:
>
> - What signals the end of the block of text to be used as data? I take it
> that it's important that these all be comment lines staring with a colon
> after the #+name label? Is there a way to do the same thing with a begin and
> end block construction?
>
> - In this line:
>
>        #+begin_src sh :stdin lines-of-text :results output
>
> does the flag :stdin mean that the following named block literally becomes
> the STDIN stream for the code block? If I replace your shell/grep example
> with this:
>
> #+begin_src perl :stdin lines-of-text :results output
> while (<>) {
>    print $_;
> }
> #+end_src
>
> ...it doesn't work, although as far as I know that perl code snippet should
> in fact simply print out the incoming lines from stdin.
>
> Thanks again,
>
> Michael

Hi,

The :stdin option is only defined for shell and awk AFAIK. (Might be
an idea to add to other languages..)

You can pass in a variable referring to the block of text, as shown
below (example for ruby but should work for perl):

#+begin_src org

#+name: more-lines-of-text
#+begin_example
What signals the end of the block of text to be used as data? I take
it that it's important that these all be comment lines staring with a
colon after the #+name label? Is there a way to do the same thing with
a begin and end block construction?
#+end_example

#+begin_src ruby :var lines=more-lines-of-text :results output
  puts lines.reverse
#+end_src

#+RESULTS:
: ?noitcurtsnoc kcolb dne dna nigeb a
: htiw gniht emas eht od ot yaw a ereht sI ?lebal eman+# eht retfa noloc
: a htiw gnirats senil tnemmoc eb lla eseht taht tnatropmi s'ti taht ti
: ekat I ?atad sa desu eb ot txet fo kcolb eht fo dne eht slangis tahW

#+end_src

Regards,
Sean

  reply	other threads:[~2013-02-09 18:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-08 17:06 How to pass a block of text to a code block as data? Michael Baum
2013-02-08 20:17 ` Sebastien Vauban
2013-02-09  2:59   ` Michael Baum
2013-02-09 18:49     ` Sean O'Halpin [this message]
2013-02-11 21:49       ` Michael Baum
2013-02-11 22:07         ` Eric Schulte

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAOXM+eWpMtt90xfa67iNrvTa_NdR=PS61mZwyfobyKFOLosn4Q@mail.gmail.com' \
    --to=sean.ohalpin@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=maabaum@gmail.com \
    --cc=wxhgmqzgwmuf@spammotel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).