I use the package
image-mode to view images in a directory. When go to the next image in the same directory, I use a function to go the next image in
(defun find-next-image (&optional backward) "Find the next file (by name) in the current directory. With prefix arg, find the previous file." (interactive "P") (when buffer-file-name (let* ((file (expand-file-name buffer-file-name)) (files (cl-remove-if (lambda (file) (cl-first (file-attributes file))) (sort (directory-files (file-name-directory file) t nil t) 'string<))) (pos (mod (+ (cl-position file files :test 'equal) (if backward -1 1)) (length files)))) (find-file (nth pos files)))) (kill-buffer (other-buffer (current-buffer) 1)) )
However, sometimes Emacs crashes when he tries to load the next image which happens to be a
.gif image. This Emacs version doesn't have any gif library to handle it.
So I need to skip
.gif-images and go to the next image after the
.gif image anyway. When looking to the function, he increments the position of the current file with 1. I thinked about it how I could solve this, that in the case of a GIF-image, he will skip it and increment again. But I couldn't figure out how I could write it.
Any suggestion would be appreciated.
UPDATE: see the solution below.