From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alan Schmitt Subject: Re: Chaining strings between babel blocks: why so many '\'? Date: Thu, 27 Mar 2014 13:41:03 +0100 Message-ID: References: <87bnwstxfs.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56607) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WTA3o-0004aY-85 for emacs-orgmode@gnu.org; Thu, 27 Mar 2014 09:09:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WTA3i-00022J-88 for emacs-orgmode@gnu.org; Thu, 27 Mar 2014 09:09:32 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:49935) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WTA3i-000222-1L for emacs-orgmode@gnu.org; Thu, 27 Mar 2014 09:09:26 -0400 In-Reply-To: <87bnwstxfs.fsf@gmail.com> (Nicolas Goaziou's message of "Wed, 26 Mar 2014 23:19:35 +0100") 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: Nicolas Goaziou Cc: emacs-orgmode --=-=-= Content-Type: text/plain Hello Nicolas, Nicolas Goaziou writes: > Hello, > > Alan Schmitt writes: > >> I've been playing with block chaining to generate some dot file then to >> export then as images. I had a little trouble finding the number of '\' >> I need to put in front of a quote if I want the quote to be quoted. Here >> is a way to make it work: >> >> #+name: foo >> #+begin_src emacs-lisp :exports none >> "bar [label = \"\\\\\"test1\\\\\"\"]\nbaz [label = \"\\\\\"test2\\\\\"\"]" >> #+end_src >> >> #+results: foo >> : bar [label = "\\"test1\\""] >> : baz [label = "\\"test2\\""] >> >> #+begin_src dot :file ~/tmp/test-dot.png :var input=foo :exports results >> graph { >> $input >> } >> #+end_src >> >> My question is: why can't I simply use this: >> >> #+name: foo >> #+begin_src emacs-lisp :exports none >> "bar [label = \"\\\"test1\\\"\"]\nbaz [label = \"\\\"test2\\\"\"]" >> #+end_src >> >> #+results: foo >> : bar [label = "\"test1\""] >> : baz [label = "\"test2\""] >> >> (I guess the answer is in the error in replace-regexp-in-string: >> (error "Invalid use of `\\' in replacement text") >> .) > > Indeed. This function, unless told not to, treats backslashes characters > specially. > >> Would it be problematic to first transform every "\\" into a "\\\\" in >> org-babel-expand-body:dot, before the call to >> replace-regexp-in-string? > > I think `replace-regexp-in-string' should be called with a non-nil > LITERAL argument in this case. Yes. I think it should also not try to mach the case (i.e., FIXEDCASE should be non-nil). Here is a patch to do that. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-ob-dot.el-Substitute-variables-literally.patch >From c6437e8b7132d95ca432b0690bf65ede6e248567 Mon Sep 17 00:00:00 2001 From: Alan Schmitt Date: Thu, 27 Mar 2014 13:35:31 +0100 Subject: [PATCH] ob-dot.el: Substitute variables literally * lisp/ob-dot.el (org-babel-expand-body:dot): Do not change the case nor interpret '\' when substituting block variables. --- lisp/ob-dot.el | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lisp/ob-dot.el b/lisp/ob-dot.el index b35d7bb..1e399e7 100644 --- a/lisp/ob-dot.el +++ b/lisp/ob-dot.el @@ -55,7 +55,9 @@ (replace-regexp-in-string (concat "\$" (regexp-quote name)) (if (stringp value) value (format "%S" value)) - body)))) + body + t + t)))) vars) body)) -- 1.8.5.3 --=-=-= Content-Type: text/plain Best, Alan --=-=-=--