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
|
||||
** 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)))
|
||||
#+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
|
||||
|
||||
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
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue