emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Using a code block as input to another code block
@ 2020-11-21 22:30 Magnus Therning
  2020-11-22 17:26 ` Berry, Charles via General discussions about Org-mode.
  2020-11-22 21:50 ` Mike Gauland
  0 siblings, 2 replies; 4+ messages in thread
From: Magnus Therning @ 2020-11-21 22:30 UTC (permalink / raw)
  To: Emacs Org Mode mailing list

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

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

What are my options? I hope there's either a way to fontify an example,
or to override the default execute function for a code block, or
something else that I'm not thinking of.

/M

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

I am always doing that which I cannot do, in order that I may learn
how to do it.
     — Pablo Picasso

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Using a code block as input to another code block
  2020-11-21 22:30 Using a code block as input to another code block Magnus Therning
@ 2020-11-22 17:26 ` Berry, Charles via General discussions about Org-mode.
  2020-11-23 11:39   ` Magnus Therning
  2020-11-22 21:50 ` Mike Gauland
  1 sibling, 1 reply; 4+ messages in thread
From: Berry, Charles via General discussions about Org-mode. @ 2020-11-22 17:26 UTC (permalink / raw)
  To: Magnus Therning; +Cc: Emacs Org Mode mailing list

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]



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Using a code block as input to another code block
  2020-11-21 22:30 Using a code block as input to another code block Magnus Therning
  2020-11-22 17:26 ` Berry, Charles via General discussions about Org-mode.
@ 2020-11-22 21:50 ` Mike Gauland
  1 sibling, 0 replies; 4+ messages in thread
From: Mike Gauland @ 2020-11-22 21:50 UTC (permalink / raw)
  To: emacs-orgmode

As far as I know, referencing a code block this way uses the results of 
executing the block as the variable, not the contents of the block.

On 22/11/2020 11:30 am, Magnus Therning 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
>
> What are my options? I hope there's either a way to fontify an example,
> or to override the default execute function for a code block, or
> something else that I'm not thinking of.
>
> /M
>
> --
> Magnus Therning              OpenPGP: 0x927912051716CE39
> email: magnus@therning.org
> twitter: magthe              http://magnus.therning.org/
>
> I am always doing that which I cannot do, in order that I may learn
> how to do it.
>       — Pablo Picasso


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Using a code block as input to another code block
  2020-11-22 17:26 ` Berry, Charles via General discussions about Org-mode.
@ 2020-11-23 11:39   ` Magnus Therning
  0 siblings, 0 replies; 4+ messages in thread
From: Magnus Therning @ 2020-11-23 11:39 UTC (permalink / raw)
  To: Berry, Charles; +Cc: Emacs Org Mode mailing list

[-- 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 --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-11-23 11:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-21 22:30 Using a code block as input to another code block Magnus Therning
2020-11-22 17:26 ` Berry, Charles via General discussions about Org-mode.
2020-11-23 11:39   ` Magnus Therning
2020-11-22 21:50 ` Mike Gauland

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).