GNU bug report logs - #79761
30.1.90; replace-regexp-as-diff fails on non-file-visiting buffers

Previous Next

Package: emacs;

Reported by: Spencer Baugh <sbaugh <at> janestreet.com>

Date: Mon, 3 Nov 2025 21:03:02 UTC

Severity: normal

Found in version 30.1.90

To reply to this bug, email your comments to 79761 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 azeng <at> janestreet.com, juri <at> linkov.net, bug-gnu-emacs <at> gnu.org:
bug#79761; Package emacs. (Mon, 03 Nov 2025 21:03:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Spencer Baugh <sbaugh <at> janestreet.com>:
New bug report received and forwarded. Copy sent to azeng <at> janestreet.com, juri <at> linkov.net, bug-gnu-emacs <at> gnu.org. (Mon, 03 Nov 2025 21:03:02 GMT) Full text and rfc822 format available.

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

From: Spencer Baugh <sbaugh <at> janestreet.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 30.1.90; replace-regexp-as-diff fails on non-file-visiting buffers
Date: Mon, 03 Nov 2025 16:01:39 -0500
1. emacs -Q
2. C-x b *scratch*
3. M-x replace-regexp-as-diff foo bar
4. Observe immediate error.

I guess this is because it relies on multi-file-replace-as-diff which
only works on file-visiting buffers.

(BTW, it would be neat if replace-regexp-as-diff was incorporated into
normal query-replace - if, perhaps, after M-% you could press "d" to
display a diff buffer with the rest of the replacements, and probably
also exit the query-replace)


In GNU Emacs 30.1.90 (build 77, x86_64-pc-linux-gnu, X toolkit, cairo
 version 1.15.12, Xaw scroll bars) of 2025-10-27 built on
 igm-qws-u22796a
Repository revision: c62810f30fbbf4054050698f37acc6c45bb30624
Repository branch: emacs-30
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Rocky Linux 8.10 (Green Obsidian)

Configured using:
 'configure --with-x-toolkit=lucid --without-gpm --without-gconf
 --without-selinux --without-imagemagick --with-modules --with-gif=no
 --with-cairo --with-rsvg --without-compress-install --with-tree-sitter
 --with-native-compilation=aot
 PKG_CONFIG_PATH=/usr/local/home/garnish/libtree-sitter/0.22.6-1/lib/pkgconfig/'

Configured features:
CAIRO DBUS FREETYPE GLIB GMP GNUTLS GSETTINGS HARFBUZZ JPEG LIBSYSTEMD
LIBXML2 MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP
SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER X11 XDBE XIM
XINPUT2 XPM LUCID ZLIB

Important settings:
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect:
  global-so-long-mode: t
  global-git-commit-mode: t
  magit-auto-revert-mode: t
  windmove-mode: t
  savehist-mode: t
  save-place-mode: t
  delete-selection-mode: t
  dired-omit-mode: t
  editorconfig-mode: t
  mode-line-bell-mode: t
  server-mode: t
  global-jane-cr-highlight-minor-mode: t
  jane-cr-highlight-minor-mode: t
  diff-hl-mode: t
  jane-fe-jenga-minor-mode: t
  jane-fe-minor-mode: t
  jane-minor-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  vc-auto-revert-mode: t
  mouse-wheel-mode: t
  tab-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  context-menu-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  minibuffer-regexp-mode: t
  line-number-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  abbrev-mode: t

