all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michael Slass <miknrene@drizzle.com>
Subject: Re: Newbie regexp question
Date: Wed, 30 Oct 2002 17:50:37 GMT	[thread overview]
Message-ID: <m3wunz95nb.fsf@localhost.localdomain> (raw)
In-Reply-To: 873cqnq0vn.fsf@fbigm.here

Friedrich Dominicus <frido@q-software-solutions.com> writes:

>Michael Slass <miknrene@drizzle.com> writes:
>
>> 
>> I think a lisp program would do better at this:
>> 
>> VERY LIGHTLY TESTED.  MAKE BACKUPS BEFORE EXPERIMENTING WITH THIS!
>> 
>> (defun paulc-purge-html-test-sections (buffer)
>>   "Delete all occurances of text between <!--Test--> and <!--End of Test-->, inclusive."
>>   (interactive "bPurge html test sections in buffer: ")
>>   (save-excursion
>>     (save-restriction
>>       (goto-char (point-min))
>>       (while (re-search-forward "<!--Test-->" nil t)
>>         (let ((beg (match-beginning 0))
>>               (end (progn (re-search-forward "<!--End of Test-->" nil t)
>>                           (match-end 0))))
>>           (if end
>>               (kill-region beg end)
>>             (error "Unmatched \"<!--Test-->\" sequence at position
>%d" beg)))))))
>Well this code is better in some areas, but Mike you missed a big
>opportunity ;-) To let the user choose what the tags are and as
>mentioned before regular expressions are overkill if you know your
>data.
>
>However a really nice solution anyway I think there is a problem with
>the end stuff. 
>
>The info pages say:
>  Search forward from point for regular expression REGEXP.
>  Set point to the end of the occurrence found, and return point.
>
>That means you will return the End tags too, if I got that right,
>which is not sure I'm a tired and had an unpleasant quarrel with
>someone I really appriciate. 

Friedrich:

Your point about the re-search is well-taken; just search-forward
would be better.

The flexibilty of your solution which lets the user choose the start
and end tags is balanced against the convenience of my solution where
he doesn't have to type that information in.

My function doesn't have a meaningful return value, so I'm not sure
what your question is.  If you're concerned that I'm not setting beg
or end correctly, please note that they are set to the return value of
the functions (match-beginning 0) and (match-end 0) which behave as
you'd imagine from the names.

I think the OP wanted the tags killed, as well as all the stuff
inbetween them, but if that's not so, switching the (match-end 0) and
the (match-beginning 0) in the defun will fix that.


-- 
Mike Slass

  reply	other threads:[~2002-10-30 17:50 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-10-30 15:07 Newbie regexp question Paul Cohen
2002-10-30 15:33 ` Friedrich Dominicus
2002-10-30 16:46   ` Paul Cohen
2002-10-30 17:19     ` Friedrich Dominicus
2002-10-30 17:24     ` Michael Slass
2002-10-30 17:42       ` Friedrich Dominicus
2002-10-30 17:50         ` Michael Slass [this message]
2002-10-30 21:37           ` Michael Slass
2002-10-30 16:49   ` Barry Margolin
2002-10-30 18:48   ` Stefan Monnier <foo@acm.com>
2002-10-30 19:29     ` Barry Margolin
2002-10-31 14:45 ` kgold
  -- strict thread matches above, loose matches on Subject: below --
2002-10-30 16:57 Bingham, Jay
2002-10-30 21:12 Bingham, Jay
     [not found] <mailman.1036012442.21874.help-gnu-emacs@gnu.org>
2002-10-31 13:56 ` Paul Cohen
2002-10-31 14:41   ` Friedrich Dominicus
2002-10-31 18:11 Bingham, Jay

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

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

  git send-email \
    --in-reply-to=m3wunz95nb.fsf@localhost.localdomain \
    --to=miknrene@drizzle.com \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.