diff options
| author | Cecilio Pardo | 2024-10-28 22:18:13 +0100 |
|---|---|---|
| committer | Eli Zaretskii | 2024-11-03 15:12:20 +0200 |
| commit | 8e7f5f97db647ce6e9606364dc15d8bbd7ef6016 (patch) | |
| tree | aa033dc97c284c7842dc291c6a9f7fbcd044fce8 /lisp/term | |
| parent | 5ee56b86938b7759dd92f507d03907280f48ffca (diff) | |
| download | emacs-8e7f5f97db647ce6e9606364dc15d8bbd7ef6016.tar.gz emacs-8e7f5f97db647ce6e9606364dc15d8bbd7ef6016.zip | |
Add support for 'yank-media' on MS-Windows
Adds the capacity to handle types different from strings to the
clipboard management functions on MS-Windows, and some logic
required to convert media types names and content to be what
yank-media and the modes that use it expect (bug#71909).
* lisp/term/w32-win.el (w32--selection-target-translations): New
variable that holds the name translations for media types.
(w32--translate-selection-target): New function, translate the
name of a media type.
(w32--translate-reverse-selection-target): New function, reverse
translation.
(w32--get-selection): Modified to translate target names when
asked for targets, and retrieve media types when asked for them.
(w32--mime-type-textual-p): New function, checks if a MIME type
is textual.
* lisp/textmodes/sgml-mode.el (html-mode--image-yank-handler):
Fixed the image save mechanism, that added line feed characters
on MS-Windows, breaking binary formats.
* src/w32image.c (gdiplus_init): Modified to fetch more
functions fromm gdiplus.
(get_encoder_clsid): Renamed to 'w32_gdip_get_encoder_clsid'
and made nonstatic.
(gdiplus_startup): Renamed to 'w32_gdiplus_startup' and
made nonstatic.
* src/w32select.c (stdfmt_name): Made global, was static
function.
(convert_dibv5_to_png): New function to convert DIBV5 clipboard
format to PNG.
(get_clipboard_format_name): New function get the name of a
format given its index.
(Fw32__get_clipboard_data_media): New function, retrieves and
converts media content.
(syms_of_w32select): Export new lisp functions.
* src/w32gdiplus.h: New file, for definitions in w32image.c
* doc/lispref/frames.texi: Updated with MS-Windows support.
* etc/NEWS: Added entry about new feature.
Diffstat (limited to 'lisp/term')
| -rw-r--r-- | lisp/term/w32-win.el | 71 |
1 files changed, 69 insertions, 2 deletions
diff --git a/lisp/term/w32-win.el b/lisp/term/w32-win.el index 75f8530010c..b5c909f4a4e 100644 --- a/lisp/term/w32-win.el +++ b/lisp/term/w32-win.el | |||
| @@ -442,15 +442,82 @@ See the documentation of `create-fontset-from-fontset-spec' for the format.") | |||
| 442 | (w32-set-clipboard-data (string-replace "\0" "\\0" value)) | 442 | (w32-set-clipboard-data (string-replace "\0" "\\0" value)) |
| 443 | (put 'x-selections (or type 'PRIMARY) value))) | 443 | (put 'x-selections (or type 'PRIMARY) value))) |
| 444 | 444 | ||
| 445 | (defun w32--get-selection (&optional type data-type) | 445 | (defvar w32--selection-target-translations |
| 446 | '((PNG . image/png) | ||
| 447 | (DIBV5 . image/png) | ||
| 448 | (HTML\ Format . text/html))) | ||
| 449 | |||
| 450 | (defun w32--translate-selection-target (target) | ||
| 451 | (let ((xlat (assoc target w32--selection-target-translations))) | ||
| 452 | (if xlat | ||
| 453 | (cdr xlat) | ||
| 454 | target))) | ||
| 455 | |||
| 456 | (defun w32--translate-reverse-selection-target (target) | ||
| 457 | (append | ||
| 458 | (mapcar #'car | ||
| 459 | (seq-filter | ||
| 460 | (lambda (x) | ||
| 461 | (eq target | ||
| 462 | (w32--translate-selection-target (car x)))) | ||
| 463 | w32--selection-target-translations)) | ||
| 464 | (list target))) | ||
| 465 | |||
| 466 | (defvar w32--textual-mime-types | ||
| 467 | '("application/xml" | ||
| 468 | "application/json" | ||
| 469 | "application/yaml" | ||
| 470 | "application/json-seq" | ||
| 471 | "\\`text/" | ||
| 472 | "+xml\\'" | ||
| 473 | "+json\\'" | ||
| 474 | "+yaml\\'" | ||
| 475 | "+json-seq\\'")) | ||
| 476 | |||
| 477 | (defun w32--mime-type-textual-p (mime-type) | ||
| 478 | "Returns t if MIME-TYPE, a symbol, names a textual MIME type. | ||
| 479 | |||
| 480 | This function is intended to classify clipboard data. All MIME subtypes | ||
| 481 | of text/ are considered textual. Also those with suffixes +xml, +json, | ||
| 482 | +yaml, +json-seq. And application/xml, application/json, | ||
| 483 | application/yaml, application/json-seq. | ||
| 484 | |||
| 485 | This classification is not exhaustive. Some MIME types not listed may | ||
| 486 | also be textual." | ||
| 487 | (string-match-p | ||
| 488 | (mapconcat #'identity w32--textual-mime-types "\\|") | ||
| 489 | (symbol-name mime-type))) | ||
| 490 | |||
| 491 | (defun w32--get-selection (&optional type data-type) | ||
| 446 | (cond ((and (eq type 'CLIPBOARD) | 492 | (cond ((and (eq type 'CLIPBOARD) |
| 447 | (eq data-type 'STRING)) | 493 | (eq data-type 'STRING)) |
| 448 | (with-demoted-errors "w32-get-clipboard-data:%S" | 494 | (with-demoted-errors "w32-get-clipboard-data:%S" |
| 449 | (w32-get-clipboard-data))) | 495 | (w32-get-clipboard-data))) |
| 450 | ((eq data-type 'TARGETS) | 496 | ((eq data-type 'TARGETS) |
| 451 | (if (eq type 'CLIPBOARD) | 497 | (if (eq type 'CLIPBOARD) |
| 452 | (w32-selection-targets type) | 498 | (vconcat |
| 499 | (delete-dups | ||
| 500 | (seq-map #'w32--translate-selection-target | ||
| 501 | (w32-selection-targets type)))) | ||
| 453 | (if (get 'x-selections (or type 'PRIMARY)) '[STRING]))) | 502 | (if (get 'x-selections (or type 'PRIMARY)) '[STRING]))) |
| 503 | ((eq type 'CLIPBOARD) | ||
| 504 | (let ((tmp-file (make-temp-file "emacs-clipboard")) | ||
| 505 | (is-textual (w32--mime-type-textual-p data-type))) | ||
| 506 | (unwind-protect | ||
| 507 | (let* ((data-types (w32--translate-reverse-selection-target data-type)) | ||
| 508 | (data (w32--get-clipboard-data-media data-types tmp-file is-textual))) | ||
| 509 | (cond | ||
| 510 | ;; data is in the file | ||
| 511 | ((eq data t) | ||
| 512 | (with-temp-buffer | ||
| 513 | (set-buffer-multibyte nil) | ||
| 514 | (insert-file-contents-literally tmp-file) | ||
| 515 | (buffer-string))) | ||
| 516 | ;; data is in data var | ||
| 517 | ((stringp data) data) | ||
| 518 | ;; No data | ||
| 519 | (t nil))) | ||
| 520 | (delete-file tmp-file)))) | ||
| 454 | (t (get 'x-selections (or type 'PRIMARY))))) | 521 | (t (get 'x-selections (or type 'PRIMARY))))) |
| 455 | 522 | ||
| 456 | (defun w32--selection-owner-p (selection) | 523 | (defun w32--selection-owner-p (selection) |