emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Pontus Michael <m.pontus@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] Noweb expansion doesn't duplicate prefix across lines
Date: Tue, 1 Apr 2014 06:19:56 +0400	[thread overview]
Message-ID: <CAPpfmH+n=K5YL+vSGkj6k9xLco8PmOJzMXi=CDBekNBa0ZRBxQ@mail.gmail.com> (raw)

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

             reply	other threads:[~2014-04-01  2:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-01  2:19 Pontus Michael [this message]
2014-04-02 23:07 ` [PATCH] Noweb expansion doesn't duplicate prefix across lines Eric Schulte
  -- strict thread matches above, loose matches on Subject: below --
2014-04-03 17:37 Pontus Michael

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPpfmH+n=K5YL+vSGkj6k9xLco8PmOJzMXi=CDBekNBa0ZRBxQ@mail.gmail.com' \
    --to=m.pontus@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).