emacs/var/elfeed/db/data/51/516620e9e01880a9b0a2ea47e1fd9a42bf33d7a2
2022-01-03 12:49:32 -06:00

1 line
2.7 KiB
Plaintext

<!-- SC_OFF --><div class="md"><p>Hey, I&#39;m experimenting with literate coding. In the process I couldn&#39;t properly evaluate a block. I wanted to use both<code>:results output</code> and <code>:export both</code>, and I&#39;m getting troubles to make those work with <code>:defines</code>. This is the code I have: </p> <pre><code>#+property: header-args :includes &lt;stdio.h&gt; #+property: header-args :defines cool_macro(x) x #+property: header-args :exports both #+property: header-args :results output #+begin_src C printf(&quot;cool_macro(7): %u\n&quot;, cool_macro(7)); printf(&quot;cool_macro(7): %u\n&quot;, cool_macro(7)); #+end_src </code></pre> <p>As it is, both <code>:exports</code> and <code>:results</code> have no effect. I figured that if I place them above the <code>:includes</code> then they&#39;ll have effect, but I get a compilation error because it cannot find the macro, as if now both <code>:includes</code> and <code>:defines</code> doesn&#39;t have effect.</p> <p>If I place those 2 after the <code>#+begin_src C</code> then everything works as expected, but it&#39;s inconvenient since I want those to affect the whole buffer..</p> <pre><code>#+property: header-args :includes &lt;stdio.h&gt; #+property: header-args :defines cool_macro(x) x #+begin_src C :results output :exports both printf(&quot;cool_macro(7): %u\n&quot;, cool_macro(7)); printf(&quot;cool_macro(7): %u\n&quot;, cool_macro(7)); #+end_src </code></pre> <p>Am I doing something really wrong or what?</p> <p>Thanks.</p> <p>Edit: Solution.</p> <p>Ok, of course the solution was in the docs: <a href="https://org-babel.readthedocs.io/en/latest/header-args/#buffer-or-file-level-header-arguments">https://org-babel.readthedocs.io/en/latest/header-args/#buffer-or-file-level-header-arguments</a> .The problem was that I was rewriting the headers, doing it multiline. The proper way to do it is in oneline or specifying that it should be appended to the existent headers with a <code>+</code>. This is how it looks when it works properly:</p> <pre><code>#+property: header-args :results output :exports both #+property: header-args+ :includes &lt;stdio.h&gt; #+property: header-args+ :defines cool_macro(x) x #+begin_src C printf(&quot;cool_macro(7): %u\n&quot;, cool_macro(7)); printf(&quot;cool_macro(7): %u\n&quot;, cool_macro(7)); #+end_src #+RESULTS: : cool_macro(7): 7 : cool_macro(7): 7 </code></pre> <p>Thanks for the help!</p> </div><!-- SC_ON --> &#32; submitted by &#32; <a href="https://www.reddit.com/user/mefff_"> /u/mefff_ </a> <br/> <span><a href="https://www.reddit.com/r/orgmode/comments/qwbk6b/orgbabel_c_and_cmacros/">[link]</a></span> &#32; <span><a href="https://www.reddit.com/r/orgmode/comments/qwbk6b/orgbabel_c_and_cmacros/">[comments]</a></span>