From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?ISO-8859-1?Q?Andreas_R=F6hler?= Newsgroups: gmane.emacs.help Subject: Re: How, in a QUERY-REPLACE-regexp, to match a RANGE of lines? Date: Fri, 19 Feb 2010 11:04:18 +0100 Message-ID: <4B7E6222.6070507@easy-emacs.de> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1266573796 20330 80.91.229.12 (19 Feb 2010 10:03:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 19 Feb 2010 10:03:16 +0000 (UTC) To: David Combs , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Feb 19 11:03:14 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1NiPhH-0004WO-L6 for geh-help-gnu-emacs@m.gmane.org; Fri, 19 Feb 2010 11:02:55 +0100 Original-Received: from localhost ([127.0.0.1]:51581 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NiPhH-0005ZC-3M for geh-help-gnu-emacs@m.gmane.org; Fri, 19 Feb 2010 05:02:55 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NiPgu-0005Z0-Ls for help-gnu-emacs@gnu.org; Fri, 19 Feb 2010 05:02:32 -0500 Original-Received: from [140.186.70.92] (port=50327 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NiPgs-0005Yn-5h for help-gnu-emacs@gnu.org; Fri, 19 Feb 2010 05:02:30 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NiPgr-0005WE-0F for help-gnu-emacs@gnu.org; Fri, 19 Feb 2010 05:02:29 -0500 Original-Received: from moutng.kundenserver.de ([212.227.126.186]:49551) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NiPgq-0005W9-Gj for help-gnu-emacs@gnu.org; Fri, 19 Feb 2010 05:02:28 -0500 Original-Received: from [192.168.178.27] (p54BE90B2.dip0.t-ipconnect.de [84.190.144.178]) by mrelayeu.kundenserver.de (node=mreu2) with ESMTP (Nemesis) id 0LZjNw-1O5cx24AJA-00lxd9; Fri, 19 Feb 2010 11:02:25 +0100 User-Agent: Thunderbird 2.0.0.19 (X11/20081227) In-Reply-To: X-Provags-ID: V01U2FsdGVkX18ACpdpkrOFP2kVINSgwxSXyRggMF2KZ3Wa+U/ /TaXfR6PftIvFZaMMuexM4LA+bz4srFV8GGK2aBtu6+4bJW/vI 5QDrLTg+CkL5LQ7g93KlXjEGRmAo++7p6qKHfWoh/E= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:71953 Archived-At: 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? > > > >