From: Lars Ingebrigtsen Date: Sat, 22 Aug 2020 13:18:15 +0000 (+0200) Subject: Restrict the range of image formats to be converted X-Git-Tag: emacs-28.0.90~6464 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=0aa4647f9cc53f3ded2c1bdea3d9f44962d318c0;p=emacs.git Restrict the range of image formats to be converted * lisp/image/image-converter.el (image-converter--filter-formats): New function. (image-converter): Mention this in the doc string. --- diff --git a/etc/NEWS b/etc/NEWS index 79b3aa37320..b4833473ec6 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -664,6 +664,14 @@ sorted there. The commands have also been extended to work when the "parent" buffer is an archive mode (i.e., zip file or the like) or tar mode buffer. +--- +*** 'image-converter' is now restricted to formats in 'auto-mode-alist'. +When using external image converters, the external program is queried +for what formats it supports. This list may contain formats that are +problematic in some contexts (like PDFs), so this list is now filtered +based on 'auto-mode-alist'. Only file names that map to 'image-mode' +are now supported. + ** EWW +++ diff --git a/lisp/image/image-converter.el b/lisp/image/image-converter.el index ee1dc845fb5..c31a3b8d3cf 100644 --- a/lisp/image/image-converter.el +++ b/lisp/image/image-converter.el @@ -33,8 +33,15 @@ "Type of the external image converter to use. The value should a symbol, either `imagemagick', `graphicsmagick', or `ffmpeg'. + If nil, Emacs will try to find one of the supported converters -installed on the system." +installed on the system. + +The actual range of image formats that will be converted depends +on what image formats the chosen converter reports being able to +handle. `auto-mode-alist' is then used to further filter what +formats that are to be supported: Only the suffixes that map to +`image-mode' will be handled." :group 'image :type 'symbol :version "27.1") @@ -186,12 +193,25 @@ data is returned as a string." "Find an installed image converter." (catch 'done (dolist (elem image-converter--converters) - (when-let ((formats (image-converter--probe (car elem)))) + (when-let ((formats (image-converter--filter-formats + (image-converter--probe (car elem))))) (setq image-converter (car elem) image-converter-regexp (concat "\\." (regexp-opt formats) "\\'") image-converter-file-name-extensions formats) (throw 'done image-converter))))) +(defun image-converter--filter-formats (suffixes) + "Filter SUFFIXES based on `auto-mode-alist'. +Only suffixes that map to `image-mode' are returned." + (cl-loop with case-fold-search = (if (not auto-mode-case-fold) + nil + t) + for suffix in suffixes + when (eq (cdr (assoc (concat "foo." suffix) auto-mode-alist + #'string-match)) + 'image-mode) + collect suffix)) + (cl-defmethod image-converter--convert ((type (eql graphicsmagick)) source image-format) "Convert using GraphicsMagick."