annotate lisp/x-select.el @ 428:3ecd8885ac67 r21-2-22

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