annotate lisp/x-select.el @ 416:ebe98a74bd68 r21-2-16

Import from CVS: tag r21-2-16
author cvs
date Mon, 13 Aug 2007 11:22:23 +0200
parents da8ed4261e83
children 11054d720c21
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
1 ;;; x-select.el --- Lisp interface to X Selections.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
2
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
3 ;; Copyright (C) 1990, 1997 Free Software Foundation, Inc.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
4 ;; Copyright (C) 1995 Sun Microsystems.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
5
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
6 ;; Maintainer: XEmacs Development Team
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
7 ;; Keywords: extensions, dumped
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
8
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
10
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
14 ;; any later version.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
15
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
19 ;; General Public License for more details.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
20
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 209
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
24 ;; Boston, MA 02111-1307, USA.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
25
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
26 ;;; Synched up with: FSF 19.30 (select.el).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
27
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
28 ;;; Commentary:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
29
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
30 ;; This file is dumped with XEmacs (when X support is compiled in).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
31
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
32 ;; The selection code requires us to use certain symbols whose names are
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
33 ;; all upper-case; this may seem tasteless, but it makes there be a 1:1
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
34 ;; correspondence between these symbols and X Atoms (which are upcased).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
35
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
36 ;;; Code:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
37
414
da8ed4261e83 Import from CVS: tag r21-2-15
cvs
parents: 412
diff changeset
38 (define-obsolete-function-alias 'x-selection-exists-p 'selection-exists-p)
da8ed4261e83 Import from CVS: tag r21-2-15
cvs
parents: 412
diff changeset
39 (define-obsolete-function-alias 'x-selection-owner-p 'selection-owner-p)
da8ed4261e83 Import from CVS: tag r21-2-15
cvs
parents: 412
diff changeset
40 (define-obsolete-variable-alias 'x-selection-converter-alist 'selection-converter-alist)
da8ed4261e83 Import from CVS: tag r21-2-15
cvs
parents: 412
diff changeset
41 (define-obsolete-variable-alias 'x-lost-selection-hooks 'lost-selection-hooks)
da8ed4261e83 Import from CVS: tag r21-2-15
cvs
parents: 412
diff changeset
42 (define-obsolete-variable-alias 'x-selected-text-type 'selected-text-type)
da8ed4261e83 Import from CVS: tag r21-2-15
cvs
parents: 412
diff changeset
43 (define-obsolete-function-alias 'x-valid-simple-selection-p 'valid-simple-selection-p)
da8ed4261e83 Import from CVS: tag r21-2-15
cvs
parents: 412
diff changeset
44 (define-obsolete-function-alias 'x-own-selection 'own-selection)
da8ed4261e83 Import from CVS: tag r21-2-15
cvs
parents: 412
diff changeset
45 (define-obsolete-function-alias 'x-disown-selection 'disown-selection)
da8ed4261e83 Import from CVS: tag r21-2-15
cvs
parents: 412
diff changeset
46 (define-obsolete-function-alias 'x-delete-primary-selection 'delete-primary-selection)
da8ed4261e83 Import from CVS: tag r21-2-15
cvs
parents: 412
diff changeset
47 (define-obsolete-function-alias 'x-copy-primary-selection 'copy-primary-selection)
da8ed4261e83 Import from CVS: tag r21-2-15
cvs
parents: 412
diff changeset
48 (define-obsolete-function-alias 'x-kill-primary-selection 'kill-primary-selection)
da8ed4261e83 Import from CVS: tag r21-2-15
cvs
parents: 412
diff changeset
49 (define-obsolete-function-alias 'x-select-make-extent-for-selection
da8ed4261e83 Import from CVS: tag r21-2-15
cvs
parents: 412
diff changeset
50 'select-make-extent-for-selection)
da8ed4261e83 Import from CVS: tag r21-2-15
cvs
parents: 412
diff changeset
51 (define-obsolete-function-alias 'x-cut-copy-clear-internal 'cut-copy-clear-internal)
da8ed4261e83 Import from CVS: tag r21-2-15
cvs
parents: 412
diff changeset
52 (define-obsolete-function-alias 'x-get-selection 'get-selection)
416
ebe98a74bd68 Import from CVS: tag r21-2-16
cvs
parents: 414
diff changeset
53 (define-obsolete-function-alias 'x-disown-selection-internal
ebe98a74bd68 Import from CVS: tag r21-2-16
cvs
parents: 414
diff changeset
54 'disown-selection-internal)
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
55
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
56 (defun x-get-secondary-selection ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
57 "Return text selected from some X window."
414
da8ed4261e83 Import from CVS: tag r21-2-15
cvs
parents: 412
diff changeset
58 (get-selection 'SECONDARY))
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
59
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
60 (defun x-get-clipboard ()
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
61 "Return text pasted to the clipboard."
414
da8ed4261e83 Import from CVS: tag r21-2-15
cvs
parents: 412
diff changeset
62 (get-selection 'CLIPBOARD))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
63
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
64 (defun x-own-secondary-selection (selection &optional type)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 209
diff changeset
65 "Make a secondary X Selection of the given argument. The argument may be a
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
66 string or a cons of two markers (in which case the selection is considered to
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
67 be the text between those markers)."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
68 (interactive (if (not current-prefix-arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
69 (list (read-string "Store text for pasting: "))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
70 (list (cons ;; these need not be ordered.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
71 (copy-marker (point-marker))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
72 (copy-marker (mark-marker))))))
416
ebe98a74bd68 Import from CVS: tag r21-2-16
cvs
parents: 414
diff changeset
73 (own-selection selection 'SECONDARY))
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
74
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
75 (defun x-notice-selection-requests (selection type successful)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
76 "for possible use as the value of x-sent-selection-hooks."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
77 (if (not successful)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
78 (message "Selection request failed to convert %s to %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
79 selection type)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
80 (message "Sent selection %s as %s" selection type)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
81
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
82 (defun x-notice-selection-failures (selection type successful)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
83 "for possible use as the value of x-sent-selection-hooks."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
84 (or successful
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
85 (message "Selection request failed to convert %s to %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
86 selection type)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
87
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
88 ;(setq x-sent-selection-hooks 'x-notice-selection-requests)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
89 ;(setq x-sent-selection-hooks 'x-notice-selection-failures)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
90
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
91
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
92 ;;; Selections in killed buffers
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
93 ;;; this function is called by kill-buffer as if it were on the
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
94 ;;; kill-buffer-hook (though it isn't really).
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
95
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
96 (defun xselect-kill-buffer-hook ()
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
97 ;; Probably the right thing is to write a C function to return a list
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
98 ;; of the selections which emacs owns, since it could conceivably own
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
99 ;; a user-defined selection type that we've never heard of.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
100 (xselect-kill-buffer-hook-1 'PRIMARY)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
101 (xselect-kill-buffer-hook-1 'SECONDARY)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
102 (xselect-kill-buffer-hook-1 'CLIPBOARD))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
103
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
104 (defun xselect-kill-buffer-hook-1 (selection)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
105 (let (value)
416
ebe98a74bd68 Import from CVS: tag r21-2-16
cvs
parents: 414
diff changeset
106 (if (and (selection-owner-p selection)
414
da8ed4261e83 Import from CVS: tag r21-2-15
cvs
parents: 412
diff changeset
107 (setq value (get-selection-internal selection '_EMACS_INTERNAL))
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
108 ;; The _EMACS_INTERNAL selection type has a converter registered
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
109 ;; for it that does no translation. This only works if emacs is
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
110 ;; requesting the selection from itself. We could have done this
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
111 ;; by writing a C function to return the raw selection data, and
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
112 ;; that might be the right way to do this, but this was easy.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
113 (or (and (consp value)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
114 (markerp (car value))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
115 (eq (current-buffer) (marker-buffer (car value))))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
116 (and (extent-live-p value)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
117 (eq (current-buffer) (extent-object value)))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
118 (and (extentp value) (not (extent-live-p value)))))
416
ebe98a74bd68 Import from CVS: tag r21-2-16
cvs
parents: 414
diff changeset
119 (disown-selection-internal selection))))
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
120
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
121
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
122 ;;; Cut Buffer support
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
123
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
124 ;;; FSF name x-get-cut-buffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
125 (defun x-get-cutbuffer (&optional which-one)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 209
diff changeset
126 "Return the value of one of the 8 X server cut buffers.
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 209
diff changeset
127 Optional arg WHICH-ONE should be a number from 0 to 7, defaulting to 0.
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 209
diff changeset
128 Cut buffers are considered obsolete; you should use selections instead.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
129 This function does nothing if support for cut buffers was not compiled
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
130 into Emacs."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
131 (and (fboundp 'x-get-cutbuffer-internal)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
132 (x-get-cutbuffer-internal
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
133 (if which-one
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
134 (aref [CUT_BUFFER0 CUT_BUFFER1 CUT_BUFFER2 CUT_BUFFER3
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
135 CUT_BUFFER4 CUT_BUFFER5 CUT_BUFFER6 CUT_BUFFER7]
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
136 which-one)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
137 'CUT_BUFFER0))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
138
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
139 ;;; FSF name x-set-cut-buffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
140 (defun x-store-cutbuffer (string &optional push)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
141 "Store STRING into the X server's primary cut buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
142 If PUSH is non-nil, also rotate the cut buffers:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
143 this means the previous value of the primary cut buffer moves the second
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
144 cut buffer, and the second to the third, and so on (there are 8 buffers.)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
145 Cut buffers are considered obsolete; you should use selections instead.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
146 This function does nothing if support for cut buffers was not compiled
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
147 into Emacs."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
148 (and (fboundp 'x-store-cutbuffer-internal)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
149 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
150 ;; Check the data type of STRING.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
151 (substring string 0 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
152 (if push
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
153 (x-rotate-cutbuffers-internal 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
154 (x-store-cutbuffer-internal 'CUT_BUFFER0 string))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
155
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
156
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
157 ;;; Random utility functions
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
158
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
159 (defun x-yank-clipboard-selection ()
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
160 "Insert the current Clipboard selection at point."
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
161 (interactive "*")
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
162 (setq last-command nil)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
163 (setq this-command 'yank) ; so that yank-pop works.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
164 (let ((clip (x-get-clipboard)))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
165 (or clip (error "there is no clipboard selection"))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
166 (push-mark)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
167 (insert clip)))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
168
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 410
diff changeset
169
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
170 ;FSFmacs (provide 'select)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
171
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
172 ;;; x-select.el ends here.