aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2025-11-23 10:32:18 +0200
committerEli Zaretskii2025-11-23 10:33:49 +0200
commitbb1f70c90180589564e1f831725c59e34013b02a (patch)
treee828ec023b0876fe39ff3a90ea8d741e1dc41d65
parent6c30c6c87d953455e55a258685b697ab531cbd25 (diff)
downloademacs-bb1f70c90180589564e1f831725c59e34013b02a.tar.gz
emacs-bb1f70c90180589564e1f831725c59e34013b02a.zip
Fix 'd' command in 'query-replace' in buffers not visiting files
* lisp/vc/diff.el (diff-file-local-copy): Use proper coding-system when writing a local copy of a non-file visiting buffer. * lisp/misearch.el (coding-system--for-buffer-diff): New variable. (multi-file-replace-as-diff): Bind it to 'utf-8-emacs'. (multi-file-diff-no-select): Use proper coding-system when reading output of Diff. (Bug#79761)
-rw-r--r--lisp/misearch.el13
-rw-r--r--lisp/vc/diff.el6
2 files changed, 16 insertions, 3 deletions
diff --git a/lisp/misearch.el b/lisp/misearch.el
index c20b75bf6f0..28cda1fcbf0 100644
--- a/lisp/misearch.el
+++ b/lisp/misearch.el
@@ -406,6 +406,9 @@ modified buffer to be able to use unsaved changes."
406(declare-function diff-setup-whitespace "diff-mode" ()) 406(declare-function diff-setup-whitespace "diff-mode" ())
407(declare-function diff-setup-buffer-type "diff-mode" ()) 407(declare-function diff-setup-buffer-type "diff-mode" ())
408 408
409(defvar coding-system--for-buffer-diff nil
410 "Used to pass encoding down to callees of `multi-file-diff-no-select'.")
411
409;;;###autoload 412;;;###autoload
410(defun multi-file-replace-as-diff (files from-string replacements regexp-flag delimited-flag) 413(defun multi-file-replace-as-diff (files from-string replacements regexp-flag delimited-flag)
411 "Show as diffs replacements of FROM-STRING with REPLACEMENTS. 414 "Show as diffs replacements of FROM-STRING with REPLACEMENTS.
@@ -439,7 +442,11 @@ as in `perform-replace'."
439 file-name 442 file-name
440 (when (or (not file-exists) 443 (when (or (not file-exists)
441 (eq multi-file-diff-unsaved 'use-modified-buffer)) 444 (eq multi-file-diff-unsaved 'use-modified-buffer))
442 (find-buffer-visiting file-name))))) 445 (find-buffer-visiting file-name))))
446 ;; Make sure any supported characters can be written to a
447 ;; file without asking the user to select a safe
448 ;; coding-system.
449 (coding-system--for-buffer-diff 'utf-8-emacs))
443 (when non-file-buffer (setq file-name (buffer-name file-name))) 450 (when non-file-buffer (setq file-name (buffer-name file-name)))
444 (when (or file-exists file-buffer) 451 (when (or file-exists file-buffer)
445 (with-temp-buffer 452 (with-temp-buffer
@@ -540,7 +547,9 @@ specify labels to use for file names."
540 (or new-alt new))))) 547 (or new-alt new)))))
541 " "))) 548 " ")))
542 (with-current-buffer buf 549 (with-current-buffer buf
543 (let ((inhibit-read-only t)) 550 (let ((inhibit-read-only t)
551 (coding-system-for-read (or coding-system--for-buffer-diff
552 coding-system-for-read)))
544 (insert command "\n") 553 (insert command "\n")
545 (call-process shell-file-name nil buf nil 554 (call-process shell-file-name nil buf nil
546 shell-command-switch command)) 555 shell-command-switch command))
diff --git a/lisp/vc/diff.el b/lisp/vc/diff.el
index c8a1b7c0efa..9e4a5349fef 100644
--- a/lisp/vc/diff.el
+++ b/lisp/vc/diff.el
@@ -118,13 +118,17 @@ Non-interactively, OLD and NEW may each be a file or a buffer."
118 (display-buffer 118 (display-buffer
119 (diff-no-select old new switches no-async))) 119 (diff-no-select old new switches no-async)))
120 120
121(defvar coding-system--for-buffer-diff) ; from misearch.el
122
121(defun diff-file-local-copy (file-or-buf) 123(defun diff-file-local-copy (file-or-buf)
122 "Like `file-local-copy' but also supports a buffer as the argument. 124 "Like `file-local-copy' but also supports a buffer as the argument.
123When FILE-OR-BUF is a buffer, return the filename of a local 125When FILE-OR-BUF is a buffer, return the filename of a local
124temporary file with the buffer's contents." 126temporary file with the buffer's contents."
125 (if (bufferp file-or-buf) 127 (if (bufferp file-or-buf)
126 (with-current-buffer file-or-buf 128 (with-current-buffer file-or-buf
127 (let ((tempfile (make-temp-file "buffer-content-"))) 129 (let ((tempfile (make-temp-file "buffer-content-"))
130 (coding-system-for-write (or coding-system--for-buffer-diff
131 coding-system-for-write)))
128 (if diff-entire-buffers 132 (if diff-entire-buffers
129 (write-region nil nil tempfile nil 'nomessage) 133 (write-region nil nil tempfile nil 'nomessage)
130 (write-region (point-min) (point-max) tempfile nil 'nomessage)) 134 (write-region (point-min) (point-max) tempfile nil 'nomessage))