Re: Using a code block as input to another code block

2020-11-23 Thread Magnus Therning

Berry, Charles  writes:

> Inline.
>
>> On Nov 21, 2020, at 2:30 PM, 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 
>> #+end_src
>>
>> #+begin_src bash :var input=input :results verbatim
>> cat <> ${input}
>> EOF
>> #+end_src
>
>
> Sounds like you want the :noweb header and code chunks, viz.
>
> #+begin_src bash :noweb yes :results verbatim
> cat < <>
> 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 <> | 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
{
  "foo": $(cat /dev/stdin)
}
EOF1
#+end_src

It's absolutely a workable solution. Thanks!

/M

--
Magnus Therning  OpenPGP: 0x927912051716CE39
email: mag...@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


signature.asc
Description: PGP signature


Re: Using a code block as input to another code block

2020-11-22 Thread Mike Gauland
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 
#+end_src

#+begin_src bash :var input=input :results verbatim
cat 

Re: Using a code block as input to another code block

2020-11-22 Thread Berry, Charles
Inline.

> On Nov 21, 2020, at 2:30 PM, 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 
> #+end_src
> 
> #+begin_src bash :var input=input :results verbatim
> cat < ${input}
> EOF
> #+end_src


Sounds like you want the :noweb header and code chunks, viz.
 
#+begin_src bash :noweb yes :results verbatim
cat <>
EOF
#+end_src

HTH,

Chuck

[deleted]




Using a code block as input to another code block

2020-11-21 Thread Magnus Therning
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 
#+end_src

#+begin_src bash :var input=input :results verbatim
cat