diff options
| author | Stefan Monnier | 2014-10-01 23:19:32 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2014-10-01 23:19:32 -0400 |
| commit | 31300bee24ddcfd7dc27e757513d3c176a7fad83 (patch) | |
| tree | 28aba34a75aeafb3246cb60f2c8c55d3043436f8 /lisp/term | |
| parent | c7c0acd47bad506647ca3445aba1ced77d201daf (diff) | |
| download | emacs-31300bee24ddcfd7dc27e757513d3c176a7fad83.tar.gz emacs-31300bee24ddcfd7dc27e757513d3c176a7fad83.zip | |
Consolidate management/ownership of selections.
* lisp/select.el (gui-get-selection-alist): New method.
(gui-get-selection): Use it. Rename from x-get-selection.
(x-get-selection): Define as obsolete alias.
(x-get-clipboard): Mark obsolete.
(gui-get-primary-selection): New function.
(x-get-selection-value): Mark obsolete.
(gui-own-selection-alist, gui-disown-selection-alist)
(gui-selection-owner-p-alist): New methods.
(gui-set-selection): Use them. Rename from x-set-selection.
(x-set-selection): Define as obsolete alias.
(gui--valid-simple-selection-p): Rename from
x-valid-simple-selection-p.
* lisp/w32-common-fns.el (gui-own-selection, gui-disown-selection)
(gui-selection-owner-p, gui-get-selection): Define for w32.
(w32-get-selection-value): Rename from x-get-selection-value.
Use the new gui-last-selected-text.
* lisp/term/x-win.el (x-get-selection-value): Remove.
(x-clipboard-yank): Declare obsolete.
(gui-own-selection, gui-disown-selection, gui-get-selection)
(gui-selection-owner-p): Define for x.
* lisp/term/w32-win.el (w32-win-suspend-error): Rename from
x-win-suspend-error.
* lisp/term/pc-win.el (w16-get-selection-value): Rename from
x-get-selection-value.
(w16-selection-owner-p): Rename from x-selection-owner-p.
(gui-own-selection, gui-disown-selection, gui-get-selection)
(gui-selection-owner-p): Define for pc.
(w16--select-text): New function.
* lisp/term/ns-win.el (gui-own-selection, gui-disown-selection)
(gui-get-selection, gui-selection-owner-p): Define for ns.
* lisp/term.el (term-mouse-paste):
* lisp/mouse.el (mouse-yank-primary): Use gui-get-primary-selection.
* src/nsselect.m (ns-own-selection-internal, ns-disown-selection-internal):
Rename from the "x-" prefix.
Diffstat (limited to 'lisp/term')
| -rw-r--r-- | lisp/term/ns-win.el | 5 | ||||
| -rw-r--r-- | lisp/term/pc-win.el | 137 | ||||
| -rw-r--r-- | lisp/term/w32-win.el | 7 | ||||
| -rw-r--r-- | lisp/term/x-win.el | 21 |
4 files changed, 61 insertions, 109 deletions
diff --git a/lisp/term/ns-win.el b/lisp/term/ns-win.el index fc13a2c5ddf..5889baf6946 100644 --- a/lisp/term/ns-win.el +++ b/lisp/term/ns-win.el | |||
| @@ -971,6 +971,11 @@ See the documentation of `create-fontset-from-fontset-spec' for the format.") | |||
| 971 | (when gui-select-enable-clipboard | 971 | (when gui-select-enable-clipboard |
| 972 | (ns-set-pasteboard text)))) | 972 | (ns-set-pasteboard text)))) |
| 973 | 973 | ||
| 974 | (gui-method-define gui-own-selection x #'ns-own-selection-internal) | ||
| 975 | (gui-method-define gui-disown-selection x #'ns-disown-selection-internal) | ||
| 976 | (gui-method-define gui-selection-owner-p x #'ns-selection-owner-p) | ||
| 977 | (gui-method-define gui-get-selection x #'x-get-selection-internal) ;FIXME:name! | ||
| 978 | |||
| 974 | (provide 'ns-win) | 979 | (provide 'ns-win) |
| 975 | 980 | ||
| 976 | ;;; ns-win.el ends here | 981 | ;;; ns-win.el ends here |
diff --git a/lisp/term/pc-win.el b/lisp/term/pc-win.el index 264d881bc15..3498937b4d2 100644 --- a/lisp/term/pc-win.el +++ b/lisp/term/pc-win.el | |||
| @@ -219,7 +219,7 @@ the operating system.") | |||
| 219 | ; | 219 | ; |
| 220 | ;;;; Selections | 220 | ;;;; Selections |
| 221 | ; | 221 | ; |
| 222 | (defun x-get-selection-value () | 222 | (defun w16-get-selection-value () |
| 223 | "Return the value of the current selection. | 223 | "Return the value of the current selection. |
| 224 | Consult the selection. Treat empty strings as if they were unset." | 224 | Consult the selection. Treat empty strings as if they were unset." |
| 225 | (if gui-select-enable-clipboard | 225 | (if gui-select-enable-clipboard |
| @@ -238,93 +238,44 @@ Consult the selection. Treat empty strings as if they were unset." | |||
| 238 | (t | 238 | (t |
| 239 | (setq gui-last-selected-text text)))))) | 239 | (setq gui-last-selected-text text)))))) |
| 240 | 240 | ||
| 241 | ;; x-selection-owner-p is used in simple.el. | 241 | ;; gui-selection-owner-p is used in simple.el. |
| 242 | (defun x-selection-owner-p (&optional _selection _terminal) | 242 | (gui-method-define gui-selection-owner-p pc #'w16-selection-owner-p) |
| 243 | "Whether the current Emacs process owns the given X Selection. | 243 | (defun w16-selection-owner-p (_selection) |
| 244 | The arg should be the name of the selection in question, typically one of | 244 | ;; FIXME: Other systems don't obey gui-select-enable-clipboard here. |
| 245 | the symbols `PRIMARY', `SECONDARY', or `CLIPBOARD'. | 245 | (if gui-select-enable-clipboard |
| 246 | \(Those are literal upper-case symbol names, since that's what X expects.) | 246 | (let ((text |
| 247 | For convenience, the symbol nil is the same as `PRIMARY', | 247 | ;; Don't die if w16-get-clipboard-data signals an error. |
| 248 | and t is the same as `SECONDARY'. | 248 | (ignore-errors |
| 249 | 249 | (w16-get-clipboard-data)))) | |
| 250 | TERMINAL should be a terminal object or a frame specifying the X | 250 | ;; We consider ourselves the owner of the selection |
| 251 | server to query. If omitted or nil, that stands for the selected | 251 | ;; if it does not exist, or exists and compares |
| 252 | frame's display, or the first available X display. | 252 | ;; equal with the last text we've put into the |
| 253 | 253 | ;; Windows clipboard. | |
| 254 | On Nextstep, TERMINAL is unused. | 254 | (cond |
| 255 | 255 | ((not text) t) | |
| 256 | \(fn &optional SELECTION TERMINAL)" | 256 | ((or (eq text gui-last-selected-text) |
| 257 | (if gui-select-enable-clipboard | 257 | (string= text gui-last-selected-text)) |
| 258 | (let (text) | 258 | text) |
| 259 | ;; Don't die if w16-get-clipboard-data signals an error. | 259 | (t nil))))) |
| 260 | (ignore-errors | 260 | |
| 261 | (setq text (w16-get-clipboard-data))) | 261 | ;; gui-own-selection and gui-disown-selection are used in gui-set-selection. |
| 262 | ;; We consider ourselves the owner of the selection if it does | 262 | (gui-method-define gui-own-selection pc |
| 263 | ;; not exist, or exists and compares equal with the last text | 263 | (lambda (_selection value) |
| 264 | ;; we've put into the Windows clipboard. | 264 | ;; FIXME: Other systems don't obey |
| 265 | (cond | 265 | ;; gui-select-enable-clipboard here. |
| 266 | ((not text) t) | 266 | (ignore-errors |
| 267 | ((or (eq text gui-last-selected-text) | 267 | (w16--select-text value)) |
| 268 | (string= text gui-last-selected-text)) | 268 | value)) |
| 269 | text) | 269 | |
| 270 | (t nil))))) | 270 | (gui-method-define gui-disown-selection pc |
| 271 | 271 | (lambda (selection &optional _time-object _terminal) | |
| 272 | ;; x-own-selection-internal and x-disown-selection-internal are used | 272 | (if (w16-selection-owner-p selection) |
| 273 | ;; in select.el:x-set-selection. | 273 | t))) |
| 274 | (defun x-own-selection-internal (_selection value &optional _frame) | 274 | |
| 275 | "Assert an X selection of the type SELECTION with and value VALUE. | 275 | ;; gui-get-selection is used in select.el |
| 276 | SELECTION is a symbol, typically `PRIMARY', `SECONDARY', or `CLIPBOARD'. | 276 | (gui-method-define gui-get-selection pc |
| 277 | \(Those are literal upper-case symbol names, since that's what X expects.) | 277 | (lambda (selection-symbol target-type) |
| 278 | VALUE is typically a string, or a cons of two markers, but may be | 278 | (w16-get-selection-value))) |
| 279 | anything that the functions on `selection-converter-alist' know about. | ||
| 280 | |||
| 281 | FRAME should be a frame that should own the selection. If omitted or | ||
| 282 | nil, it defaults to the selected frame. | ||
| 283 | |||
| 284 | On Nextstep, FRAME is unused. | ||
| 285 | |||
| 286 | \(fn SELECTION VALUE &optional FRAME)" | ||
| 287 | (ignore-errors | ||
| 288 | (x-select-text value)) | ||
| 289 | value) | ||
| 290 | |||
| 291 | (defun x-disown-selection-internal (selection &optional _time-object _terminal) | ||
| 292 | "If we own the selection SELECTION, disown it. | ||
| 293 | Disowning it means there is no such selection. | ||
| 294 | |||
| 295 | Sets the last-change time for the selection to TIME-OBJECT (by default | ||
| 296 | the time of the last event). | ||
| 297 | |||
| 298 | TERMINAL should be a terminal object or a frame specifying the X | ||
| 299 | server to query. If omitted or nil, that stands for the selected | ||
| 300 | frame's display, or the first available X display. | ||
| 301 | |||
| 302 | On Nextstep, the TIME-OBJECT and TERMINAL arguments are unused. | ||
| 303 | On MS-DOS, all this does is return non-nil if we own the selection. | ||
| 304 | |||
| 305 | \(fn SELECTION &optional TIME-OBJECT TERMINAL)" | ||
| 306 | (if (x-selection-owner-p selection) | ||
| 307 | t)) | ||
| 308 | |||
| 309 | ;; x-get-selection-internal is used in select.el | ||
| 310 | (defun x-get-selection-internal (_selection-symbol _target-type | ||
| 311 | &optional _time-stamp _terminal) | ||
| 312 | "Return text selected from some X window. | ||
| 313 | SELECTION-SYMBOL is typically `PRIMARY', `SECONDARY', or `CLIPBOARD'. | ||
| 314 | \(Those are literal upper-case symbol names, since that's what X expects.) | ||
| 315 | TARGET-TYPE is the type of data desired, typically `STRING'. | ||
| 316 | |||
| 317 | TIME-STAMP is the time to use in the XConvertSelection call for foreign | ||
| 318 | selections. If omitted, defaults to the time for the last event. | ||
| 319 | |||
| 320 | TERMINAL should be a terminal object or a frame specifying the X | ||
| 321 | server to query. If omitted or nil, that stands for the selected | ||
| 322 | frame's display, or the first available X display. | ||
| 323 | |||
| 324 | On Nextstep, TIME-STAMP and TERMINAL are unused. | ||
| 325 | |||
| 326 | \(fn SELECTION-SYMBOL TARGET-TYPE &optional TIME-STAMP TERMINAL)" | ||
| 327 | (x-get-selection-value)) | ||
| 328 | 279 | ||
| 329 | ;; From src/fontset.c: | 280 | ;; From src/fontset.c: |
| 330 | (fset 'query-fontset 'ignore) | 281 | (fset 'query-fontset 'ignore) |
| @@ -429,7 +380,7 @@ Errors out because it is not supposed to be called, ever." | |||
| 429 | (setq split-window-keep-point t) | 380 | (setq split-window-keep-point t) |
| 430 | ;; Arrange for the kill and yank functions to set and check the | 381 | ;; Arrange for the kill and yank functions to set and check the |
| 431 | ;; clipboard. | 382 | ;; clipboard. |
| 432 | (setq interprogram-paste-function 'x-get-selection-value) | 383 | (setq interprogram-paste-function #'w16-get-selection-value) |
| 433 | (menu-bar-enable-clipboard) | 384 | (menu-bar-enable-clipboard) |
| 434 | (run-hooks 'terminal-init-msdos-hook)) | 385 | (run-hooks 'terminal-init-msdos-hook)) |
| 435 | 386 | ||
| @@ -446,10 +397,10 @@ Errors out because it is not supposed to be called, ever." | |||
| 446 | 397 | ||
| 447 | (declare-function w16-set-clipboard-data "w16select.c" | 398 | (declare-function w16-set-clipboard-data "w16select.c" |
| 448 | (string &optional ignored)) | 399 | (string &optional ignored)) |
| 449 | (gui-method-define gui-select-text pc | 400 | (gui-method-define gui-select-text pc #'w16--select-text) |
| 450 | (lambda (text) | 401 | (defun w16--select-text (text) |
| 451 | (when gui-select-enable-clipboard | 402 | (when gui-select-enable-clipboard |
| 452 | (w16-set-clipboard-data text)))) | 403 | (w16-set-clipboard-data text))) |
| 453 | 404 | ||
| 454 | ;; --------------------------------------------------------------------------- | 405 | ;; --------------------------------------------------------------------------- |
| 455 | 406 | ||
diff --git a/lisp/term/w32-win.el b/lisp/term/w32-win.el index 3eb8e69c28d..8ef718ad230 100644 --- a/lisp/term/w32-win.el +++ b/lisp/term/w32-win.el | |||
| @@ -205,9 +205,8 @@ European languages which are distributed with Windows as | |||
| 205 | 205 | ||
| 206 | See the documentation of `create-fontset-from-fontset-spec' for the format.") | 206 | See the documentation of `create-fontset-from-fontset-spec' for the format.") |
| 207 | 207 | ||
| 208 | (defun x-win-suspend-error () | 208 | (defun w32-win-suspend-error () |
| 209 | "Report an error when a suspend is attempted. | 209 | "Report an error when a suspend is attempted." |
| 210 | This returns an error if any Emacs frames are X frames, or always under W32." | ||
| 211 | (error "Suspending an Emacs running under W32 makes no sense")) | 210 | (error "Suspending an Emacs running under W32 makes no sense")) |
| 212 | 211 | ||
| 213 | (defvar dynamic-library-alist) | 212 | (defvar dynamic-library-alist) |
| @@ -353,7 +352,7 @@ This returns an error if any Emacs frames are X frames, or always under W32." | |||
| 353 | (cons '(reverse . t) default-frame-alist))))) | 352 | (cons '(reverse . t) default-frame-alist))))) |
| 354 | 353 | ||
| 355 | ;; Don't let Emacs suspend under Windows. | 354 | ;; Don't let Emacs suspend under Windows. |
| 356 | (add-hook 'suspend-hook 'x-win-suspend-error) | 355 | (add-hook 'suspend-hook #'w32-win-suspend-error) |
| 357 | 356 | ||
| 358 | ;; Turn off window-splitting optimization; w32 is usually fast enough | 357 | ;; Turn off window-splitting optimization; w32 is usually fast enough |
| 359 | ;; that this is only annoying. | 358 | ;; that this is only annoying. |
diff --git a/lisp/term/x-win.el b/lisp/term/x-win.el index daaef61e494..a50f886c66a 100644 --- a/lisp/term/x-win.el +++ b/lisp/term/x-win.el | |||
| @@ -1290,16 +1290,9 @@ The value nil is the same as the list (UTF8_STRING COMPOUND_TEXT STRING)." | |||
| 1290 | ;; Arrange for the kill and yank functions to set and check the clipboard. | 1290 | ;; Arrange for the kill and yank functions to set and check the clipboard. |
| 1291 | (setq interprogram-paste-function 'x-selection-value) | 1291 | (setq interprogram-paste-function 'x-selection-value) |
| 1292 | 1292 | ||
| 1293 | ;; Make paste from other applications use the decoding in x-select-request-type | ||
| 1294 | ;; and not just STRING. | ||
| 1295 | (defun x-get-selection-value () | ||
| 1296 | "Get the current value of the PRIMARY selection. | ||
| 1297 | Request data types in the order specified by `x-select-request-type'." | ||
| 1298 | (x-selection-value-internal 'PRIMARY)) | ||
| 1299 | |||
| 1300 | (defun x-clipboard-yank () | 1293 | (defun x-clipboard-yank () |
| 1301 | ;; FIXME: How is that different from `clipboard-yank'? | ||
| 1302 | "Insert the clipboard contents, or the last stretch of killed text." | 1294 | "Insert the clipboard contents, or the last stretch of killed text." |
| 1295 | (declare (obsolete clipboard-yank "25.1")) | ||
| 1303 | (interactive "*") | 1296 | (interactive "*") |
| 1304 | (let ((clipboard-text (x-selection-value-internal 'CLIPBOARD)) | 1297 | (let ((clipboard-text (x-selection-value-internal 'CLIPBOARD)) |
| 1305 | (x-select-enable-clipboard t)) | 1298 | (x-select-enable-clipboard t)) |
| @@ -1325,9 +1318,9 @@ Request data types in the order specified by `x-select-request-type'." | |||
| 1325 | 1318 | ||
| 1326 | (defun x-win-suspend-error () | 1319 | (defun x-win-suspend-error () |
| 1327 | "Report an error when a suspend is attempted. | 1320 | "Report an error when a suspend is attempted. |
| 1328 | This returns an error if any Emacs frames are X frames, or always under W32." | 1321 | This returns an error if any Emacs frames are X frames." |
| 1329 | ;; Don't allow suspending if any of the frames are X frames. | 1322 | ;; Don't allow suspending if any of the frames are X frames. |
| 1330 | (if (memq 'x (mapcar 'window-system (frame-list))) | 1323 | (if (memq 'x (mapcar #'window-system (frame-list))) |
| 1331 | (error "Cannot suspend Emacs while running under X"))) | 1324 | (error "Cannot suspend Emacs while running under X"))) |
| 1332 | 1325 | ||
| 1333 | (defvar x-initialized nil | 1326 | (defvar x-initialized nil |
| @@ -1469,15 +1462,19 @@ This returns an error if any Emacs frames are X frames, or always under W32." | |||
| 1469 | (gui-method-define gui-select-text x | 1462 | (gui-method-define gui-select-text x |
| 1470 | (lambda (text) | 1463 | (lambda (text) |
| 1471 | (when x-select-enable-primary | 1464 | (when x-select-enable-primary |
| 1472 | (x-set-selection 'PRIMARY text) | 1465 | (gui-set-selection 'PRIMARY text) |
| 1473 | (setq x-last-selected-text-primary text)) | 1466 | (setq x-last-selected-text-primary text)) |
| 1474 | (when x-select-enable-clipboard | 1467 | (when x-select-enable-clipboard |
| 1475 | ;; When cutting, the selection is cleared and PRIMARY | 1468 | ;; When cutting, the selection is cleared and PRIMARY |
| 1476 | ;; set to the empty string. Prevent that, PRIMARY | 1469 | ;; set to the empty string. Prevent that, PRIMARY |
| 1477 | ;; should not be reset by cut (Bug#16382). | 1470 | ;; should not be reset by cut (Bug#16382). |
| 1478 | (setq saved-region-selection text) | 1471 | (setq saved-region-selection text) |
| 1479 | (x-set-selection 'CLIPBOARD text) | 1472 | (gui-set-selection 'CLIPBOARD text) |
| 1480 | (setq x-last-selected-text-clipboard text)))) | 1473 | (setq x-last-selected-text-clipboard text)))) |
| 1474 | (gui-method-define gui-own-selection x #'x-own-selection-internal) | ||
| 1475 | (gui-method-define gui-disown-selection x #'x-disown-selection-internal) | ||
| 1476 | (gui-method-define gui-selection-owner-p x #'x-selection-owner-p) | ||
| 1477 | (gui-method-define gui-get-selection x #'x-get-selection-internal) | ||
| 1481 | 1478 | ||
| 1482 | ;; Initiate drag and drop | 1479 | ;; Initiate drag and drop |
| 1483 | (add-hook 'after-make-frame-functions 'x-dnd-init-frame) | 1480 | (add-hook 'after-make-frame-functions 'x-dnd-init-frame) |