help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: New to elisp, learning by doing


From: Kai Großjohann
Subject: Re: New to elisp, learning by doing
Date: Mon, 17 Feb 2003 08:16:51 +0100
User-agent: Gnus/5.090016 (Oort Gnus v0.16) Emacs/21.3.50

"John Rabkin" <yoni-r@actcom.com> 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)))
  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
standard Lisp datatype, I'm afraid.  (Or is there an Emacs Lisp
package for this?)
-- 
A turnip curses Elvis


reply via email to

[Prev in Thread] Current Thread [Next in Thread]