diff options
| author | Juri Linkov | 2025-12-24 19:35:04 +0200 |
|---|---|---|
| committer | Juri Linkov | 2025-12-24 19:35:04 +0200 |
| commit | 2fc957795acbbdc853aa3750b4b843752ab03486 (patch) | |
| tree | 2147152507357948bb7b2df955b4734c4adf4841 | |
| parent | d576216adb21a2b5ae49236e4bf11dd067432204 (diff) | |
| download | emacs-2fc957795acbbdc853aa3750b4b843752ab03486.tar.gz emacs-2fc957795acbbdc853aa3750b4b843752ab03486.zip | |
* 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.
| -rw-r--r-- | lisp/image-mode.el | 17 |
1 files 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." | |||
| 1285 | (cl-case (car buffer) | 1285 | (cl-case (car buffer) |
| 1286 | (dired | 1286 | (dired |
| 1287 | (dired-goto-file file) | 1287 | (dired-goto-file file) |
| 1288 | (let (found) | 1288 | (let ((orig-file (dired-get-filename nil t)) |
| 1289 | found) | ||
| 1289 | (while (and (not found) | 1290 | (while (and (not found) |
| 1290 | ;; Stop if we reach the end/start of the buffer. | 1291 | orig-file |
| 1292 | ;; Stop if we reach the end/start of the buffer | ||
| 1293 | ;; (used only when 'dired-movement-style' is nil). | ||
| 1291 | (if (> n 0) | 1294 | (if (> n 0) |
| 1292 | (not (eobp)) | 1295 | (not (eobp)) |
| 1293 | (not (bobp)))) | 1296 | (not (bobp)))) |
| 1294 | (dired-next-line n) | 1297 | (dired-next-line n) |
| 1295 | (let ((candidate (dired-get-filename nil t))) | 1298 | (let ((candidate (dired-get-filename nil t))) |
| 1296 | (when (and candidate | 1299 | (if (and candidate |
| 1297 | (string-match-p regexp candidate)) | 1300 | (string-match-p regexp candidate)) |
| 1298 | (setq found candidate)))) | 1301 | (setq found candidate) |
| 1302 | ;; When after wrapping with non-nil 'dired-movement-style' | ||
| 1303 | ;; arrived at the original file, exit the loop. | ||
| 1304 | (if (equal orig-file candidate) | ||
| 1305 | (setq orig-file nil))))) | ||
| 1299 | (if found | 1306 | (if found |
| 1300 | (setq next found) | 1307 | (setq next found) |
| 1301 | ;; If we didn't find a next/prev file, then restore | 1308 | ;; If we didn't find a next/prev file, then restore |