emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[O] [PATCH] COMMENT and noweb-ref


From: Sebastian Miele
Subject: [O] [PATCH] COMMENT and noweb-ref
Date: Sun, 20 Oct 2019 22:09:34 +0000
User-agent: mu4e 1.3.5; emacs 26.3

Attachment: 0001-ob-core-Respect-COMMENTed-headlines-when-expanding-n.patch
Description: Text document

>From 66c7904298a33900e389acb184fbe7511960b34d Mon Sep 17 00:00:00 2001
From: Sebastian Miele <address@hidden>
Date: Sun, 20 Oct 2019 21:38:03 +0000
Subject: [PATCH 2/2] Add tests about omission of commented src blocks when
 e.g. tangling

* testing/lisp/test-ob.el (test-ob/noweb-expansion): Add clause to
test.
* testing/lisp/test-ob-tangle.el (ob-tangle/commented-src-blocks): Add
test.
---
 testing/lisp/test-ob-tangle.el | 84 ++++++++++++++++++++++++++++++++++
 testing/lisp/test-ob.el        | 24 ++++++++++
 2 files changed, 108 insertions(+)

diff --git a/testing/lisp/test-ob-tangle.el b/testing/lisp/test-ob-tangle.el
index 47c31dff5..301f7aff7 100644
--- a/testing/lisp/test-ob-tangle.el
+++ b/testing/lisp/test-ob-tangle.el
@@ -296,6 +296,90 @@ another block
                    (org-split-string (buffer-string))))
              (delete-file file))))))
 
+(ert-deftest ob-tangle/commented-src-blocks ()
+  "Test omission of commented src blocks."
+  (should
+   (equal '("A")
+         (let ((file (make-temp-file "org-tangle-")))
+           (unwind-protect
+               (progn
+                 (org-test-with-temp-text-in-file
+                     (format "#+property: header-args :tangle %S
+* A
+
+  #+begin_src emacs-lisp
+  A
+  #+end_src
+
+* COMMENT B
+
+  #+begin_src emacs-lisp
+  B
+  #+end_src
+
+* C
+
+  # #+begin_src emacs-lisp
+  # C
+  # #+end_src
+
+* D
+
+  #+begin_comment
+  #+begin_src emacs-lisp
+  D
+  #+end_src
+  #+end_comment"
+                             file)
+                   (org-babel-tangle))
+                 (with-temp-buffer
+                   (insert-file-contents file)
+                   (org-split-string (buffer-string))))
+             (delete-file file)))))
+  (should
+   (equal '("A")
+         (let ((file (make-temp-file "org-tangle-")))
+           (unwind-protect
+               (progn
+                 (org-test-with-temp-text-in-file
+                     (format "#+property: header-args :tangle %S
+* A
+
+  #+begin_src elisp :noweb yes
+  A
+  <<B>>
+  <<C>>
+  <<D>>
+  #+end_src
+
+* COMMENT B
+
+  #+begin_src elisp :noweb-ref B
+  B
+  #+end_src
+
+* C
+
+  # #+begin_src elisp :noweb-ref C
+  # C
+  # #+end_src
+
+* D
+
+  #+begin_comment
+  #+begin_src elisp :noweb-ref D
+  D
+  #+end_src
+  #+end_comment"
+                             file)
+                   (let (org-babel-noweb-error-all-langs
+                         org-babel-noweb-error-langs)
+                     (org-babel-tangle)))
+                 (with-temp-buffer
+                   (insert-file-contents file)
+                   (org-split-string (buffer-string))))
+             (delete-file file))))))
+
 (provide 'test-ob-tangle)
 
 ;;; test-ob-tangle.el ends here
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index 367c70f83..681f3403e 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -758,6 +758,30 @@ x
 #+name: bar
 #+begin_src emacs-lisp
   baz
+#+end_src"
+           (org-babel-expand-noweb-references))))
+  ;; Respect COMMENT headlines
+  (should
+   (equal "C"
+         (org-test-with-temp-text "
+#+begin_src emacs-lisp :noweb yes<point>
+  <<foo>>
+#+end_src
+
+* COMMENT A
+#+name: foo
+#+begin_src emacs-lisp
+  A
+#+end_src
+
+* COMMENT B
+#+begin_src emacs-lisp :noweb-ref foo
+  B
+#+end_src
+
+* C
+#+begin_src emacs-lisp :noweb-ref foo
+  C
 #+end_src"
            (org-babel-expand-noweb-references)))))
 
-- 
2.23.0

I wrote:

> org-babel-tangle on
>
>   * A
>
>     #+BEGIN_SRC elisp :tangle yes :noweb yes
>     ;; A
>     <<B>>
>     #+END_SRC
>
>   * COMMENT B
>
>     #+BEGIN_SRC elisp :noweb-ref B
>     ;; B
>     #+END_SRC
>
>   * COMMENT C
>
>     #+BEGIN_SRC elisp :tangle yes
>     ;; C
>     #+END_SRC
>
> produces a file with A and B in it. Expected: Just A. Changing
>
>     #+BEGIN_SRC elisp :noweb-ref B
>     ;; B
>     #+END_SRC
>
> to
>
>     # #+BEGIN_SRC elisp :noweb-ref B
>     # ;; B
>     # #+END_SRC
>
> does yield the expected result.

Attached is a patch that fixes the problem.

A second patch is attached that contains tests about this and related
stuff. It is an updated version of an unapplied patch that I
sent to this list earlier this month
(https://lists.gnu.org/archive/html/emacs-orgmode/2019-10/msg00013.html).

Best wishes
Sebastian

reply via email to

[Prev in Thread] Current Thread [Next in Thread]