From 2531d704c0da697fc063deff4336db525df4b73a Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Tue, 9 Feb 2010 19:38:50 -0700 Subject: [PATCH] babel: now able to reference links as results --- contrib/babel/lisp/org-babel-ref.el | 2 ++ contrib/babel/lisp/org-babel.el | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/contrib/babel/lisp/org-babel-ref.el b/contrib/babel/lisp/org-babel-ref.el index 200d81208..dc5102051 100644 --- a/contrib/babel/lisp/org-babel-ref.el +++ b/contrib/babel/lisp/org-babel-ref.el @@ -150,6 +150,7 @@ return nil." (case type ('results-line (org-babel-read-result)) ('table (org-babel-read-table)) + ('file (org-babel-read-file)) ('source-block (org-babel-execute-src-block nil nil params)) ('lob (org-babel-execute-src-block nil lob-info params)))) (if (symbolp result) @@ -202,6 +203,7 @@ of the supported reference types are found. Supported reference types are tables and source blocks." (cond ((org-at-table-p) 'table) ((looking-at "^#\\+BEGIN_SRC") 'source-block) + ((looking-at org-bracket-link-regexp) 'file) ((looking-at org-babel-result-regexp) 'results-line))) (provide 'org-babel-ref) diff --git a/contrib/babel/lisp/org-babel.el b/contrib/babel/lisp/org-babel.el index a26c3ce95..01b730d54 100644 --- a/contrib/babel/lisp/org-babel.el +++ b/contrib/babel/lisp/org-babel.el @@ -657,6 +657,7 @@ following the source block." (let ((case-fold-search t) result-string) (cond ((org-at-table-p) (org-babel-read-table)) + ((looking-at org-bracket-link-regexp) (org-babel-read-link)) ((looking-at org-block-regexp) (org-babel-trim (match-string 4))) ((looking-at ": ") (setq result-string @@ -679,6 +680,21 @@ following the source block." (mapcar #'org-babel-read row))) (org-table-to-lisp))) +(defun org-babel-read-link () + "Read the link at `point' into emacs-lisp. If the path of the +link is a file path it is expanded using `expand-file-name'." + (let* ((case-fold-search t) + (raw (and (looking-at org-bracket-link-regexp) + (org-babel-clean-text-properties (match-string 1)))) + (type (and (string-match org-link-types-re raw) + (match-string 1 raw)))) + (cond + ((not type) (expand-file-name raw)) + ((string= type "file") + (and (string-match "file\\(.*\\):\\(.+\\)" raw) + (expand-file-name (match-string 2 raw)))) + (t raw)))) + (defun org-babel-insert-result (result &optional result-params info hash) "Insert RESULT into the current buffer after the end of the current source block. With optional argument RESULT-PARAMS