unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#73745: Add query-replace-reverse functions
@ 2024-10-11 11:00 Dan Jacobson
  2024-10-11 13:08 ` Eli Zaretskii
  2024-10-14 17:45 ` Juri Linkov
  0 siblings, 2 replies; 5+ messages in thread
From: Dan Jacobson @ 2024-10-11 11:00 UTC (permalink / raw)
  To: 73745

I am looking at the M-% prompt:
```
Query replace (default <h2 → <h2 class="zzz"): <h2 → <h2 class="zz"
```
and I am wondering how to get it to do the reverse?

It is prompting with my previous action, but now I want to do the exact
opposite,   `<h2 class="zz" → <h`
No, I can't just put my (emacs -nw) cursor on top of the arrow and hit M-t.
https://stackoverflow.com/questions/39700435/emacs-query-replace-regexp-reverse-order-of-default#comment132667451_39705933
because my string is not so simple.

>Just hit the undo button.

I don't want to do an undo, I want to do a reverse query replace of my
previous query replace.

Wait. And then it dawned on me: emacs needs a
reverse-previous-query-replace function.

It would be just like query-replace, but using B -> A instead of A -> B.

And doing ESC p should march through the query replace history, but with
each pair reversed!

And same for query-replace-regexp. There needs to be a
reverse-query-replace-regexp too.

Or maybe call them query-replace-reverse, etc.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#73745: Add query-replace-reverse functions
  2024-10-11 11:00 bug#73745: Add query-replace-reverse functions Dan Jacobson
@ 2024-10-11 13:08 ` Eli Zaretskii
  2024-10-14 17:45 ` Juri Linkov
  1 sibling, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2024-10-11 13:08 UTC (permalink / raw)
  To: Dan Jacobson; +Cc: 73745

> From: Dan Jacobson <jidanni@jidanni.org>
> Date: Fri, 11 Oct 2024 19:00:02 +0800
> 
> I am looking at the M-% prompt:
> ```
> Query replace (default <h2 → <h2 class="zzz"): <h2 → <h2 class="zz"
> ```
> and I am wondering how to get it to do the reverse?

Type M-p or <UP> arrow twice.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#73745: Add query-replace-reverse functions
  2024-10-11 11:00 bug#73745: Add query-replace-reverse functions Dan Jacobson
  2024-10-11 13:08 ` Eli Zaretskii
@ 2024-10-14 17:45 ` Juri Linkov
  2024-10-14 21:32   ` Stefan Kangas
  1 sibling, 1 reply; 5+ messages in thread
From: Juri Linkov @ 2024-10-14 17:45 UTC (permalink / raw)
  To: Dan Jacobson; +Cc: 73745

> It is prompting with my previous action, but now I want to do the exact
> opposite,   `<h2 class="zz" → <h`
> No, I can't just put my (emacs -nw) cursor on top of the arrow and hit M-t.

Some time ago we discussed 'M-t' to reverse 'from'/'to' parts.
But the problem is that for multi-word replacements
'M-t' should still transpose words inside 'from' or 'to'
separately.

All transpose keys ‘C-t’ (‘transpose-chars’), ‘M-t’
(‘transpose-words’), ‘C-M-t’ (‘transpose-sexps’), even ‘C-x C-t’
(‘transpose-lines’) for multi-line replacements -
all these keys can't be used to reverse 'from'/'to'.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#73745: Add query-replace-reverse functions
  2024-10-14 17:45 ` Juri Linkov
@ 2024-10-14 21:32   ` Stefan Kangas
  2024-10-15  6:17     ` Juri Linkov
  0 siblings, 1 reply; 5+ messages in thread
From: Stefan Kangas @ 2024-10-14 21:32 UTC (permalink / raw)
  To: Juri Linkov, Dan Jacobson; +Cc: 73745

Juri Linkov <juri@linkov.net> writes:

>> It is prompting with my previous action, but now I want to do the exact
>> opposite,   `<h2 class="zz" → <h`
>> No, I can't just put my (emacs -nw) cursor on top of the arrow and hit M-t.
>
> Some time ago we discussed 'M-t' to reverse 'from'/'to' parts.
> But the problem is that for multi-word replacements
> 'M-t' should still transpose words inside 'from' or 'to'
> separately.
>
> All transpose keys ‘C-t’ (‘transpose-chars’), ‘M-t’
> (‘transpose-words’), ‘C-M-t’ (‘transpose-sexps’), even ‘C-x C-t’
> (‘transpose-lines’) for multi-line replacements -
> all these keys can't be used to reverse 'from'/'to'.

How about something like `C-c M-t`?





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#73745: Add query-replace-reverse functions
  2024-10-14 21:32   ` Stefan Kangas
@ 2024-10-15  6:17     ` Juri Linkov
  0 siblings, 0 replies; 5+ messages in thread
From: Juri Linkov @ 2024-10-15  6:17 UTC (permalink / raw)
  To: Stefan Kangas; +Cc: 73745, Dan Jacobson

>>> It is prompting with my previous action, but now I want to do the exact
>>> opposite,   `<h2 class="zz" → <h`
>>> No, I can't just put my (emacs -nw) cursor on top of the arrow and hit M-t.
>>
>> Some time ago we discussed 'M-t' to reverse 'from'/'to' parts.
>> But the problem is that for multi-word replacements
>> 'M-t' should still transpose words inside 'from' or 'to'
>> separately.
>>
>> All transpose keys ‘C-t’ (‘transpose-chars’), ‘M-t’
>> (‘transpose-words’), ‘C-M-t’ (‘transpose-sexps’), even ‘C-x C-t’
>> (‘transpose-lines’) for multi-line replacements -
>> all these keys can't be used to reverse 'from'/'to'.
>
> How about something like `C-c M-t`?

I see no other keys on the `C-c` keymap in the minibuffer:

  No commands with a binding that start with C-c.

OTOH, while reading a regexp for `C-M-%` there is:

  M-s c		read-regexp-toggle-case-fold

So maybe `M-s M-t` is not too bad.





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-10-15  6:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-11 11:00 bug#73745: Add query-replace-reverse functions Dan Jacobson
2024-10-11 13:08 ` Eli Zaretskii
2024-10-14 17:45 ` Juri Linkov
2024-10-14 21:32   ` Stefan Kangas
2024-10-15  6:17     ` Juri Linkov

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).