Function: org--image-yank-media-handler
org--image-yank-media-handler is a byte-compiled function defined in
org.el.gz.
Signature
(org--image-yank-media-handler MIMETYPE DATA)
Documentation
Save image DATA of mime-type MIMETYPE and insert link at point.
It is saved as per org-yank-image-save-method. The name for the
image is prompted and the extension is automatically added to the
end.
Source Code
;; Defined in /usr/src/emacs/lisp/org/org.el.gz
(defun org--image-yank-media-handler (mimetype data)
"Save image DATA of mime-type MIMETYPE and insert link at point.
It is saved as per `org-yank-image-save-method'. The name for the
image is prompted and the extension is automatically added to the
end."
(cl-assert (fboundp 'mailcap-mime-type-to-extension)) ; Emacs >=29
(cl-assert (fboundp 'file-name-with-extension)) ; Emacs >=28
(let* ((ext (symbol-name
(with-no-warnings ; Suppress warning in Emacs <29
(mailcap-mime-type-to-extension mimetype))))
(iname (funcall org-yank-image-file-name-function))
(filename (with-no-warnings ; Suppress warning in Emacs <28
(file-name-with-extension iname ext)))
(dirname (cond ((eq org-yank-image-save-method 'attach) temporary-file-directory)
((stringp org-yank-image-save-method) org-yank-image-save-method)
((functionp org-yank-image-save-method)
(let ((retval (funcall org-yank-image-save-method)))
(when (not (stringp retval))
(user-error
"`org-yank-image-save-method' did not return a string: %S"
retval))
retval))
(t (user-error
"Unknown value of `org-yank-image-save-method': %S"
org-yank-image-save-method))))
(absname (expand-file-name
filename
dirname)))
(when (and (not (eq org-yank-image-save-method 'attach))
(not (file-directory-p dirname)))
(make-directory dirname t))
;; DATA is a raw image. Tell Emacs to write it raw, without
;; trying to auto-detect the coding system.
(let ((coding-system-for-write 'emacs-internal))
(with-temp-file absname
(insert data)))
(insert
(if (not (eq org-yank-image-save-method 'attach))
(org-link-make-string-for-buffer (concat "file:" absname))
(progn
(require 'org-attach)
(apply #'org-link-make-string-for-buffer
(org-attach-attach absname nil 'mv)))))))