Alan Schmitt <alan.schmitt <at> polytechnique.org> writes: > > Hello, > > I'm trying to write some filters from Pygments, and to record what I'm > doing and make my life simpler, I'm doing it in an orgmode buffer. In > that buffer, I have the code I want to highlight in a source block, and > the python code for the Pygments extension in another block. I'm trying > to find out how to pass the escaped code from the source to highlight to > the python buffer. > > I tried using noweb, but the expansion is verbatim and python complains > about the line breaks. So I'm wondering if there is a way to: > - pass a source block as an escaped string to another source block, or > - save a source block to a temporary file, and pass the file name to > a second source block. >
defun a function that formats your src block, then use it in a header :var x=(foo "src-block-name") or maybe wrap (foo ...) in a `format' call or `prin1-to-string' call. An example is below. === Another alternative is to use this idiom (see 14.10 Noweb reference syntax) <<code-block-name(optional arguments)>> where the code-block-name specifies a formatter (in elisp, say) and the optional argument is the name of the code block you want to format. HTH, Chuck ,---- | #+NAME: prin-block | #+BEGIN_SRC emacs-lisp :var a="abc" | (defun foo (blk) | (save-excursion | (org-babel-goto-named-src-block blk) | (nth 1 (org-babel-get-src-block-info 'light)))) | | #+END_SRC | | #+NAME: weird-text | #+BEGIN_SRC python | just some plain text; | | \\ a double slash | | escape eol \n | | OK?? | #+END_SRC | | | #+BEGIN_SRC python :var a=(foo "weird-text") :results output | print(a); | #+END_SRC | | #+RESULTS: | : just some plain text; | : | : \\ a double slash | : | : escape eol \n | : | : OK?? | | #+header: :var a=(prin1-to-string (foo "weird-text")) | #+BEGIN_SRC python :results output | print(a); | #+END_SRC | | #+RESULTS: | : "just some plain text; | : | : \\\\ a double slash | : | : escape eol \\n | : | : OK??" `----