1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-02 10:11:05 -08:00

* 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.
This commit is contained in:
Juri Linkov 2025-12-24 19:35:04 +02:00
parent d576216adb
commit 2fc957795a

View file

@ -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