Features:
(shadow emacsbug cl-print tramp-cache time-stamp tramp-sh shortdoc
help-fns radix-tree face-remap bug-reference macrostep-c cmacexp
macrostep cc-mode cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align
cc-engine cc-vars cc-defs whitespace qp smiley gnus-cite textsec
uni-scripts idna-mapping ucs-normalize uni-confusable textsec-check
gnus-async gnus-bcklg gnus-agent gnus-srvr gnus-score score-mode
nnvirtual nntp gnus-ml gnus-msg disp-table nndoc gnus-cache gnus-dup
display-line-numbers mm-archive debbugs-gnu debbugs soap-client rng-xsd
rng-dt rng-util xsd-regexp debbugs-compat dabbrev misc wgrep tramp
trampver tramp-integration tramp-message tramp-compat tramp-loaddefs
mail-extr markdown-mode edit-indirect sort find-dired url-http-ntlm ntlm
hmac-md5 hex-util md4 network-stream url-http url-gw nsm url-cache
agent-shell agent-shell-heartbeat agent-shell-qwen agent-shell-openai
agent-shell-goose agent-shell-google agent-shell-diff
agent-shell-anthropic agent-shell-ui shell-maker markdown-overlays acp
acp-traffic pulse color ocaml-eglot ocaml-eglot-type-enclosing flycheck
ffap oc-basic org-element org-persist org-id org-refile org-element-ast
inline avl-tree generator ol-eww eww xdg url-queue mm-url ol-rmail
ol-mhe ol-irc ol-info ol-gnus nnselect ol-docview doc-view jka-compr
image-mode exif ol-bibtex bibtex ol-bbdb ol-w3m ol-doi org-link-doi rect
vc-git misearch multi-isearch dired-aux files-x jane-fe-diff
jane-fe-show goto-addr jane-fe-todo jane-fe-wl jane-fe-history
jane-fe-feature-specific gnus-art mm-uu mml2015 mm-view mml-smime smime
gnutls dig gnus-sum shr pixel-fill kinsoku url-file svg dom gnus-group
gnus-undo gnus-start gnus-dbus dbus xml gnus-cloud nnimap nnmail
mail-source utf7 nnoo parse-time iso8601 gnus-spec gnus-int gnus-range
gnus-win jane-dune open-junk-file vc-fe grep let-alist so-long vc-hg
skeleton page-ext magit-extras magit-bookmark magit-submodule
magit-blame magit-stash magit-reflog magit-bisect magit-push magit-pull
magit-fetch magit-clone magit-remote magit-commit magit-sequence
magit-notes magit-worktree magit-tag magit-merge magit-branch
magit-reset magit-files magit-refs magit-status magit magit-repos
magit-apply magit-wip magit-log which-func magit-diff git-commit dash
magit-core magit-autorevert magit-margin magit-transient magit-process
with-editor magit-mode transient edmacro kmacro benchmark magit-git
magit-base magit-section cursor-sensor llama cond-let compat gnus
nnheader range windmove org org-macro org-pcomplete org-list
org-footnote org-faces org-entities noutline outline ob-dot ob-shell ob
ob-tangle org-src sh-script treesit executable ob-ref ob-lob ob-table
ob-exp ob-comint ob-emacs-lisp ob-core ob-eval org-cycle org-table ol
org-fold org-fold-core org-keys oc org-loaddefs cal-menu calendar
cal-loaddefs org-version org-compat org-macs format-spec gdb-mi bindat
vundo modus-vivendi-theme modus-themes savehist saveplace finder-inf
site-start jane-customization jane-which-key which-key delsel
jane-build-status jane-fe-workspace jane-patdiff jane-diagnose
jane-async-merlin jane-completion jane-aide jane-yasnippet jane-fe-menu
ecaml autorevert dired-x editorconfig editorconfig-core
editorconfig-core-handle editorconfig-fnmatch mode-line-bell help-at-pt
jane-micro-features server jane-diff smerge-mode unified-test-mode
shell-file jane-fe-read-feature jane-fe-regex jane-fe-vtable vtable
mule-util jane-fe-project jane-fe-feature-table hl-line jane-fe-button
jane-sexp rainbow-delimiters jane-python jane-ocaml gud hydra lv
jane-merlin merlin-xref merlin-cap merlin hi-lock advice crm
ocaml-eglot-xref ocaml-eglot-req ocaml-eglot-util tuareg tuareg-compat
tuareg-opam smie caml-types caml-help view find-file jane-cr jane-align
shell pcomplete diff-hl log-view log-edit message sendmail yank-media
puny dired dired-loaddefs rfc822 mml mml-sec epa derived gnus-util
mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047 rfc2045 mm-util
ietf-drums mail-prsvr mailabbrev mail-utils gmm-utils mailheader add-log
pcvs-util vc-dir vc vc-dispatcher jane-telemetry jane-ecaml ecaml_plugin
time-date comp comp-cstr cl-extra bookmark jane-rust ocp-indent
jane-eglot eglot tree-widget external-completion jsonrpc xref flymake
thingatpt project diff diff-mode track-changes easy-mmode ert ewoc debug
backtrace help-mode find-func filenotify warnings imenu contrib-loaddefs
jane-loaddefs jane-util jane-elpa-pin cus-edit pp cus-start cus-load
wid-edit jane-constants adaptive-wrap-autoloads agent-shell-autoloads
acp-autoloads caml-autoloads corfu-autoloads csv-mode-autoloads
cyberpunk-theme-autoloads debbugs-autoloads diffview-autoloads
git-commit-autoloads keycast-autoloads mct-autoloads
shell-maker-autoloads url-http-ntlm-autoloads url-auth utop-autoloads
vc-hgcmd-autoloads vertico-autoloads vundo-autoloads ace-link-autoloads
aggressive-indent-autoloads ahk-mode-autoloads
all-the-icons-ivy-rich-autoloads amx-autoloads auto-compile-autoloads
auto-dictionary-autoloads auto-highlight-symbol-autoloads
auto-yasnippet-autoloads base16-theme-autoloads
bash-completion-autoloads blacken-autoloads browse-at-remote-autoloads
centered-cursor-mode-autoloads claude-code-ide-autoloads
clean-aindent-mode-autoloads code-cells-autoloads
column-enforce-mode-autoloads company-box-autoloads
company-lua-autoloads company-posframe-autoloads
company-quickhelp-autoloads company-shell-autoloads
company-statistics-autoloads company-web-autoloads
consult-yasnippet-autoloads counsel-css-autoloads
counsel-projectile-autoloads counsel-autoloads
cpp-auto-include-autoloads dap-mode-autoloads bui-autoloads
define-word-autoloads diff-hl-autoloads diminish-autoloads
dired-quick-sort-autoloads disable-mouse-autoloads disaster-autoloads
doom-modeline-autoloads doom-themes-autoloads dotenv-mode-autoloads
drag-stuff-autoloads eat-autoloads edit-indirect-autoloads
eldoc-box-autoloads elisp-def-autoloads elisp-slime-nav-autoloads
embark-consult-autoloads consult-autoloads embark-autoloads
emmet-mode-autoloads emr-autoloads clang-format-autoloads
envrc-autoloads esh-help-autoloads eshell-prompt-extras-autoloads
eshell-z-autoloads ess-autoloads eval-sexp-fu-autoloads
evil-anzu-autoloads anzu-autoloads evil-args-autoloads
evil-cleverparens-autoloads evil-collection-autoloads annalist-autoloads
evil-easymotion-autoloads evil-escape-autoloads evil-exchange-autoloads
evil-goggles-autoloads evil-iedit-state-autoloads
evil-indent-plus-autoloads evil-leader-autoloads evil-lion-autoloads
evil-lisp-state-autoloads bind-map-autoloads evil-matchit-autoloads
evil-mc-autoloads evil-nerd-commenter-autoloads evil-numbers-autoloads
evil-org-autoloads evil-quickscope-autoloads evil-surround-autoloads
evil-textobj-line-autoloads evil-tutor-autoloads
evil-visual-mark-mode-autoloads evil-visualstar-autoloads
expand-region-autoloads eyebrowse-autoloads fish-mode-autoloads
flx-autoloads flycheck-bashate-autoloads flycheck-eglot-autoloads
eglot-autoloads flycheck-elsa-autoloads flycheck-package-autoloads
flycheck-pos-tip-autoloads flyspell-correct-helm-autoloads
flyspell-correct-ivy-autoloads flyspell-correct-popup-autoloads
flyspell-correct-autoloads flyspell-popup-autoloads
frame-local-autoloads fzf-autoloads gh-md-autoloads git-gutter-autoloads
git-link-autoloads git-messenger-autoloads popup-autoloads
git-modes-autoloads git-timemachine-autoloads
gitignore-templates-autoloads gnu-elpa-keyring-update-autoloads compile
text-property-search comint ansi-osc ansi-color ring comp-run
comp-common epg rfc6068 epg-config gnu-elpa-keyring-update
gnuplot-autoloads golden-ratio-autoloads google-c-style-autoloads
gruvbox-theme-autoloads autothemer-autoloads haskell-mode-autoloads
hc-zenburn-theme-autoloads helm-ag-autoloads helm-c-yasnippet-autoloads
helm-comint-autoloads helm-company-autoloads company-autoloads
helm-css-scss-autoloads helm-descbinds-autoloads helm-make-autoloads
helm-mode-manager-autoloads helm-org-rifle-autoloads
helm-projectile-autoloads helm-purpose-autoloads helm-pydoc-autoloads
helm-swoop-autoloads helm-autoloads helm-core-autoloads
helpful-autoloads elisp-refs-autoloads highlight-indentation-autoloads
highlight-numbers-autoloads highlight-parentheses-autoloads
ibuffer-projectile-autoloads iedit-autoloads impatient-mode-autoloads
importmagic-autoloads epc-autoloads ctable-autoloads
concurrent-autoloads deferred-autoloads indent-guide-autoloads
inheritenv-autoloads ivy-avy-autoloads ivy-hydra-autoloads
ivy-purpose-autoloads ivy-rich-autoloads ivy-xref-autoloads
ivy-yasnippet-autoloads js-doc-autoloads js2-refactor-autoloads
json-mode-autoloads json-navigator-autoloads json-reformat-autoloads
json-snatcher-autoloads jsonnet-mode-autoloads ligature-autoloads
link-hint-autoloads livid-mode-autoloads lorem-ipsum-autoloads
lsp-docker-autoloads lsp-treemacs-autoloads lsp-mode-autoloads
eldoc-autoloads lua-mode-autoloads macrostep-autoloads
magit-gitflow-autoloads magit-popup-autoloads magit-svn-autoloads
magit-todos-autoloads hl-todo-autoloads marginalia-autoloads
markdown-toc-autoloads material-theme-autoloads merlin-eldoc-autoloads
merlin-autoloads mode-line-bell-autoloads monokai-theme-autoloads
multi-line-autoloads multi-term-autoloads multi-vterm-autoloads
multiple-cursors-autoloads mwim-autoloads nameless-autoloads
nerd-icons-autoloads nix-mode-autoloads nodejs-repl-autoloads
npm-mode-autoloads ob-powershell-autoloads ocaml-eglot-autoloads
ocp-indent-autoloads olivetti-autoloads open-junk-file-autoloads
orderless-autoloads org-alert-autoloads org-appear-autoloads
org-cliplink-autoloads org-contrib-autoloads org-download-autoloads
async-autoloads org-jira-autoloads org-mime-autoloads
org-modern-autoloads org-pomodoro-autoloads alert-autoloads
log4e-autoloads gntp-autoloads org-present-autoloads
org-projectile-autoloads org-project-capture-autoloads
org-category-capture-autoloads org-re-reveal-autoloads htmlize-autoloads
org-rich-yank-autoloads org-roam-autoloads org-sticky-header-autoloads
org-superstar-autoloads org-transclusion-autoloads orgit-forge-autoloads
orgit-autoloads forge-autoloads ghub-autoloads closql-autoloads
emacsql-autoloads origami-autoloads overseer-autoloads ox-gfm-autoloads
ox-jira-autoloads org-autoloads package-lint-autoloads
page-break-lines-autoloads paradox-autoloads paredit-autoloads
parent-mode-autoloads pcre2el-autoloads persistent-scratch-autoloads
pip-requirements-autoloads pippel-autoloads pkg-info-autoloads
epl-autoloads poly-markdown-autoloads polymode-autoloads
popwin-autoloads pos-tip-autoloads powershell-autoloads
prettier-js-autoloads protobuf-mode-autoloads pug-mode-autoloads
py-isort-autoloads pydoc-autoloads pytest-autoloads pyvenv-autoloads
quickrun-autoloads rainbow-delimiters-autoloads request-autoloads
rg-autoloads ron-mode-autoloads rustic-autoloads flycheck-autoloads
markdown-mode-autoloads rust-mode-autoloads sass-mode-autoloads
haml-mode-autoloads scss-mode-autoloads shell-pop-autoloads
shfmt-autoloads reformatter-autoloads shrink-path-autoloads f-autoloads
shut-up-autoloads skewer-mode-autoloads js2-mode-autoloads
simple-httpd-autoloads slim-mode-autoloads smartparens-autoloads
smeargle-autoloads sml-mode-autoloads solarized-theme-autoloads
sphinx-doc-autoloads spinner-autoloads sql-indent-autoloads
sqlup-mode-autoloads string-edit-at-point-autoloads
string-inflection-autoloads swiper-autoloads ivy-autoloads
symbol-overlay-autoloads tagedit-autoloads term-cursor-autoloads
terminal-here-autoloads toc-org-autoloads toml-mode-autoloads
treemacs-all-the-icons-autoloads all-the-icons-autoloads
treemacs-evil-autoloads evil-autoloads goto-chg-autoloads
treemacs-icons-dired-autoloads treemacs-magit-autoloads magit-autoloads
pcase with-editor-autoloads transient-autoloads magit-section-autoloads
llama-autoloads cond-let-autoloads treemacs-persp-autoloads
persp-mode-autoloads treemacs-projectile-autoloads treemacs-autoloads
cfrs-autoloads ht-autoloads hydra-autoloads lv-autoloads
pfuture-autoloads ace-window-autoloads avy-autoloads s-autoloads
projectile-autoloads treepy-autoloads tuareg-autoloads rx
typescript-mode-autoloads undo-fu-autoloads undo-fu-session-autoloads
unfill-autoloads unicode-fonts-autoloads ucs-utils-autoloads
font-utils-autoloads persistent-soft-autoloads list-utils-autoloads
pcache-autoloads urgrep-autoloads uuidgen-autoloads valign-autoloads
vba-mode-autoloads verb-autoloads vi-tilde-fringe-autoloads
vmd-mode-autoloads volatile-highlights-autoloads vterm-autoloads
web-beautify-autoloads web-completion-data-autoloads web-mode-autoloads
web-server-autoloads websocket-autoloads wfnames-autoloads
wgrep-autoloads which-key-posframe-autoloads posframe-autoloads
window-purpose-autoloads imenu-list-autoloads winum-autoloads
dash-autoloads info writeroom-mode-autoloads
visual-fill-column-autoloads ws-butler-autoloads xterm-color-autoloads
yaml-autoloads yasnippet-snippets-autoloads yasnippet-autoloads
zenburn-theme-autoloads package browse-url url url-proxy url-privacy
url-expand url-methods url-history url-cookie generate-lisp-file
url-domsuf url-util mailcap url-handlers url-parse auth-source cl-seq
eieio eieio-core cl-macs icons password-cache json subr-x map byte-opt
gv bytecomp byte-compile url-vars cl-loaddefs cl-lib rmc iso-transl
tooltip cconv eldoc paren electric uniquify ediff-hook vc-hooks
lisp-float-type elisp-mode mwheel term/x-win x-win term/common-win x-dnd
touch-screen tool-bar dnd fontset image fringe tabulated-list replace
newcomment text-mode lisp-mode prog-mode register page tab-bar menu-bar
rfn-eshadow isearch easymenu timer select scroll-bar mouse jit-lock
font-lock syntax font-core term/tty-colors frame minibuffer nadvice seq
simple cl-generic indonesian philippine cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese eucjp-ms
cp51932 hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese composite emoji-zwj charscript charprop case-table
epa-hook jka-cmpr-hook help abbrev obarray oclosure cl-preloaded button
loaddefs theme-loaddefs regexp-opt faces cus-face macroexp files window
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget keymap hashtable-print-readable backquote threads dbusbind
inotify dynamic-setting system-font-setting font-render-setting cairo
x-toolkit xinput2 x multi-tty move-toolbar make-network-process
native-compile emacs)

