From 113a6a0a885c8bfb1f3c75a8a985a73686662113 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Wed, 13 Jul 2022 01:53:20 +0200 Subject: [PATCH] Tweak image-converter-add-handler interface * doc/emacs/files.texi (Image Mode): Adjust documentation. * lisp/image/image-converter.el (image-convert): Let the converter know whether it's a file or not. --- doc/emacs/files.texi | 14 +++++++++----- lisp/image/image-converter.el | 10 ++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/doc/emacs/files.texi b/doc/emacs/files.texi index da138204761..20468c0c177 100644 --- a/doc/emacs/files.texi +++ b/doc/emacs/files.texi @@ -2364,15 +2364,19 @@ viewing Krita files as simple images, you could say something like: @lisp (image-converter-add "kra" - (lambda (file) - (call-process "unzip" nil t nil - "-qq" "-c" "-x" file "mergedimage.png")))) + (lambda (file data-p) + (if data-p + (error "Can't decode non-files") + (call-process "unzip" nil t nil + "-qq" "-c" "-x" file "mergedimage.png")))) @end lisp The function takes two parameters, where the first is a file name suffix, and the second is a function to do the ``conversion''. This -function takes one parameter, the file name, and should output an -image in @code{image-convert-to-format} format in the current buffer. +function takes two parameters, where the first is the file name or a +string with the data, and the second says whether the first parameter +is data or not, and should output an image in +@code{image-convert-to-format} format in the current buffer. @findex thumbs-mode @cindex mode, Thumbs diff --git a/lisp/image/image-converter.el b/lisp/image/image-converter.el index ed3ba49071a..9c2f24819a3 100644 --- a/lisp/image/image-converter.el +++ b/lisp/image/image-converter.el @@ -136,7 +136,7 @@ converted image data is returned as a string." (file-name-extension source))) (extra-converter (gethash type image-converter--extra-converters))) (if extra-converter - (funcall extra-converter source) + (funcall extra-converter source format) (when-let ((err (image-converter--convert image-converter source format))) (error "%s" err)))) @@ -309,9 +309,11 @@ Only suffixes that map to `image-mode' are returned." ;;;###autoload (defun image-converter-add-handler (suffix converter) "Make Emacs use CONVERTER to parse image files that end with SUFFIX. -CONVERTER is a function with one parameter, the file name. The -converter should output the image in the current buffer, -converted to `image-convert-to-format'." +CONVERTER is a function with two parameters, where the first is +the file name or a string with the image data, and the second is +non-nil if the first parameter is image data. The converter +should output the image in the current buffer, converted to +`image-convert-to-format'." (cl-pushnew suffix image-converter-file-name-extensions :test #'equal) (setq image-converter-file-name-extensions (sort image-converter-file-name-extensions #'string<))