1

I want to have: - a source code block fontified on export - but not executed - and used as input for another source code block.

I can have it fontified in org-mode and not exported if I use a begin_example block. But can I let it be fontified on export (to html or latex) es well? Or, vice versa, can I suppress a begin_src from being executed?

What I have so far is this:

#+name: uninterpreted_sh
#+header: :exports code
#+begin_src sh
echo "Direct"
#+end_src

#+name: uninterpreted
#+begin_example sh
echo "Direct"
#+end_example

#+header: :exports both
#+header: :results output
#+begin_src sh :stdin uninterpreted
VALUE=$(cat)
echo "I got: $VALUE"
#+end_src

#+RESULTS:
: I got: echo "Direct"

There I can get uninterpreted_sh fontified and can use uninterpreted as stdin.

A last resort might be to supress the begin_example from beeing exported altogether?

Note: ther results I get from the last source block is exactly what I want.

4
  • src blocks aren't evaluated with the :exports code argument. They are evaluated when you pass them as the argument to :stdin. If you change your begin_example block to a begin_src block, doesn't that give you what you want?
    – Tyler
    Jul 5, 2016 at 15:40
  • unfortunately no, because then the shell will be called with echo "Direct" writing Driectto stdout which then is used as result and as stdin for the next block. But I want the whole source block as is to be put as input.
    – theldoria
    Jul 5, 2016 at 18:21
  • In other words, I wand to get as result : I got: echo "Direct", and not : I got: Direct.
    – theldoria
    Jul 5, 2016 at 18:22
  • I would be happy if an example block wiith a language argument would be highlighted. Surprisingly the example block looks like a source block with correct language specific mode in org buffer.
    – theldoria
    Jul 5, 2016 at 18:25

1 Answer 1

0

I have a solution, although it's not perfect.

I advice the export function of the source block language in question:

(defun org-babel-execute-exports-code-around (org-fun &rest args)
  "Do not execute code blocks that exports code."
  (let ((exports (cdr (assoc :exports (cadr args)))))
    (if (string= exports "code")
        (car args)
      (apply org-fun args))))
(advice-add 'org-babel-execute:shell :around #'org-babel-execute-exports-code-around)

Then I get what I wanted with the following org file:

#+name: uninterpreted_sh
#+header: :exports code
#+begin_src sh
echo "Direct"
#+end_src

#+header: :exports both
#+header: :results output
#+begin_src sh :stdin uninterpreted_sh
VALUE=$(cat)
echo "I got: $VALUE"
#+end_src

#+RESULTS:
: I got: echo "Direct"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.