Memory information:
((conses 16 1726423 221677) (symbols 48 65787 3)
 (strings 32 312747 22177) (string-bytes 1 10157161)
 (vectors 16 141108) (vector-slots 8 2469669 144475)
 (floats 8 920 568) (intervals 56 65230 7046) (buffers 992 256))




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79761; Package emacs. (Tue, 04 Nov 2025 07:50:01 GMT) Full text and rfc822 format available.

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

From: Juri Linkov <juri <at> linkov.net>
To: Spencer Baugh <sbaugh <at> janestreet.com>
Cc: 79761 <at> debbugs.gnu.org, azeng <at> janestreet.com
Subject: Re: bug#79761: 30.1.90; replace-regexp-as-diff fails on
 non-file-visiting buffers
Date: Tue, 04 Nov 2025 09:45:20 +0200
> 1. emacs -Q
> 2. C-x b *scratch*
> 3. M-x replace-regexp-as-diff foo bar
> 4. Observe immediate error.
>
> I guess this is because it relies on multi-file-replace-as-diff which
> only works on file-visiting buffers.

replace-regexp-as-diff was intended to work only on file-visiting buffers.
However, neither its name nor its docstring mention this.  So we could
extend it to support non-file buffers.  This should be straightforward to do
since multi-file-diff-no-select is based on diff-no-select that supports
non-file buffers.

