浏览代码

babel: now able to reference links as results

Eric Schulte 15 年之前
父节点
当前提交
2531d704c0
共有 2 个文件被更改,包括 18 次插入0 次删除
  1. 2 0
      contrib/babel/lisp/org-babel-ref.el
  2. 16 0
      contrib/babel/lisp/org-babel.el

+ 2 - 0
contrib/babel/lisp/org-babel-ref.el

@@ -150,6 +150,7 @@ return nil."
 	    (case type
 	    (case type
 	      ('results-line (org-babel-read-result))
 	      ('results-line (org-babel-read-result))
 	      ('table (org-babel-read-table))
 	      ('table (org-babel-read-table))
+              ('file (org-babel-read-file))
 	      ('source-block (org-babel-execute-src-block nil nil params))
 	      ('source-block (org-babel-execute-src-block nil nil params))
 	      ('lob (org-babel-execute-src-block nil lob-info params))))
 	      ('lob (org-babel-execute-src-block nil lob-info params))))
       (if (symbolp result)
       (if (symbolp result)
@@ -202,6 +203,7 @@ of the supported reference types are found.  Supported reference
 types are tables and source blocks."
 types are tables and source blocks."
   (cond ((org-at-table-p) 'table)
   (cond ((org-at-table-p) 'table)
         ((looking-at "^#\\+BEGIN_SRC") 'source-block)
         ((looking-at "^#\\+BEGIN_SRC") 'source-block)
+        ((looking-at org-bracket-link-regexp) 'file)
         ((looking-at org-babel-result-regexp) 'results-line)))
         ((looking-at org-babel-result-regexp) 'results-line)))
 
 
 (provide 'org-babel-ref)
 (provide 'org-babel-ref)

+ 16 - 0
contrib/babel/lisp/org-babel.el

@@ -657,6 +657,7 @@ following the source block."
   (let ((case-fold-search t) result-string)
   (let ((case-fold-search t) result-string)
     (cond
     (cond
      ((org-at-table-p) (org-babel-read-table))
      ((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 org-block-regexp) (org-babel-trim (match-string 4)))
      ((looking-at ": ")
      ((looking-at ": ")
       (setq result-string
       (setq result-string
@@ -679,6 +680,21 @@ following the source block."
               (mapcar #'org-babel-read row)))
               (mapcar #'org-babel-read row)))
           (org-table-to-lisp)))
           (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)
 (defun org-babel-insert-result (result &optional result-params info hash)
   "Insert RESULT into the current buffer after the end of the
   "Insert RESULT into the current buffer after the end of the
 current source block.  With optional argument RESULT-PARAMS
 current source block.  With optional argument RESULT-PARAMS