aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenichi Handa2007-11-18 14:52:03 +0000
committerKenichi Handa2007-11-18 14:52:03 +0000
commit0c861f59777b4e45451e47c4438c88df0681cef2 (patch)
tree81f229c072b745ad732bd59dd9fc74cfa6754fb3
parentb8f931edac1ae4269f59bd1dce10427805b19a0a (diff)
downloademacs-0c861f59777b4e45451e47c4438c88df0681cef2.tar.gz
emacs-0c861f59777b4e45451e47c4438c88df0681cef2.zip
(x-selection-value): If x-select-request-type is
nil, try also STRING at last. (x-select-request-type): Doc adjusted the change of x-selection-value.
-rw-r--r--lisp/term/x-win.el50
1 files changed, 7 insertions, 43 deletions
diff --git a/lisp/term/x-win.el b/lisp/term/x-win.el
index bbe9a00be65..eb2e559a0d1 100644
--- a/lisp/term/x-win.el
+++ b/lisp/term/x-win.el
@@ -2203,55 +2203,18 @@ in the clipboard."
2203 2203
2204(defvar x-select-request-type nil 2204(defvar x-select-request-type nil
2205 "*Data type request for X selection. 2205 "*Data type request for X selection.
2206The value is nil, one of the following data types, or a list of them: 2206The value is one of the following data types, a list of them, or nil:
2207 `COMPOUND_TEXT', `UTF8_STRING', `STRING', `TEXT' 2207 `COMPOUND_TEXT', `UTF8_STRING', `STRING', `TEXT'
2208 2208
2209If the value is nil, try `COMPOUND_TEXT' and `UTF8_STRING', and
2210use the more appropriate result. If both fail, try `STRING', and
2211then `TEXT'.
2212
2213If the value is one of the above symbols, try only the specified 2209If the value is one of the above symbols, try only the specified
2214type. 2210type.
2215 2211
2216If the value is a list of them, try each of them in the specified 2212If the value is a list of them, try each of them in the specified
2217order until succeed.") 2213order until succeed.
2218 2214
2219;; Helper function for x-selection-value. Select UTF8 or CTEXT 2215The value nil is the same as this list:
2220;; whichever is more appropriate. Here, we use this heurisitcs. 2216 \(UTF8_STRING COMPOUND_TEXT STRING)
2221;; 2217")
2222;; (1) If their lengthes are different, select the longer one. This
2223;; is because an X client may just cut off unsupported characters.
2224;;
2225;; (2) Otherwise, if they are different at Nth character, and that
2226;; of UTF8 is a Latin character and that of CTEXT belongs to a CJK
2227;; character set, select UTF8. Also select UTF8 if the Nth
2228;; character of UTF8 is non-ASCII where as that of CTEXT is ASCII.
2229;; This is because an X client may replace unsupported characters
2230;; with some ASCII character (typically ` ' or `?') in CTEXT.
2231;;
2232;; (3) Otherwise, select CTEXT. This is because legacy charsets are
2233;; better for the current Emacs, especially when the selection owner
2234;; is also Emacs.
2235
2236(defun x-select-utf8-or-ctext (utf8 ctext)
2237 (let ((len-utf8 (length utf8))
2238 (len-ctext (length ctext))
2239 (selected ctext)
2240 (i 0)
2241 char)
2242 (if (/= len-utf8 len-ctext)
2243 (if (> len-utf8 len-ctext) utf8 ctext)
2244 (let ((result (compare-strings utf8 0 len-utf8 ctext 0 len-ctext)))
2245 (if (eq result t)
2246 ctext
2247 (let ((utf8-char (aref utf8 (1- (abs result))))
2248 (ctext-char (aref ctext (1- (abs result)))))
2249 (if (or (and (aref (char-category-set utf8-char) ?l)
2250 (aref (char-category-set ctext-char) ?C))
2251 (and (>= utf8-char 128)
2252 (< ctext-char 128)))
2253 utf8
2254 ctext)))))))
2255 2218
2256;; Get a selection value of type TYPE by calling x-get-selection with 2219;; Get a selection value of type TYPE by calling x-get-selection with
2257;; an appropiate DATA-TYPE argument decided by `x-select-request-type'. 2220;; an appropiate DATA-TYPE argument decided by `x-select-request-type'.
@@ -2259,7 +2222,8 @@ order until succeed.")
2259;; error, this function return nil. 2222;; error, this function return nil.
2260 2223
2261(defun x-selection-value (type) 2224(defun x-selection-value (type)
2262 (let ((request-type (or x-select-request-type '(UTF8_STRING COMPOUND_TEXT))) 2225 (let ((request-type (or x-select-request-type
2226 '(UTF8_STRING COMPOUND_TEXT STRING)))
2263 text) 2227 text)
2264 (if (consp request-type) 2228 (if (consp request-type)
2265 (while (and request-type (not text)) 2229 (while (and request-type (not text))