I simply need to take the output of org-element-parse-buffer
and put it in a file -- maybe with some "if-does-not-exist" etc. bells and whistles. In CL I have with-open-file
and write
as tools. For example, here's CL to read a file containing lines like foo=bar
and output to a new file like this (foo . bar)
(defun arabic_to_roman (filename)
(cl-flet ((read-it ()
(with-open-file (in filename
:direction :input
:if-does-not-exist nil)
(loop for line = (read-line in nil)
for pos = (position \= line)
while line collect (cons (subseq line 0 pos)
(subseq line (1+ pos))))))
(write-it (list)
(with-open-file (cl-stream #p"ar_out.txt"
:direction :output
:if-exists :overwrite
:if-does-not-exist :create)
(write list :stream stream :escape nil :readably nil :pretty nil))))
(write-it (read-it))
'done-read-write))
This is someone abstruse compared to other languages -- but then I don't find anything like this in elisp. How is read-write done in elisp. What I find seems only buffer-oriented. . . .
with-temp-file
?: gnu.org/software/emacs/manual/html_node/elisp/… I don't understand all the cl-stuff, but it probably is not necessary to use any of that. The same page of the manual also discusseswrite-region
, which may also be helpful. See alsowith-temp-buffer
: gnu.org/software/emacs/manual/html_node/elisp/…org-element-parse-buffer
and write it to a file directly. Sure, I could do buffer work, but can't I just do normal file stuff in elisp?