From mboxrd@z Thu Jan 1 00:00:00 1970 From: Charles Berry Subject: Re: passing the contents of a block as an escaped string Date: Tue, 24 Jun 2014 16:37:23 +0000 (UTC) Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:60832) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzTj6-0005ka-Ni for emacs-orgmode@gnu.org; Tue, 24 Jun 2014 12:37:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WzTj0-0001h3-0B for emacs-orgmode@gnu.org; Tue, 24 Jun 2014 12:37:44 -0400 Received: from plane.gmane.org ([80.91.229.3]:60521) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WzTiz-0001gs-Om for emacs-orgmode@gnu.org; Tue, 24 Jun 2014 12:37:37 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1WzTiw-0000ut-GG for emacs-orgmode@gnu.org; Tue, 24 Jun 2014 18:37:34 +0200 Received: from 137.110.38.64 ([137.110.38.64]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 24 Jun 2014 18:37:34 +0200 Received: from ccberry by 137.110.38.64 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 24 Jun 2014 18:37:34 +0200 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Alan Schmitt 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) <> 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??" `----