From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Ehud Karni" Newsgroups: gmane.emacs.help Subject: Re: New to elisp, learning by doing Date: Mon, 17 Feb 2003 20:24:19 +0200 Organization: Mivtach-Simon Insurance agencies Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <200302171824.h1HIOJoC024441@beta.mvs.co.il> References: <84of5bidgc.fsf@lucy.is.informatik.uni-duisburg.de> Reply-To: ehud@unix.mvs.co.il NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-8 Content-Transfer-Encoding: 7bit X-Trace: main.gmane.org 1045507009 30393 80.91.224.249 (17 Feb 2003 18:36:49 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 17 Feb 2003 18:36:49 +0000 (UTC) Cc: Gnu Emacs help 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 18kq8E-0007tj-00 for ; Mon, 17 Feb 2003 19:36:46 +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 18kq9H-0007Wh-01 for gnu-help-gnu-emacs@m.gmane.org; Mon, 17 Feb 2003 13:37:51 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 18kq8N-000749-00 for help-gnu-emacs@gnu.org; Mon, 17 Feb 2003 13:36:55 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 18kq4A-0004XA-00 for help-gnu-emacs@gnu.org; Mon, 17 Feb 2003 13:32:35 -0500 Original-Received: from unix.simonwiesel.co.il ([192.114.178.12] helo=unix.mvs.co.il) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18kpxt-0002UD-00 for help-gnu-emacs@gnu.org; Mon, 17 Feb 2003 13:26:06 -0500 Original-Received: from beta.mvs.co.il (beta [10.253.0.3]) by unix.mvs.co.il (8.11.6/8.11.6) with ESMTP id h1HIOKA25863; Mon, 17 Feb 2003 20:24:20 +0200 Original-Received: from beta.mvs.co.il (localhost [127.0.0.1]) by beta.mvs.co.il (8.12.5/8.12.5) with ESMTP id h1HIOKH6024458; Mon, 17 Feb 2003 20:24:20 +0200 Original-Received: (from ehud@localhost) by beta.mvs.co.il (8.12.5/8.12.5/Submit) id h1HIOJoC024441; Mon, 17 Feb 2003 20:24:19 +0200 X-Authentication-Warning: beta.mvs.co.il: ehud set sender to ehud@unix.mvs.co.il using -f Original-To: kai.grossjohann@uni-duisburg.de In-reply-to: <84of5bidgc.fsf@lucy.is.informatik.uni-duisburg.de> (kai.grossjohann@uni-duisburg.de) X-Mailer: Emacs 21.2.91.3 rmail (send-msg 1.108) Original-cc: John Rabkin 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:6797 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:6797 -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Mon, 17 Feb 2003 08:16:51 +0100, kai.grossjohann@uni-duisburg.de wrote: > > > 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))) > INSERT-TOC) I would do it with strings in a straight forward logic: (let ((toc "") ;; this the same as nil (but gives its usage intent) (RGXP "<[hH][1-6]>.*")) (goto-char (point-min)) (while (re-search-forward RGXP nil t) (setq toc (concat toc (match-string 0) "\n"))) (goto-char (point-min)) (insert toc)) Please note: 1. The search will not cross lines (it will not find a header if the opening tag is on one line and the closing tag on another line). 2. The search does check that the opening and closing tags are the same level (e.g.

....

). If you want to overcome these problem its is better to do the search in 2 steps, finding the opening tag and THEN searching its MATCHING closing tag. Ehud. - -- Ehud Karni Tel: +972-3-7966-561 /"\ Mivtach - Simon Fax: +972-3-7966-667 \ / ASCII Ribbon Campaign Insurance agencies (USA) voice mail and X Against HTML Mail http://www.mvs.co.il FAX: 1-815-5509341 / \ mailto:ehud@unix.mvs.co.il Better Safe Than Sorry -----BEGIN PGP SIGNATURE----- Comment: use http://www.keyserver.net/ to get my key (and others) iD8DBQE+USjSLFvTvpjqOY0RAk0hAJ4xQeBTTLVVjFpOpxRwigui+ht6egCghT6i HquQCCKskFDxaLE3tNJkaYE= =iicu -----END PGP SIGNATURE-----