From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Rodolfo Medina Newsgroups: gmane.emacs.help Subject: Re: replace-regexp from A to B? Date: Sun, 26 Aug 2018 19:54:12 +0200 Message-ID: <87lg8thv3v.fsf@gmail.com> References: <86tvnhktf7.fsf@zoho.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1535305979 31211 195.159.176.226 (26 Aug 2018 17:52:59 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 26 Aug 2018 17:52:59 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Aug 26 19:52:55 2018 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ftzDa-00080X-D7 for geh-help-gnu-emacs@m.gmane.org; Sun, 26 Aug 2018 19:52:54 +0200 Original-Received: from localhost ([::1]:49914 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftzFg-00020A-L1 for geh-help-gnu-emacs@m.gmane.org; Sun, 26 Aug 2018 13:55:04 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55532) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftzF7-0001yr-2r for help-gnu-emacs@gnu.org; Sun, 26 Aug 2018 13:54:29 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ftzF3-0002NQ-TG for help-gnu-emacs@gnu.org; Sun, 26 Aug 2018 13:54:29 -0400 Original-Received: from [195.159.176.226] (port=52053 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ftzF3-0002JN-L0 for help-gnu-emacs@gnu.org; Sun, 26 Aug 2018 13:54:25 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1ftzCu-0007BS-0m for help-gnu-emacs@gnu.org; Sun, 26 Aug 2018 19:52:12 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 48 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:/veHjqBBHh3clH0KJup44D05hTs= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 195.159.176.226 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:117752 Archived-At: Emanuel Berg writes: > Rodolfo Medina wrote: > >> Is it possible, and how?, to perform >> a replace-regexp from a certain point, e.g. >> the current one, or from a certain >> word/expression, up to the next occurrence of >> a certain other word/expression...? In my >> case, with MusiXTeX documents, the starting >> point should be the TeX command `\startpiece' >> and the final one `\Endpiece'. So I could >> replace strings/expressions within a single >> musical piece without going out of it. > > You can set the region manually and then use > a function with > > (goto-char START) > (while (re-search-forward REGEXP STOP t) > (replace-match TO-STRING nil nil)) > > where START is (region-beginning) and STOP is > (region-end). First check if there is a region > with (use-region-p) ! > > Or if you want it fully automated make a search > for "\startpiece" and set START, then make > a search for "\Endpiece" and set STOP. Do this > in Elisp as well. > > But then you'd have to supply them (the > delimitators) as arguments so it won't > necessarily be faster because you'd have to > type them each time rather than to set > the region. > > If they (the delimitators) are always the same > you could hard-code them, of course. Then it'll > be very fast to invoke :) Thanks, Yuri and Emanuel... I've seen that a single MusiXTeX piece can be considered as a tex paragraph, because no blank line should be inserted into it... So I can perform my replace-regexp with the `M-h' prefix so applying it only to the current paragraph/piece... Rodolfo