From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Sean O'Halpin" Subject: Re: How to pass a block of text to a code block as data? Date: Sat, 9 Feb 2013 18:49:26 +0000 Message-ID: References: <8638x6y2zn.fsf@somewhere.org> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Return-path: Received: from eggs.gnu.org ([208.118.235.92]:35076) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U4FUO-0007j8-OZ for emacs-orgmode@gnu.org; Sat, 09 Feb 2013 13:49:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1U4FUN-0007Dl-Nh for emacs-orgmode@gnu.org; Sat, 09 Feb 2013 13:49:28 -0500 Received: from mail-wi0-x22a.google.com ([2a00:1450:400c:c05::22a]:55798) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1U4FUN-0007Dg-Ea for emacs-orgmode@gnu.org; Sat, 09 Feb 2013 13:49:27 -0500 Received: by mail-wi0-f170.google.com with SMTP id hm11so2058010wib.1 for ; Sat, 09 Feb 2013 10:49:26 -0800 (PST) In-Reply-To: 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: Michael Baum Cc: Sebastien Vauban , emacs-orgmode@gnu.org On Sat, Feb 9, 2013 at 2:59 AM, Michael Baum 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