ob-ref: resolve variable references to headline contents
* lisp/ob-ref.el (org-babel-ref-resolve): Now resolves references to headlines by either global or custom id, in which case the contents of the headline are returned literally.
This commit is contained in:
parent
8348f9cfbb
commit
a2cf4b43f2
|
@ -88,7 +88,7 @@ the variable."
|
|||
(save-excursion
|
||||
(let ((case-fold-search t)
|
||||
type args new-refere new-header-args new-referent result
|
||||
lob-info split-file split-ref index index-row index-col)
|
||||
lob-info split-file split-ref index index-row index-col id)
|
||||
;; if ref is indexed grab the indices -- beware nested indices
|
||||
(when (and (string-match "\\[\\([^\\[]+\\)\\]$" ref)
|
||||
(let ((str (substring ref 0 (match-beginning 0))))
|
||||
|
@ -106,8 +106,8 @@ the variable."
|
|||
(setq args (mapcar (lambda (ref) (cons :var ref))
|
||||
(org-babel-ref-split-args new-referent))))
|
||||
(when (> (length new-header-args) 0)
|
||||
(setq args (append (org-babel-parse-header-arguments new-header-args)
|
||||
args)))
|
||||
(setq args (append (org-babel-parse-header-arguments
|
||||
new-header-args) args)))
|
||||
(setq ref new-refere)))
|
||||
(when (string-match "^\\(.+\\):\\(.+\\)$" ref)
|
||||
(setq split-file (match-string 1 ref))
|
||||
|
@ -126,6 +126,13 @@ the variable."
|
|||
(re-search-backward res-rx nil t)))
|
||||
(re-search-forward src-rx nil t)
|
||||
(re-search-backward src-rx nil t)
|
||||
;; check for local or global headlines by id
|
||||
(setq id
|
||||
(or
|
||||
(re-search-forward (concat "^[ \t]*:CUSTOM_ID:[ \t]+"
|
||||
rx "[ \t]*$") nil t)
|
||||
(condition-case nil (progn (org-id-goto ref) t)
|
||||
(error nil))))
|
||||
;; check the Library of Babel
|
||||
(setq lob-info (cdr (assoc (intern ref)
|
||||
org-babel-library-of-babel)))))
|
||||
|
@ -136,22 +143,33 @@ the variable."
|
|||
;; loc (marker-position id-loc))
|
||||
;; (move-marker id-loc nil)
|
||||
(error "reference '%s' not found in this buffer" ref))
|
||||
(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"))))
|
||||
(cond
|
||||
(lob-info (setq type 'lob))
|
||||
(id (setq type 'id))
|
||||
(t (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")))))
|
||||
(let ((params (append args '((:results . "silent")))))
|
||||
(setq result
|
||||
(case type
|
||||
('results-line (org-babel-read-result))
|
||||
('table (org-babel-read-table))
|
||||
('list (org-babel-read-list))
|
||||
('file (org-babel-read-link))
|
||||
('source-block (org-babel-execute-src-block nil nil params))
|
||||
('lob (org-babel-execute-src-block nil lob-info params)))))
|
||||
(results-line (org-babel-read-result))
|
||||
(table (org-babel-read-table))
|
||||
(list (org-babel-read-list))
|
||||
(file (org-babel-read-link))
|
||||
(source-block (org-babel-execute-src-block nil nil params))
|
||||
(lob (org-babel-execute-src-block nil lob-info params))
|
||||
(id (save-restriction
|
||||
(org-narrow-to-subtree)
|
||||
(buffer-substring
|
||||
(save-excursion (goto-char (point-min))
|
||||
(forward-line 1)
|
||||
(when (looking-at "[ \t]*:PROPERTIES:")
|
||||
(re-search-forward ":END:" nil)
|
||||
(forward-char))
|
||||
(point))
|
||||
(point-max)))))))
|
||||
(if (symbolp result)
|
||||
(format "%S" result)
|
||||
(if (and index (listp result))
|
||||
|
|
Loading…
Reference in New Issue