[O] [PATCH] COMMENT and noweb-ref

2019-10-20 Thread Sebastian Miele
Sorry. I messed up the previous mail. Please ignore it.

I wrote:

> org-babel-tangle on
>
>   * A
>
> #+BEGIN_SRC elisp :tangle yes :noweb yes
> ;; A
> <>
> #+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
>From ddf0b6d89d30766158311c047d6de10091cb0377 Mon Sep 17 00:00:00 2001
From: Sebastian Miele 
Date: Sun, 20 Oct 2019 21:34:02 +
Subject: [PATCH 1/2] ob-core: Respect COMMENTed headlines when expanding noweb
 references

* lisp/ob-core.el (org-babel-expand-noweb-references): Add calls to
org-in-commented-heading-p where appropriate.
---
 lisp/ob-core.el | 21 -
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 572f97919..b99545ab5 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2780,7 +2780,8 @@ block but are passed literally to the \"example-block\"."
(concat (funcall c-wrap (car cs)) "\n"
b "\n"
(funcall c-wrap (cadr cs)
- (if (re-search-forward name-regexp nil t)
+ (if (and (re-search-forward name-regexp nil t)
+  (not (org-in-commented-heading-p)))
  ;; Found a source block named SOURCE-NAME.
  ;; Assume it is unique; do not look after
  ;; `:noweb-ref' header argument.
@@ -2791,14 +2792,16 @@ block but are passed literally to the 
\"example-block\"."
;; those with a matching Noweb reference.
(let ((expansion nil))
  (org-babel-map-src-blocks nil
-   (let* ((info (org-babel-get-src-block-info 'light))
-  (parameters (nth 2 info)))
- (when (equal source-name
-  (cdr (assq :noweb-ref parameters)))
-   (push (funcall expand-body info) expansion)
-   (push (or (cdr (assq :noweb-sep parameters))
- "\n")
- expansion
+   (unless (org-in-commented-heading-p)
+ (let* ((info
+ (org-babel-get-src-block-info 'light))
+(parameters (nth 2 info)))
+   (when (equal source-name
+(cdr (assq :noweb-ref parameters)))
+ (push (funcall expand-body info) expansion)
+ (push (or (cdr (assq :noweb-sep parameters))
+   "\n")
+   expansion)
  (when expansion
(mapconcat #'identity
   (nreverse (cdr expansion))
-- 
2.23.0

>From 66c7904298a33900e389acb184fbe7511960b34d Mon Sep 17 00:00:00 2001
From: Sebastian Miele 
Date: Sun, 20 Oct 2019 21:38:03 +
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
+  

[O] [PATCH] COMMENT and noweb-ref

2019-10-20 Thread Sebastian Miele
>From ddf0b6d89d30766158311c047d6de10091cb0377 Mon Sep 17 00:00:00 2001
From: Sebastian Miele 
Date: Sun, 20 Oct 2019 21:34:02 +
Subject: [PATCH 1/2] ob-core: Respect COMMENTed headlines when expanding noweb
 references

* lisp/ob-core.el (org-babel-expand-noweb-references): Add calls to
org-in-commented-heading-p where appropriate.
---
 lisp/ob-core.el | 21 -
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 572f97919..b99545ab5 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2780,7 +2780,8 @@ block but are passed literally to the \"example-block\"."
(concat (funcall c-wrap (car cs)) "\n"
b "\n"
(funcall c-wrap (cadr cs)
- (if (re-search-forward name-regexp nil t)
+ (if (and (re-search-forward name-regexp nil t)
+  (not (org-in-commented-heading-p)))
  ;; Found a source block named SOURCE-NAME.
  ;; Assume it is unique; do not look after
  ;; `:noweb-ref' header argument.
@@ -2791,14 +2792,16 @@ block but are passed literally to the 
\"example-block\"."
;; those with a matching Noweb reference.
(let ((expansion nil))
  (org-babel-map-src-blocks nil
-   (let* ((info (org-babel-get-src-block-info 'light))
-  (parameters (nth 2 info)))
- (when (equal source-name
-  (cdr (assq :noweb-ref parameters)))
-   (push (funcall expand-body info) expansion)
-   (push (or (cdr (assq :noweb-sep parameters))
- "\n")
- expansion
+   (unless (org-in-commented-heading-p)
+ (let* ((info
+ (org-babel-get-src-block-info 'light))
+(parameters (nth 2 info)))
+   (when (equal source-name
+(cdr (assq :noweb-ref parameters)))
+ (push (funcall expand-body info) expansion)
+ (push (or (cdr (assq :noweb-sep parameters))
+   "\n")
+   expansion)
  (when expansion
(mapconcat #'identity
   (nreverse (cdr expansion))
-- 
2.23.0

>From 66c7904298a33900e389acb184fbe7511960b34d Mon Sep 17 00:00:00 2001
From: Sebastian Miele 
Date: Sun, 20 Oct 2019 21:38:03 +
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
+  <>
+  <>
+  <>
+  #+end_src
+
+* COMMENT B
+
+  #+begin_src elisp :noweb-ref B
+  B
+  #+end_src
+
+* C
+
+  # #+begin_src elisp :noweb-ref C
+