From: Skip Montanaro <skip.montanaro@gmail.com>
To: rodolfo.medina@gmail.com
Cc: Help GNU Emacs <help-gnu-emacs@gnu.org>
Subject: Re: Automate replace-regexp
Date: Sat, 25 Aug 2018 11:04:58 -0500 [thread overview]
Message-ID: <CANc-5UyB0pBn2ie9KMznYrR1jS8XHbkW9kqrY8y9MVCVqC9jmw@mail.gmail.com> (raw)
In-Reply-To: <87ftz2tqxi.fsf@gmail.com>
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
<rodolfo.medina@gmail.com> 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
>
>
next prev parent reply other threads:[~2018-08-25 16:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-25 15:19 Automate replace-regexp Rodolfo Medina
2018-08-25 16:04 ` Skip Montanaro [this message]
2018-08-26 2:15 ` Rodolfo Medina
2018-08-26 2:40 ` Rodolfo Medina
2018-08-26 4:01 ` Rodolfo Medina
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CANc-5UyB0pBn2ie9KMznYrR1jS8XHbkW9kqrY8y9MVCVqC9jmw@mail.gmail.com \
--to=skip.montanaro@gmail.com \
--cc=help-gnu-emacs@gnu.org \
--cc=rodolfo.medina@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.