emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Chaining strings between babel blocks: why so many '\'?
@ 2014-03-26 21:59 Alan Schmitt
  2014-03-26 22:19 ` Nicolas Goaziou
  0 siblings, 1 reply; 7+ messages in thread
From: Alan Schmitt @ 2014-03-26 21:59 UTC (permalink / raw)
  To: emacs-orgmode

Hello,

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:

--8<---------------cut here---------------start------------->8---
#+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
--8<---------------cut here---------------end--------------->8---

My question is: why can't I simply use this:

--8<---------------cut here---------------start------------->8---
#+name: foo
#+begin_src emacs-lisp :exports none
"bar [label = \"\\\"test1\\\"\"]\nbaz [label = \"\\\"test2\\\"\"]"
#+end_src

#+results: foo
: bar [label = "\"test1\""]
: baz [label = "\"test2\""]
--8<---------------cut here---------------end--------------->8---

(I guess the answer is in the error in replace-regexp-in-string:
(error "Invalid use of `\\' in replacement text")
.)

Would it be problematic to first transform every "\\" into a "\\\\" in
org-babel-expand-body:dot, before the call to replace-regexp-in-string?

Thanks,

Alan

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Chaining strings between babel blocks: why so many '\'?
  2014-03-26 21:59 Chaining strings between babel blocks: why so many '\'? Alan Schmitt
@ 2014-03-26 22:19 ` Nicolas Goaziou
  2014-03-26 23:35   ` Peter Neilson
  2014-03-27 12:41   ` Alan Schmitt
  0 siblings, 2 replies; 7+ messages in thread
From: Nicolas Goaziou @ 2014-03-26 22:19 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: emacs-orgmode

Hello,

Alan Schmitt <alan.schmitt@polytechnique.org> 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.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Chaining strings between babel blocks: why so many '\'?
  2014-03-26 22:19 ` Nicolas Goaziou
@ 2014-03-26 23:35   ` Peter Neilson
  2014-03-27 12:41   ` Alan Schmitt
  1 sibling, 0 replies; 7+ messages in thread
From: Peter Neilson @ 2014-03-26 23:35 UTC (permalink / raw)
  To: emacs-orgmode

On Wed, 26 Mar 2014 18:19:35 -0400, Nicolas Goaziou <n.goaziou@gmail.com>  
wrote:

> Hello,
>
> Alan Schmitt <alan.schmitt@polytechnique.org> 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.

Maybe someone (neilson runs and hides!) should write a tool that allows  
construction of C++11-style raw string literals that would  
auto-transmogrify into the backslash mess that elisp requires.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Chaining strings between babel blocks: why so many '\'?
  2014-03-26 22:19 ` Nicolas Goaziou
  2014-03-26 23:35   ` Peter Neilson
@ 2014-03-27 12:41   ` Alan Schmitt
  2014-03-29 11:10     ` Alan Schmitt
  1 sibling, 1 reply; 7+ messages in thread
From: Alan Schmitt @ 2014-03-27 12:41 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 1616 bytes --]

Hello Nicolas,

Nicolas Goaziou <n.goaziou@gmail.com> writes:

> Hello,
>
> Alan Schmitt <alan.schmitt@polytechnique.org> 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-dot.el-Substitute-variables-literally.patch --]
[-- Type: text/x-patch, Size: 751 bytes --]

From c6437e8b7132d95ca432b0690bf65ede6e248567 Mon Sep 17 00:00:00 2001
From: Alan Schmitt <alan.schmitt@polytechnique.org>
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


[-- Attachment #3: Type: text/plain, Size: 13 bytes --]


Best,

Alan

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: Chaining strings between babel blocks: why so many '\'?
  2014-03-27 12:41   ` Alan Schmitt
@ 2014-03-29 11:10     ` Alan Schmitt
  2014-04-16 15:37       ` Bastien
  0 siblings, 1 reply; 7+ messages in thread
From: Alan Schmitt @ 2014-03-29 11:10 UTC (permalink / raw)
  To: Eric Schulte; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 99 bytes --]

Hi Eric,

I see you are the author of ob-dot.el. Should I push the attached patch?

Thanks,

Alan


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-dot.el-Substitute-variables-literally.patch --]
[-- Type: text/x-patch, Size: 751 bytes --]

From c6437e8b7132d95ca432b0690bf65ede6e248567 Mon Sep 17 00:00:00 2001
From: Alan Schmitt <alan.schmitt@polytechnique.org>
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


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: Chaining strings between babel blocks: why so many '\'?
  2014-03-29 11:10     ` Alan Schmitt
@ 2014-04-16 15:37       ` Bastien
  2014-04-16 18:01         ` Alan Schmitt
  0 siblings, 1 reply; 7+ messages in thread
From: Bastien @ 2014-04-16 15:37 UTC (permalink / raw)
  To: Alan Schmitt; +Cc: emacs-orgmode, Eric Schulte

Hi Alan,

Alan Schmitt <alan.schmitt@polytechnique.org> writes:

> I see you are the author of ob-dot.el. Should I push the attached
> patch?

I applied the patch in the master branch, so that Eric can revert it
without too much trouble if needed -- but I think it's not needed.

Thanks,

-- 
 Bastien

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Chaining strings between babel blocks: why so many '\'?
  2014-04-16 15:37       ` Bastien
@ 2014-04-16 18:01         ` Alan Schmitt
  0 siblings, 0 replies; 7+ messages in thread
From: Alan Schmitt @ 2014-04-16 18:01 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode, Eric Schulte

On 2014-04-16 17:37, Bastien <bzg@gnu.org> writes:

> Hi Alan,
>
> Alan Schmitt <alan.schmitt@polytechnique.org> writes:
>
>> I see you are the author of ob-dot.el. Should I push the attached
>> patch?
>
> I applied the patch in the master branch, so that Eric can revert it
> without too much trouble if needed -- but I think it's not needed.

Thanks a lot,

Alan

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-04-16 18:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-26 21:59 Chaining strings between babel blocks: why so many '\'? Alan Schmitt
2014-03-26 22:19 ` Nicolas Goaziou
2014-03-26 23:35   ` Peter Neilson
2014-03-27 12:41   ` Alan Schmitt
2014-03-29 11:10     ` Alan Schmitt
2014-04-16 15:37       ` Bastien
2014-04-16 18:01         ` Alan Schmitt

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).