Org-mode mailing list
 help / color / mirror / Atom feed
From: Magnus Therning <magnus@therning.org>
To: "Berry, Charles" <ccberry@health.ucsd.edu>
Cc: Emacs Org Mode mailing list <emacs-orgmode@gnu.org>
Subject: Re: Using a code block as input to another code block
Date: Mon, 23 Nov 2020 12:39:10 +0100
Message-ID: <873610480x.fsf@therning.org> (raw)
In-Reply-To: <6DE39B70-57CF-48E7-BD22-39D7140A2EA2@health.ucsd.edu>

[-- Attachment #1: Type: text/plain, Size: 2030 bytes --]


Berry, Charles <ccberry@health.ucsd.edu> writes:

> Inline.
>
>> On Nov 21, 2020, at 2:30 PM, Magnus Therning <magnus@therning.org> wrote:
>>
>> I know I can use an example block (literal example) as input to a code
>> block, but I haven't found a way to fontify examples. Since my input is
>> code (JSON, and various programming languages) I would really like to
>> have that, as well as the language's mode when editing by using
>> ~org-edit-source-code~.
>>
>> A code block gives me fontification, but I haven't found a way to pass a
>> code block as is to another code block.
>>
>> For instance, something like this:
>>
>> #+name: code-input
>> #+begin_src C
>> #include <foo.h>
>> #+end_src
>>
>> #+begin_src bash :var input=input :results verbatim
>> cat <<EOF | cpp
>> ${input}
>> EOF
>> #+end_src
>
>
> Sounds like you want the :noweb header and code chunks, viz.
>
> #+begin_src bash :noweb yes :results verbatim
> cat <<EOF | cpp
> <<code-input>>
> EOF
> #+end_src
>
> HTH,
>
> Chuck
>
> [deleted]

Ah, I didn't think of that. It does have some limitations though as
:noweb isn't as flexible as shell expansion. For instance, I'm not able
to do

#+name: my-json
#+begin_src json
{
  ...
}
#+end_src

#+begin_src bash :noweb yes :results verbatim
cat <<EOF
{
  "foo": $(echo <<my-json>> | jq '@text')
}
EOF
#+end_src

Though it isn't too difficult to work around in this case:

#+begin_src bash :noweb yes :results verbatim
cat <<EOF0 | jq '@text' | cat <<EOF1
<<my-json>>
EOF0
{
  "foo": $(cat /dev/stdin)
}
EOF1
#+end_src

It's absolutely a workable solution. Thanks!

/M

--
Magnus Therning              OpenPGP: 0x927912051716CE39
email: magnus@therning.org
twitter: magthe              http://magnus.therning.org/

Sometimes I wonder whether the world is being run by smart people who
are putting us on or by imbeciles who really mean it.
     — Mark Twain
Clearly, it's the imbeciles. And they really mean it.
     — DBT

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]

  reply	other threads:[~2020-11-23 11:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-21 22:30 Magnus Therning
2020-11-22 17:26 ` Berry, Charles via General discussions about Org-mode.
2020-11-23 11:39   ` Magnus Therning [this message]
2020-11-22 21:50 ` Mike Gauland

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://orgmode.org

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

  git send-email \
    --in-reply-to=873610480x.fsf@therning.org \
    --to=magnus@therning.org \
    --cc=ccberry@health.ucsd.edu \
    --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

Org-mode mailing list

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://orgmode.org/list/0 list/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 list list/ https://orgmode.org/list \
		emacs-orgmode@gnu.org
	public-inbox-index list

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.emacs.orgmode
	nntp://news.gmane.io/gmane.emacs.orgmode


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git