Browse Source

DONE added =file= result type

Eric Schulte 16 years ago
parent
commit
9076b528ad
2 changed files with 31 additions and 11 deletions
  1. 20 9
      litorgy/litorgy.el
  2. 11 2
      rorg.org

+ 20 - 9
litorgy/litorgy.el

@@ -246,8 +246,10 @@ replace - insert results after the source block replacing any
 
 
 silent -- no results are inserted"
 silent -- no results are inserted"
   (if insert (setq insert (split-string insert)))
   (if insert (setq insert (split-string insert)))
-  (if (stringp result) ;; unless results are a list, ensure they're a string
-      (setq result (litorgy-clean-text-properties result))
+  (if (stringp result)
+      (progn
+        (setq result (litorgy-clean-text-properties result))
+        (if (member "file" insert) (setq result (litorgy-result-to-file result))))
     (unless (listp result) (setq result (format "%S" result))))
     (unless (listp result) (setq result (format "%S" result))))
   (if (and insert (member "replace" insert)) (litorgy-remove-result))
   (if (and insert (member "replace" insert)) (litorgy-remove-result))
   (if (= (length result) 0)
   (if (= (length result) 0)
@@ -261,9 +263,11 @@ silent -- no results are inserted"
       (save-excursion
       (save-excursion
         (goto-char (litorgy-where-is-src-block-result)) (forward-line 1)
         (goto-char (litorgy-where-is-src-block-result)) (forward-line 1)
         (if (stringp result) ;; assume the result is a table if it's not a string
         (if (stringp result) ;; assume the result is a table if it's not a string
-            (litorgy-examplize-region (point) (progn (insert result) (point)))
+            (if (member "file" insert)
+                (insert result)
+              (litorgy-examplize-region (point) (progn (insert result) (point))))
           (progn
           (progn
-            (insert ;; TODO ensure that string aren't over-quoted
+            (insert
              (concat (orgtbl-to-orgtbl
              (concat (orgtbl-to-orgtbl
                       (if (consp (car result)) result (list result))
                       (if (consp (car result)) result (list result))
                       '(:fmt (lambda (cell) (format "%S" cell)))) "\n"))
                       '(:fmt (lambda (cell) (format "%S" cell)))) "\n"))
@@ -284,13 +288,20 @@ relies on `litorgy-insert-result'."
                    (save-excursion
                    (save-excursion
                      (if (org-at-table-p)
                      (if (org-at-table-p)
                          (org-table-end)
                          (org-table-end)
-                       (if (while (if (looking-at ": ")
-                                      (progn (while (looking-at ": ")
-                                               (forward-line 1)) t))
-                             (forward-line 1))
-                           (forward-line -1))
+                       (while (if (looking-at "\\(: \\|\\[\\[\\)")
+                                  (progn (while (looking-at "\\(: \\|\\[\\[\\)")
+                                           (forward-line 1)) t))
+                         (forward-line 1))
+                       (forward-line -1)
                        (point))))))
                        (point))))))
 
 
+(defun litorgy-result-to-file (result)
+  "Return an `org-mode' link with the path being the value or
+RESULT, and the display being the `file-name-nondirectory' if
+non-nil."
+  (let ((name (file-name-nondirectory result)))
+    (concat "[[" result (if name (concat "][" name "]]") "]]"))))
+
 (defun litorgy-examplize-region (beg end)
 (defun litorgy-examplize-region (beg end)
   "Comment out region using the ': ' org example quote."
   "Comment out region using the ': ' org example quote."
   (interactive "*r")
   (interactive "*r")

+ 11 - 2
rorg.org

@@ -4,7 +4,7 @@
 #+STARTUP: oddeven
 #+STARTUP: oddeven
 
 
 * Tasks [13/25]
 * Tasks [13/25]
-** TODO results-type header (vector/file) [1/3]
+** TODO results-type header (vector/file) [2/3]
    In response to a point in Dan's email.  We should allow the user to
    In response to a point in Dan's email.  We should allow the user to
    force scalar or vector results.  This could be done with a header
    force scalar or vector results.  This could be done with a header
    argument, and the default behavior could be controlled through a
    argument, and the default behavior could be controlled through a
@@ -41,11 +41,20 @@
 
 
 #+resname:
 #+resname:
 
 
-*** TODO file result types
+*** DONE file result types
 When inserting into an org-mode buffer create a link with the path
 When inserting into an org-mode buffer create a link with the path
 being the value, and optionally the display being the
 being the value, and optionally the display being the
 =file-name-nondirectory= if it exists.
 =file-name-nondirectory= if it exists.
 
 
+#+srcname: task-file-result
+#+begin_src python :results replace file
+"something"
+#+end_src
+
+#+resname:
+[[something][something]]
+
+
 This will be useful because blocks like =ditaa= and =dot= can return
 This will be useful because blocks like =ditaa= and =dot= can return
 the string path of their files, and can add =file= to their results
 the string path of their files, and can add =file= to their results
 header.
 header.