emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] Noweb expansion doesn't duplicate prefix across lines
@ 2014-04-01  2:19 Pontus Michael
  2014-04-02 23:07 ` Eric Schulte
  0 siblings, 1 reply; 3+ messages in thread
From: Pontus Michael @ 2014-04-01  2:19 UTC (permalink / raw)
  To: emacs-orgmode

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

* 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(-)

[-- Attachment #2: 0001-Noweb-expansion-doesn-t-duplicate-prefix-across-line.patch --]
[-- Type: text/x-patch, Size: 3348 bytes --]

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."

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

* Re: [PATCH] Noweb expansion doesn't duplicate prefix across lines
  2014-04-01  2:19 [PATCH] Noweb expansion doesn't duplicate prefix across lines Pontus Michael
@ 2014-04-02 23:07 ` Eric Schulte
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Schulte @ 2014-04-02 23:07 UTC (permalink / raw)
  To: Pontus Michael; +Cc: emacs-orgmode

This simply seems to trade one use case (noweb expansion behind a
prefix), with another (multiple noweb expansions on the same line).

Is there a way to support both use cases?

Pontus Michael <m.pontus@gmail.com> writes:

> * 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(-)
>

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D

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

* Re: [PATCH] Noweb expansion doesn't duplicate prefix across lines
@ 2014-04-03 17:37 Pontus Michael
  0 siblings, 0 replies; 3+ messages in thread
From: Pontus Michael @ 2014-04-03 17:37 UTC (permalink / raw)
  To: schulte.eric, emacs-orgmode

Hello Eric.

I produced a list of arguments in the support of this change, which
can be reviewed here:
http://lists.gnu.org/archive/html/emacs-orgmode/2014-03/msg01543.html

Please let me know if your question still stands after taking those
concerns into account.

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

end of thread, other threads:[~2014-04-03 17:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-04-01  2:19 [PATCH] Noweb expansion doesn't duplicate prefix across lines Pontus Michael
2014-04-02 23:07 ` Eric Schulte
  -- strict thread matches above, loose matches on Subject: below --
2014-04-03 17:37 Pontus Michael

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).