Library of Babel source blocks are now available from any org-mode file

This commit is contained in:
Eric Schulte 2009-06-14 15:01:55 -07:00
parent f1302d1cca
commit d72b438f5e
2 changed files with 16 additions and 8 deletions

View File

@ -48,6 +48,9 @@ add files to this list use the `org-babel-lob-ingest' command."
(org-babel-map-source-blocks file
(let ((source-name (intern (org-babel-get-src-block-name)))
(info (org-babel-get-src-block-info)))
;; remove :var elements from params
;; (once we have a better way of combining parameter lists then we won't have to do this)
(setf (third info) (assq-delete-all :var (third info)))
(setq org-babel-library-of-babel
(cons (cons source-name info)
(assq-delete-all source-name org-babel-library-of-babel))))))

View File

@ -90,7 +90,7 @@ return nil."
"Resolve the reference and return it's value"
(save-excursion
(let ((case-fold-search t)
type args new-refere new-referent result)
type args new-refere new-referent result lob-info)
;; assign any arguments to pass to source block
(when (string-match "^\\(.+?\\)\(\\(.*\\)\)$" ref)
(setq new-refere (match-string 1 ref))
@ -112,7 +112,9 @@ return nil."
(or (re-search-forward result_regexp nil t)
(re-search-forward result_regexp nil t)
(re-search-forward regexp nil t)
(re-search-backward regexp nil t)))
(re-search-backward regexp nil t)
;; check the Library of Babel
(setq lob-info (cdr (assoc (intern ref) org-babel-library-of-babel)))))
;; ;; TODO: allow searching for names in other buffers
;; (setq id-loc (org-id-find ref 'marker)
;; buffer (marker-buffer id-loc)
@ -120,11 +122,13 @@ return nil."
;; (move-marker id-loc nil)
(progn (message (format "reference '%s' not found in this buffer" ref))
(error (format "reference '%s' not found in this buffer" ref))))
(while (not (setq type (org-babel-ref-at-ref-p)))
(forward-line 1)
(beginning-of-line)
(if (or (= (point) (point-min)) (= (point) (point-max)))
(error "reference not found")))
(if lob-info
(setq type 'lob)
(while (not (setq type (org-babel-ref-at-ref-p)))
(forward-line 1)
(beginning-of-line)
(if (or (= (point) (point-min)) (= (point) (point-max)))
(error "reference not found"))))
(case type
('table
(mapcar (lambda (row)
@ -134,7 +138,8 @@ return nil."
('source-block
(setq result (org-babel-execute-src-block
t nil (org-combine-plists args nil)))
(if (symbolp result) (format "%S" result) result))))))
(if (symbolp result) (format "%S" result) result))
('lob (setq result (org-babel-execute-src-block t lob-info args)))))))
(defun org-babel-ref-at-ref-p ()
"Return the type of reference located at point or nil of none