emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
   commit 1b58f780cf470c890fdfe960d08c33f0ba7913aa (patch)
   parent a706d1612 wrap code block results in drawers rather than blocks
     tree 13ceef7aa4a29ead257b0e9afb128a227fa3a29c
   author Eric Schulte <eric.schulte@gmx.com>  2011-12-11 09:28:58 -0700
committer Eric Schulte <eric.schulte@gmx.com>  2011-12-11 09:51:28 -0700

faster method of collecting continuing code blocks

* lisp/ob.el (org-babel-expand-noweb-references): Rather than collect
  the info from *every* block in the current buffer, simply regexp
  search for those blocks which appear to match the continued source
  name.
---
 lisp/ob.el | 40 ++++++++++++++++------------------------
 1 file changed, 16 insertions(+), 24 deletions(-)

diff --git a/lisp/ob.el b/lisp/ob.el
index 4d779d550..9ae495455 100644
--- a/lisp/ob.el
+++ b/lisp/ob.el
@@ -2072,21 +2072,14 @@ block but are passed literally to the \"example-block\"."
          (lang (nth 0 info))
          (body (nth 1 info))
 	 (comment (string= "noweb" (cdr (assoc :comments (nth 2 info)))))
+	 (rx-prefix (regexp-opt (list org-babel-src-name-regexp ":noweb-ref")))
          (new-body "") index source-name evaluate prefix blocks-in-buffer)
     (flet ((nb-add (text) (setq new-body (concat new-body text)))
 	   (c-wrap (text)
 		   (with-temp-buffer
 		     (funcall (intern (concat lang "-mode")))
 		     (comment-region (point) (progn (insert text) (point)))
-		     (org-babel-trim (buffer-string))))
-	   (blocks () ;; return the info lists of all blocks in this buffer
-		   (let (infos)
-		     (save-restriction
-		       (widen)
-		       (org-babel-map-src-blocks nil
-			 (setq infos (cons (org-babel-get-src-block-info 'light)
-					   infos))))
-		     (reverse infos))))
+		     (org-babel-trim (buffer-string)))))
       (with-temp-buffer
         (insert body) (goto-char (point-min))
         (setq index (point))
@@ -2120,21 +2113,20 @@ block but are passed literally to the \"example-block\"."
 		    (when (org-babel-ref-goto-headline-id source-name)
 		      (org-babel-ref-headline-body)))
 		  ;; find the expansion of reference in this buffer
-		  (mapconcat
-		   (lambda (i)
-		     (when (string= source-name
-				    (or (cdr (assoc :noweb-ref (nth 2 i)))
-					(nth 4 i)))
-		       (let ((body (org-babel-expand-noweb-references i)))
-			 (if comment
-			     ((lambda (cs)
-				(concat (c-wrap (car cs)) "\n"
-					body "\n" (c-wrap (cadr cs))))
-			      (org-babel-tangle-comment-links i))
-			   body))))
-		   (or blocks-in-buffer
-		       (setq blocks-in-buffer (blocks)))
-		   "")
+		  (let ((rx (concat rx-prefix "[ \t]+" source-name))
+			expansion)
+		    (save-excursion
+		      (goto-char (point-min))
+		      (while (re-search-forward rx nil t)
+			(let* ((i (org-babel-get-src-block-info 'light))
+			       (body (org-babel-expand-noweb-references i)))
+			  (if comment
+			      ((lambda (cs)
+				 (concat (c-wrap (car cs)) "\n"
+					 body "\n" (c-wrap (cadr cs))))
+			       (org-babel-tangle-comment-links i))
+			    (setq expansion (concat expansion body))))))
+		    expansion)
 		  ;; possibly raise an error if named block doesn't exist
 		  (if (member lang org-babel-noweb-error-langs)
 		      (error "%s" (concat


glossary
--------
Commit objects reference one tree, and zero or more parents.

Single parent commits can typically generate a patch in
unified diff format via `git format-patch'.

Multiple parents means the commit is a merge.

Root commits have no ancestor.  Note that it is
possible to have multiple root commits when merging independent histories.

Every commit references one top-level tree object.

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