* Automate replace-regexp
@ 2018-08-25 15:19 Rodolfo Medina
2018-08-25 16:04 ` Skip Montanaro
0 siblings, 1 reply; 5+ messages in thread
From: Rodolfo Medina @ 2018-08-25 15:19 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Automate replace-regexp
2018-08-25 15:19 Automate replace-regexp Rodolfo Medina
@ 2018-08-25 16:04 ` Skip Montanaro
2018-08-26 2:15 ` Rodolfo Medina
0 siblings, 1 reply; 5+ messages in thread
From: Skip Montanaro @ 2018-08-25 16:04 UTC (permalink / raw)
To: rodolfo.medina; +Cc: Help GNU Emacs
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
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Automate replace-regexp
2018-08-25 16:04 ` Skip Montanaro
@ 2018-08-26 2:15 ` Rodolfo Medina
2018-08-26 2:40 ` Rodolfo Medina
2018-08-26 4:01 ` Rodolfo Medina
0 siblings, 2 replies; 5+ messages in thread
From: Rodolfo Medina @ 2018-08-26 2:15 UTC (permalink / raw)
To: help-gnu-emacs
Skip Montanaro <skip.montanaro@gmail.com> 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
> <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
>>
>>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Automate replace-regexp
2018-08-26 2:15 ` Rodolfo Medina
@ 2018-08-26 2:40 ` Rodolfo Medina
2018-08-26 4:01 ` Rodolfo Medina
1 sibling, 0 replies; 5+ messages in thread
From: Rodolfo Medina @ 2018-08-26 2:40 UTC (permalink / raw)
To: help-gnu-emacs
Rodolfo Medina <rodolfo.medina@gmail.com> writes:
> Skip Montanaro <skip.montanaro@gmail.com> 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...
It seems it begins to work now...
Rodolfo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Automate replace-regexp
2018-08-26 2:15 ` Rodolfo Medina
2018-08-26 2:40 ` Rodolfo Medina
@ 2018-08-26 4:01 ` Rodolfo Medina
1 sibling, 0 replies; 5+ messages in thread
From: Rodolfo Medina @ 2018-08-26 4:01 UTC (permalink / raw)
To: help-gnu-emacs
Rodolfo Medina <rodolfo.medina@gmail.com> writes:
> Besides, the command should only act in the present paragraph...
...Or better, to the next occurrence of the TeX command `\Endpiece'...
(MusiXTeX document...)
Rodolfo
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-08-26 4:01 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-25 15:19 Automate replace-regexp Rodolfo Medina
2018-08-25 16:04 ` Skip Montanaro
2018-08-26 2:15 ` Rodolfo Medina
2018-08-26 2:40 ` Rodolfo Medina
2018-08-26 4:01 ` Rodolfo Medina
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).