emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Sébastien Vauban" <wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org>
To: emacs-orgmode-mXXj517/zsQ@public.gmane.org
Subject: Re: [babel] How to kill two birds with one stone?
Date: Mon, 28 Feb 2011 16:16:49 +0100	[thread overview]
Message-ID: <80wrkknq8u.fsf@somewhere.org> (raw)
In-Reply-To: 87sjvj6oul.fsf@gmail.com

Hi Eric,

"Eric Schulte" wrote:
> I haven't followed this discussion very closely, but I'm not sure why it
> would be necessary to pass data through STDIN rather than through a variable
> or an external file.
>
> I took a shot at the dot graph example you proposed, the following works for
> me over a simple example directory.

For sure, your version works, but it does not address the two goals -- I hope
they don't exclude each other -- I wanna try to reach.

This should clarify the subject.

#+TITLE:     graph-dir-eric-schulte
#+DATE:      2011-02-28
#+LANGUAGE:  en_US

* Directory to search

#+results: graph-dir
: graph-dir

* List all files in dir

#+source: graph-files
#+begin_src sh :results vector :var dir=graph-dir
  find $dir -type f -exec basename {} \;
#+end_src

#+results: graph-files
| dan        |
| eric       |
| other      |
| seb_vauban |

* Association of files with mentions

#+source: graph-associations
#+begin_src sh :var dir=graph-dir :var files=graph-files
  for i in $files; do
      for j in `grep -l -r $i $dir`; do
          echo $i, `basename $j`
      done
  done
#+end_src

#+results: graph-associations
| dan        | eric       |
| eric       | seb_vauban |
| other      | eric       |
| other      | seb_vauban |
| seb_vauban | dan        |

* Ultimate goal

The first goal of this document was to write small snippets of code, with a
clear and concise specification, and test its results when applied on some
input data. This goal is clearly met.

Though, the following goal, the ultimate one, is to be able to output an
independent shell script -- out of this stuff --, so that the program can be
run independently by anybody, just from a simple shell.

How could I write such a "combined" shell script?

Something in the spirit of:

#+source: graph-associations-sh-script
#+begin_src sh :var dir=graph-dir :noweb yes
  cd $dir
  for i in `<<graph-files>>`; do
      for j in `grep -l -r $i $dir`; do
          echo $i, `basename $j`
      done
  done
#+end_src

#+results: graph-associations-sh-script

But, of course (because of the =dir= var?), the above does not work, at least
for my first goal: seeing "in situ" (part of) the results it returns when it
is run.

Maybe it's possible to reach both goals, maybe it's not -- I've no definite
clue about this.

- Maybe we need =stdin= to be properly "handled" for this, nothing more?

- Maybe we need to add some extra hard constraints on how to write the little
  program parts, such as "don't use the Babel :var mechanism"?

- Etc...

* Executive summary

To sum up what I'm trying to explain, I'd like the ability to write *and run*
small snippets of code, such as:

#+source: block-1
#+begin_src sh
... do this...
#+end_src

#+source: block-2
#+begin_src sh
... do that...
#+end_src

*and* to be able to produce the shell script that would run them all from a
shell (no need for Emacs), something like:

#+source: full-code
#+begin_src sh :tangle yes
<<block-1>>
<<block-2>>
#+end_src

or

#+source: full-code
#+begin_src sh :tangle yes
<<block-1>> | <<block-2>>
#+end_src

or

#+source: full-code
#+begin_src sh :tangle yes
for i in `<<block-1>>`; do
    <<block-2>>
done
#+end_src

or ... (depending on what the code does) ...

Which conditions would allow one to make both dreams true at the same time?

Best regards,
  Seb

-- 
Sébastien Vauban


_______________________________________________
Emacs-orgmode mailing list
Please use `Reply All' to send replies to the list.
Emacs-orgmode-mXXj517/zsQ@public.gmane.org
http://lists.gnu.org/mailman/listinfo/emacs-orgmode

      parent reply	other threads:[~2011-02-28 15:16 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-04 16:00 [babel] How to kill two birds with one stone? Sébastien Vauban
2011-02-04 17:43 ` Dan Davison
2011-02-04 22:23   ` Sébastien Vauban
2011-02-06 16:51   ` Sébastien Vauban
2011-02-20  8:57     ` Eric Schulte
2011-02-25 14:27       ` Sébastien Vauban
2011-02-25 22:44         ` Nick Dokos
2011-02-25 22:55           ` Nick Dokos
2011-02-28 13:59           ` Sébastien Vauban
2011-02-26  0:24         ` Eric Schulte
2011-02-26  9:56           ` Closing #+results: with #+end declaration? Bastien
2011-02-27 20:00             ` Eric Schulte
2011-02-28 13:54               ` Sébastien Vauban
2011-03-03 11:11               ` Bastien
2011-02-28 15:16       ` Sébastien Vauban [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=80wrkknq8u.fsf@somewhere.org \
    --to=wxhgmqzgwmuf-genee64ty+gs+fvcfc7uqw@public.gmane.org \
    --cc=emacs-orgmode-mXXj517/zsQ@public.gmane.org \
    /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).