ob-tangle: continued code blocks now implemented with the :noweb-ref header arg

Now *all* code blocks which either are named `ref-name' or have the
  :noweb-ref header argument value `ref-name' will have their bodies
  concatenated when resolving the noweb reference <<ref-name>>.

* lisp/ob.el (org-babel-expand-noweb-references): Concatenating all
  bodies with the appropriate name or :noweb-ref header argument.
This commit is contained in:
Eric Schulte 2011-06-15 21:14:03 -07:00
parent 23e7adbdaa
commit 8c37281cb6
1 changed files with 33 additions and 28 deletions

View File

@ -1842,13 +1842,21 @@ 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)))))
(new-body "") index source-name evaluate prefix) (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))
@ -1873,35 +1881,32 @@ block but are passed literally to the \"example-block\"."
(if evaluate (if evaluate
(let ((raw (org-babel-ref-resolve source-name))) (let ((raw (org-babel-ref-resolve source-name)))
(if (stringp raw) raw (format "%S" raw))) (if (stringp raw) raw (format "%S" raw)))
(or (nth 2 (assoc (intern source-name) (or
org-babel-library-of-babel)) ;; retrieve from the library of babel
(save-restriction (nth 2 (assoc (intern source-name)
(widen) org-babel-library-of-babel))
(let ((point (org-babel-find-named-block ;; find the expansion of reference in this buffer
source-name))) (or (mapconcat
(if point (lambda (i)
(save-excursion (when (string= source-name
(goto-char point) (or (cdr (assoc :noweb-ref (nth 2 i)))
;; possibly wrap body in comments (nth 4 i)))
(let* ((i (org-babel-get-src-block-info 'light)) (let ((body (org-babel-expand-noweb-references i)))
(body (org-babel-trim (if comment
(org-babel-expand-noweb-references ((lambda (cs) (concat (c-wrap (car cs)) "\n"
i)))) body "\n" (c-wrap (cadr cs))))
(if comment (org-babel-tangle-comment-links i))
((lambda (cs) (concat (c-wrap (car cs)) "\n" body))))
body (or blocks-in-buffer
"\n" (c-wrap (cadr cs)))) (setq blocks-in-buffer (blocks)))
(org-babel-tangle-comment-links i)) "")
body))) ;; possibly raise an error if named block doesn't exist
;; optionally raise an error if named (if (member lang org-babel-noweb-error-langs)
;; source-block doesn't exist (error "%s" (concat
(if (member lang org-babel-noweb-error-langs)
(error "%s"
(concat
"<<" source-name ">> " "<<" source-name ">> "
"could not be resolved (see " "could not be resolved (see "
"`org-babel-noweb-error-langs')")) "`org-babel-noweb-error-langs')"))
"")))))) ""))))
"[\n\r]") (concat "\n" prefix))))) "[\n\r]") (concat "\n" prefix)))))
(nb-add (buffer-substring index (point-max))))) (nb-add (buffer-substring index (point-max)))))
new-body)) new-body))