From mboxrd@z Thu Jan 1 00:00:00 1970 From: Eric Schulte Subject: Re: [babel] Problem with tangling and newlines Date: Fri, 15 Jul 2011 09:34:13 -0600 Message-ID: <87sjq7k10w.fsf@gmail.com> References: <80y601ols0.fsf@somewhere.org> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([140.186.70.92]:57539) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QhkSn-0006JH-49 for emacs-orgmode@gnu.org; Fri, 15 Jul 2011 11:38:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QhkSi-0001lr-9x for emacs-orgmode@gnu.org; Fri, 15 Jul 2011 11:38:00 -0400 Received: from mail-iw0-f169.google.com ([209.85.214.169]:44733) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QhkSh-0001jy-5y for emacs-orgmode@gnu.org; Fri, 15 Jul 2011 11:37:55 -0400 Received: by mail-iw0-f169.google.com with SMTP id 8so1408124iwn.0 for ; Fri, 15 Jul 2011 08:37:54 -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: Sebastien Vauban Cc: emacs-orgmode@gnu.org Hi Seb, This is tricky because in some languages (e.g., Haskell and Python) whitespace needs to be respected, and the newlines are treated as part of the code block. We used to trim all whitespace padding from the edges of code blocks during tangling, however that caused problems, so now we do no trimming, which is causing problems for your use case. Perhaps the best compromise would be to trim only the last trailing newline from the body of the code block (given that it is not optional and could be considered part of the block syntax rather than part of the code body). I believe that behavior would support all use cases... OK, I've just made this change and pushed it up to the repository, all Babel tests are still passing to it shouldn't be overly destructive. The following behavior now works. ** including noweb refs w/o last newline #+begin_src sh :noweb yes <> |\ <> #+end_src #+source: my-name #+begin_src sh echo "eric schulte" #+end_src #+source: capitalize-name #+begin_src sh sed 's/^e/E/;s/ s/ S/' #+end_src and (from the test suite), the following #+begin_src sh :tangle yes :noweb yes :shebang #!/bin/sh <> #+end_src ** query all mounted disks #+begin_src sh :noweb-ref fullest-disk df #+end_src ** strip the header row #+begin_src sh :noweb-ref fullest-disk |sed '1d' #+end_src ** sort by the percent full #+begin_src sh :noweb-ref fullest-disk |awk '{print $5 " " $6}'|sort -n |tail -1 #+end_src ** extract the mount point #+begin_src sh :noweb-ref fullest-disk |awk '{print $2}' #+end_src now tangles to df|sed '1d'|awk '{print $5 " " $6}'|sort -n |tail -1|awk '{print $2}' which is pretty nice. Thanks for bringing this up -- Eric "Sebastien Vauban" writes: > Hi, > > Tangling this: > > #+begin_src sh :tangle my-csv2ledger-wrapper.sh :noweb yes > #!/bin/bash > # my-csv2ledger-wrapper.sh -- Convert CSV files to Ledger data > > <> |\ > <> |\ > <> > > exit 0 > #+end_src > > now gives: > > #!/bin/bash > # my-csv2ledger-wrapper.sh -- Convert CSV files to Ledger data > > cat > |\ > sed -r 's/^([[:digit:]]{2})\/([[:digit:]]{2})\/([[:digit:]]{2})/\2\/\1\/20\3/g' |\ > sed -r 's/^([[:digit:]]{2})-([[:digit:]]{2})-([[:digit:]]{4})/\2\/\1\/\3/g' > |\ > sed -r 's/([[:digit:]])\.([[:digit:]]{3})/\1\2/g' |\ > sed -r 's/([[:digit:]]),([[:digit:]]{2})/\1.\2/g' |\ > sed -r 's/,/./g' |\ > sed -r 's/;/,/g' > > exit 0 > > which is not executable anymore because the pipe is not ending the line of > commands. > > This is quite recent (v7.6?). > > Best regards, > Seb -- Eric Schulte http://cs.unm.edu/~eschulte/