emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Eric Schulte <schulte.eric@gmail.com>
To: Sebastien Vauban <wxhgmqzgwmuf@spammotel.com>
Cc: emacs-orgmode@gnu.org
Subject: Re: [babel] Problem with tangling and newlines
Date: Fri, 15 Jul 2011 09:34:13 -0600	[thread overview]
Message-ID: <87sjq7k10w.fsf@gmail.com> (raw)
In-Reply-To: 80y601ols0.fsf@somewhere.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
      <<my-name>> |\
      <<capitalize-name>>
    #+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
      <<fullest-disk>>
    #+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" <wxhgmqzgwmuf@spammotel.com> 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
>
> <<load-data>> |\
> <<americanize-date>> |\
> <<americanize-csv>>
>
> 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/

      reply	other threads:[~2011-07-15 15:38 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-13 22:31 [babel] Problem with tangling and newlines Sebastien Vauban
2011-07-15 15:34 ` Eric Schulte [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87sjq7k10w.fsf@gmail.com \
    --to=schulte.eric@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=wxhgmqzgwmuf@spammotel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).