> (BTW, it would be neat if replace-regexp-as-diff was incorporated into
> normal query-replace - if, perhaps, after M-% you could press "d" to
> display a diff buffer with the rest of the replacements, and probably
> also exit the query-replace)

Nice idea - this will help to review the remaining replacements and decide
whether they all can be replaced with !.  So I will implement this as well.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#79761; Package emacs. (Tue, 04 Nov 2025 18:17:02 GMT) Full text and rfc822 format available.

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

From: Juri Linkov <juri <at> linkov.net>
To: Spencer Baugh <sbaugh <at> janestreet.com>
Cc: 79761 <at> debbugs.gnu.org, azeng <at> janestreet.com
Subject: Re: bug#79761: 30.1.90; replace-regexp-as-diff fails on
 non-file-visiting buffers
Date: Tue, 04 Nov 2025 20:15:23 +0200
[Message part 1 (text/plain, inline)]
>> I guess this is because it relies on multi-file-replace-as-diff which
>> only works on file-visiting buffers.
>
> replace-regexp-as-diff was intended to work only on file-visiting buffers.
> However, neither its name nor its docstring mention this.  So we could
> extend it to support non-file buffers.  This should be straightforward to do
> since multi-file-diff-no-select is based on diff-no-select that supports
> non-file buffers.
>
>> (BTW, it would be neat if replace-regexp-as-diff was incorporated into
>> normal query-replace - if, perhaps, after M-% you could press "d" to
>> display a diff buffer with the rest of the replacements, and probably
>> also exit the query-replace)
>
> Nice idea - this will help to review the remaining replacements and decide
> whether they all can be replaced with !.  So I will implement this as well.

