diff options
| author | Stefan Monnier | 2007-11-09 19:37:03 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2007-11-09 19:37:03 +0000 |
| commit | c7e36bd9920ef0212078db8ab32a7e700acff460 (patch) | |
| tree | 10cd9b732ea4c8d0d23e65c6df77d5c7bd310d02 | |
| parent | 686f5b9a2f3810579bfb3c306a9d15d7899aef23 (diff) | |
| download | emacs-c7e36bd9920ef0212078db8ab32a7e700acff460.tar.gz emacs-c7e36bd9920ef0212078db8ab32a7e700acff460.zip | |
(x-select-text, x-cut-buffer-or-selection-value):
Make them work in tty frames.
(interprogram-cut-function, interprogram-paste-function): Set them globally.
| -rw-r--r-- | lisp/ChangeLog | 7 | ||||
| -rw-r--r-- | lisp/term/x-win.el | 225 |
2 files changed, 122 insertions, 110 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 1d801ae3d2a..7c60512ebc9 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,10 @@ | |||
| 1 | 2007-11-09 Stefan Monnier <monnier@iro.umontreal.ca> | ||
| 2 | |||
| 3 | * term/x-win.el (x-select-text, x-cut-buffer-or-selection-value): | ||
| 4 | Make them work in tty frames. | ||
| 5 | (interprogram-cut-function, interprogram-paste-function): | ||
| 6 | Set them globally. | ||
| 7 | |||
| 1 | 2007-11-09 Juanma Barranquero <lekktu@gmail.com> | 8 | 2007-11-09 Juanma Barranquero <lekktu@gmail.com> |
| 2 | 9 | ||
| 3 | * international/iso-cvt.el (iso-spanish, iso-german, iso-iso2tex) | 10 | * international/iso-cvt.el (iso-spanish, iso-german, iso-iso2tex) |
diff --git a/lisp/term/x-win.el b/lisp/term/x-win.el index 3310bc5507e..f058c877ab8 100644 --- a/lisp/term/x-win.el +++ b/lisp/term/x-win.el | |||
| @@ -2179,25 +2179,26 @@ Also, set the value of X cut buffer 0, for backward compatibility | |||
| 2179 | with older X applications. | 2179 | with older X applications. |
| 2180 | gildea@stop.mail-abuse.org says it's not desirable to put kills | 2180 | gildea@stop.mail-abuse.org says it's not desirable to put kills |
| 2181 | in the clipboard." | 2181 | in the clipboard." |
| 2182 | ;; Don't send the cut buffer too much text. | 2182 | ;; With multi-tty, this function may be called from a tty frame. |
| 2183 | ;; It becomes slow, and if really big it causes errors. | 2183 | (when (eq (framep (selected-frame)) 'x) |
| 2184 | (cond ((>= (length text) x-cut-buffer-max) | 2184 | ;; Don't send the cut buffer too much text. |
| 2185 | (x-set-cut-buffer "" push) | 2185 | ;; It becomes slow, and if really big it causes errors. |
| 2186 | (setq x-last-selected-text-cut "" | 2186 | (cond ((>= (length text) x-cut-buffer-max) |
| 2187 | x-last-selected-text-cut-encoded "")) | 2187 | (x-set-cut-buffer "" push) |
| 2188 | (t | 2188 | (setq x-last-selected-text-cut "" |
| 2189 | (setq x-last-selected-text-cut text | 2189 | x-last-selected-text-cut-encoded "")) |
| 2190 | x-last-cut-buffer-coding 'iso-latin-1 | 2190 | (t |
| 2191 | x-last-selected-text-cut-encoded | 2191 | (setq x-last-selected-text-cut text |
| 2192 | ;; ICCCM says cut buffer always contain ISO-Latin-1 | 2192 | x-last-cut-buffer-coding 'iso-latin-1 |
| 2193 | (encode-coding-string text 'iso-latin-1)) | 2193 | x-last-selected-text-cut-encoded |
| 2194 | (x-set-cut-buffer x-last-selected-text-cut-encoded push))) | 2194 | ;; ICCCM says cut buffer always contain ISO-Latin-1 |
| 2195 | (x-set-selection 'PRIMARY text) | 2195 | (encode-coding-string text 'iso-latin-1)) |
| 2196 | (setq x-last-selected-text-primary text) | 2196 | (x-set-cut-buffer x-last-selected-text-cut-encoded push))) |
| 2197 | (when x-select-enable-clipboard | 2197 | (x-set-selection 'PRIMARY text) |
| 2198 | (x-set-selection 'CLIPBOARD text) | 2198 | (setq x-last-selected-text-primary text) |
| 2199 | (setq x-last-selected-text-clipboard text)) | 2199 | (when x-select-enable-clipboard |
| 2200 | ) | 2200 | (x-set-selection 'CLIPBOARD text) |
| 2201 | (setq x-last-selected-text-clipboard text)))) | ||
| 2201 | 2202 | ||
| 2202 | (defvar x-select-request-type nil | 2203 | (defvar x-select-request-type nil |
| 2203 | "*Data type request for X selection. | 2204 | "*Data type request for X selection. |
| @@ -2318,99 +2319,103 @@ order until succeed.") | |||
| 2318 | ;; it returns nil the second time. This is so that a single | 2319 | ;; it returns nil the second time. This is so that a single |
| 2319 | ;; selection won't be added to the kill ring over and over. | 2320 | ;; selection won't be added to the kill ring over and over. |
| 2320 | (defun x-cut-buffer-or-selection-value () | 2321 | (defun x-cut-buffer-or-selection-value () |
| 2321 | (let (clip-text primary-text cut-text) | 2322 | ;; With multi-tty, this function may be called from a tty frame. |
| 2322 | (when x-select-enable-clipboard | 2323 | (when (eq (framep (selected-frame)) 'x) |
| 2323 | (setq clip-text (x-selection-value 'CLIPBOARD)) | 2324 | (let (clip-text primary-text cut-text) |
| 2324 | (if (string= clip-text "") (setq clip-text nil)) | 2325 | (when x-select-enable-clipboard |
| 2325 | 2326 | (setq clip-text (x-selection-value 'CLIPBOARD)) | |
| 2326 | ;; Check the CLIPBOARD selection for 'newness', is it different | 2327 | (if (string= clip-text "") (setq clip-text nil)) |
| 2328 | |||
| 2329 | ;; Check the CLIPBOARD selection for 'newness', is it different | ||
| 2330 | ;; from what we remebered them to be last time we did a | ||
| 2331 | ;; cut/paste operation. | ||
| 2332 | (setq clip-text | ||
| 2333 | (cond ;; check clipboard | ||
| 2334 | ((or (not clip-text) (string= clip-text "")) | ||
| 2335 | (setq x-last-selected-text-clipboard nil)) | ||
| 2336 | ((eq clip-text x-last-selected-text-clipboard) nil) | ||
| 2337 | ((string= clip-text x-last-selected-text-clipboard) | ||
| 2338 | ;; Record the newer string, | ||
| 2339 | ;; so subsequent calls can use the `eq' test. | ||
| 2340 | (setq x-last-selected-text-clipboard clip-text) | ||
| 2341 | nil) | ||
| 2342 | (t (setq x-last-selected-text-clipboard clip-text))))) | ||
| 2343 | |||
| 2344 | (setq primary-text (x-selection-value 'PRIMARY)) | ||
| 2345 | ;; Check the PRIMARY selection for 'newness', is it different | ||
| 2346 | ;; from what we remebered them to be last time we did a | ||
| 2347 | ;; cut/paste operation. | ||
| 2348 | (setq primary-text | ||
| 2349 | (cond ;; check primary selection | ||
| 2350 | ((or (not primary-text) (string= primary-text "")) | ||
| 2351 | (setq x-last-selected-text-primary nil)) | ||
| 2352 | ((eq primary-text x-last-selected-text-primary) nil) | ||
| 2353 | ((string= primary-text x-last-selected-text-primary) | ||
| 2354 | ;; Record the newer string, | ||
| 2355 | ;; so subsequent calls can use the `eq' test. | ||
| 2356 | (setq x-last-selected-text-primary primary-text) | ||
| 2357 | nil) | ||
| 2358 | (t | ||
| 2359 | (setq x-last-selected-text-primary primary-text)))) | ||
| 2360 | |||
| 2361 | (setq cut-text (x-get-cut-buffer 0)) | ||
| 2362 | |||
| 2363 | ;; Check the x cut buffer for 'newness', is it different | ||
| 2327 | ;; from what we remebered them to be last time we did a | 2364 | ;; from what we remebered them to be last time we did a |
| 2328 | ;; cut/paste operation. | 2365 | ;; cut/paste operation. |
| 2329 | (setq clip-text | 2366 | (setq cut-text |
| 2330 | (cond;; check clipboard | 2367 | (let ((next-coding (or next-selection-coding-system 'iso-latin-1))) |
| 2331 | ((or (not clip-text) (string= clip-text "")) | 2368 | (cond ;; check cut buffer |
| 2332 | (setq x-last-selected-text-clipboard nil)) | 2369 | ((or (not cut-text) (string= cut-text "")) |
| 2333 | ((eq clip-text x-last-selected-text-clipboard) nil) | 2370 | (setq x-last-selected-text-cut nil)) |
| 2334 | ((string= clip-text x-last-selected-text-clipboard) | 2371 | ;; This short cut doesn't work because x-get-cut-buffer |
| 2335 | ;; Record the newer string, | 2372 | ;; always returns a newly created string. |
| 2336 | ;; so subsequent calls can use the `eq' test. | 2373 | ;; ((eq cut-text x-last-selected-text-cut) nil) |
| 2337 | (setq x-last-selected-text-clipboard clip-text) | 2374 | ((and (string= cut-text x-last-selected-text-cut-encoded) |
| 2338 | nil) | 2375 | (eq x-last-cut-buffer-coding next-coding)) |
| 2339 | (t | 2376 | ;; See the comment above. No need of this recording. |
| 2340 | (setq x-last-selected-text-clipboard clip-text)))) | 2377 | ;; Record the newer string, |
| 2341 | ) | 2378 | ;; so subsequent calls can use the `eq' test. |
| 2342 | 2379 | ;; (setq x-last-selected-text-cut cut-text) | |
| 2343 | (setq primary-text (x-selection-value 'PRIMARY)) | 2380 | nil) |
| 2344 | ;; Check the PRIMARY selection for 'newness', is it different | 2381 | (t |
| 2345 | ;; from what we remebered them to be last time we did a | 2382 | (setq x-last-selected-text-cut-encoded cut-text |
| 2346 | ;; cut/paste operation. | 2383 | x-last-cut-buffer-coding next-coding |
| 2347 | (setq primary-text | 2384 | x-last-selected-text-cut |
| 2348 | (cond;; check primary selection | 2385 | ;; ICCCM says cut buffer always contain ISO-Latin-1, but |
| 2349 | ((or (not primary-text) (string= primary-text "")) | 2386 | ;; use next-selection-coding-system if not nil. |
| 2350 | (setq x-last-selected-text-primary nil)) | 2387 | (decode-coding-string |
| 2351 | ((eq primary-text x-last-selected-text-primary) nil) | 2388 | cut-text next-coding)))))) |
| 2352 | ((string= primary-text x-last-selected-text-primary) | 2389 | |
| 2353 | ;; Record the newer string, | 2390 | ;; As we have done one selection, clear this now. |
| 2354 | ;; so subsequent calls can use the `eq' test. | 2391 | (setq next-selection-coding-system nil) |
| 2355 | (setq x-last-selected-text-primary primary-text) | 2392 | |
| 2356 | nil) | 2393 | ;; At this point we have recorded the current values for the |
| 2357 | (t | 2394 | ;; selection from clipboard (if we are supposed to) primary, |
| 2358 | (setq x-last-selected-text-primary primary-text)))) | 2395 | ;; and cut buffer. So return the first one that has changed |
| 2359 | 2396 | ;; (which is the first non-null one). | |
| 2360 | (setq cut-text (x-get-cut-buffer 0)) | 2397 | ;; |
| 2361 | 2398 | ;; NOTE: There will be cases where more than one of these has | |
| 2362 | ;; Check the x cut buffer for 'newness', is it different | 2399 | ;; changed and the new values differ. This indicates that |
| 2363 | ;; from what we remebered them to be last time we did a | 2400 | ;; something like the following has happened since the last time |
| 2364 | ;; cut/paste operation. | 2401 | ;; we looked at the selections: Application X set all the |
| 2365 | (setq cut-text | 2402 | ;; selections, then Application Y set only one or two of them (say |
| 2366 | (let ((next-coding (or next-selection-coding-system 'iso-latin-1))) | 2403 | ;; just the cut-buffer). In this case since we don't have |
| 2367 | (cond;; check cut buffer | 2404 | ;; timestamps there is no way to know what the 'correct' value to |
| 2368 | ((or (not cut-text) (string= cut-text "")) | 2405 | ;; return is. The nice thing to do would be to tell the user we |
| 2369 | (setq x-last-selected-text-cut nil)) | 2406 | ;; saw multiple possible selections and ask the user which was the |
| 2370 | ;; This short cut doesn't work because x-get-cut-buffer | 2407 | ;; one they wanted. |
| 2371 | ;; always returns a newly created string. | 2408 | ;; This code is still a big improvement because now the user can |
| 2372 | ;; ((eq cut-text x-last-selected-text-cut) nil) | 2409 | ;; futz with the current selection and get emacs to pay attention |
| 2373 | ((and (string= cut-text x-last-selected-text-cut-encoded) | 2410 | ;; to the cut buffer again (previously as soon as clipboard or |
| 2374 | (eq x-last-cut-buffer-coding next-coding)) | 2411 | ;; primary had been set the cut buffer would essentially never be |
| 2375 | ;; See the comment above. No need of this recording. | 2412 | ;; checked again). |
| 2376 | ;; Record the newer string, | 2413 | (or clip-text primary-text cut-text) |
| 2377 | ;; so subsequent calls can use the `eq' test. | 2414 | ))) |
| 2378 | ;; (setq x-last-selected-text-cut cut-text) | 2415 | |
| 2379 | nil) | 2416 | ;; Arrange for the kill and yank functions to set and check the clipboard. |
| 2380 | (t | 2417 | (setq interprogram-cut-function 'x-select-text) |
| 2381 | (setq x-last-selected-text-cut-encoded cut-text | 2418 | (setq interprogram-paste-function 'x-cut-buffer-or-selection-value) |
| 2382 | x-last-cut-buffer-coding next-coding | ||
| 2383 | x-last-selected-text-cut | ||
| 2384 | ;; ICCCM says cut buffer always contain ISO-Latin-1, but | ||
| 2385 | ;; use next-selection-coding-system if not nil. | ||
| 2386 | (decode-coding-string | ||
| 2387 | cut-text next-coding)))))) | ||
| 2388 | |||
| 2389 | ;; As we have done one selection, clear this now. | ||
| 2390 | (setq next-selection-coding-system nil) | ||
| 2391 | |||
| 2392 | ;; At this point we have recorded the current values for the | ||
| 2393 | ;; selection from clipboard (if we are supposed to) primary, | ||
| 2394 | ;; and cut buffer. So return the first one that has changed | ||
| 2395 | ;; (which is the first non-null one). | ||
| 2396 | ;; | ||
| 2397 | ;; NOTE: There will be cases where more than one of these has | ||
| 2398 | ;; changed and the new values differ. This indicates that | ||
| 2399 | ;; something like the following has happened since the last time | ||
| 2400 | ;; we looked at the selections: Application X set all the | ||
| 2401 | ;; selections, then Application Y set only one or two of them (say | ||
| 2402 | ;; just the cut-buffer). In this case since we don't have | ||
| 2403 | ;; timestamps there is no way to know what the 'correct' value to | ||
| 2404 | ;; return is. The nice thing to do would be to tell the user we | ||
| 2405 | ;; saw multiple possible selections and ask the user which was the | ||
| 2406 | ;; one they wanted. | ||
| 2407 | ;; This code is still a big improvement because now the user can | ||
| 2408 | ;; futz with the current selection and get emacs to pay attention | ||
| 2409 | ;; to the cut buffer again (previously as soon as clipboard or | ||
| 2410 | ;; primary had been set the cut buffer would essentially never be | ||
| 2411 | ;; checked again). | ||
| 2412 | (or clip-text primary-text cut-text) | ||
| 2413 | )) | ||
| 2414 | 2419 | ||
| 2415 | (defun x-clipboard-yank () | 2420 | (defun x-clipboard-yank () |
| 2416 | "Insert the clipboard contents, or the last stretch of killed text." | 2421 | "Insert the clipboard contents, or the last stretch of killed text." |