library-of-babel: more flexible reading of files into elisp
This commit is contained in:
parent
a618566cd6
commit
d6208a7fe5
|
@ -29,26 +29,25 @@ A collection of simple utility functions
|
||||||
|
|
||||||
* File I/O
|
* File I/O
|
||||||
** reading and writing files
|
** 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
|
#+srcname: read
|
||||||
#+begin_src emacs-lisp :var path=""
|
#+begin_src emacs-lisp :var file=""
|
||||||
(with-temp-filebuffer path
|
(if (member "vector" result-params)
|
||||||
(buffer-substring (point-min) (point-max)))
|
(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
|
#+end_src
|
||||||
|
|
||||||
Read the lines of the file at =path= into a list.
|
Write =data= to a file at =file=. If =data= is a list, then write it
|
||||||
#+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.
|
as a table in traditional Org-mode table syntax.
|
||||||
#+srcname: write
|
#+srcname: write
|
||||||
#+begin_src emacs-lisp :var data="" :var path=""
|
#+begin_src emacs-lisp :var data="" :var file=""
|
||||||
(with-temp-file path
|
(with-temp-file file
|
||||||
(org-babel-insert-result data))
|
(org-babel-insert-result data))
|
||||||
nil
|
nil
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
Loading…
Reference in New Issue