mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-09-29 18:36:26 +00:00
Library of Babel source blocks are now available from any org-mode file
This commit is contained in:
parent
f1302d1cca
commit
d72b438f5e
|
@ -48,6 +48,9 @@ add files to this list use the `org-babel-lob-ingest' command."
|
||||||
(org-babel-map-source-blocks file
|
(org-babel-map-source-blocks file
|
||||||
(let ((source-name (intern (org-babel-get-src-block-name)))
|
(let ((source-name (intern (org-babel-get-src-block-name)))
|
||||||
(info (org-babel-get-src-block-info)))
|
(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
|
(setq org-babel-library-of-babel
|
||||||
(cons (cons source-name info)
|
(cons (cons source-name info)
|
||||||
(assq-delete-all source-name org-babel-library-of-babel))))))
|
(assq-delete-all source-name org-babel-library-of-babel))))))
|
||||||
|
|
|
@ -90,7 +90,7 @@ return nil."
|
||||||
"Resolve the reference and return it's value"
|
"Resolve the reference and return it's value"
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(let ((case-fold-search t)
|
(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
|
;; assign any arguments to pass to source block
|
||||||
(when (string-match "^\\(.+?\\)\(\\(.*\\)\)$" ref)
|
(when (string-match "^\\(.+?\\)\(\\(.*\\)\)$" ref)
|
||||||
(setq new-refere (match-string 1 ref))
|
(setq new-refere (match-string 1 ref))
|
||||||
|
@ -112,7 +112,9 @@ return nil."
|
||||||
(or (re-search-forward result_regexp nil t)
|
(or (re-search-forward result_regexp nil t)
|
||||||
(re-search-forward result_regexp nil t)
|
(re-search-forward result_regexp nil t)
|
||||||
(re-search-forward 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
|
;; ;; TODO: allow searching for names in other buffers
|
||||||
;; (setq id-loc (org-id-find ref 'marker)
|
;; (setq id-loc (org-id-find ref 'marker)
|
||||||
;; buffer (marker-buffer id-loc)
|
;; buffer (marker-buffer id-loc)
|
||||||
|
@ -120,11 +122,13 @@ return nil."
|
||||||
;; (move-marker id-loc nil)
|
;; (move-marker id-loc nil)
|
||||||
(progn (message (format "reference '%s' not found in this buffer" ref))
|
(progn (message (format "reference '%s' not found in this buffer" ref))
|
||||||
(error (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)))
|
(if lob-info
|
||||||
(forward-line 1)
|
(setq type 'lob)
|
||||||
(beginning-of-line)
|
(while (not (setq type (org-babel-ref-at-ref-p)))
|
||||||
(if (or (= (point) (point-min)) (= (point) (point-max)))
|
(forward-line 1)
|
||||||
(error "reference not found")))
|
(beginning-of-line)
|
||||||
|
(if (or (= (point) (point-min)) (= (point) (point-max)))
|
||||||
|
(error "reference not found"))))
|
||||||
(case type
|
(case type
|
||||||
('table
|
('table
|
||||||
(mapcar (lambda (row)
|
(mapcar (lambda (row)
|
||||||
|
@ -134,7 +138,8 @@ return nil."
|
||||||
('source-block
|
('source-block
|
||||||
(setq result (org-babel-execute-src-block
|
(setq result (org-babel-execute-src-block
|
||||||
t nil (org-combine-plists args nil)))
|
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 ()
|
(defun org-babel-ref-at-ref-p ()
|
||||||
"Return the type of reference located at point or nil of none
|
"Return the type of reference located at point or nil of none
|
||||||
|
|
Loading…
Reference in a new issue