]> git.eshelyaron.com Git - emacs.git/commitdiff
Tweak image-converter-add-handler interface
authorLars Ingebrigtsen <larsi@gnus.org>
Tue, 12 Jul 2022 23:53:20 +0000 (01:53 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Tue, 12 Jul 2022 23:53:20 +0000 (01:53 +0200)
* 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
lisp/image/image-converter.el

index da138204761623d31126f7538946408b58d1655b..20468c0c177e06c06c9fff044e7f03f71c656888 100644 (file)
@@ -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
index ed3ba49071a0bfeffd421b381a20e118b049dfdf..9c2f24819a375d6e83bbfc0cd0a18e9273ef81c4 100644 (file)
@@ -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<))