summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Schulte <schulte.eric@gmail.com>2010-06-06 19:56:09 -0700
committerEric Schulte <schulte.eric@gmail.com>2010-06-06 19:56:09 -0700
commit4e43e7fea8441378713374c87b6bc18089491631 (patch)
tree795cad4b46edc191e24cc7f11e10e5a1fc03c253
parent367d81d9dcc631b038306d605210c2b32d2951d6 (diff)
downloadorg-mode-4e43e7fea8441378713374c87b6bc18089491631.tar.gz
babel: adding library-of-babel functions for file I/O
* contrib/babel/lisp/org-babel.el (org-babel-insert-result): Replaced call to `org-cycle' with a call to the simpler and more appropriate `org-table-align'. * contrib/babel/library-of-babel.org (Read/Write): adding library-of-babel functions for file I/O
-rw-r--r--contrib/babel/library-of-babel.org26
-rw-r--r--contrib/babel/lisp/org-babel.el2
2 files changed, 27 insertions, 1 deletions
diff --git a/contrib/babel/library-of-babel.org b/contrib/babel/library-of-babel.org
index 441d1f4..ded8792 100644
--- a/contrib/babel/library-of-babel.org
+++ b/contrib/babel/library-of-babel.org
@@ -35,6 +35,32 @@
The raw Org-mode text of this file can be downloaded at
[[repofile:contrib/babel/library-of-babel.org][library-of-babel.org]]
+* File I/O
+** reading and writing files
+Read the contents of the file at =path= into a string.
+#+srcname: read
+#+begin_src emacs-lisp :var path=""
+ (with-temp-filebuffer path
+ (buffer-substring (point-min) (point-max)))
+#+end_src
+
+Read the lines of the file at =path= into a list.
+#+srcname: read-lines
+#+begin_src emacs-lisp :var path=""
+ (split-string
+ (with-temp-filebuffer path
+ (buffer-substring (point-min) (point-max))))
+#+end_src
+
+Write =data= to a file at =path=. If =data= is a list, then write it
+as a table in traditional Org-mode table syntax.
+#+srcname: write
+#+begin_src emacs-lisp :var data="" :var path=""
+ (with-temp-file path
+ (org-babel-insert-result data))
+ nil
+#+end_src
+
* Plotting code
** R
diff --git a/contrib/babel/lisp/org-babel.el b/contrib/babel/lisp/org-babel.el
index b6e50d1..8a16cb8 100644
--- a/contrib/babel/lisp/org-babel.el
+++ b/contrib/babel/lisp/org-babel.el
@@ -965,7 +965,7 @@ code ---- the results are extracted in the syntax of the source
(listp (cdr (car result)))))
result (list result))
'(:fmt (lambda (cell) (format "%s" cell)))) "\n"))
- (goto-char beg) (org-cycle))
+ (goto-char beg) (org-table-align))
((member "file" result-params)
(insert result))
((member "html" result-params)