Resolve :noweb-ref when set at the property level during noweb expansion

* lisp/ob.el (org-babel-expand-noweb-references): Rather than using a
  pure regexp solution to resolve noweb references, actually check the
  information of every code block in the buffer.  This will cause a
  slowdown in noweb reference expansion, but is necessary for correct
  behavior.
This commit is contained in:
Eric Schulte 2011-12-29 12:46:42 -07:00
parent 44bd38556c
commit 18708a2b5a
1 changed files with 13 additions and 13 deletions

View File

@ -2014,8 +2014,6 @@ 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 (concat "\\(" org-babel-src-name-regexp "\\|"
":noweb-ref[ \t]+" "\\)"))
(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)
@ -2056,19 +2054,21 @@ 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
(let ((rx (concat rx-prefix source-name)) (let (expansion)
expansion)
(save-excursion (save-excursion
(goto-char (point-min)) (goto-char (point-min))
(while (re-search-forward rx nil t) (org-babel-map-src-blocks nil
(let* ((i (org-babel-get-src-block-info 'light)) (let ((i (org-babel-get-src-block-info 'light)))
(body (org-babel-expand-noweb-references i))) (when (equal (or (cdr (assoc :noweb-ref (nth 2 i)))
(if comment (nth 4 i))
((lambda (cs) source-name)
(concat (c-wrap (car cs)) "\n" (let ((body (org-babel-expand-noweb-references i)))
body "\n" (c-wrap (cadr cs)))) (if comment
(org-babel-tangle-comment-links i)) ((lambda (cs)
(setq expansion (concat expansion body)))))) (concat (c-wrap (car cs)) "\n"
body "\n" (c-wrap (cadr cs))))
(org-babel-tangle-comment-links i))
(setq expansion (concat expansion body))))))))
expansion) expansion)
;; 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)