* lisp/ob-core.el (org-babel-expand-noweb-references): Change the the
  behavior of noweb expansion by replacing the prefix duplication with
  whitespace.  Fix handling of multiple noweb references on the same
  line by using temporary buffer to replace noweb references in place
  instead of collecting the intervals between references and their
  expansion text into a variable.

* doc/org.texi: Reflect the change by removing the section under
  subheading "Noweb prefix lines".

Tests pass and don't require actualization.
---
 doc/org.texi    | 24 ------------------------
 lisp/ob-core.el | 26 +++++++-------------------
 2 files changed, 7 insertions(+), 43 deletions(-)
diff --git a/doc/org.texi b/doc/org.texi
index 9205abb..876f673 100644
--- a/doc/org.texi
+++ b/doc/org.texi
@@ -15042,30 +15042,6 @@ references will be removed when the code block is exported.
 expanded before the block is evaluated.
 @end itemize
 
-@subsubheading Noweb prefix lines
-Noweb insertions are now placed behind the line prefix of the
-@code{<<reference>>}.
-This behavior is illustrated in the following example.  Because the
-@code{<<example>>} noweb reference appears behind the SQL comment syntax,
-each line of the expanded noweb reference will be commented.
-
-This code block:
-
-@example
--- <<example>>
-@end example
-
-expands to:
-
-@example
--- this is the
--- multi-line body of example
-@end example
-
-Note that noweb replacement text that does not contain any newlines will not
-be affected by this change, so it is still possible to use inline noweb
-references.
-
 @node noweb-ref
 @subsubsection @code{:noweb-ref}
 @cindex @code{:noweb-ref}, src header argument
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 0adfc33..1ae16d7 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2536,34 +2536,23 @@ block but are passed literally to the \"example-block\"."
 	 (comment (string= "noweb" (cdr (assoc :comments (nth 2 info)))))
 	 (rx-prefix (concat "\\(" org-babel-src-name-regexp "\\|"
 			    ":noweb-ref[ \t]+" "\\)"))
-         (new-body "")
-	 (nb-add (lambda (text) (setq new-body (concat new-body text))))
 	 (c-wrap (lambda (text)
 		   (with-temp-buffer
 		     (funcall (intern (concat lang "-mode")))
 		     (comment-region (point) (progn (insert text) (point)))
 		     (org-babel-trim (buffer-string)))))
-	 index source-name evaluate prefix)
+	 source-name evaluate prefix)
     (with-temp-buffer
       (org-set-local 'org-babel-noweb-wrap-start ob-nww-start)
       (org-set-local 'org-babel-noweb-wrap-end ob-nww-end)
       (insert body) (goto-char (point-min))
-      (setq index (point))
-      (while (and (re-search-forward (org-babel-noweb-wrap) nil t))
+      (while (re-search-forward (org-babel-noweb-wrap) nil t)
+	(goto-char (match-beginning 0))
 	(save-match-data (setf source-name (match-string 1)))
 	(save-match-data (setq evaluate (string-match "\(.*\)" source-name)))
-	(save-match-data
-	  (setq prefix
-		(buffer-substring (match-beginning 0)
-				  (save-excursion
-				    (beginning-of-line 1) (point)))))
-	;; add interval to new-body (removing noweb reference)
-	(goto-char (match-beginning 0))
-	(funcall nb-add (buffer-substring index (point)))
-	(goto-char (match-end 0))
-	(setq index (point))
-	(funcall
-         nb-add
+	(save-match-data (setq prefix (make-string (current-column) ?\s)))
+	(delete-region (point) (match-end 0))
+	(insert
          (with-current-buffer parent-buffer
            (save-restriction
              (widen)
@@ -2625,8 +2614,7 @@ block but are passed literally to the \"example-block\"."
                                    "`org-babel-noweb-error-langs')"))
                     "")))
                "[\n\r]") (concat "\n" prefix))))))
-      (funcall nb-add (buffer-substring index (point-max))))
-    new-body))
+      (buffer-string))))
 
 (defun org-babel-script-escape (str &optional force)
   "Safely convert tables into elisp lists."

Reply via email to