From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Baum Subject: Re: How to pass a block of text to a code block as data? Date: Fri, 8 Feb 2013 21:59:20 -0500 Message-ID: References: <8638x6y2zn.fsf@somewhere.org> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=f46d044519d9c821bb04d541dcbe Return-path: Received: from eggs.gnu.org ([208.118.235.92]:49582) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U40ew-0005sq-VZ for emacs-orgmode@gnu.org; Fri, 08 Feb 2013 21:59:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U40ev-0002kw-Gn for emacs-orgmode@gnu.org; Fri, 08 Feb 2013 21:59:22 -0500 Received: from mail-ob0-f179.google.com ([209.85.214.179]:47165) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U40ev-0002ko-9s for emacs-orgmode@gnu.org; Fri, 08 Feb 2013 21:59:21 -0500 Received: by mail-ob0-f179.google.com with SMTP id un3so4592262obb.10 for ; Fri, 08 Feb 2013 18:59:20 -0800 (PST) In-Reply-To: <8638x6y2zn.fsf@somewhere.org> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Sebastien Vauban Cc: emacs-orgmode@gnu.org --f46d044519d9c821bb04d541dcbe Content-Type: text/plain; charset=ISO-8859-1 Sebastien: Thanks! That helps a lot. I'm having trouble extending your example, however. A couple of questions -- - 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 On Fri, Feb 8, 2013 at 3:17 PM, Sebastien Vauban wrote: > Hi Michael, > > Michael Baum wrote: > > I haven't been able to figure this out from the org-mode documents yet. > > What I would like to do is have a source code block in python or perl or > > something similar. to which I can pass a reference to several lines of > text > > that the source code block, when evaluated, would then act on. Which > would > > involve iterating through the data text one line at a time and writing > the > > output to a buffer. > > > > The text data could be indicated by a specific headline or a named block > of > > some sort or maybe an internal link, I'm not particularly fussy just so > > there's a mechanism to do this. > > > > Would appreciate any guidance. > > #+name: lines-of-text > : I haven't been able to figure this out from the org-mode documents yet. > : What I would like to do is have a source code block in python or perl or > : something similar. to which I can pass a reference to several lines of > text > : that the source code block, when evaluated, would then act on. Which > would > : involve iterating through the data text one line at a time and writing > the > : output to a buffer. > > #+begin_src sh :stdin lines-of-text :results output > grep would > #+end_src > > #+results: > #+begin_example > What I would like to do is have a source code block in python or perl or > that the source code block, when evaluated, would then act on. Which would > #+end_example > > Best regards, > Seb > > -- > Sebastien Vauban > > > -- ==================================== Michael Baum You should never have your best trousers on when you go out to fight for freedom and truth. - Ibsen --f46d044519d9c821bb04d541dcbe Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Sebastien:

Thanks! That helps a lot. I'm having trouble extendin= g your example, however. A couple of questions --

- What signals the= end of the block of text to be used as data? I take it that it's impor= tant 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 const= ruction?

- In this line:
=A0=A0=A0=A0=A0=A0 #+begin_src sh :stdin lines-of-te= xt :results output

does the flag :stdin mean that the following name= d 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 (<>= ;) {
=A0=A0 print $_;
}
#+end_src

...it doesn't work, a= lthough as far as I know that perl code snippet should in fact simply print= out the incoming lines from stdin.

Thanks again,

Michael

On Fri, = Feb 8, 2013 at 3:17 PM, Sebastien Vauban <wxhgmqzgwmuf@spammotel.= com> wrote:
Hi Michael,

Michael Baum wrote:
> I haven't been able to figure this out from the org-mode documents= yet.
> What I would like to do is have a source code block in python or perl = or
> something similar. to which I can pass a reference to several lines of= text
> that the source code block, when evaluated, would then act on. Which w= ould
> involve iterating through the data text one line at a time and writing= the
> output to a buffer.
>
> The text data could be indicated by a specific headline or a named blo= ck of
> some sort or maybe an internal link, I'm not particularly fussy ju= st so
> there's a mechanism to do this.
>
> Would appreciate any guidance.

#+name: lines-of-text
: I haven't been able to figure this out from the org-mode documents ye= t.
: What I would like to do is have a source code block in = python or perl or
: something similar. to which I can pass a reference to several lines of te= xt
: that the source code block, when evaluated, would then act on. Which woul= d
: involve iterating through the data text one line at a time and writing th= e
: output to a buffer.

#+begin_src sh :stdin lines-of-text :results output
=A0 grep would
#+end_src

#+results:
#+begin_example
What I would like to do is have a source code block in py= thon or perl or
that the source code block, when evaluated, would t= hen act on. Which would
#+end_example

Best regards,
=A0 Seb

--
Sebastien Vauban





--
=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D
Michael Baum <maabaum@gmail.com>

You should never have your best tro= users on when you go out
=A0to fight for freedom and truth. - Ibsen --f46d044519d9c821bb04d541dcbe--