Browse Source

starting work on allowing opening of src-block results

  not yet working
Eric Schulte 16 years ago
parent
commit
3692c4b3a5
3 changed files with 64 additions and 28 deletions
  1. 2 27
      lisp/org-babel-ref.el
  2. 47 0
      lisp/org-babel.el
  3. 15 1
      org-babel.org

+ 2 - 27
lisp/org-babel-ref.el

@@ -136,8 +136,8 @@ return nil."
               (error "reference not found"))))
               (error "reference not found"))))
       ;; (message "type=%S" type) ;; debugging
       ;; (message "type=%S" type) ;; debugging
       (case type
       (case type
-        ('results-line (org-babel-ref-read-result))
-        ('table (org-babel-ref-read-table))
+        ('results-line (org-babel-read-result))
+        ('table (org-babel-read-table))
         ('source-block
         ('source-block
          (setq result (org-babel-execute-src-block t nil args))
          (setq result (org-babel-execute-src-block t nil args))
          (if (symbolp result) (format "%S" result) result))
          (if (symbolp result) (format "%S" result) result))
@@ -168,30 +168,5 @@ types are tables and source blocks."
         ((looking-at "^#\\+BEGIN_SRC") 'source-block)
         ((looking-at "^#\\+BEGIN_SRC") 'source-block)
         ((looking-at "^#\\+RESNAME:") 'results-line)))
         ((looking-at "^#\\+RESNAME:") 'results-line)))
 
 
-(defun org-babel-ref-read-result ()
-  "Read the result at `point' into emacs-lisp."
-  (cond
-   ((org-at-table-p) (org-babel-ref-read-table))
-   ((looking-at ": ")
-    (let ((result-string
-           (org-babel-trim
-            (mapconcat (lambda (line) (if (and (> (length line) 1)
-                                               (string= ": " (substring line 0 2)))
-                                          (substring line 2)
-                                        line))
-                       (split-string
-                        (buffer-substring (point) (org-babel-result-end)) "[\r\n]+")
-                       "\n"))))
-      (or (org-babel-number-p result-string) result-string)))
-   ((looking-at "^#\\+RESNAME:")
-    (save-excursion (forward-line 1) (org-babel-ref-read-result)))))
-
-(defun org-babel-ref-read-table ()
-  "Read the table at `point' into emacs-lisp."
-  (mapcar (lambda (row)
-            (if (and (symbolp row) (equal row 'hline)) row
-              (mapcar #'org-babel-read row)))
-          (org-table-to-lisp)))
-
 (provide 'org-babel-ref)
 (provide 'org-babel-ref)
 ;;; org-babel-ref.el ends here
 ;;; org-babel-ref.el ends here

+ 47 - 0
lisp/org-babel.el

@@ -389,6 +389,31 @@ line.  If no result exists for this block then create a
                             (move-beginning-of-line 1) t)))
                             (move-beginning-of-line 1) t)))
                (point))))))
                (point))))))
 
 
+(defun org-babel-read-result ()
+  "Read the result at `point' into emacs-lisp."
+  (cond
+   ((org-at-table-p) (org-babel-read-table))
+   ((looking-at ": ")
+    (let ((result-string
+           (org-babel-trim
+            (mapconcat (lambda (line) (if (and (> (length line) 1)
+                                               (string= ": " (substring line 0 2)))
+                                          (substring line 2)
+                                        line))
+                       (split-string
+                        (buffer-substring (point) (org-babel-result-end)) "[\r\n]+")
+                       "\n"))))
+      (or (org-babel-number-p result-string) result-string)))
+   ((looking-at "^#\\+RESNAME:")
+    (save-excursion (forward-line 1) (org-babel-read-result)))))
+
+(defun org-babel-read-table ()
+  "Read the table at `point' into emacs-lisp."
+  (mapcar (lambda (row)
+            (if (and (symbolp row) (equal row 'hline)) row
+              (mapcar #'org-babel-read row)))
+          (org-table-to-lisp)))
+
 (defun org-babel-insert-result (result &optional insert)
 (defun org-babel-insert-result (result &optional insert)
   "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 INSERT controls
 current source block.  With optional argument INSERT controls
@@ -435,6 +460,28 @@ silent -- no results are inserted"
             (org-cycle))))
             (org-cycle))))
       (message "finished"))))
       (message "finished"))))
 
 
+(defun org-babel-open-src-block-result ()
+  (interactive)
+  "If `point' is on a src block then open the results of the
+source code block, otherwise return nil."
+  (when (org-babel-get-src-block-info)
+    (save-excursion
+      ;; go to the results, if there aren't any then run the block
+      (goto-char (or (org-babel-where-is-src-block-result)
+                     (progn (org-babel-execute-src-block)
+                            (org-babel-where-is-src-block-result))))
+      ;; open the results
+      (if (looking-at org-bracket-link-regexp)
+          ;; file
+          (org-open-at-point)
+        ;; vector or scalar
+        (let ((results (org-babel-read-result)))
+          (pop-to-buffer (get-buffer-create "org-babel-results"))
+          (delete-region (point-min) (point-max))
+          (if (listp results)
+              (insert (orgtbl-to-tsv results))
+            (insert results)))))))
+
 (defun org-babel-result-to-org-string (result)
 (defun org-babel-result-to-org-string (result)
   "Return RESULT as a string in org-mode format.  This function
   "Return RESULT as a string in org-mode format.  This function
 relies on `org-babel-insert-result'."
 relies on `org-babel-insert-result'."

+ 15 - 1
org-babel.org

@@ -464,6 +464,21 @@ This could also act reasonably with other results types...
 - file :: use org-open-at-point to open the file
 - file :: use org-open-at-point to open the file
 - scalar :: open results unquoted in a new buffer
 - scalar :: open results unquoted in a new buffer
 - tabular :: export the table to a new buffer and open that buffer
 - tabular :: export the table to a new buffer and open that buffer
+
+#+srcname: task-opening-results-of-blocks
+#+begin_src ditaa :results replace :file blue.png :cmdline -r
++---------+
+| cBLU    |
+|         |
+|    +----+
+|    |cPNK|
+|    |    |
++----+----+
+#+end_src
+
+#+resname:
+
+
 ** TODO Finalise behaviour regarding vector/scalar output
 ** TODO Finalise behaviour regarding vector/scalar output
 *** DONE Stop spaces causing vector output
 *** DONE Stop spaces causing vector output
 This simple example of multilingual chaining produces vector output if
 This simple example of multilingual chaining produces vector output if
@@ -2315,7 +2330,6 @@ dot("$(2a,0)$",(2,0),N+E);
 #+resname:
 #+resname:
 [[file:asymptote-test.png][asymptote-test.png]]
 [[file:asymptote-test.png][asymptote-test.png]]
 
 
-
 *** DONE ruby
 *** DONE ruby
 *** DONE python
 *** DONE python
 *** DONE R
 *** DONE R