diff options
| -rw-r--r-- | lisp/term/x-win.el | 63 |
1 files changed, 12 insertions, 51 deletions
diff --git a/lisp/term/x-win.el b/lisp/term/x-win.el index 8f5c092f126..bbe9a00be65 100644 --- a/lisp/term/x-win.el +++ b/lisp/term/x-win.el | |||
| @@ -2254,61 +2254,22 @@ order until succeed.") | |||
| 2254 | ctext))))))) | 2254 | ctext))))))) |
| 2255 | 2255 | ||
| 2256 | ;; Get a selection value of type TYPE by calling x-get-selection with | 2256 | ;; Get a selection value of type TYPE by calling x-get-selection with |
| 2257 | ;; an appropiate DATA-TYPE argument decidd by `x-select-request-type'. | 2257 | ;; an appropiate DATA-TYPE argument decided by `x-select-request-type'. |
| 2258 | ;; The return value is already decoded. If x-get-selection causes an | 2258 | ;; The return value is already decoded. If x-get-selection causes an |
| 2259 | ;; error, this function return nil. | 2259 | ;; error, this function return nil. |
| 2260 | 2260 | ||
| 2261 | (defun x-selection-value (type) | 2261 | (defun x-selection-value (type) |
| 2262 | (let (text) | 2262 | (let ((request-type (or x-select-request-type '(UTF8_STRING COMPOUND_TEXT))) |
| 2263 | (cond ((null x-select-request-type) | 2263 | text) |
| 2264 | (let (utf8 ctext utf8-coding) | 2264 | (if (consp request-type) |
| 2265 | ;; We try both UTF8_STRING and COMPOUND_TEXT, and choose | 2265 | (while (and request-type (not text)) |
| 2266 | ;; the more appropriate one. If both fail, try STRING. | 2266 | (condition-case nil |
| 2267 | 2267 | (setq text (x-get-selection type (car request-type))) | |
| 2268 | ;; At first try UTF8_STRING. | 2268 | (error nil)) |
| 2269 | (setq utf8 (condition-case nil | 2269 | (setq request-type (cdr request-type))) |
| 2270 | (x-get-selection type 'UTF8_STRING) | 2270 | (condition-case nil |
| 2271 | (error nil)) | 2271 | (setq text (x-get-selection type request-type)) |
| 2272 | utf8-coding last-coding-system-used) | 2272 | (error nil))) |
| 2273 | (if utf8 | ||
| 2274 | ;; If it is a local selection, or it contains only | ||
| 2275 | ;; ASCII characers, choose it. | ||
| 2276 | (if (or (not (get-text-property 0 'foreign-selection utf8)) | ||
| 2277 | (= (length utf8) (string-bytes utf8))) | ||
| 2278 | (setq text utf8))) | ||
| 2279 | ;; If not yet decided, try COMPOUND_TEXT. | ||
| 2280 | (if (not text) | ||
| 2281 | (if (setq ctext (condition-case nil | ||
| 2282 | (x-get-selection type 'COMPOUND_TEXT) | ||
| 2283 | (error nil))) | ||
| 2284 | ;; If UTF8_STRING was also successful, choose the | ||
| 2285 | ;; more appropriate one from UTF8 and CTEXT. | ||
| 2286 | (if utf8 | ||
| 2287 | (setq text (x-select-utf8-or-ctext utf8 ctext)) | ||
| 2288 | ;; Othewise, choose CTEXT. | ||
| 2289 | (setq text ctext)) | ||
| 2290 | (setq text utf8))) | ||
| 2291 | ;; If not yet decided, try STRING. | ||
| 2292 | (or text | ||
| 2293 | (setq text (condition-case nil | ||
| 2294 | (x-get-selection type 'STRING) | ||
| 2295 | (error nil)))) | ||
| 2296 | (if (eq text utf8) | ||
| 2297 | (setq last-coding-system-used utf8-coding)))) | ||
| 2298 | |||
| 2299 | ((consp x-select-request-type) | ||
| 2300 | (let ((tail x-select-request-type)) | ||
| 2301 | (while (and tail (not text)) | ||
| 2302 | (condition-case nil | ||
| 2303 | (setq text (x-get-selection type (car tail))) | ||
| 2304 | (error nil)) | ||
| 2305 | (setq tail (cdr tail))))) | ||
| 2306 | |||
| 2307 | (t | ||
| 2308 | (condition-case nil | ||
| 2309 | (setq text (x-get-selection type x-select-request-type)) | ||
| 2310 | (error nil)))) | ||
| 2311 | |||
| 2312 | (if text | 2273 | (if text |
| 2313 | (remove-text-properties 0 (length text) '(foreign-selection nil) text)) | 2274 | (remove-text-properties 0 (length text) '(foreign-selection nil) text)) |
| 2314 | text)) | 2275 | text)) |