[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: New to elisp, learning by doing
From: |
Ehud Karni |
Subject: |
Re: New to elisp, learning by doing |
Date: |
Mon, 17 Feb 2003 20:24:19 +0200 |
-----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-----
- New to elisp, learning by doing, John Rabkin, 2003/02/16
- Re: New to elisp, learning by doing, Christopher J. White, 2003/02/16
- Re: New to elisp, learning by doing, Kai Großjohann, 2003/02/17
- Re: New to elisp, learning by doing,
Ehud Karni <=
- Message not available
- Re: New to elisp, learning by doing, Hannu Koivisto, 2003/02/17
- Re: New to elisp, learning by doing, Oliver Scholz, 2003/02/18
- Re: New to elisp, learning by doing, Kevin Rodgers, 2003/02/17