I had the following hook:

(add-hook 'image-mode-hook 'imagex-sticky-maximize)

imagex-sticky-maximize is a function that maximizes the image to the borders of the window. I prefer to see my images to his fullest inside the window.

This works fine so far. But I noticed that Emacs crashes if the next file is a *.gif file. So disabling the imagex-sticky-maximize helps. But I would like to enable that function when the file is a *.PNG, or *.JPG or *.TIFF image.

So I was looking for a solution. I know you have the auto-mode-alist. When you declare something like this:

(add-to-list 'auto-mode-alist '("\\.clj$\\'" . paredit-mode))

Then paredit mode will be called as minor mode, when you open file with the extension *.clj. This works only for minor modes. I was looking for a sort of auto-function-alist, that calls imagex-sticky-maximize when a specifix extension is being opened. However, I couldn't find anything of this.

Any suggestion in that direction would be appreciated.


You can easily write your own function that checks the extension of the file name of the current buffer, and call a function if it does (or doesn't) match.

For example (warning: untested):

(defun my-image-mode-hook ()
  (let ((name (buffer-file-name)))
    (when name
      (let ((ext (file-name-extension name)))
        (unless (string= (downcase ext) "gif")
(add-hook 'image-mode-hook 'my-image-mode-hook)
| improve this answer | |
  • Thanks for your suggestion. It would be a good idea indeed. Your function doesn't nothing by the way, you need to (add-hook 'image-mode-hook 'my-image-mode-hook). – ReneFroger Oct 19 '15 at 14:45
  • @ReneFroger, thanks, answer updated! (Damn you auto completion...) – Lindydancer Oct 19 '15 at 14:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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