Re: [O] How to pass a block of text to a code block as data?
Michael Baum writes: > Sean, that helps too, thank you. Now that you and Sebastien have gone to > all this trouble I found the part of the manual that sort of describes > this, but I clearly didn't understand it before. Possible needs a more > worked-out example for the slow among us, like self. > Patches are welcome, especially documentation patches. [...] > > NOTICE THAT while both return the result as Example text, the first simple > prepends each line with a colon, simple Example form, and the second wraps > the result in an Example block without altering the lines. > > Not sure why? Is this just a function of the number of lines of the text? > Yes, this is a function of the number of lines in the output text. You can control where this switch is made by changing the value of org-babel-min-lines-for-block-output. Best, -- Eric Schulte http://cs.unm.edu/~eschulte
Re: [O] How to pass a block of text to a code block as data?
Sean, that helps too, thank you. Now that you and Sebastien have gone to all this trouble I found the part of the manual that sort of describes this, but I clearly didn't understand it before. Possible needs a more worked-out example for the slow among us, like self. I've noticed one curious thing in trying a perl example. See first: -8<-- #+name: wake #+BEGIN_EXAMPLE riverrun, past Eve and Adam's, from swerve of shore to bend of bay, brings us by a commodius vicus of recirculation back to Howth Castle and Environs. Sir Tristram, violer d'amores, fr'over the short sea, had passen- core rearrived from North Armorica on this side the scraggy isthmus of Europe Minor to wielderfight his penisolate war: nor had topsawyer's rocks by the stream Oconee exaggerated themselse to Laurens County's gorgios while they went doublin their mumper all the time: nor avoice from afire bellowsed mishe mishe to #+END_EXAMPLE #+begin_src perl :var inlines=wake :results output foreach $aln (split(/$/,$inlines)) { print $aln; } #+end_src #+results: : riverrun, past Eve and Adam's, from swerve of shore to bend : of bay, brings us by a commodius vicus of recirculation back to : Howth Castle and Environs. : Sir Tristram, violer d'amores, fr'over the short sea, had passen- : core rearrived from North Armorica on this side the scraggy : isthmus of Europe Minor to wielderfight his penisolate war: nor : had topsawyer's rocks by the stream Oconee exaggerated themselse : to Laurens County's gorgios while they went doublin their mumper : all the time: nor avoice from afire bellowsed mishe mishe to -8<-- and then a more complicated block that's closer to my real task: -8<-- #+NAME: job2 #+BEGIN_EXAMPLE !START !ID:7655 !DATE:02/10/2013 !CLOSE:03/15/2013 !UNTILFILLED: !POSITION:Science Editor !COMPANY:East Newark Times Herald News and World Defender !BEGIN-DESCRIPTION Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. !END-DESCRIPTION !BEGIN-SPECIAL Duis eget lorem ac odio lobortis suscipit nec et neque. Sed at quam ut mauris scelerisque congue id eget dui. Quisque tellus lectus, tristique eu posuere in, faucibus vitae urna. Duis vitae orci purus, quis euismod augue. !END-SPECIAL !SALARY:16.67 per hour !BEGIN-CONTACT Please submit online at http://enthnawd.org/jobs !END-CONTACT !END #+END_EXAMPLE #+begin_src perl :var inlines=job2 :results output foreach $aln (split(/$/,$inlines)) { print $aln; } #+end_src #+results: #+begin_example !START !ID:7655 !DATE:02/10/2013 !CLOSE:03/15/2013 !UNTILFILLED: !POSITION:Science Editor !COMPANY:East Newark Times Herald News and World Defender !BEGIN-DESCRIPTION Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. !END-DESCRIPTION !BEGIN-SPECIAL Duis eget lorem ac odio lobortis suscipit nec et neque. Sed at quam ut mauris scelerisque congue id eget dui. Quisque tellus lectus, tristique eu posuere in, faucibus vitae urna. Duis vitae orci purus, quis euismod augue. !END-SPECIAL !SALARY:16.67 per hour !BEGIN-CONTACT Please submit online at http://enthnawd.org/jobs !END-CONTACT !END #+end_example -8<-- NOTICE THAT while both return the result as Example text, the first simple prepends each line with a colon, simple Example form, and the second wraps the result in an Example block without altering the lines. Not sure why? Is this just a function of the number of lines of the text? Michael -- Michael Baum You should never have your best trousers on when you go out to fight for freedom and truth. - Ibsen
Re: [O] How to pass a block of text to a code block as data?
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
Re: [O] How to pass a block of text to a code block as data?
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
Re: [O] How to pass a block of text to a code block as data?
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
[O] How to pass a block of text to a code block as data?
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. -- Michael Baum