DONE added =file= result type

This commit is contained in:
Eric Schulte 2009-05-22 15:38:51 -07:00
parent d8734f7edb
commit 9076b528ad
2 changed files with 31 additions and 11 deletions

View File

@ -246,8 +246,10 @@ replace - insert results after the source block replacing any
silent -- no results are inserted"
(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))))
(if (and insert (member "replace" insert)) (litorgy-remove-result))
(if (= (length result) 0)
@ -261,9 +263,11 @@ silent -- no results are inserted"
(save-excursion
(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
(litorgy-examplize-region (point) (progn (insert result) (point)))
(if (member "file" insert)
(insert result)
(litorgy-examplize-region (point) (progn (insert result) (point))))
(progn
(insert ;; TODO ensure that string aren't over-quoted
(insert
(concat (orgtbl-to-orgtbl
(if (consp (car result)) result (list result))
'(:fmt (lambda (cell) (format "%S" cell)))) "\n"))
@ -284,13 +288,20 @@ relies on `litorgy-insert-result'."
(save-excursion
(if (org-at-table-p)
(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))))))
(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)
"Comment out region using the ': ' org example quote."
(interactive "*r")

View File

@ -4,7 +4,7 @@
#+STARTUP: oddeven
* 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
force scalar or vector results. This could be done with a header
argument, and the default behavior could be controlled through a
@ -41,11 +41,20 @@
#+resname:
*** TODO file result types
*** DONE file result types
When inserting into an org-mode buffer create a link with the path
being the value, and optionally the display being the
=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
the string path of their files, and can add =file= to their results
header.