yuwen <address@hidden> writes:
I tried to read them back into lisp objects:
(let ((buffer (find-file-noselect "~/src/el/tmp.txt")))
(set-buffer buffer)
(goto-char (point-min))
(while (setq obj (read buffer))
;;; do something ))
but there's an error message :
setq: End of file during parsing
So, what's the right way to read lisp objects from a file/buffer?
It is normal for (read buffer) to fail at the end of the buffer, so
you can catch this error using condition-case.
Or you can skip forward over whitespace and newlines after each read,
then check for eobp (end-of-buffer-p), and exit the loop if that is
true.
Or you prepend "(" and append ")" to the buffer contents, then invoke
read just once. This will give you a list of objects.
Kai