Here is the first version that supports non-file buffers
and 'd' in query-replace:

[replace-regexp-as-diff-non-file.patch (text/x-diff, inline)]
diff --git a/lisp/misearch.el b/lisp/misearch.el
index 5d41ae5fc15..b74d7879c49 100644
--- a/lisp/misearch.el
+++ b/lisp/misearch.el
@@ -406,6 +406,7 @@ multi-file-diff-unsaved
 (declare-function diff-setup-whitespace "diff-mode" ())
 (declare-function diff-setup-buffer-type "diff-mode" ())
 
+;;;###autoload
 (defun multi-file-replace-as-diff (files from-string replacements regexp-flag delimited-flag)
   "Show as diffs replacements of FROM-STRING with REPLACEMENTS.
 FILES is a list of file names.  REGEXP-FLAG and DELIMITED-FLAG have
@@ -427,12 +428,19 @@ multi-file-replace-as-diff
       (setq buffer-read-only t)
       (diff-mode))
     (dolist (file-name files)
-      (let* ((file-exists (file-exists-p file-name))
+      (let* ((non-file-buffer (and (buffer-live-p file-name)
+                                   (not (buffer-local-value
+                                         'buffer-file-name file-name))))
+             (file-exists (unless non-file-buffer
+                            (file-exists-p file-name)))
              (file-buffer
-              (when (or (not file-exists)
-                        (eq multi-file-diff-unsaved 'use-modified-buffer))
-                (find-buffer-visiting file-name))))
-        (when file-name
+              (if non-file-buffer
+                  file-name
+                (when (or (not file-exists)
+                          (eq multi-file-diff-unsaved 'use-modified-buffer))
+                  (find-buffer-visiting file-name)))))
+        (when non-file-buffer (setq file-name (buffer-name file-name)))
+        (when (or file-exists file-buffer)
           (with-temp-buffer
             (if (and file-buffer
                      (or (not file-exists)
@@ -488,7 +496,8 @@ replace-regexp-as-diff
            t t)))
      (list (nth 0 common) (nth 1 common) (nth 2 common))))
   (multi-file-replace-as-diff
-   (list buffer-file-name) regexp to-string t delimited))
+   (list (or buffer-file-name (current-buffer)))
+   regexp to-string t delimited))
 
 (defvar diff-use-labels)
 (declare-function diff-check-labels "diff" (&optional force))
diff --git a/lisp/replace.el b/lisp/replace.el
index 107c5eadeb2..414238bf240 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -2492,6 +2492,7 @@ query-replace-map
     (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 +2519,7 @@ query-replace-map
 `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'.")
 
@@ -3333,6 +3334,16 @@ perform-replace
 			 (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'

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.