1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-05 22:20:24 -08:00

Show the diff buffer with replacements by typing 'd' in 'query-replace'

* doc/emacs/search.texi (Query Replace): Mention new key 'd'.

* lisp/replace.el (query-replace-help): Mention the key 'd'.
(query-replace-map): Bind the key 'd' to 'diff'.
(perform-replace): When 'def' is equal to 'diff',
call 'multi-file-replace-as-diff' to show the diff buffer
with replacements (bug#79761).
This commit is contained in:
Juri Linkov 2025-11-20 20:39:29 +02:00
parent ae5c361d32
commit f4d353f9c9
3 changed files with 21 additions and 1 deletions

View file

@ -1908,6 +1908,10 @@ made.
to undo all the replacements and go back to where the first to undo all the replacements and go back to where the first
replacement was made. replacement was made.
@item d
to show the diff buffer that changes all occurrences to their
replacements.
@item C-r @item C-r
to enter a recursive editing level, in case the occurrence needs to be to enter a recursive editing level, in case the occurrence needs to be
edited rather than just replaced with @var{newstring}. When you are edited rather than just replaced with @var{newstring}. When you are

View file

@ -2007,6 +2007,10 @@ This can be used by external ELPA packages for performance optimizations
in special cases. For more information, see "(tramp) New operations" in in special cases. For more information, see "(tramp) New operations" in
the Tramp manual. the Tramp manual.
** Isearch and Replace
*** Typing 'd' during 'query-replace' shows the diff buffer with replacements.
** Diff ** Diff
--- ---

View file

@ -2459,6 +2459,7 @@ To be added to `context-menu-functions'."
\\`U' to undo all replacements, \\`U' to undo all replacements,
\\`e' to edit the replacement string. \\`e' to edit the replacement string.
\\`E' to edit the replacement string with exact case. \\`E' to edit the replacement string with exact case.
\\`d' to display the diff buffer with all replacements.
\\`C-l' to clear the screen, redisplay, and offer same replacement again, \\`C-l' to clear the screen, redisplay, and offer same replacement again,
\\`Y' to replace all remaining matches in all remaining buffers (in \\`Y' to replace all remaining matches in all remaining buffers (in
multi-buffer replacements) with no more questions, multi-buffer replacements) with no more questions,
@ -2492,6 +2493,7 @@ re-executed as a normal key sequence."
(define-key map "^" 'backup) (define-key map "^" 'backup)
(define-key map "u" 'undo) (define-key map "u" 'undo)
(define-key map "U" 'undo-all) (define-key map "U" 'undo-all)
(define-key map "d" 'diff)
(define-key map "\C-h" 'help) (define-key map "\C-h" 'help)
(define-key map [f1] 'help) (define-key map [f1] 'help)
(define-key map [help] 'help) (define-key map [help] 'help)
@ -2518,7 +2520,7 @@ The valid answers include `act', `skip', `act-and-show',
`scroll-down', `scroll-other-window', `scroll-other-window-down', `scroll-down', `scroll-other-window', `scroll-other-window-down',
`edit', `edit-replacement', `edit-replacement-exact-case', `edit', `edit-replacement', `edit-replacement-exact-case',
`delete-and-edit', `automatic', `backup', `undo', `undo-all', `delete-and-edit', `automatic', `backup', `undo', `undo-all',
`quit', and `help'. `diff', `quit', and `help'.
This keymap is used by `y-or-n-p' as well as `query-replace'.") This keymap is used by `y-or-n-p' as well as `query-replace'.")
@ -3334,6 +3336,16 @@ characters."
(replace-dehighlight) (replace-dehighlight)
(save-excursion (recursive-edit)) (save-excursion (recursive-edit))
(setq replaced t)) (setq replaced t))
((eq def 'diff)
(let ((display-buffer-overriding-action
'(nil (inhibit-same-window . t))))
(save-selected-window
(multi-file-replace-as-diff
(list (or buffer-file-name (current-buffer)))
from-string (or replacements next-replacement)
regexp-flag delimited-flag))))
((commandp def t) ((commandp def t)
(call-interactively def)) (call-interactively def))
;; Note: we do not need to treat `exit-prefix' ;; Note: we do not need to treat `exit-prefix'