Function: yank-media

yank-media is an autoloaded, interactive and byte-compiled function defined in yank-media.el.gz.

Signature

(yank-media)

Documentation

Yank media (images, HTML and the like) from the clipboard.

This command depends on the current major mode having support for accepting the media type. The mode has to register itself using the yank-media-handler mechanism.

Also see yank-media-types for a command that lets you explore all the different selection types.

View in manual

Probably introduced at or before Emacs version 29.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/yank-media.el.gz
;;;###autoload
(defun yank-media ()
  "Yank media (images, HTML and the like) from the clipboard.
This command depends on the current major mode having support for
accepting the media type.  The mode has to register itself using
the `yank-media-handler' mechanism.

Also see `yank-media-types' for a command that lets you explore
all the different selection types."
  (interactive)
  (unless yank-media--registered-handlers
    (user-error "The `%s' mode hasn't registered any handlers" major-mode))
  (let ((all-types nil))
    (pcase-dolist (`(,handled-type . ,handler)
                   yank-media--registered-handlers)
      (dolist (type (yank-media--find-matching-media handled-type))
        (push (cons type handler) all-types)))
    (unless all-types
      (user-error
       "No handler in the current buffer for anything on the clipboard"))
    ;; We have a handler in the current buffer; if there's just
    ;; matching type, just call the handler.
    (if (length= all-types 1)
        (funcall (cdar all-types) (caar all-types)
                 (yank-media--get-selection (caar all-types)))
      ;; More than one type the user for what type to insert.
      (let ((type
             (intern
              (completing-read "Several types available, choose one: "
                               (mapcar #'car all-types) nil t))))
        (funcall (alist-get type all-types)
                 type (yank-media--get-selection type))))))