From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: yuwen Newsgroups: gmane.emacs.devel Subject: Re: read lisp objects from buffer Date: Tue, 12 Oct 2004 16:56:56 +0800 Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Message-ID: <416B9C58.5000303@micetek.com.cn> References: <416A4F7C.8020504@micetek.com.cn> <861xg5scai.fsf@ketchup.de.uu.net> Reply-To: yuwen@micetek.com.cn NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1097572434 14047 80.91.229.6 (12 Oct 2004 09:13:54 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 12 Oct 2004 09:13:54 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Oct 12 11:13:47 2004 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1CHIj5-0006o4-00 for ; Tue, 12 Oct 2004 11:13:47 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CHIq4-00036j-3e for ged-emacs-devel@m.gmane.org; Tue, 12 Oct 2004 05:21:00 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CHIaN-00082K-8m for emacs-devel@gnu.org; Tue, 12 Oct 2004 05:04:47 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CHIaL-00081Z-QZ for emacs-devel@gnu.org; Tue, 12 Oct 2004 05:04:46 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CHIaL-00081U-N0 for emacs-devel@gnu.org; Tue, 12 Oct 2004 05:04:45 -0400 Original-Received: from [61.170.187.228] (helo=athlon.micetek.com.cn) by monty-python.gnu.org with esmtp (Exim 4.34) id 1CHISw-0007tA-2r for emacs-devel@gnu.org; Tue, 12 Oct 2004 04:57:17 -0400 Original-Received: from yuwen.micetek.com.cn ([172.20.1.20]) by athlon.micetek.com.cn with esmtp (Exim 3.35 #1 (Debian)) id 1CHISp-0004nZ-00 for ; Tue, 12 Oct 2004 16:56:59 +0800 User-Agent: Mozilla Thunderbird 0.7 (Windows/20040616) X-Accept-Language: en-us, en Original-To: emacs-devel@gnu.org In-Reply-To: <861xg5scai.fsf@ketchup.de.uu.net> X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:28283 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:28283 Kai Grossjohann wrote: > yuwen 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 > Thank you. I use condition-case to protect the reading buffer process, and catch the `end-of-file' error: (condition-case nil (while (setq obj (read buffer)) ;;; do something (end-of-file (kill-buffer buffer)))))) Best regards, Dai Yuwen