[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How, in a QUERY-REPLACE-regexp, to match a RANGE of lines?
From: |
Andreas Röhler |
Subject: |
Re: How, in a QUERY-REPLACE-regexp, to match a RANGE of lines? |
Date: |
Fri, 19 Feb 2010 11:04:18 +0100 |
User-agent: |
Thunderbird 2.0.0.19 (X11/20081227) |
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?
>
>
>
>