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.
This commit is contained in:
Eric Schulte 2011-12-11 09:28:58 -07:00
parent a706d16127
commit 1b58f780cf
1 changed files with 16 additions and 24 deletions

View File

@ -2072,21 +2072,14 @@ block but are passed literally to the \"example-block\"."
(lang (nth 0 info)) (lang (nth 0 info))
(body (nth 1 info)) (body (nth 1 info))
(comment (string= "noweb" (cdr (assoc :comments (nth 2 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) (new-body "") index source-name evaluate prefix blocks-in-buffer)
(flet ((nb-add (text) (setq new-body (concat new-body text))) (flet ((nb-add (text) (setq new-body (concat new-body text)))
(c-wrap (text) (c-wrap (text)
(with-temp-buffer (with-temp-buffer
(funcall (intern (concat lang "-mode"))) (funcall (intern (concat lang "-mode")))
(comment-region (point) (progn (insert text) (point))) (comment-region (point) (progn (insert text) (point)))
(org-babel-trim (buffer-string)))) (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))))
(with-temp-buffer (with-temp-buffer
(insert body) (goto-char (point-min)) (insert body) (goto-char (point-min))
(setq index (point)) (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) (when (org-babel-ref-goto-headline-id source-name)
(org-babel-ref-headline-body))) (org-babel-ref-headline-body)))
;; find the expansion of reference in this buffer ;; find the expansion of reference in this buffer
(mapconcat (let ((rx (concat rx-prefix "[ \t]+" source-name))
(lambda (i) expansion)
(when (string= source-name (save-excursion
(or (cdr (assoc :noweb-ref (nth 2 i))) (goto-char (point-min))
(nth 4 i))) (while (re-search-forward rx nil t)
(let ((body (org-babel-expand-noweb-references i))) (let* ((i (org-babel-get-src-block-info 'light))
(body (org-babel-expand-noweb-references i)))
(if comment (if comment
((lambda (cs) ((lambda (cs)
(concat (c-wrap (car cs)) "\n" (concat (c-wrap (car cs)) "\n"
body "\n" (c-wrap (cadr cs)))) body "\n" (c-wrap (cadr cs))))
(org-babel-tangle-comment-links i)) (org-babel-tangle-comment-links i))
body)))) (setq expansion (concat expansion body))))))
(or blocks-in-buffer expansion)
(setq blocks-in-buffer (blocks)))
"")
;; possibly raise an error if named block doesn't exist ;; possibly raise an error if named block doesn't exist
(if (member lang org-babel-noweb-error-langs) (if (member lang org-babel-noweb-error-langs)
(error "%s" (concat (error "%s" (concat