From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Hannu Koivisto Newsgroups: gmane.emacs.help Subject: Re: New to elisp, learning by doing Date: Mon, 17 Feb 2003 11:27:39 +0200 Organization: NOYB Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <87wujzb6k4.fsf@lynx.ionific.com> References: <84of5bidgc.fsf@lucy.is.informatik.uni-duisburg.de> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit X-Trace: main.gmane.org 1045512499 22390 80.91.224.249 (17 Feb 2003 20:08:19 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 17 Feb 2003 20:08:19 +0000 (UTC) Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18krYo-0005oy-00 for ; Mon, 17 Feb 2003 21:08:18 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18krat-0006Nk-01 for gnu-help-gnu-emacs@m.gmane.org; Mon, 17 Feb 2003 15:10:27 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!uio.no!newsfeed.song.fi!fi.sn.net!newsfeed2.fi.sn.net!feeder2.news.jippii.net!reader1.news.jippii.net!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.090014 (Oort Gnus v0.14) Emacs/21.2 (i386-debian-linux-gnu) Cancel-Lock: sha1:2Pgq4hjMe3WVUES8z4ThdAM+UQA= Original-Lines: 39 Original-NNTP-Posting-Host: 195.197.252.71 Original-X-Complaints-To: newsmaster@saunalahti.com Original-X-Trace: reader1.news.jippii.net 1045474058 195.197.252.71 (Mon, 17 Feb 2003 11:27:38 EET) Original-NNTP-Posting-Date: Mon, 17 Feb 2003 11:27:38 EET Original-Xref: shelby.stanford.edu gnu.emacs.help:110311 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:6813 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:6813 kai.grossjohann@uni-duisburg.de (Kai Großjohann) writes: > "John Rabkin" writes: > >> My goal in elisp is a .el that writes a table of contents from HTML >> headers. The program would search for header tags in the buffer beginning >> at point and write them in order one under the other. > > I would collect the header tags and/or their contents in a list of > strings, I think. Then, after reaching the end of the buffer, I'd > write them out near the beginning of the buffer. > > (let ((toc nil)) > (goto-char (point-max)) > (while (re-search-backward REGEXP nil t) > (setq toc (cons TOC-ENTRY toc))) I suggest you look up `push'. > INSERT-TOC) > > Note that I'm searching backwards because the entries are added to > the beginning of the list. If searching backwards proves > inconvenient, then you could reverse the list (using nreverse) after > you're done. Or you implement a little queue. Queues are not a You could do those things if you were a C programmer who only has primitive iteration constructs like while and for. (require 'cl) (let ((toc (loop while (re-search-forward regexp nil t) collect toc-entry))) (move-to-wherever-you-want-toc) (loop for entry in toc do (insert (format entry-and-maybe-other-stuff)))) -- Hannu