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 10:00:45 +0800 Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Message-ID: <416B3ACD.7030808@micetek.com.cn> References: <416A4F7C.8020504@micetek.com.cn> <861xg5scai.fsf@ketchup.de.uu.net> 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 1097546521 28147 80.91.229.6 (12 Oct 2004 02:02:01 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 12 Oct 2004 02:02:01 +0000 (UTC) Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Oct 12 04:01:42 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 1CHByw-0003Xc-00 for ; Tue, 12 Oct 2004 04:01:42 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CHC5u-0003iX-Gb for ged-emacs-devel@m.gmane.org; Mon, 11 Oct 2004 22:08:54 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1CHC5n-0003iM-VF for emacs-devel@gnu.org; Mon, 11 Oct 2004 22:08:48 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1CHC5n-0003i2-BU for emacs-devel@gnu.org; Mon, 11 Oct 2004 22:08:47 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1CHC5n-0003hs-8Z for emacs-devel@gnu.org; Mon, 11 Oct 2004 22:08:47 -0400 Original-Received: from [202.130.225.2] (helo=out01.east.net) by monty-python.gnu.org with esmtp (Exim 4.34) id 1CHByJ-0002Jf-Or for emacs-devel@gnu.org; Mon, 11 Oct 2004 22:01:04 -0400 Original-Received: (qmail 11772 invoked from network); 12 Oct 2004 09:47:33 +0800 Original-Received: from unknown (HELO smtp01.east.net) ([202.130.225.4]) (envelope-sender ) by 0 (qmail-ldap-1.03) with SMTP for ; 12 Oct 2004 09:47:33 +0800 Original-Received: (qmail 28507 invoked by uid 607); 12 Oct 2004 10:08:01 +0800 Original-Received: from yuwen@micetek.com.cn by smtp01 by uid 604 with qmail-scanner-1.16 (hbedv: 6.25.0.59/6.25.0.74. Clear:. Processed in 0.741 secs); 12 Oct 2004 02:08:01 -0000 Original-Received: from unknown (HELO [172.20.1.20]) (Authenticated?user:?yuwen@micetek.com.cn@[61.170.187.228]) (envelope-sender ) by 0 (qmail-ldap-1.03) with SMTP for ; 12 Oct 2004 10:08:00 +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:28270 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:28270 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. > 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