GNU bug report logs - #73745
Add query-replace-reverse functions

Previous Next

Package: emacs;

Reported by: Dan Jacobson <jidanni <at> jidanni.org>

Date: Fri, 11 Oct 2024 11:03:01 UTC

Severity: wishlist

To reply to this bug, email your comments to 73745 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#73745; Package emacs. (Fri, 11 Oct 2024 11:03:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Dan Jacobson <jidanni <at> jidanni.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Fri, 11 Oct 2024 11:03:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Dan Jacobson <jidanni <at> jidanni.org>
To: bug-gnu-emacs <at> gnu.org
Subject: Add query-replace-reverse functions
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?

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.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#73745; Package emacs. (Fri, 11 Oct 2024 13:09:02 GMT) Full text and rfc822 format available.

Message #8 received at 73745 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Dan Jacobson <jidanni <at> jidanni.org>
Cc: 73745 <at> debbugs.gnu.org
Subject: Re: bug#73745: Add query-replace-reverse functions
Date: Fri, 11 Oct 2024 16:08:13 +0300
> From: Dan Jacobson <jidanni <at> 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.




Severity set to 'wishlist' from 'normal' Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Sat, 12 Oct 2024 13:34:02 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#73745; Package emacs. (Mon, 14 Oct 2024 17:50:01 GMT) Full text and rfc822 format available.

Message #13 received at 73745 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Dan Jacobson <jidanni <at> jidanni.org>
Cc: 73745 <at> debbugs.gnu.org
Subject: Re: bug#73745: Add query-replace-reverse functions
Date: Mon, 14 Oct 2024 20:45:43 +0300
> 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'.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#73745; Package emacs. (Mon, 14 Oct 2024 21:35:01 GMT) Full text and rfc822 format available.

Message #16 received at 73745 <at> debbugs.gnu.org (full text, mbox):

From: Stefan Kangas <stefankangas <at> gmail.com>
To: Juri Linkov <juri <at> linkov.net>, Dan Jacobson <jidanni <at> jidanni.org>
Cc: 73745 <at> debbugs.gnu.org
Subject: Re: bug#73745: Add query-replace-reverse functions
Date: Mon, 14 Oct 2024 21:32:56 +0000
Juri Linkov <juri <at> 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`?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#73745; Package emacs. (Tue, 15 Oct 2024 06:30:02 GMT) Full text and rfc822 format available.

Message #19 received at 73745 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> linkov.net>
To: Stefan Kangas <stefankangas <at> gmail.com>
Cc: 73745 <at> debbugs.gnu.org, Dan Jacobson <jidanni <at> jidanni.org>
Subject: Re: bug#73745: Add query-replace-reverse functions
Date: Tue, 15 Oct 2024 09:17:08 +0300
>>> 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.




This bug report was last modified 243 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.