From mboxrd@z Thu Jan 1 00:00:00 1970 From: "Eric Schulte" Subject: Re: PERL, org-mode and literal document input. Date: Thu, 05 May 2011 11:19:08 -0600 Message-ID: <87vcxouauw.fsf@gmail.com> References: <87ei4gc0kg.fsf@ufl.edu> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([140.186.70.92]:44155) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QI5ZH-0000uf-IS for emacs-orgmode@gnu.org; Thu, 05 May 2011 16:54:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QI5ZG-0004id-8s for emacs-orgmode@gnu.org; Thu, 05 May 2011 16:54:39 -0400 Received: from mail-pz0-f41.google.com ([209.85.210.41]:54884) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QI5ZG-0004iX-11 for emacs-orgmode@gnu.org; Thu, 05 May 2011 16:54:38 -0400 Received: by pzk4 with SMTP id 4so1622347pzk.0 for ; Thu, 05 May 2011 13:54:37 -0700 (PDT) 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: "Allen S. Rout" Cc: emacs-orgmode@gnu.org Hi Allen, Judging from your example org-mode text below I would suggest the following... First, the block of yaml is miss-formed, you have a "#+source:" line, and a "#end_src" line, but you are missing a required "#+begin_src yaml". Second, if you will be referencing the contents of a yaml code block you will need to define an `org-babel-execute:yaml' function. For the simple case of returning the contents of the code block the following will work. (defun org-babel-execute:yaml (body params) body) alternately you could just include your yaml as an example block #+results: yaml-config : erpalpha:... I hope some of the above works for you. Please let me know if either of these solutions are appropriate. Best -- Eric asr@ufl.edu (Allen S. Rout) writes: > Greetings. > > I've got a YAML config file and some processing I'm doing to it. I'd > love to have both the bits inside the maintenance document I'm writing > to manage a service. This seems a perfect use for code blocks and their > evaluation. However, I get behavior out of my attempt to do this which > I find strange. > > I include a minimal, failing example below. > > The problem "appears" to be somewhere in the :var reference designed to > introduce the other code block. There are two problems, one pretty > egregious, the other somewhat subtle. > > Egregious first: > > For some reason, whatever process sucks up config_yml and inserts it > into '$config' in mogrify_pl just elides the first two lines. > > Additionally, the contents of the variable are very strangely > formatted. The contents of most of the first YAML document (less the > first two lines) are each on a separate line. > > However, the last of the first doc and all of the second doc are in a > single line. > > > Subtle: > > The last few newlines are also elided. This might not seem to be a big > deal, but YAML really wants to end with a trailing newline. I figure I > should be able to express that in the doc, and not tag one on in my > code. > > ... > > If I add a #+begin_src line to config_yml, and then build a results > section by hand, and copy the identical document there, then the > variable is imported more or less as I'd expect: $config is one large > scalar value, with the contents of config_yml inserted. The trailing > newlines are still stripped, but this is better at least. > > > I've been searching for something like "Echo this" to put in my > begin_src; it would seem a little silly but not awful to define a > process to just copy the contents of the source block to the result, and > go from there. But it's inelegant, to say the least. > > ... > > So: Is there a conventional way I should get org to treat the source > block 'the same way' it treats the results block? Failing that, is > there a common idiom to run a source block to get the result "Echo me > verbatim into the results block" ? > > I see profligate use of org-babel-trim in the code. Does that mean that > permitting leading or trailing whitespace is a regular source of > problems? I didn't want to start dinking with it casually. > > ... > > > Any pointers would be deeply appreciated. > > > *** YAML transform. > > #+srcname: config_yml > --- > erpalpha: > - alpha-rac-1.erp.ufl.edu > - alpha-rac-2.erp.ufl.edu > erpbeta: > - beta-rac-1.erp.ufl.edu > - beta-rac-2.erp.ufl.edu > --- > erpalpha: > FS: /export/alpha > nodes: > erpalpha: '' > erpbeta: RO > > erpbeta: > FS: /export/beta > nodes: > erpalpha: RO > erpbeta: > > > #+end_src > > > #+srcname: mogrify_pl > #+begin_src perl :results output :var config=config_yml() > use YAML(); > use Data::Dumper; > > # $stream = join("",<$foo>); > > print "===$config===\n"; > > print $#config,"\n"; > > foreach $line (@{$config}) > { print "[$line]\n"; } > > print Dumper($config); > > > # ($nodegroups,$filespaces) = YAML::Load($config); > # print YAML::Dump($nodegroups,$filespaces); > > #+end_src > > #+results: mogrify_pl > #+begin_example > ===ARRAY(0x853b818)=== > -1 > [alpha-rac-1.erp.ufl.edu] > [alpha-rac-2.erp.ufl.edu > erpbeta:] > [beta-rac-1.erp.ufl.edu] > [beta-rac-2.erp.ufl.edu > --- > erpalpha: > FS: /export/alpha > nodes: > erpalpha: '' > erpbeta: RO > > erpbeta: > FS: /export/beta > nodes: > erpalpha: RO > erpbeta:] > $VAR1 = [ > 'alpha-rac-1.erp.ufl.edu', > 'alpha-rac-2.erp.ufl.edu > erpbeta:', > 'beta-rac-1.erp.ufl.edu', > 'beta-rac-2.erp.ufl.edu > --- > erpalpha: > FS: /export/alpha > nodes: > erpalpha: \'\' > erpbeta: RO > > erpbeta: > FS: /export/beta > nodes: > erpalpha: RO > erpbeta:' > ]; > #+end_example > > > - Allen S. Rout > > > -- Eric Schulte http://cs.unm.edu/~eschulte/