From d6208a7fe57acc1b3da71698e676abcbdc31622a Mon Sep 17 00:00:00 2001 From: Eric Schulte Date: Mon, 19 Jul 2010 17:00:20 -0700 Subject: [PATCH] library-of-babel: more flexible reading of files into elisp --- contrib/babel/library-of-babel.org | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/contrib/babel/library-of-babel.org b/contrib/babel/library-of-babel.org index ea972a71f..f7d239416 100644 --- a/contrib/babel/library-of-babel.org +++ b/contrib/babel/library-of-babel.org @@ -29,26 +29,25 @@ A collection of simple utility functions * File I/O ** reading and writing files -Read the contents of the file at =path= into a string. +Read the contents of the file at =file=. The =:results vector= and +=:results scalar= header arguments can be used to read the contents of +file as either a table or 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)))) +#+begin_src emacs-lisp :var file="" + (if (member "vector" result-params) + (with-temp-buffer + (org-table-import (expand-file-name file) nil) + (org-table-to-lisp)) + (with-temp-buffer + (insert-file-contents (expand-file-name file)) + (buffer-string))) #+end_src -Write =data= to a file at =path=. If =data= is a list, then write it +Write =data= to a file at =file=. 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 +#+begin_src emacs-lisp :var data="" :var file="" + (with-temp-file file (org-babel-insert-result data)) nil #+end_src -- 2.11.4.GIT