diff --git a/doc/emacs/search.texi b/doc/emacs/search.texi index 70bb6b04abd..11626480fe9 100644 --- a/doc/emacs/search.texi +++ b/doc/emacs/search.texi @@ -1908,6 +1908,10 @@ made. to undo all the replacements and go back to where the first replacement was made. +@item d +to show the diff buffer that changes all occurrences to their +replacements. + @item C-r to enter a recursive editing level, in case the occurrence needs to be edited rather than just replaced with @var{newstring}. When you are diff --git a/etc/NEWS b/etc/NEWS index 090a6db8044..e490115a23f 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -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 the Tramp manual. +** Isearch and Replace + +*** Typing 'd' during 'query-replace' shows the diff buffer with replacements. + ** Diff --- diff --git a/lisp/replace.el b/lisp/replace.el index 6635cc6afe4..b0689b93e06 100644 --- a/lisp/replace.el +++ b/lisp/replace.el @@ -2459,6 +2459,7 @@ To be added to `context-menu-functions'." \\`U' to undo all replacements, \\`e' to edit the replacement string. \\`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, \\`Y' to replace all remaining matches in all remaining buffers (in 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 "u" 'undo) (define-key map "U" 'undo-all) + (define-key map "d" 'diff) (define-key map "\C-h" 'help) (define-key map [f1] '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', `edit', `edit-replacement', `edit-replacement-exact-case', `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'.") @@ -3334,6 +3336,16 @@ characters." (replace-dehighlight) (save-excursion (recursive-edit)) (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) (call-interactively def)) ;; Note: we do not need to treat `exit-prefix'