From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: posts@grierwhite.com (Christopher J. White) Newsgroups: gmane.emacs.help Subject: Re: New to elisp, learning by doing Date: Sun, 16 Feb 2003 21:03:34 -0500 Organization: Posted via Supernews, http://www.supernews.com Sender: help-gnu-emacs-bounces+gnu-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1045447411 26672 80.91.224.249 (17 Feb 2003 02:03:31 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 17 Feb 2003 02:03:31 +0000 (UTC) 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 18kad0-0006w2-00 for ; Mon, 17 Feb 2003 03:03:30 +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 18kafE-0007yv-01 for gnu-help-gnu-emacs@m.gmane.org; Sun, 16 Feb 2003 21:05:48 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!nntp.cs.ubc.ca!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!sn-xit-03!sn-xit-06!sn-post-01!supernews.com!corp.supernews.com!not-for-mail Original-Newsgroups: gnu.emacs.help User-Agent: Gnus/5.090014 (Oort Gnus v0.14) Emacs/21.2 (powerpc-apple-darwin) Cancel-Lock: sha1:NcoQDkCvC3dn5qNY7UFfq6xIt+Y= Original-X-Complaints-To: abuse@supernews.com Original-Lines: 49 Original-Xref: shelby.stanford.edu gnu.emacs.help:110256 Original-To: help-gnu-emacs@gnu.org 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:6758 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:6758 >>>>> "john" == John Rabkin writes: john> After fighting with elisp for a couple of weeks in my spare time john> I turn to anyone who can give me a clue or a push in the right john> direction. This is what I have: john> (defun html-yank-header () john> "Copies and yanks HTML headers" john> (interactive) john> (save-excursion john> (setq start_p (- (re-search-forward "\") 4)) john> (setq end_p (re-search-forward "\<\/h[12345]\>")) john> (copy-region-as-kill start_p end_p) john> ) john> (yank) john> ) john> This grabs the header closest to point and copies it to john> point. Now I need the program to recurse N times where N is the john> number of header tags in the buffer. Despite your experience with loops, I would use certainly use one for this case. I don't really see how you could do it without a loop unless you know how many times to search. Here's a few things to investigate: - iterate over the return value of (re-search-forward) passing t as the NOERROR argument... (while (re-search-forward "..." nil t) ... ) - use markers to save positions: (make-marker), (set-marker) and (marker-position) You can bounce back and forth from the TOC point to the search point. You need to use markers for this, as just using (point) won't work if you are inserting text at the beginning of the file because (point) is an offset, not a relative reference. ...cj -- ------------------------ -- Christopher J. White -- -- chris @ -- grierwhite.com ------------------------