From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sean McAfee Newsgroups: gmane.emacs.help Subject: Iterating over all buffer lines Date: Thu, 17 Jan 2013 12:55:00 -0800 Organization: A noiseless patient Spider Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1358456114 7892 80.91.229.3 (17 Jan 2013 20:55:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 17 Jan 2013 20:55:14 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jan 17 21:55:32 2013 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TvwUk-0006z9-Qc for geh-help-gnu-emacs@m.gmane.org; Thu, 17 Jan 2013 21:55:30 +0100 Original-Received: from localhost ([::1]:36857 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TvwUU-000414-93 for geh-help-gnu-emacs@m.gmane.org; Thu, 17 Jan 2013 15:55:14 -0500 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed101.telia.com!starscream.dk.telia.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 21 Injection-Info: mx04.eternal-september.org; posting-host="9602142ff40e0c8bd8027a6f5e009406"; logging-data="5311"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+qFQUIXN99io5aPaoAtuvTaib6Z1Aj7UA=" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:z8tFqPyPnS5exNIz3RjTKdZ/CoE= sha1:biif3z4fukcYuViXqX+3K8AziJc= Original-Xref: usenet.stanford.edu gnu.emacs.help:196392 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:88687 Archived-At: I have some code where I want to loop over all of the lines of text in a buffer. I had a prior solution that involved repeatedly searching for the regexp "^.+$", but that seemed a little heavyweight. Also, it only found non-empty lines, and changing the "+" to a "*" to return all lines causes an infinite loop. I just tried my hand at writing a general iterate-all-lines construct, and came up with this: (loop for last-point = (point) while (= 0 (forward-line)) for line = (buffer-substring-no-properties last-point (- (point) (if (bolp) 1 0))) ;; do something with line ) Newlines are not returned, and as can be seen, I have to take care to handle a final line that is missing a terminating newline. Is there a better and/or more idiomatic way to go about it?