unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Hannu Koivisto <azure@iki.fi>
Subject: Re: New to elisp, learning by doing
Date: Mon, 17 Feb 2003 11:27:39 +0200	[thread overview]
Message-ID: <87wujzb6k4.fsf@lynx.ionific.com> (raw)
In-Reply-To: 84of5bidgc.fsf@lucy.is.informatik.uni-duisburg.de

kai.grossjohann@uni-duisburg.de (Kai Großjohann) writes:

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

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

  reply	other threads:[~2003-02-17  9:27 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 [this message]
2003-02-18  8:02     ` Kai Großjohann
2003-02-17 18:24   ` Ehud Karni
     [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=87wujzb6k4.fsf@lynx.ionific.com \
    --to=azure@iki.fi \
    /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).