From: "Andreas Röhler" <andreas.roehler@easy-emacs.de>
To: David Combs <dkcombs@panix.com>, help-gnu-emacs@gnu.org
Subject: Re: How, in a QUERY-REPLACE-regexp, to match a RANGE of lines?
Date: Fri, 19 Feb 2010 11:04:18 +0100 [thread overview]
Message-ID: <4B7E6222.6070507@easy-emacs.de> (raw)
In-Reply-To: <hlhj5r$2mv$1@panix2.panix.com>
David Combs wrote:
> subj: How, in a QUERY-REPLACE-regexp, to match a RANGE of lines?
>
>
>
> Like from a line containing xxx up through the nearest one containing yyy?
>
>
> Totally separate question:
>
> (Any easy way to give error msg if you see another xxx-line before
> that yyy? -- other than by explicit loop looking at each line and
> remembering what it saw?)
>
>
> Or do you have to write an explicit loop -- checking each individual
> line, remembering what you've seen so far (eg, xxx), etc.
>
> In elisp, how would you do that?
(defun my-search-and-warn (&optional beg end)
" "
(interactive)
(lexical-let ((beg (cond (beg beg)
((region-active-p)
(region-beginning))
(t (point-min))))
(end (cond (end end)
((region-active-p)
(copy-marker (region-end)))
(t (point-max))))
(orig (point)))
(my-search-and-warn-intern beg end orig)))
(defun my-search-and-warn-intern (beg end orig)
(goto-char beg)
(if (search-forward "xxx" orig t 2)
(message "%s" "Found \"xxx\" before starting-point")
(when (search-forward "xxx" end t 1)
(push-mark (match-beginning 0))
(search-forward "yyy" end t 1)
(exchange-point-and-mark))))
Andreas
--
https://code.launchpad.net/~a-roehler/python-mode
https://code.launchpad.net/s-x-emacs-werkstatt/
>
>
> Thanks,
>
> David
>
> PS: reason for this: I've got a bunch of Amazon reviews (hundreds
> of them), each containing these six lines:
>
>
> | Help other customers find the most helpful reviews
> | Was this review helpful to you? Yes No
> |
> |
> | Report this | Permalink
> | Comment Comment
>
>
>
> But, now and then, I might have already removed any
> one or more of them. So I got to make sure it's as
> I think it is.
>
>
> Any way to recognize those six lines with ONE regexp?
>
>
>
>
prev parent reply other threads:[~2010-02-19 10:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-17 20:22 How, in a QUERY-REPLACE-regexp, to match a RANGE of lines? David Combs
2010-02-17 23:12 ` Peter Dyballa
[not found] ` <mailman.1412.1266448375.14305.help-gnu-emacs@gnu.org>
2010-02-19 5:59 ` David Combs
2010-02-19 9:25 ` Peter Dyballa
2010-02-19 10:04 ` Andreas Röhler [this message]
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=4B7E6222.6070507@easy-emacs.de \
--to=andreas.roehler@easy-emacs.de \
--cc=dkcombs@panix.com \
--cc=help-gnu-emacs@gnu.org \
/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.