emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Julien Fantin <julienfantin@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [babel] ob-C.el annoyances
Date: Fri, 15 Apr 2011 15:54:46 +0200	[thread overview]
Message-ID: <m2mxjraac9.fsf@gmail.com> (raw)

Hi list, hi Eric,

I've been using ob-C to go through the K&R book, and I've noticed a few
annoyances along the way.

* Use of the captial C identifier 

Support functions are defined as ob-C-*. In consequence, I need to
#+begin_src C to get a block to execute, because #+begin_src c fails
with "No org-babel-execute function for c!". The problem is that I can't
edit the block since there is no C-mode. Defining an alias fixed the
issue, but it doesn't work OOTB, and doesn't feel like a good solution
at all.

Is there a reasoning behind this, or where you, as I suspect, trying to
define some support functions that would work for both C and C++ ?


* Feeding text into blocks

This is not directly related to ob-C.el, but I was looking for a way to
feed some text to a block's STDIN while it was executed by babel.  I
wanted to specifiy this text either inline from the block's header
arguments or from a dedicated text block.

It'd ideally look like this :

** Inline

#+begin_src c :feed foo bar
int main(void) {
    while ((c = getchar()) != EOF) {
        putchar(c);
    }
    return 0;
}
#+end_src

#+results:
: foo bar

** From a text block

#+source: my-stdin
#+begin_src text
foo bar
#+end_src

#+begin_src c :feed my-stdin
int main(void) {
    while ((c = getchar()) != EOF) {
        putchar(c);
    }
    return 0;
}
#+end_src

#+results:
: foo bar

TL;DR if this is already possible somehow please skip the following and let
me know :)

I couldn't figure out how to pipe the text from within babel though. So
I resorted to tangling the text blocks, and redefined
org-babel-C-execute to use that new header argument :feed. It gets
prepended to the cmdline in the org-babel-eval function call ; if foo is
an existing file it gets cat'ed through a pipe to the rest of the
cmdline in org-babel-eval, otherwise it is simply echo'ed. This is not
as good as what I described above, but after getting to use it, I really
think a generalization of this use-case is desirable.

Please let me know whar you think.

Regards,
Julien.

             reply	other threads:[~2011-04-15 13:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-15 13:54 Julien Fantin [this message]
2011-04-15 16:24 ` [babel] ob-C.el annoyances Eric Schulte

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=m2mxjraac9.fsf@gmail.com \
    --to=julienfantin@gmail.com \
    --cc=emacs-orgmode@gnu.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).