소스 검색

library-of-babel: more flexible reading of files into elisp

Eric Schulte 14 년 전
부모
커밋
d6208a7fe5
1개의 변경된 파일14개의 추가작업 그리고 15개의 파일을 삭제
  1. 14 15
      contrib/babel/library-of-babel.org

+ 14 - 15
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