[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: read lisp objects from buffer
From: |
Kai Grossjohann |
Subject: |
Re: read lisp objects from buffer |
Date: |
Mon, 11 Oct 2004 13:51:33 +0200 |
User-agent: |
Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (gnu/linux) |
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