0

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.

ReneFroger
  • 3,855
  • 22
  • 63
  • 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**: http://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: https://sourceforge.net/projects/emacs-bin/files/snapshots/ See also 64-bit -- **with image support**: http://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
  • Using the most recent Emacs master/trunk Win32-bit binary built by Dani Moncayo (available in the second link from the comment hereinabove) -- i.e., `emacs-master-20151009@183320-bin-i686-mingw32.7z` -- and `giflib-5.1.0-w32-bin.zip` from ezwinports -- https://sourceforge.net/projects/ezwinports/files/ -- I was able to successfully open/view a `*.gif` image with **Emacs -Q** without crashing. – lawlist Oct 17 '15 at 21:19
  • Do you see the animation then or only the bytecompiled code of the `*.gif` file? I only get the text, notice that I use the Emacs 25.05 version. I think it would be better to stay in the scope of my original question. – ReneFroger Oct 18 '15 at 10:18
  • The default behavior -- using the prebuilt binary from Dany Moncayo made on October 9, 2015, with `libgif-7.dll` from ezwinports in the `bin` directory where `emacs.exe` is located -- is a still image of the first in the series of `.gif` images. To animate the image, just press the return key. In my case, I tested a `.gif` that has 50 different combined images. Eli Z. (one of the lead developers on the Emacs team) strongly suggests in his responses to bug reports that Emacs be built with and used with the `.dll` files from ezwinports -- i.e., Eli Z. maintains that ezwinports repository. – lawlist Oct 18 '15 at 15:05
  • The question in this particular thread is a classic **X** / **Y** situation -- i.e., the original poster is *100%* certain that a workaround to the **X** problem involves using **Y** as a solution -- i.e., skip .gif images because Emacs crashes. The solution is **not** to skip .gif images, but rather to use a working installation of Emacs master/trunk with proper image support. Staying within the scope of the question would mean that the person responding must *erroneously* assume that using a broken installation of Emacs is a good thing, and working around that problem is also a good thing. – lawlist Oct 18 '15 at 15:29
  • Well, you might be right. But I could it get it working with the latest prebuilt binary from Dany Moncayo made on October 9, 2015, and starting with `emacs -q`. 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`. Thanks for your help anyway, it's appreciated. – ReneFroger Oct 19 '15 at 10:12

1 Answers1

0

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.

ReneFroger
  • 3,855
  • 22
  • 63