From b979865cf8cf2fa8ec73ac8bc6cfee32f6de68fc Mon Sep 17 00:00:00 2001 From: Manuel Giraud Date: Tue, 16 Jan 2024 10:47:45 +0100 Subject: [PATCH] Refill 'image-dired-display-image-buffer' Bug#68486 * lisp/image/image-dired.el (image-dired-display-image): Refill 'image-dired-display-image-buffer' instead of killing it, open a new file and then renaming it. --- lisp/image/image-dired.el | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lisp/image/image-dired.el b/lisp/image/image-dired.el index 9eb68e240fe..b08aa129b98 100644 --- a/lisp/image/image-dired.el +++ b/lisp/image/image-dired.el @@ -1260,18 +1260,18 @@ image-dired-display-image (setq file (expand-file-name file)) (when (not (file-exists-p file)) (error "No such file: %s" file)) - (let ((buf (get-buffer image-dired-display-image-buffer)) + (let ((buf (get-buffer-create image-dired-display-image-buffer)) (cur-win (selected-window))) - (when buf - (kill-buffer buf)) - (when-let ((buf (find-file-noselect file nil t))) - (pop-to-buffer buf) - (rename-buffer image-dired-display-image-buffer) - (if (string-match (image-file-name-regexp) file) - (image-dired-image-mode) - ;; Support visiting PDF files. - (normal-mode)) - (select-window cur-win)))) + (with-current-buffer buf + (let ((inhibit-read-only t)) + (erase-buffer) + (insert-file-contents file) + (if (string-match (image-file-name-regexp) file) + (image-dired-image-mode) + ;; Support visiting PDF files. + (normal-mode)))) + (when buf (pop-to-buffer buf)) + (select-window cur-win))) (defun image-dired-display-this (&optional arg) "Display current thumbnail's original image in display buffer. -- 2.43.0