summaryrefslogtreecommitdiff
path: root/lisp/select.el
diff options
context:
space:
mode:
authorYuuki Harano <masm+github@masm11.me>2021-11-13 16:25:48 +0900
committerYuuki Harano <masm+github@masm11.me>2021-11-13 16:25:48 +0900
commitc31d3dacf7f153589b6e7a5f5204937c64e7fd24 (patch)
treeb898c1d298e0d149faef0e9a6d641ce212df4e7e /lisp/select.el
parentc3377ae3b7fdb8714e03586589d1b2804cf08e17 (diff)
parentb4c6ab8cb67be4d5b3e0041981968c6cce4afe89 (diff)
downloademacs-c31d3dacf7f153589b6e7a5f5204937c64e7fd24.tar.gz
Merge branch 'master' of git.sv.gnu.org:/srv/git/emacs into feature/pgtk
Diffstat (limited to 'lisp/select.el')
-rw-r--r--lisp/select.el24
1 files changed, 17 insertions, 7 deletions
diff --git a/lisp/select.el b/lisp/select.el
index a77a005cd3d..5e7f4a696a3 100644
--- a/lisp/select.el
+++ b/lisp/select.el
@@ -307,7 +307,10 @@ the formats available in the clipboard if TYPE is `CLIPBOARD'."
(let ((data (gui-backend-get-selection (or type 'PRIMARY)
(or data-type 'STRING))))
(when (and (stringp data)
- (setq data-type (get-text-property 0 'foreign-selection data)))
+ ;; If this text property is set, then the data needs to
+ ;; be decoded -- otherwise it has already been decoded
+ ;; by the lower level functions.
+ (get-text-property 0 'foreign-selection data))
(let ((coding (or next-selection-coding-system
selection-coding-system
(pcase data-type
@@ -315,15 +318,22 @@ the formats available in the clipboard if TYPE is `CLIPBOARD'."
('text/plain\;charset=utf-8 'utf-8)
('COMPOUND_TEXT 'compound-text-with-extensions)
('C_STRING nil)
- ('STRING 'iso-8859-1)
- (_ (error "Unknown selection data type: %S"
- type))))))
- (setq data (if coding (decode-coding-string data coding)
- ;; This is for C_STRING case.
+ ('STRING 'iso-8859-1)))))
+ (setq data
+ (cond (coding (decode-coding-string data coding))
;; We want to convert each non-ASCII byte to the
;; corresponding eight-bit character, which has
;; a codepoint >= #x3FFF00.
- (string-to-multibyte data))))
+ ((eq data-type 'C_STRING)
+ (string-to-multibyte data))
+ ;; Guess at the charset for types like text/html
+ ;; -- it can be anything, and different
+ ;; applications use different encodings.
+ ((string-match-p "\\`text/" (symbol-name data-type))
+ (decode-coding-string
+ data (car (detect-coding-string data))))
+ ;; Do nothing.
+ (t data))))
(setq next-selection-coding-system nil)
(put-text-property 0 (length data) 'foreign-selection data-type data))
data))