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: Automate replace-regexp Date: Sun, 26 Aug 2018 04:15:59 +0200 Message-ID: <87d0u5q3ds.fsf@gmail.com> References: <87ftz2tqxi.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1535249699 8419 195.159.176.226 (26 Aug 2018 02:14:59 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 26 Aug 2018 02:14: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 04:14: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 1ftkZp-00022C-9K for geh-help-gnu-emacs@m.gmane.org; Sun, 26 Aug 2018 04:14:53 +0200 Original-Received: from localhost ([::1]:47663 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftkbv-0002eB-Em for geh-help-gnu-emacs@m.gmane.org; Sat, 25 Aug 2018 22:17:03 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35114) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftkbC-0002de-6I for help-gnu-emacs@gnu.org; Sat, 25 Aug 2018 22:16:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ftkb7-00041h-Oa for help-gnu-emacs@gnu.org; Sat, 25 Aug 2018 22:16:18 -0400 Original-Received: from [195.159.176.226] (port=37334 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ftkb4-0003sF-ER for help-gnu-emacs@gnu.org; Sat, 25 Aug 2018 22:16:12 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1ftkYt-0000oq-JU for help-gnu-emacs@gnu.org; Sun, 26 Aug 2018 04:13:55 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 87 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:H4U2k6KlsOrGhNRB9fY6cmJk1pg= 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:117739 Archived-At: Skip Montanaro writes: > If it's a one-time thing, since replace-regexp is a command (uses > (interactive) to prompt for missing parameters), I'd just define a > macro with C-x (. From my edit-last-kbd-macro session (ugly, but only > took a moment to define): > > ESC > xreplace-regex ;; self-insert-command * 14 > TAB ;; indent-for-tab-command > RET ;; newline > 2*\ ;; self-insert-command > bar ;; self-insert-command * 3 > SPC ;; self-insert-command > %[0-9]+ ;; self-insert-command * 7 > RET ;; newline > \ ;; self-insert-command > bar ;; self-insert-command * 3 > RET ;; newline > ESC > xrepla ;; self-insert-command * 6 > TAB ;; indent-for-tab-command > reg ;; self-insert-command * 3 > TAB ;; indent-for-tab-command > RET ;; newline > 2*\ ;; self-insert-command > bar ;; self-insert-command * 3 > RET ;; newline > \ ;; self-insert-command > bar ;; self-insert-command * 3 > SPC ;; self-insert-command > %,(+ ;; self-insert-command * 4 > SPC ;; self-insert-command > 2#) ;; self-insert-command * 3 > RET ;; newline Thanks... But I had problem in defining such a kbd macro... Every time I try to insert `M-x query-replace-regexp ...' it would execute that command in the present buffer rather than simply register it as a kbd macro... > Once you've got that, you can name it (name-last-kbd-macro), then if > you want to save it across sessions, edit your ~/.emacs file, and > execute insert-kbd-macro, which does the obvious thing. > > Now, I rarely go to those lengths, and if I need to, it's sometimes > simpler to just defun a new function. In this case, it might well be, > something like: > > (defun my-replace () > (interactive) > (replace-regexp "..." "...") > (replace-regexp "..." "...")) Here I had problems in replacing `...' with the proper expressions. If I insert these: "\\bar %[0-9]+", "\\bar", "\\bar %\,(+ 2 \#)", the command fails. Besides, the command should only act in the present paragraph... Thanks, Rodolfo > > YMMV. > > Skip > On Sat, Aug 25, 2018 at 10:36 AM Rodolfo Medina > wrote: >> >> Hi all... >> >> In a document, I wish to automate the following two replace-regexp, >> immediately >> one after the other, only within the current paragraph: >> >> \\bar %[0-9]+ -> \\bar >> \\bar -> \\bar %\,(+ 2 \#) >> >> How can I achieve that, defining a proper command...? >> >> Thanks for any help, >> >> Rodolfo >> >>