From 1b58f780cf470c890fdfe960d08c33f0ba7913aa Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Sun, 11 Dec 2011 09:28:58 -0700 Subject: [PATCH] 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 -- git format-patch -1 --stdout -C 1b58f780cf470c890fdfe960d08c33f0ba7913aa