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 image-mode.

(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.

  • How about adding support for *.gif files? – lawlist Oct 17 '15 at 19:27
  • @lawlist that is not possible in my case. I use a compiled version of Emacs for Windows, and I couldn't find any Emacs binary, version 25 with gif-library for Windows. So that's currently not in the scope of this question, unfortunately. But thanks for your question. – ReneFroger Oct 17 '15 at 19:34
  • Here is a cheat sheet of how to build Emacs master branch (aka trunk) for Windows 32 bit -- with image support: emacs.stackexchange.com/a/17040/2287 The following prebuilt version of Emacs master/trunk just needs the *.dll files added to the bin directory where the emacs.exe is located: sourceforge.net/projects/emacs-bin/files/snapshots See also 64-bit -- with image support: sourceforge.net/projects/emacsbinw64/files/snapshot There is no reason to go through life without enjoying Emacs master/trunk to the fullest extent available on Windows. – lawlist Oct 17 '15 at 19:46
  • Type M-x describe-variable RET dynamic-library-alist RET to obtain a listing of the required .dll files that go in the bin directory. The call of this particular question (in my opinion) is essentially: "I am using an incomplete installation of Emacs master branch (aka trunk) for Windows and I would like some help with a workaround for problems relating to a lack of image support . . ." The answer (in my opinion) is to just fix it so that it's not broken. – lawlist Oct 17 '15 at 19:59
  • Thanks for your explaination. With dynamic-library-alist, I see the libgif-7.dll is used for gif-extension. And it's available in bin-folder too. So I wonder why it's not used, since Emacs crashes when a gif file is being loaded. And I have already thought of compiling my own Emacs, but I'm not technical enough to run compilations , so please don't consider that in my case. – ReneFroger Oct 17 '15 at 20:43
up vote 0 down vote accepted

As @lawlist suggest, you can get the prebuilt version of Emacs master/trunk which uses the gif support added to the bin directory where the emacs.exe is located: sourceforge.net/projects/emacs-bin/files/snapshots See also 64-bit -- with image support: sourceforge.net/projects/emacsbinw64/files/snapshot for Windows.

With my configuration, I couldn't it get working, which leds me to suspect my configuration. The culprit turns out to be image+ and imagex-sticky-maximize, which I disabled. Now Emacs don't crashes anymore.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.