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.
This commit is contained in:
Lars Ingebrigtsen 2022-07-13 01:53:20 +02:00
parent cbe9a55923
commit 113a6a0a88
2 changed files with 15 additions and 9 deletions

View 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

View 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<))