diff --git a/contrib/babel/library-of-babel.org b/contrib/babel/library-of-babel.org index 441d1f4fa..ded879220 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 b6e50d1b4..8a16cb82a 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)