annotate lisp/x-select.el @ 318:afd57c14dfc8 r21-0b57

Import from CVS: tag r21-0b57
author cvs
date Mon, 13 Aug 2007 10:45:36 +0200
parents 57709be46d1b
children 74fd4e045ea6
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
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
38 (defvar x-selected-text-type
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
39 (if (featurep 'mule) '(COMPOUND_TEXT STRING) 'STRING)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
40 "The type atom used to obtain selections from the X server.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
41 Can be either a valid X selection data type, or a list of such types.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
42 COMPOUND_TEXT and STRING are the most commonly used data types.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
43 If a list is provided, the types are tried in sequence until
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
44 there is a successful conversion.")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
45
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
46 (defun x-get-selection (&optional type data-type)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
47 "Return the value of an X Windows selection.
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 209
diff changeset
48 The argument TYPE (default `PRIMARY') says which selection,
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
49 and the argument DATA-TYPE (default `STRING', or `COMPOUND_TEXT' under Mule)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
50 says how to convert the data."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
51 (or type (setq type 'PRIMARY))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
52 (or data-type (setq data-type x-selected-text-type))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
53 (let ((text
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
54 (if (consp data-type)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
55 (condition-case err
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
56 (x-get-selection-internal type (car data-type))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
57 (selection-conversion-error
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
58 (if (cdr data-type)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
59 (x-get-selection type (cdr data-type))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
60 (signal (car err) (cdr err)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
61 (x-get-selection-internal type data-type))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
62 (when (and (consp text) (symbolp (car text)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
63 (setq text (cdr text)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
64 (when (not (stringp text))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
65 (error "Selection is not a string: %S" text))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
66 text))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
67
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
68 (defun x-get-secondary-selection ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
69 "Return text selected from some X window."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
70 (x-get-selection 'SECONDARY))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
71
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
72 (defun x-get-clipboard ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
73 "Return text pasted to the clipboard."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
74 (x-get-selection 'CLIPBOARD))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
75
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
76 ;; FSFmacs calls this `x-set-selection', and reverses the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
77 ;; arguments (duh ...). This order is more logical.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
78 (defun x-own-selection (data &optional type)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
79 "Make an X Windows selection of type TYPE and value DATA.
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 209
diff changeset
80 The argument TYPE (default `PRIMARY') says which selection,
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
81 and DATA specifies the contents. DATA may be a string,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
82 a symbol, an integer (or a cons of two integers or list of two integers).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
83
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
84 The selection may also be a cons of two markers pointing to the same buffer,
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 209
diff changeset
85 or an overlay. In these cases, the selection is considered to be the text
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
86 between the markers *at whatever time the selection is examined*.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
87 Thus, editing done in the buffer after you specify the selection
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
88 can alter the effective value of the selection.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
89
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
90 The data may also be a vector of valid non-vector selection values.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
91
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
92 Interactively, the text of the region is used as the selection value."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
93 (interactive (if (not current-prefix-arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
94 (list (read-string "Store text for pasting: "))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
95 (list (substring (region-beginning) (region-end)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
96 ;FSFmacs huh?? It says:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
97 ;; "This is for temporary compatibility with pre-release Emacs 19."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
98 ;(if (stringp type)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
99 ; (setq type (intern type)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
100 (or (x-valid-simple-selection-p data)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
101 (and (vectorp data)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
102 (let ((valid t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
103 (i (1- (length data))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
104 (while (>= i 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
105 (or (x-valid-simple-selection-p (aref data i))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
106 (setq valid nil))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
107 (setq i (1- i)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
108 valid))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
109 (signal 'error (list "invalid selection" data)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
110 (or type (setq type 'PRIMARY))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
111 (if data
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
112 (x-own-selection-internal type data)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
113 (x-disown-selection-internal type))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
114 (cond ((eq type 'PRIMARY)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
115 (setq primary-selection-extent
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
116 (select-make-extent-for-selection
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
117 data primary-selection-extent)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
118 ((eq type 'SECONDARY)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
119 (setq secondary-selection-extent
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
120 (select-make-extent-for-selection
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
121 data secondary-selection-extent))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
122 (setq zmacs-region-stays t)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
123 data)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
124
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
125 (defun x-valid-simple-selection-p (data)
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents: 272
diff changeset
126 (valid-simple-selection-p data))
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
127
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
128 (defun x-own-secondary-selection (selection &optional type)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 209
diff changeset
129 "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
130 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
131 be the text between those markers)."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
132 (interactive (if (not current-prefix-arg)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
133 (list (read-string "Store text for pasting: "))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
134 (list (cons ;; these need not be ordered.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
135 (copy-marker (point-marker))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
136 (copy-marker (mark-marker))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
137 (x-own-selection selection 'SECONDARY))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
138
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
139
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
140 (defun x-own-clipboard (string)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
141 "Paste the given string to the X Clipboard."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
142 (x-own-selection string 'CLIPBOARD))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
143
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
144
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
145 (defun x-disown-selection (&optional secondary-p)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
146 "Assuming we own the selection, disown it. With an argument, discard the
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
147 secondary selection instead of the primary selection."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
148 (x-disown-selection-internal (if secondary-p 'SECONDARY 'PRIMARY)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
149
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
150 (defun x-dehilight-selection (selection)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
151 "for use as a value of `x-lost-selection-hooks'."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
152 (cond ((eq selection 'PRIMARY)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
153 (if primary-selection-extent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
154 (let ((inhibit-quit t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
155 (if (consp primary-selection-extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
156 (mapcar 'delete-extent primary-selection-extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
157 (delete-extent primary-selection-extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
158 (setq primary-selection-extent nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
159 (if zmacs-regions (zmacs-deactivate-region)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
160 ((eq selection 'SECONDARY)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
161 (if secondary-selection-extent
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
162 (let ((inhibit-quit t))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
163 (if (consp secondary-selection-extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
164 (mapcar 'delete-extent secondary-selection-extent)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
165 (delete-extent secondary-selection-extent))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
166 (setq secondary-selection-extent nil)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
167 nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
168
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
169 (setq x-lost-selection-hooks 'x-dehilight-selection)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
170
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
171 (defun x-notice-selection-requests (selection type successful)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
172 "for possible use as the value of x-sent-selection-hooks."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
173 (if (not successful)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
174 (message "Selection request failed to convert %s to %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
175 selection type)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
176 (message "Sent selection %s as %s" selection type)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
177
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
178 (defun x-notice-selection-failures (selection type successful)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
179 "for possible use as the value of x-sent-selection-hooks."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
180 (or successful
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
181 (message "Selection request failed to convert %s to %s"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
182 selection type)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
183
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
184 ;(setq x-sent-selection-hooks 'x-notice-selection-requests)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
185 ;(setq x-sent-selection-hooks 'x-notice-selection-failures)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
186
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
187
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
188 ;;; Selections in killed buffers
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 209
diff changeset
189 ;;; this function is called by kill-buffer as if it were on the
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
190 ;;; kill-buffer-hook (though it isn't really).
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
191
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
192 (defun xselect-kill-buffer-hook ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
193 ;; Probably the right thing is to write a C function to return a list
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
194 ;; of the selections which emacs owns, since it could conceivably own
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
195 ;; a user-defined selection type that we've never heard of.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
196 (xselect-kill-buffer-hook-1 'PRIMARY)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
197 (xselect-kill-buffer-hook-1 'SECONDARY)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
198 (xselect-kill-buffer-hook-1 'CLIPBOARD))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
199
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
200 (defun xselect-kill-buffer-hook-1 (selection)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
201 (let (value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
202 (if (and (x-selection-owner-p selection)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
203 (setq value (x-get-selection-internal selection '_EMACS_INTERNAL))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
204 ;; The _EMACS_INTERNAL selection type has a converter registered
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
205 ;; for it that does no translation. This only works if emacs is
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
206 ;; requesting the selection from itself. We could have done this
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
207 ;; by writing a C function to return the raw selection data, and
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
208 ;; that might be the right way to do this, but this was easy.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
209 (or (and (consp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
210 (markerp (car value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
211 (eq (current-buffer) (marker-buffer (car value))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
212 (and (extent-live-p value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
213 (eq (current-buffer) (extent-object value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
214 (and (extentp value) (not (extent-live-p value)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
215 (x-disown-selection-internal selection))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
216
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
217
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
218 ;;; Cut Buffer support
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
219
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
220 ;;; FSF name x-get-cut-buffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
221 (defun x-get-cutbuffer (&optional which-one)
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 209
diff changeset
222 "Return the value of one of the 8 X server cut buffers.
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 209
diff changeset
223 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
224 Cut buffers are considered obsolete; you should use selections instead.
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
225 This function does nothing if support for cut buffers was not compiled
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
226 into Emacs."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
227 (and (fboundp 'x-get-cutbuffer-internal)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
228 (x-get-cutbuffer-internal
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
229 (if which-one
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
230 (aref [CUT_BUFFER0 CUT_BUFFER1 CUT_BUFFER2 CUT_BUFFER3
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
231 CUT_BUFFER4 CUT_BUFFER5 CUT_BUFFER6 CUT_BUFFER7]
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
232 which-one)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
233 'CUT_BUFFER0))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
234
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
235 ;;; FSF name x-set-cut-buffer
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
236 (defun x-store-cutbuffer (string &optional push)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
237 "Store STRING into the X server's primary cut buffer.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
238 If PUSH is non-nil, also rotate the cut buffers:
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
239 this means the previous value of the primary cut buffer moves the second
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
240 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
241 Cut buffers are considered obsolete; you should use selections instead.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
242 This function does nothing if support for cut buffers was not compiled
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
243 into Emacs."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
244 (and (fboundp 'x-store-cutbuffer-internal)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
245 (progn
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
246 ;; Check the data type of STRING.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
247 (substring string 0 0)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
248 (if push
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
249 (x-rotate-cutbuffers-internal 1))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
250 (x-store-cutbuffer-internal 'CUT_BUFFER0 string))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
251
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
252
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
253 ;;; Random utility functions
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
254
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
255 (defun x-yank-clipboard-selection ()
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
256 "Insert the current Clipboard selection at point."
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
257 (interactive "*")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
258 (setq last-command nil)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
259 (setq this-command 'yank) ; so that yank-pop works.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
260 (let ((clip (x-get-clipboard)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
261 (or clip (error "there is no clipboard selection"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
262 (push-mark)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
263 (insert clip)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
264
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
265 ;;; Functions to convert the selection into various other selection types.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
266 ;;; Every selection type that emacs handles is implemented this way, except
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
267 ;;; for TIMESTAMP, which is a special case.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
268
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
269 (defun xselect-convert-to-text (selection type value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
270 (cond ((stringp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
271 value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
272 ((extentp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
273 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
274 (set-buffer (extent-object value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
275 (save-restriction
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
276 (widen)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
277 (buffer-substring (extent-start-position value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
278 (extent-end-position value)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
279 ((and (consp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
280 (markerp (car value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
281 (markerp (cdr value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
282 (or (eq (marker-buffer (car value)) (marker-buffer (cdr value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
283 (signal 'error
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
284 (list "markers must be in the same buffer"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
285 (car value) (cdr value))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
286 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
287 (set-buffer (or (marker-buffer (car value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
288 (error "selection is in a killed buffer")))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
289 (save-restriction
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
290 (widen)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
291 (buffer-substring (car value) (cdr value)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
292 (t nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
293
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
294 (defun xselect-convert-to-string (selection type value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
295 (let ((outval (xselect-convert-to-text selection type value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
296 ;; force the string to be not in Compound Text format.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
297 (if (stringp outval)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
298 (cons 'STRING outval)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
299 outval)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
300
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
301 (defun xselect-convert-to-compound-text (selection type value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
302 ;; converts to compound text automatically
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
303 (xselect-convert-to-text selection type value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
304
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
305 (defun xselect-convert-to-length (selection type value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
306 (let ((value
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
307 (cond ((stringp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
308 (length value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
309 ((extentp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
310 (extent-length value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
311 ((and (consp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
312 (markerp (car value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
313 (markerp (cdr value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
314 (or (eq (marker-buffer (car value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
315 (marker-buffer (cdr value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
316 (signal 'error
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
317 (list "markers must be in the same buffer"
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
318 (car value) (cdr value))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
319 (abs (- (car value) (cdr value)))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
320 (if value ; force it to be in 32-bit format.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
321 (cons (ash value -16) (logand value 65535))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
322 nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
323
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
324 (defun xselect-convert-to-targets (selection type value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
325 ;; return a vector of atoms, but remove duplicates first.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
326 (let* ((all (cons 'TIMESTAMP (mapcar 'car selection-converter-alist)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
327 (rest all))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
328 (while rest
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
329 (cond ((memq (car rest) (cdr rest))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
330 (setcdr rest (delq (car rest) (cdr rest))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
331 ((eq (car (cdr rest)) '_EMACS_INTERNAL) ; shh, it's a secret
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
332 (setcdr rest (cdr (cdr rest))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
333 (t
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
334 (setq rest (cdr rest)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
335 (apply 'vector all)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
336
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
337 (defun xselect-convert-to-delete (selection type value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
338 (x-disown-selection-internal selection)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
339 ;; A return value of nil means that we do not know how to do this conversion,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
340 ;; and replies with an "error". A return value of NULL means that we have
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
341 ;; done the conversion (and any side-effects) but have no value to return.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
342 'NULL)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
343
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
344 (defun xselect-convert-to-filename (selection type value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
345 (cond ((extentp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
346 (buffer-file-name (or (extent-object value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
347 (error "selection is in a killed buffer"))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
348 ((and (consp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
349 (markerp (car value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
350 (markerp (cdr value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
351 (buffer-file-name (or (marker-buffer (car value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
352 (error "selection is in a killed buffer"))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
353 (t nil)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
354
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
355 (defun xselect-convert-to-charpos (selection type value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
356 (let (a b tmp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
357 (cond ((cond ((extentp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
358 (setq a (extent-start-position value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
359 b (extent-end-position value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
360 ((and (consp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
361 (markerp (car value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
362 (markerp (cdr value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
363 (setq a (car value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
364 b (cdr value))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
365 (setq a (1- a) b (1- b)) ; zero-based
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
366 (if (< b a) (setq tmp a a b b tmp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
367 (cons 'SPAN
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
368 (vector (cons (ash a -16) (logand a 65535))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
369 (cons (ash b -16) (logand b 65535))))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
370
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
371 (defun xselect-convert-to-lineno (selection type value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
372 (let (a b buf tmp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
373 (cond ((cond ((extentp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
374 (setq buf (extent-object value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
375 a (extent-start-position value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
376 b (extent-end-position value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
377 ((and (consp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
378 (markerp (car value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
379 (markerp (cdr value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
380 (setq a (marker-position (car value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
381 b (marker-position (cdr value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
382 buf (marker-buffer (car value)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
383 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
384 (set-buffer buf)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
385 (save-restriction
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
386 (widen)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
387 (goto-char a)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
388 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
389 (setq a (1+ (count-lines 1 (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
390 (goto-char b)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
391 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
392 (setq b (1+ (count-lines 1 (point))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
393 (if (< b a) (setq tmp a a b b tmp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
394 (cons 'SPAN
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
395 (vector (cons (ash a -16) (logand a 65535))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
396 (cons (ash b -16) (logand b 65535))))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
397
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
398 (defun xselect-convert-to-colno (selection type value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
399 (let (a b buf tmp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
400 (cond ((cond ((extentp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
401 (setq buf (extent-object value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
402 a (extent-start-position value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
403 b (extent-end-position value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
404 ((and (consp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
405 (markerp (car value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
406 (markerp (cdr value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
407 (setq a (car value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
408 b (cdr value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
409 buf (marker-buffer a))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
410 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
411 (set-buffer buf)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
412 (goto-char a)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
413 (setq a (current-column))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
414 (goto-char b)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
415 (setq b (current-column)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
416 (if (< b a) (setq tmp a a b b tmp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
417 (cons 'SPAN
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
418 (vector (cons (ash a -16) (logand a 65535))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
419 (cons (ash b -16) (logand b 65535))))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
420
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
421 (defun xselect-convert-to-sourceloc (selection type value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
422 (let (a b buf file-name tmp)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
423 (cond ((cond ((extentp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
424 (setq buf (or (extent-object value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
425 (error "selection is in a killed buffer"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
426 a (extent-start-position value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
427 b (extent-end-position value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
428 file-name (buffer-file-name buf)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
429 ((and (consp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
430 (markerp (car value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
431 (markerp (cdr value)))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
432 (setq a (marker-position (car value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
433 b (marker-position (cdr value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
434 buf (or (marker-buffer (car value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
435 (error "selection is in a killed buffer"))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
436 file-name (buffer-file-name buf))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
437 (save-excursion
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
438 (set-buffer buf)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
439 (save-restriction
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
440 (widen)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
441 (goto-char a)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
442 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
443 (setq a (1+ (count-lines 1 (point))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
444 (goto-char b)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
445 (beginning-of-line)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
446 (setq b (1+ (count-lines 1 (point))))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
447 (if (< b a) (setq tmp a a b b tmp))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
448 (format "%s:%d" file-name a)))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
449
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
450 (defun xselect-convert-to-os (selection type size)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
451 (symbol-name system-type))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
452
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
453 (defun xselect-convert-to-host (selection type size)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
454 (system-name))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
455
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
456 (defun xselect-convert-to-user (selection type size)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
457 (user-full-name))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
458
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
459 (defun xselect-convert-to-class (selection type size)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
460 x-emacs-application-class)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
461
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
462 ;; We do not try to determine the name Emacs was invoked with,
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
463 ;; because it is not clean for a program's behavior to depend on that.
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
464 (defun xselect-convert-to-name (selection type size)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
465 ;invocation-name
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
466 "xemacs")
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
467
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
468 (defun xselect-convert-to-integer (selection type value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
469 (and (integerp value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
470 (cons (ash value -16) (logand value 65535))))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
471
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
472 (defun xselect-convert-to-atom (selection type value)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
473 (and (symbolp value) value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
474
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
475 (defun xselect-convert-to-identity (selection type value) ; used internally
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
476 (vector value))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
477
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
478 (setq selection-converter-alist
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
479 '((TEXT . xselect-convert-to-text)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
480 (STRING . xselect-convert-to-string)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
481 (COMPOUND_TEXT . xselect-convert-to-compound-text)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
482 (TARGETS . xselect-convert-to-targets)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
483 (LENGTH . xselect-convert-to-length)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
484 (DELETE . xselect-convert-to-delete)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
485 (FILE_NAME . xselect-convert-to-filename)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
486 (CHARACTER_POSITION . xselect-convert-to-charpos)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
487 (SOURCE_LOC . xselect-convert-to-sourceloc)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
488 (LINE_NUMBER . xselect-convert-to-lineno)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
489 (COLUMN_NUMBER . xselect-convert-to-colno)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
490 (OWNER_OS . xselect-convert-to-os)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
491 (HOST_NAME . xselect-convert-to-host)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
492 (USER . xselect-convert-to-user)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
493 (CLASS . xselect-convert-to-class)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
494 (NAME . xselect-convert-to-name)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
495 (ATOM . xselect-convert-to-atom)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
496 (INTEGER . xselect-convert-to-integer)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
497 (_EMACS_INTERNAL . xselect-convert-to-identity)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
498 ))
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
499
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
500 ;FSFmacs (provide 'select)
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
501
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents:
diff changeset
502 ;;; x-select.el ends here.