From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Skip Montanaro Newsgroups: gmane.emacs.help Subject: Re: Automate replace-regexp Date: Sat, 25 Aug 2018 11:04:58 -0500 Message-ID: References: <87ftz2tqxi.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1535213405 11425 195.159.176.226 (25 Aug 2018 16:10:05 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 25 Aug 2018 16:10:05 +0000 (UTC) Cc: Help GNU Emacs To: rodolfo.medina@gmail.com Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Aug 25 18:10:01 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 1ftb8T-0002oZ-GU for geh-help-gnu-emacs@m.gmane.org; Sat, 25 Aug 2018 18:10:01 +0200 Original-Received: from localhost ([::1]:46403 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftbAZ-0004Nq-Ct for geh-help-gnu-emacs@m.gmane.org; Sat, 25 Aug 2018 12:12:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:45987) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ftb9T-00040q-4K for help-gnu-emacs@gnu.org; Sat, 25 Aug 2018 12:11:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ftb44-0004Q6-Rl for help-gnu-emacs@gnu.org; Sat, 25 Aug 2018 12:05:29 -0400 Original-Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]:40031) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ftb42-0004Oh-T1 for help-gnu-emacs@gnu.org; Sat, 25 Aug 2018 12:05:28 -0400 Original-Received: by mail-pg1-x535.google.com with SMTP id z25-v6so5591032pgu.7 for ; Sat, 25 Aug 2018 09:05:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hq4fPtunjdzFUjXa1s3v46pX8nnv2EXaz/zt/jA8EOg=; b=YmH92303YMH8jT6RaVYkeZjheskI8b/Gr/KN6YflMpI/uM146d1V9PFPEkNqnvfmyX Jgis3/L94bM1MPC4y83r/44ihtSSrduPMHdqn8NTY1UgxOAshag+yPss0LYX+WjJVG0B aszzJgMKV99w8WtH/zEIoUpG5Tiv4C0T/veAzWalGoa5iT7wBAA9+LrWH6GvV6ts5sm7 vo3ArbOo0XA21N38CeAGQvbCqghp1CodFjZUt1nKUOnwKf0Ozo7q1gdMGU0HHm41NVYa n8kR6cxU79cg7/JuOMvjZ1S3rB7bp4CDtWOVKAW3CeCD7DLJoDBuKFfTVU6BsVrsgd2T hU4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hq4fPtunjdzFUjXa1s3v46pX8nnv2EXaz/zt/jA8EOg=; b=lhe1zJOQN0NgAyz8YLx5kK98wD8a+ExgbX1BYAoqZu7ds6OZ2DS5rS3UcZ8QLiPftC NHnW4zgfDqIFYv4aeDXVqbnbo639c2m+LheZ2hzkU7/AWtOEpRo83JSxO3Qfs31rNlmZ cZ9VbVCaklHJ4qpmHtOLRUNuhl3U6YK7qo2p6ot6JsnCfM0tdBRAW8CzHx3DIKEvYlmt AmhxAu7NW1XgEt3t3OHUq65A4U1vVsgaQi4KjumL5LZquF48g/yLqbL0f8KSnbm6lWRz L4BRFRFHnCtG9ZppM5Mq733NbHVO6INGtTRoREemMrMUnANTs3EdU4S5asg1Vm4Uaw8s j4nA== X-Gm-Message-State: APzg51CgAmPF+XyNmpdDdYfCOZbIlkb5PZ4OsTKtTgxHQyJHXsit9GK+ hLk519Qxz0v7O8E5hXosIliWG5Yeuku9GkrmNYfAJwY= X-Google-Smtp-Source: ANB0VdbkklxB0Vf9RDcdOcg5yveGxMoOG7+hBU8nTaSZkw4FkWhJSktd1LMMDbmMXAWVvHfuSGBgsrIaHUpUQjueUIA= X-Received: by 2002:a62:e511:: with SMTP id n17-v6mr6664944pff.210.1535213124757; Sat, 25 Aug 2018 09:05:24 -0700 (PDT) In-Reply-To: <87ftz2tqxi.fsf@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::535 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:117735 Archived-At: 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 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 "..." "...")) 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 > >