From mboxrd@z Thu Jan 1 00:00:00 1970 From: Thibault Marin Subject: Re: Tangling org file with nested org source block Date: Fri, 20 Oct 2017 23:05:08 -0500 Message-ID: <87wp3pcfij.fsf@dell-desktop.WORKGROUP> References: <87ing3h702.fsf@dell-desktop.WORKGROUP> Reply-To: thibault.marin@gmx.com Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:48136) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e5l2F-00076R-M6 for emacs-orgmode@gnu.org; Sat, 21 Oct 2017 00:05:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e5l2A-0005YO-Iv for emacs-orgmode@gnu.org; Sat, 21 Oct 2017 00:05:19 -0400 Received: from mout.gmx.net ([212.227.17.22]:56086) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1e5l2A-0005Xo-7e for emacs-orgmode@gnu.org; Sat, 21 Oct 2017 00:05:14 -0400 Received: from dell-desktop ([99.47.196.62]) by mail.gmx.com (mrgmx101 [212.227.17.174]) with ESMTPSA (Nemesis) id 0MKu9E-1e5l272LmS-0002Ps for ; Sat, 21 Oct 2017 06:05:12 +0200 In-reply-to: <87ing3h702.fsf@dell-desktop.WORKGROUP> 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" To: "emacs-orgmode@gnu.org" --=-=-= Content-Type: text/plain Following-up on the issue I reported some time ago with tangling of nested source blocks, I would like to propose a patch for review. Before the patch, the following file: ,---- | #+PROPERTY: header-args :tangle output.org | | #+BEGIN_SRC org | | ,* Test | | ,#+BEGIN_SRC org | ,,#+BEGIN_SRC emacs-lisp | '(1 2 3) | ,,#+END_SRC | ,#+END_SRC | | #+END_SRC `---- is tangled to: ,---- output.org | * Test | | #+BEGIN_SRC org | #+BEGIN_SRC emacs-lisp | '(1 2 3) | #+END_SRC | #+END_SRC `---- which misses the escaping (commas) for the inner source block. Tangling after applying the proposed patch results in: ,---- output.org | * Test | | #+BEGIN_SRC org | ,#+BEGIN_SRC emacs-lisp | '(1 2 3) | ,#+END_SRC | #+END_SRC `---- which is properly escaped. The patch also contains a simple test to validate tangling of nested blocks. Could this be considered for a merge? Thanks in advance thibault --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-ob-tangle.el-Fix-tangling-of-org-block-with-nested-s.patch >From 6300856f8b9623b1ac0a40b7fe62751805159558 Mon Sep 17 00:00:00 2001 From: thibault Date: Fri, 20 Oct 2017 22:20:35 -0500 Subject: [PATCH] ob-tangle.el: Fix tangling of org block with nested source block * lisp/ob-tangle.el (org-babel-tangle-single-block): Prevent double unescaping of source block by removing unnecessary call to `org-unescape-code-in-string'. * testing/lisp/test-ob-tangle.el (ob-tangle/nested-block) New function. Test tangle of org block with nested source block. --- lisp/ob-tangle.el | 7 +++---- testing/lisp/test-ob-tangle.el | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/lisp/ob-tangle.el b/lisp/ob-tangle.el index adc680676..09d011fc3 100644 --- a/lisp/ob-tangle.el +++ b/lisp/ob-tangle.el @@ -494,10 +494,9 @@ non-nil, return the full association list to be used by link) source-name params - (org-unescape-code-in-string - (if org-src-preserve-indentation - (org-trim body t) - (org-trim (org-remove-indentation body)))) + (if org-src-preserve-indentation + (org-trim body t) + (org-trim (org-remove-indentation body))) comment))) (if only-this-block (list (cons src-lang (list result))) diff --git a/testing/lisp/test-ob-tangle.el b/testing/lisp/test-ob-tangle.el index 06a73f063..73b75323e 100644 --- a/testing/lisp/test-ob-tangle.el +++ b/testing/lisp/test-ob-tangle.el @@ -197,6 +197,31 @@ another block (org-babel-tangle-jump-to-org) (buffer-string))))))) +(ert-deftest ob-tangle/nested-block () + "Test tangling of org file with nested block." + (should + (string= + "#+begin_src org +,#+begin_src emacs-lisp +1 +,#+end_src +#+end_src +" + (org-test-with-temp-text-in-file + "#+header: :tangle \"test-ob-tangle.org\" +#+begin_src org +,#+begin_src org +,,#+begin_src emacs-lisp +1 +,,#+end_src +,#+end_src +#+end_src" + (unwind-protect + (progn (org-babel-tangle) + (with-temp-buffer (insert-file-contents "test-ob-tangle.org") + (buffer-string))) + (delete-file "test-ob-tangle.org")))))) + (provide 'test-ob-tangle) ;;; test-ob-tangle.el ends here -- 2.14.1 --=-=-=--