From 2fc957795acbbdc853aa3750b4b843752ab03486 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Wed, 24 Dec 2025 19:35:04 +0200 Subject: [PATCH] * lisp/image-mode.el (image-mode--next-file): Fix infinite loop. Fix the case when an image file is visited in the directory with image files without image file extensions, and 'dired-movement-style' is non-nil, and 'dired-next-line' wraps to the top of the dired buffer, doesn't find the next image file and goes into an infinite loop. Remember the original file name and exit the loop when after wrapping 'dired-next-line' reaches the original file. --- lisp/image-mode.el | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lisp/image-mode.el b/lisp/image-mode.el index 39192a42b6c..c23cced1790 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el @@ -1285,17 +1285,24 @@ If N is negative, go to the previous file." (cl-case (car buffer) (dired (dired-goto-file file) - (let (found) + (let ((orig-file (dired-get-filename nil t)) + found) (while (and (not found) - ;; Stop if we reach the end/start of the buffer. + orig-file + ;; Stop if we reach the end/start of the buffer + ;; (used only when 'dired-movement-style' is nil). (if (> n 0) (not (eobp)) (not (bobp)))) (dired-next-line n) (let ((candidate (dired-get-filename nil t))) - (when (and candidate - (string-match-p regexp candidate)) - (setq found candidate)))) + (if (and candidate + (string-match-p regexp candidate)) + (setq found candidate) + ;; When after wrapping with non-nil 'dired-movement-style' + ;; arrived at the original file, exit the loop. + (if (equal orig-file candidate) + (setq orig-file nil))))) (if found (setq next found) ;; If we didn't find a next/prev file, then restore