Initial git import
[sxemacs] / lisp / x-select.el
1 ;;; x-select.el --- Lisp interface to X Selections.
2
3 ;; Copyright (C) 1990, 1997 Free Software Foundation, Inc.
4 ;; Copyright (C) 1995 Sun Microsystems.
5
6 ;; Maintainer: SXEmacs Development Team
7 ;; Keywords: extensions, dumped
8
9 ;; This file is part of SXEmacs.
10
11 ;; SXEmacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
15
16 ;; SXEmacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Synched up with: FSF 19.30 (select.el).
25
26 ;;; Commentary:
27
28 ;; This file is dumped with SXEmacs (when X support is compiled in).
29
30 ;; The selection code requires us to use certain symbols whose names are
31 ;; all upper-case; this may seem tasteless, but it makes there be a 1:1
32 ;; correspondence between these symbols and X Atoms (which are upcased).
33
34 ;;; Code:
35
36 (define-obsolete-function-alias 'x-selection-exists-p 'selection-exists-p)
37 (define-obsolete-function-alias 'x-selection-owner-p 'selection-owner-p)
38 (define-obsolete-variable-alias 'x-selection-converter-alist 'selection-converter-alist)
39 (define-obsolete-variable-alias 'x-lost-selection-hooks 'lost-selection-hooks)
40 (define-obsolete-variable-alias 'x-selected-text-type 'selected-text-type)
41 (define-obsolete-function-alias 'x-valid-simple-selection-p 'valid-simple-selection-p)
42 (define-obsolete-function-alias 'x-own-selection 'own-selection)
43 (define-obsolete-function-alias 'x-disown-selection 'disown-selection)
44 (define-obsolete-function-alias 'x-delete-primary-selection 'delete-primary-selection)
45 (define-obsolete-function-alias 'x-copy-primary-selection 'copy-primary-selection)
46 (define-obsolete-function-alias 'x-kill-primary-selection 'kill-primary-selection)
47 (define-obsolete-function-alias 'x-select-make-extent-for-selection
48   'select-make-extent-for-selection)
49 (define-obsolete-function-alias 'x-cut-copy-clear-internal 'cut-copy-clear-internal)
50 (define-obsolete-function-alias 'x-get-selection 'get-selection)
51 (define-obsolete-function-alias 'x-get-clipboard 'get-clipboard)
52 (define-obsolete-function-alias 'x-yank-clipboard-selection
53   'yank-clipboard-selection)
54 (define-obsolete-function-alias 'x-disown-selection-internal
55   'disown-selection-internal)
56
57 (defun x-get-secondary-selection ()
58   "Return text selected from some X window."
59   (get-selection 'SECONDARY))
60
61 (defun x-own-secondary-selection (selection &optional type)
62   "Make a secondary X Selection of the given argument.  The argument may be a
63 string or a cons of two markers (in which case the selection is considered to
64 be the text between those markers)."
65   (interactive (if (not current-prefix-arg)
66                    (list (read-string "Store text for pasting: "))
67                  (list (cons ;; these need not be ordered.
68                         (copy-marker (point-marker))
69                         (copy-marker (mark-marker))))))
70   (own-selection selection 'SECONDARY))
71
72 (defun x-notice-selection-requests (selection type successful)
73   "for possible use as the value of `x-sent-selection-hooks'."
74   (if (not successful)
75       (message "Selection request failed to convert %s to %s"
76                selection type)
77     (message "Sent selection %s as %s" selection type)))
78
79 (defun x-notice-selection-failures (selection type successful)
80   "for possible use as the value of `x-sent-selection-hooks'."
81   (or successful
82       (message "Selection request failed to convert %s to %s"
83                selection type)))
84
85 ;(setq x-sent-selection-hooks 'x-notice-selection-requests)
86 ;(setq x-sent-selection-hooks 'x-notice-selection-failures)
87
88 \f
89 ;;; Cut Buffer support
90
91 ;;; FSF name x-get-cut-buffer
92 (defun x-get-cutbuffer (&optional which-one)
93   "Return the value of one of the 8 X server cut buffers.
94 Optional arg WHICH-ONE should be a number from 0 to 7, defaulting to 0.
95 Cut buffers are considered obsolete; you should use selections instead.
96 This function does nothing if cut buffer support was not compiled in."
97   (when (fboundp 'x-get-cutbuffer-internal)
98     (x-get-cutbuffer-internal
99      (aref [CUT_BUFFER0 CUT_BUFFER1 CUT_BUFFER2 CUT_BUFFER3
100                         CUT_BUFFER4 CUT_BUFFER5 CUT_BUFFER6 CUT_BUFFER7]
101            (or which-one 0)))))
102
103 ;;; FSF name x-set-cut-buffer
104 (defun x-store-cutbuffer (string &optional push)
105   "Store STRING into the X server's primary cut buffer.
106 If optional arg PUSH is non-nil, also rotate the cut buffers: this
107 means the previous value of the primary cut buffer moves to the second
108 cut buffer, and the second to the third, and so on (there are 8 buffers.)
109 Cut buffers are considered obsolete; you should use selections instead.
110 This function does nothing if cut buffer support was not compiled in."
111   (when (fboundp 'x-store-cutbuffer-internal)
112     (when push
113       (x-rotate-cutbuffers-internal 1))
114     (x-store-cutbuffer-internal 'CUT_BUFFER0 string)))
115
116 \f
117 ;FSFmacs (provide 'select)
118
119 ;;; x-select.el ends here.