unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "Ehud Karni" <ehud@unix.mvs.co.il>
Cc: Gnu Emacs help <help-gnu-emacs@gnu.org>
Subject: Re: New to elisp, learning by doing
Date: Mon, 17 Feb 2003 20:24:19 +0200	[thread overview]
Message-ID: <200302171824.h1HIOJoC024441@beta.mvs.co.il> (raw)
In-Reply-To: <84of5bidgc.fsf@lucy.is.informatik.uni-duisburg.de> (kai.grossjohann@uni-duisburg.de)

-----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]>.*</[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. <H1> .... </H3>).

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-----

  parent reply	other threads:[~2003-02-17 18:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-16 22:45 New to elisp, learning by doing John Rabkin
2003-02-17  2:03 ` Christopher J. White
2003-02-17  7:16 ` Kai Großjohann
2003-02-17  9:27   ` Hannu Koivisto
2003-02-18  8:02     ` Kai Großjohann
2003-02-17 18:24   ` Ehud Karni [this message]
     [not found]   ` <mailman.2034.1045507046.21513.help-gnu-emacs@gnu.org>
2003-02-17 19:50     ` Kai Großjohann
2003-02-18 10:26   ` Oliver Scholz
2003-02-17 18:47 ` Kevin Rodgers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200302171824.h1HIOJoC024441@beta.mvs.co.il \
    --to=ehud@unix.mvs.co.il \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).