From: Lars Ingebrigtsen Date: Mon, 21 Mar 2022 17:05:18 +0000 (+0100) Subject: Make `n' in image-mode work more reliably with external formats X-Git-Tag: emacs-29.0.90~1931^2~1009 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d74cd0cf1f96e256c479599939efacd11600c0c8;p=emacs.git Make `n' in image-mode work more reliably with external formats * lisp/image-mode.el (image-mode): Init the external machinery so that commands like `n' work for those files. * lisp/image/image-converter.el (image-converter-initialize): Factored out into own function. (image-convert-p): Use it. (image-convert): Ditto. --- diff --git a/lisp/image-mode.el b/lisp/image-mode.el index b2af3f06a27..38a5e7cdfdc 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el @@ -625,6 +625,8 @@ image as text, when opening such images in `image-mode'." (put 'image-mode 'mode-class 'special) +(declare-function image-converter-initialize "image-converter.el") + ;;;###autoload (defun image-mode () "Major mode for image files. @@ -650,7 +652,12 @@ Key bindings: "Empty file" "(New file)") "Empty buffer")) - (image-mode--display))) + (image-mode--display) + ;; Ensure that we recognize externally parsed image formats in + ;; commands like `n'. + (when image-use-external-converter + (require 'image-converter) + (image-converter-initialize)))) (defun image-mode--display () (if (not (image-get-display-property)) diff --git a/lisp/image/image-converter.el b/lisp/image/image-converter.el index b8c9a620024..a339e95ab4a 100644 --- a/lisp/image/image-converter.el +++ b/lisp/image/image-converter.el @@ -68,15 +68,19 @@ not, conversion will fail." (imagemagick :command "convert" :probe ("-list" "format"))) "List of supported image converters to try.") +(defun image-converter-initialize () + "Determine the external image converter to be used. +This also determines which external formats we can parse." + (unless image-converter + (image-converter--find-converter))) + (defun image-convert-p (source &optional data-p) "Return `image-convert' if SOURCE is an image that can be converted. SOURCE can either be a file name or a string containing image data. In the latter case, DATA-P should be non-nil. If DATA-P is a string, it should be a MIME format string like \"image/gif\"." - ;; Find an installed image converter. - (unless image-converter - (image-converter--find-converter)) + (image-converter-initialize) ;; When image-converter was customized (when (and image-converter (not image-converter-regexp)) (when-let ((formats (image-converter--probe image-converter))) @@ -111,9 +115,7 @@ IMAGE can also be an image object as returned by `create-image'. This function converts the image the preferred format, and the converted image data is returned as a string." - ;; Find an installed image converter. - (unless image-converter - (image-converter--find-converter)) + (image-converter-initialize) (unless image-converter (error "No external image converters available")) (when (and image-format