From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: replace-regexp Date: Fri, 07 May 2021 08:54:53 +0200 Message-ID: <87v97v6mxg.fsf@gnu.org> References: <87tunf1mz5.fsf@zoho.eu> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32356"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.5.13; emacs 28.0.50 To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri May 07 09:09:05 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1leubf-0008HS-LD for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 07 May 2021 09:09:03 +0200 Original-Received: from localhost ([::1]:53338 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1leube-0000cO-8T for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 07 May 2021 03:09:02 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49760) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1leubB-0000cB-ED for help-gnu-emacs@gnu.org; Fri, 07 May 2021 03:08:33 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:44250) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1leubB-00027f-6k for help-gnu-emacs@gnu.org; Fri, 07 May 2021 03:08:33 -0400 Original-Received: from auth1-smtp.messagingengine.com ([66.111.4.227]:40395) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.86_2) (envelope-from ) id 1leubB-00089E-4T for help-gnu-emacs@gnu.org; Fri, 07 May 2021 03:08:33 -0400 Original-Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailauth.nyi.internal (Postfix) with ESMTP id 04A3227C0054 for ; Fri, 7 May 2021 03:08:32 -0400 (EDT) Original-Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Fri, 07 May 2021 03:08:32 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdeguddguddtlecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepfhgfhffvufffjgfkgggtsehttd ertddtredtnecuhfhrohhmpefvrghsshhilhhoucfjohhrnhcuoehtshguhhesghhnuhdr ohhrgheqnecuggftrfgrthhtvghrnhepveevieekteekveeigfefffeivdetgeduvdffue euudevgedttdehvdfhueevfffhnecukfhppeekjedrudeifedrfedurdduheegnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepthhhohhrnhdomh gvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqkeeijeefkeejkeegqdeifeehvdel kedqthhsughhpeepghhnuhdrohhrghesfhgrshhtmhgrihhlrdhfmh X-ME-Proxy: Original-Received: from thinkpad-t440p (p57a31f9a.dip0.t-ipconnect.de [87.163.31.154]) by mail.messagingengine.com (Postfix) with ESMTPA for ; Fri, 7 May 2021 03:08:31 -0400 (EDT) In-reply-to: <87tunf1mz5.fsf@zoho.eu> X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:129549 Archived-At: Emanuel Berg via Users list for the GNU Emacs text editor writes: > so I wrote this and it does the job but reports the error > "while: Invalid search bound (wrong side of point)" > > (defun md-latex (beg end) > (interactive "r") > (save-excursion > (goto-char beg) > (while (re-search-forward "_\\(.*\\)_" end t) > (replace-match "\\\\textit{\\1}") ))) I think you didn't call your command interactively but through code like (md-latex 170 82) where the BEG was larger than END. When being called interactively the "r" spec makes sure that BEG is always the smaller one, no matter if point is before mark or the other way round. > Also this "interactive use only", in general, what's the deal with > that? > > If it is just a matter of re-writing it the way I did (only without > the error) I don't see why that cannot be dealt with so the user can > just call the/a function with a simple interface, be it interactively > or in Lisp... I guess it's because `replace-regexp' does much more than just `re-search-forward' and `replace-match' in order to provide a convenient interface for the user. Also it supports stuff like \? as replacement which will query the user. You'd normally wouldn't want/need that. So if all you want is replace some regexp, `re-search-forward' with `replace-match' is the non-overhead way to go. Bye, Tassilo