comparison lisp/term/x-win.el @ 58695:b742505dc5c4

(x-last-selected-text-cut-encoded): New variable. (x-select-text): Don't treat eight-bit-control/graphic chars specially. Store the encoded text in the X cut buffer. (x-cut-buffer-or-selection-value): Compare the X cut buffer text with x-last-selected-text-cut-encoded.
author Kenichi Handa <handa@m17n.org>
date Wed, 01 Dec 2004 00:35:37 +0000
parents 302e4e1415d3
children eaa9acd9122c 549734260e34 f2ebccfa87d4
comparison
equal deleted inserted replaced
58694:84ddf6dba7e1 58695:b742505dc5c4
2094 pasted text.") 2094 pasted text.")
2095 (defvar x-last-selected-text-primary nil 2095 (defvar x-last-selected-text-primary nil
2096 "The value of the PRIMARY X selection last time we selected or 2096 "The value of the PRIMARY X selection last time we selected or
2097 pasted text.") 2097 pasted text.")
2098 (defvar x-last-selected-text-cut nil 2098 (defvar x-last-selected-text-cut nil
2099 "The value of the X cut buffer last time we selected or pasted text.") 2099 "The value of the X cut buffer last time we selected or pasted text.
2100 The actual text stored in the X cut buffer is what encoded from this value.")
2101 (defvar x-last-selected-text-cut-encoded nil
2102 "The value of the X cut buffer last time we selected or pasted text.
2103 This is the actual text stored in the X cut buffer.")
2100 2104
2101 ;;; It is said that overlarge strings are slow to put into the cut buffer. 2105 ;;; It is said that overlarge strings are slow to put into the cut buffer.
2102 ;;; Note this value is overridden below. 2106 ;;; Note this value is overridden below.
2103 (defvar x-cut-buffer-max 20000 2107 (defvar x-cut-buffer-max 20000
2104 "Max number of characters to put in the cut buffer.") 2108 "Max number of characters to put in the cut buffer.")
2117 (defun x-select-text (text &optional push) 2121 (defun x-select-text (text &optional push)
2118 ;; Don't send the cut buffer too much text. 2122 ;; Don't send the cut buffer too much text.
2119 ;; It becomes slow, and if really big it causes errors. 2123 ;; It becomes slow, and if really big it causes errors.
2120 (cond ((>= (length text) x-cut-buffer-max) 2124 (cond ((>= (length text) x-cut-buffer-max)
2121 (x-set-cut-buffer "" push) 2125 (x-set-cut-buffer "" push)
2122 (setq x-last-selected-text-cut "")) 2126 (setq x-last-selected-text-cut ""
2123 ;; Don't store a multibyte string that contains 2127 x-last-selected-text-cut-encoded ""))
2124 ;; eight-bit-control/graphic chars because they can't be
2125 ;; restored correctly by x-get-cut-buffer.
2126 ((and (multibyte-string-p text)
2127 (let ((charsets (find-charset-string text)))
2128 (or (memq 'eight-bit-control charsets)
2129 (memq 'eight-bit-graphic charsets))))
2130 (x-set-cut-buffer "" push)
2131 (setq x-last-selected-text-cut ""))
2132 (t 2128 (t
2133 (x-set-cut-buffer text push) 2129 (setq x-last-selected-text-cut text
2134 (setq x-last-selected-text-cut text))) 2130 x-last-selected-text-cut-encoded
2131 (encode-coding-string text (or locale-coding-system
2132 'iso-latin-1)))
2133 (x-set-cut-buffer x-last-selected-text-cut-encoded push)))
2135 (x-set-selection 'PRIMARY text) 2134 (x-set-selection 'PRIMARY text)
2136 (setq x-last-selected-text-primary text) 2135 (setq x-last-selected-text-primary text)
2137 (when x-select-enable-clipboard 2136 (when x-select-enable-clipboard
2138 (x-set-selection 'CLIPBOARD text) 2137 (x-set-selection 'CLIPBOARD text)
2139 (setq x-last-selected-text-clipboard text)) 2138 (setq x-last-selected-text-clipboard text))
2289 2288
2290 ;; Check the x cut buffer for 'newness', is it different 2289 ;; Check the x cut buffer for 'newness', is it different
2291 ;; from what we remebered them to be last time we did a 2290 ;; from what we remebered them to be last time we did a
2292 ;; cut/paste operation. 2291 ;; cut/paste operation.
2293 (setq cut-text 2292 (setq cut-text
2294 (cond;; check primary selection 2293 (cond;; check cut buffer
2295 ((or (not cut-text) (string= cut-text "")) 2294 ((or (not cut-text) (string= cut-text ""))
2296 (setq x-last-selected-text-cut nil)) 2295 (setq x-last-selected-text-cut nil))
2297 ((eq cut-text x-last-selected-text-cut) nil) 2296 ;; This short cut doesn't work because x-get-cut-buffer
2298 ((string= cut-text x-last-selected-text-cut) 2297 ;; always returns a newly created string.
2298 ;; ((eq cut-text x-last-selected-text-cut) nil)
2299 ((string= cut-text x-last-selected-text-cut-encoded)
2300 ;; See the comment above. No need of this recording.
2299 ;; Record the newer string, 2301 ;; Record the newer string,
2300 ;; so subsequent calls can use the `eq' test. 2302 ;; so subsequent calls can use the `eq' test.
2301 (setq x-last-selected-text-cut cut-text) 2303 ;; (setq x-last-selected-text-cut cut-text)
2302 nil) 2304 nil)
2303 (t 2305 (t
2304 (setq x-last-selected-text-cut cut-text)))) 2306 (setq x-last-selected-text-cut-encoded cut-text
2307 x-last-selected-text-cut
2308 (decode-coding-string cut-text (or locale-coding-system
2309 'iso-latin-1))))))
2305 2310
2306 ;; As we have done one selection, clear this now. 2311 ;; As we have done one selection, clear this now.
2307 (setq next-selection-coding-system nil) 2312 (setq next-selection-coding-system nil)
2308 2313
2309 ;; At this point we have recorded the current values for the 2314 ;; At this point we have recorded the current values for the