all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How, in a QUERY-REPLACE-regexp, to match a RANGE of lines?
@ 2010-02-17 20:22 David Combs
  2010-02-17 23:12 ` Peter Dyballa
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: David Combs @ 2010-02-17 20:22 UTC (permalink / raw
  To: help-gnu-emacs

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?


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?





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How, in a QUERY-REPLACE-regexp, to match a RANGE of lines?
  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 10:04 ` Andreas Röhler
  2 siblings, 0 replies; 5+ messages in thread
From: Peter Dyballa @ 2010-02-17 23:12 UTC (permalink / raw
  To: David Combs; +Cc: help-gnu-emacs


Am 17.02.2010 um 21:22 schrieb David Combs:

> subj: How, in a QUERY-REPLACE-regexp, to match a RANGE of lines?

Activate Active Region Highlight, mark the region, perform regexp.

--
Greetings

   Pete

"What do you think of Western Civilisation?"
"I think it would be a good idea!"
				– Mohandas Karamchand Gandhi





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How, in a QUERY-REPLACE-regexp, to match a RANGE of lines?
       [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
  0 siblings, 1 reply; 5+ messages in thread
From: David Combs @ 2010-02-19  5:59 UTC (permalink / raw
  To: help-gnu-emacs

In article <mailman.1412.1266448375.14305.help-gnu-emacs@gnu.org>,
Peter Dyballa  <Peter_Dyballa@Web.DE> wrote:
>
>Am 17.02.2010 um 21:22 schrieb David Combs:
>
>> subj: How, in a QUERY-REPLACE-regexp, to match a RANGE of lines?
>
>Activate Active Region Highlight, mark the region, perform regexp.

I'm not sure I really understand that.

From one interpretation, it means find the first line, save it's start-location in
register x, say, then search down for the end line, go to its end, C-x space,
go to register x, C-x C-x, C-w, and it's gone.

From another interpretation, well, I don't understand any of it.

Your "commands" are:

Activate

Active region

Highlite it somehow

then "mark" the region it somehow (as above in first interpretation?),

and THEN and ONLY then do some regexp stuff.


Peter, I haven't a clue what you're talking about.

Thanks for the work, but sorry, I understand not one piece of it.


David


PS: oh, I haven't a clue how this would interact with query-replace.  What,
turn the first arg (regexp) into a function which goes out and DOES some
stuff (side-effects?), then RETURNS a regexp, which is what Q-R will
finally receive as its first arg?




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How, in a QUERY-REPLACE-regexp, to match a RANGE of lines?
  2010-02-19  5:59   ` David Combs
@ 2010-02-19  9:25     ` Peter Dyballa
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Dyballa @ 2010-02-19  9:25 UTC (permalink / raw
  To: David Combs; +Cc: help-gnu-emacs


Am 19.02.2010 um 06:59 schrieb David Combs:

> Your "commands" are:
>
> Activate
>
> Active region
>
> Highlite it somehow


No. "Active Region Highlight" is a concept inside GNU Emacs. You can  
find its trace in the Options menu. When it's on (activated), then  
many operations are restricted to this high-lighted region.

--
Greetings

   Pete

The light at the end of the tunnel has been turned off due to budget  
cuts.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How, in a QUERY-REPLACE-regexp, to match a RANGE of lines?
  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 10:04 ` Andreas Röhler
  2 siblings, 0 replies; 5+ messages in thread
From: Andreas Röhler @ 2010-02-19 10:04 UTC (permalink / raw
  To: David Combs, help-gnu-emacs

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?
> 
> 
> 
> 





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-02-19 10:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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

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.