Function: w32--get-selection

w32--get-selection is a byte-compiled function defined in w32-win.el.gz.

Signature

(w32--get-selection &optional TYPE DATA-TYPE)

Source Code

;; Defined in /usr/src/emacs/lisp/term/w32-win.el.gz
(defun w32--get-selection (&optional type data-type)
  (cond ((and (eq type 'CLIPBOARD)
              (memq data-type '(STRING UTF8_STRING TEXT)))
         (with-demoted-errors "w32-get-clipboard-data:%S"
           (w32-get-clipboard-data)))
        ((eq data-type 'TARGETS)
         (if (eq type 'CLIPBOARD)
             (vconcat
              (delete-dups
               (seq-map #'w32--translate-selection-target
                        (w32-selection-targets type))))
           (if (get 'x-selections (or type 'PRIMARY)) '[STRING])))
        ((eq type 'CLIPBOARD)
         (let ((tmp-file (make-temp-file "emacs-clipboard"))
               (is-textual (w32--mime-type-textual-p data-type)))
           (unwind-protect
               (let* ((data-types (w32--translate-reverse-selection-target data-type))
                      (data (w32--get-clipboard-data-media data-types tmp-file is-textual)))
                 (cond
                  ;; data is in the file
                  ((eq data t)
                   (with-temp-buffer
                     (set-buffer-multibyte nil)
                     (insert-file-contents-literally tmp-file)
                     (buffer-string)))
                  ;; data is in data var
                  ((stringp data) data)
                  ;; No data
                  (t nil)))
             (delete-file tmp-file))))
        (t (get 'x-selections (or type 'PRIMARY)))))