GNU bug report logs - #79835
[PATCH] Add query-replace-read-transpose-from-to

Previous Next

Package: emacs;

Reported by: Jens Schmidt <jschmidt4gnu <at> vodafonemail.de>

Date: Fri, 14 Nov 2025 19:54:02 UTC

Severity: normal

Tags: patch

To reply to this bug, email your comments to 79835 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 juri <at> linkov.net, bug-gnu-emacs <at> gnu.org:
bug#79835; Package emacs. (Fri, 14 Nov 2025 19:54:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Jens Schmidt <jschmidt4gnu <at> vodafonemail.de>:
New bug report received and forwarded. Copy sent to juri <at> linkov.net, bug-gnu-emacs <at> gnu.org. (Fri, 14 Nov 2025 19:54:02 GMT) Full text and rfc822 format available.

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

From: Jens Schmidt <jschmidt4gnu <at> vodafonemail.de>
To: bug-gnu-emacs <at> gnu.org
Subject: [PATCH] Add query-replace-read-transpose-from-to
Date: Fri, 14 Nov 2025 20:52:37 +0100
[Message part 1 (text/plain, inline)]
Tags: patch

Occasionally I find it useful to transpose/swap the "from" and "to" in
the minibuffer query of a `query-replace' or `query-replace-regexp'.
For example:

- To undo a replacement that (because of other editing that already has
  happened) cannot be easily undone with C-_.

- To replace first "foo" => "bar", then "bar" => "baz" for a subset of
  the previous replacements.

The attached patch provides a new command
`query-replace-read-transpose-from-to' that does exactly that.

There is one cave-at: For the new command I extended the prefix M-s
already used by `query-replace-regexp' (through `read-regexp-map') also
to be used by plain `query-replace' (through new
`query-replace-read-map').  This hides the current binding of M-s for
`next-matching-history-element'.  See patch for details.

If you find this idea useful, I'd make that a full-fledged patch.  Which
in that case probably just means to add a NEWS entry: I don't consider
this feature important enough to document it in any manual, and
replace-tests.el does not seem to have the infrastructure to simulate
minibuffer actions.

Thanks!

In GNU Emacs 31.0.50 (build 2, x86_64-pc-linux-gnu, GTK+ Version
 3.24.49, cairo version 1.18.4) of 2025-11-14 built on sappc2
Repository revision: 394090486ccbf94f42661cac592ca5f29b5b1fe8
Repository branch: add-query-replace-read-transpose-from-to
Windowing system distributor 'The X.Org Foundation', version 11.0.12401006
System Description: Debian GNU/Linux 13 (trixie)

Configured using:
 'configure -C --build x86_64-linux-gnu --sharedstatedir=/var/lib
 --localstatedir=/var/lib --with-libsystemd --with-pop=yes
 --with-sound=alsa --without-gconf --with-mailutils --with-cairo
 --with-x=yes --with-x-toolkit=gtk3 --with-toolkit-scroll-bars
 build_alias=x86_64-linux-gnu'

[0001-Add-query-replace-read-transpose-from-to.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79835; Package emacs. (Sun, 16 Nov 2025 17:11:02 GMT) Full text and rfc822 format available.

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

From: Juri Linkov <juri <at> linkov.net>
To: Jens Schmidt <jschmidt4gnu <at> vodafonemail.de>
Cc: 79835 <at> debbugs.gnu.org
Subject: Re: bug#79835: [PATCH] Add query-replace-read-transpose-from-to
Date: Sun, 16 Nov 2025 18:55:34 +0200
> If you find this idea useful, I'd make that a full-fledged patch.  Which
> in that case probably just means to add a NEWS entry: I don't consider
> this feature important enough to document it in any manual, and
> replace-tests.el does not seem to have the infrastructure to simulate
> minibuffer actions.

Thank you very much for implementing this long-missed feature.
Adding a NEWS entry would be nice.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79835; Package emacs. (Sun, 16 Nov 2025 22:06:01 GMT) Full text and rfc822 format available.

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

From: Jens Schmidt <jschmidt4gnu <at> vodafonemail.de>
To: Juri Linkov <juri <at> linkov.net>
Cc: 79835 <at> debbugs.gnu.org
Subject: Re: bug#79835: [PATCH] Add query-replace-read-transpose-from-to
Date: Sun, 16 Nov 2025 23:04:58 +0100
[Message part 1 (text/plain, inline)]
On 2025-11-16  17:55, Juri Linkov wrote:

> Thank you very much for implementing this long-missed feature.
> Adding a NEWS entry would be nice.

Please see the attached patch.  Thanks!
[0001-Add-query-replace-read-transpose-from-to.patch (text/x-patch, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79835; Package emacs. (Mon, 17 Nov 2025 12:32:02 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Jens Schmidt <jschmidt4gnu <at> vodafonemail.de>
Cc: 79835 <at> debbugs.gnu.org, juri <at> linkov.net
Subject: Re: bug#79835: [PATCH] Add query-replace-read-transpose-from-to
Date: Mon, 17 Nov 2025 14:31:22 +0200
> Cc: 79835 <at> debbugs.gnu.org
> Date: Sun, 16 Nov 2025 23:04:58 +0100
> From:  Jens Schmidt via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
> 
> > Thank you very much for implementing this long-missed feature.
> > Adding a NEWS entry would be nice.
> 
> Please see the attached patch.  Thanks!

Thanks.

> +(defun query-replace-read-transpose-from-to ()
> +  "Transpose the `from' and `to' of a `query-replace' operation."

This should use FROM and TO.  Something like

  Transpose the FROM and TO arguments of a `query-replace' operation.

> +(defvar-keymap query-replace-read-map
>    :parent minibuffer-local-map
> +  ;; defining M-s as a prefix here has the side effect of hiding
        ^^^^^^^^
Please start a sentence with a capital letter.




This bug report was last modified today.

Previous Next


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