30.23 Yanking Media

Data saved within window system selections and the MS-Windows clipboard is not restricted to plain text. It is possible for selection data to encompass images or other binary data of the like, as well as rich text content instanced by HTML, and also PostScript. Since the selection data types incident to this data are at variance with those for plain text, the insertion of such data is facilitated by a set of functions dubbed yank-media handlers, which are registered by each major mode undertaking its insertion and called where warranted upon the execution of the yank-media command.

Function: yank-media-handler types handler

Register a yank-media handler which applies to the current buffer.

types can be a symbol designating a selection data type (see Accessing Selections), a regexp against which such types are matched, or a list of these symbols and regexps. For instance:

(yank-media-handler 'text/html #'my-html-handler)
(yank-media-handler "image/.*" #'my-image-handler)

When a selection offers a data type matching types, the function handler is called to insert its data, with the symbol designating the matching selection data type, and the data returned by gui-get-selection.

The yank-media command auto selects the preferred MIME type by default. The rules used for the selection can be controlled through the variables yank-media-autoselect-function and yank-media-preferred-types.

Variable: yank-media-autoselect-function

This variable should specify a function that will be called with the list of MIME types available for the current major mode, and should return a list of preferred MIME types to use. The first MIME type in the list will always be used by the yank-media command when auto selection is requested.

Variable: yank-media-preferred-types

This variable changes the default selection process of yank-media-autoselect-function. It is a list that should contain the sole MIME type to choose in the order of their preference. It can also contain a function in which case it is called with the list of available MIME types and must return a list of preferred MIME types in order of their preference. This list is passed onto the yank-media command so the first element of the returned list is chosen when auto selection is requested.

The yank-media-types command presents a list of selection data types that are currently available, which is useful when implementing yank-media handlers; for programs generally offer an eclectic and seldom consistent medley of data types.