;; 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)
+ (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
(gui-get-selection 'CLIPBOARD 'TARGETS)))
(defun yank-media--get-selection (type)
- (when-let ((data (gui-get-selection 'CLIPBOARD type)))
- (when-let ((charset (get-text-property 0 'charset data)))
- (setq data (encode-coding-string data charset)))
- ;; Some programs add a nul character at the end of text/*
- ;; selections. Remove that.
- (when (and (string-match-p "\\`text/" (symbol-name type))
- (zerop (elt data (1- (length data)))))
- (setq data (substring data 0 (1- (length data)))))
- data))
+ (let ((selection-coding-system 'binary))
+ (when-let ((data (gui-backend-get-selection 'CLIPBOARD type)))
+ (when (string-match-p "\\`text/" (symbol-name type))
+ ;; Some programs add a nul character at the end of text/*
+ ;; selections. Remove that.
+ (when (zerop (elt data (1- (length data))))
+ (setq data (substring data 0 (1- (length data)))))
+ (setq data (decode-coding-string
+ data (car (detect-coding-string data)))))
+ data)))
;;;###autoload
(defun register-yank-media-handler (types handler)