209
|
1 ;;; x-select.el --- Lisp interface to X Selections.
|
|
2
|
|
3 ;; Copyright (C) 1990, 1997 Free Software Foundation, Inc.
|
|
4 ;; Copyright (C) 1995 Sun Microsystems.
|
|
5
|
|
6 ;; Maintainer: XEmacs Development Team
|
|
7 ;; Keywords: extensions, dumped
|
|
8
|
|
9 ;; This file is part of XEmacs.
|
|
10
|
|
11 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
12 ;; under the terms of the GNU General Public License as published by
|
|
13 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
14 ;; any later version.
|
|
15
|
|
16 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
19 ;; General Public License for more details.
|
|
20
|
|
21 ;; You should have received a copy of the GNU General Public License
|
|
22 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
24 ;; Boston, MA 02111-1307, USA.
|
|
25
|
|
26 ;;; Synched up with: FSF 19.30 (select.el).
|
|
27
|
|
28 ;;; Commentary:
|
|
29
|
|
30 ;; This file is dumped with XEmacs (when X support is compiled in).
|
|
31
|
|
32 ;; The selection code requires us to use certain symbols whose names are
|
|
33 ;; all upper-case; this may seem tasteless, but it makes there be a 1:1
|
|
34 ;; correspondence between these symbols and X Atoms (which are upcased).
|
|
35
|
|
36 ;;; Code:
|
|
37
|
|
38 (defvar x-selected-text-type
|
|
39 (if (featurep 'mule) '(COMPOUND_TEXT STRING) 'STRING)
|
|
40 "The type atom used to obtain selections from the X server.
|
|
41 Can be either a valid X selection data type, or a list of such types.
|
|
42 COMPOUND_TEXT and STRING are the most commonly used data types.
|
|
43 If a list is provided, the types are tried in sequence until
|
|
44 there is a successful conversion.")
|
|
45
|
|
46 (defun x-get-selection (&optional type data-type)
|
|
47 "Return the value of an X Windows selection.
|
|
48 The argument TYPE (default `PRIMARY') says which selection,
|
|
49 and the argument DATA-TYPE (default `STRING', or `COMPOUND_TEXT' under Mule)
|
|
50 says how to convert the data."
|
|
51 (or type (setq type 'PRIMARY))
|
|
52 (or data-type (setq data-type x-selected-text-type))
|
|
53 (let ((text
|
|
54 (if (consp data-type)
|
|
55 (condition-case err
|
|
56 (x-get-selection-internal type (car data-type))
|
|
57 (selection-conversion-error
|
|
58 (if (cdr data-type)
|
|
59 (x-get-selection type (cdr data-type))
|
|
60 (signal (car err) (cdr err)))))
|
|
61 (x-get-selection-internal type data-type))))
|
|
62 (when (and (consp text) (symbolp (car text)))
|
|
63 (setq text (cdr text)))
|
|
64 (when (not (stringp text))
|
|
65 (error "Selection is not a string: %S" text))
|
|
66 text))
|
|
67
|
|
68 (defun x-get-secondary-selection ()
|
|
69 "Return text selected from some X window."
|
|
70 (x-get-selection 'SECONDARY))
|
|
71
|
|
72 (defun x-get-clipboard ()
|
|
73 "Return text pasted to the clipboard."
|
|
74 (x-get-selection 'CLIPBOARD))
|
|
75
|
|
76
|
|
77 (defvar primary-selection-extent nil
|
|
78 "The extent of the primary selection; don't use this.")
|
|
79
|
|
80 (defvar secondary-selection-extent nil
|
|
81 "The extent of the secondary selection; don't use this.")
|
|
82
|
|
83
|
|
84 (defun x-select-make-extent-for-selection (selection previous-extent)
|
|
85 ;; Given a selection, this makes an extent in the buffer which holds that
|
|
86 ;; selection, for highlighting purposes. If the selection isn't associated
|
|
87 ;; with a buffer, this does nothing.
|
|
88 (let ((buffer nil)
|
|
89 (valid (and (extentp previous-extent)
|
|
90 (extent-object previous-extent)
|
|
91 (buffer-live-p (extent-object previous-extent))))
|
|
92 start end)
|
|
93 (cond ((stringp selection)
|
|
94 ;; if we're selecting a string, lose the previous extent used
|
|
95 ;; to highlight the selection.
|
|
96 (setq valid nil))
|
|
97 ((consp selection)
|
|
98 (setq start (min (car selection) (cdr selection))
|
|
99 end (max (car selection) (cdr selection))
|
|
100 valid (and valid
|
|
101 (eq (marker-buffer (car selection))
|
|
102 (extent-object previous-extent)))
|
|
103 buffer (marker-buffer (car selection))))
|
|
104 ((extentp selection)
|
|
105 (setq start (extent-start-position selection)
|
|
106 end (extent-end-position selection)
|
|
107 valid (and valid
|
|
108 (eq (extent-object selection)
|
|
109 (extent-object previous-extent)))
|
|
110 buffer (extent-object selection)))
|
|
111 (t
|
|
112 (signal 'error (list "invalid selection" selection))))
|
|
113
|
|
114 (if valid
|
|
115 nil
|
|
116 (condition-case ()
|
|
117 (if (listp previous-extent)
|
|
118 (mapcar 'delete-extent previous-extent)
|
|
119 (delete-extent previous-extent))
|
|
120 (error nil)))
|
|
121
|
|
122 (if (not buffer)
|
|
123 ;; string case
|
|
124 nil
|
|
125 ;; normal case
|
|
126 (if valid
|
|
127 (set-extent-endpoints previous-extent start end)
|
|
128 (setq previous-extent (make-extent start end buffer))
|
|
129
|
|
130 ;; Make the extent be closed on the right, which means that if
|
|
131 ;; characters are inserted exactly at the end of the extent, the
|
|
132 ;; extent will grow to cover them. This is important for shell
|
|
133 ;; buffers - suppose one makes a selection, and one end is at
|
|
134 ;; point-max. If the shell produces output, that marker will remain
|
|
135 ;; at point-max (its position will increase). So it's important that
|
|
136 ;; the extent exhibit the same behavior, lest the region covered by
|
|
137 ;; the extent (the visual indication), and the region between point
|
|
138 ;; and mark (the actual selection value) become different!
|
|
139 (set-extent-property previous-extent 'end-open nil)
|
|
140
|
|
141 (cond
|
|
142 (mouse-track-rectangle-p
|
|
143 (setq previous-extent (list previous-extent))
|
|
144 (default-mouse-track-next-move-rect start end previous-extent)
|
|
145 ))
|
|
146 previous-extent))))
|
|
147
|
|
148 ;; FSFmacs calls this `x-set-selection', and reverses the
|
|
149 ;; arguments (duh ...). This order is more logical.
|
|
150 (defun x-own-selection (data &optional type)
|
|
151 "Make an X Windows selection of type TYPE and value DATA.
|
|
152 The argument TYPE (default `PRIMARY') says which selection,
|
|
153 and DATA specifies the contents. DATA may be a string,
|
|
154 a symbol, an integer (or a cons of two integers or list of two integers).
|
|
155
|
|
156 The selection may also be a cons of two markers pointing to the same buffer,
|
|
157 or an overlay. In these cases, the selection is considered to be the text
|
|
158 between the markers *at whatever time the selection is examined*.
|
|
159 Thus, editing done in the buffer after you specify the selection
|
|
160 can alter the effective value of the selection.
|
|
161
|
|
162 The data may also be a vector of valid non-vector selection values.
|
|
163
|
|
164 Interactively, the text of the region is used as the selection value."
|
|
165 (interactive (if (not current-prefix-arg)
|
|
166 (list (read-string "Store text for pasting: "))
|
|
167 (list (substring (region-beginning) (region-end)))))
|
|
168 ;FSFmacs huh?? It says:
|
|
169 ;; "This is for temporary compatibility with pre-release Emacs 19."
|
|
170 ;(if (stringp type)
|
|
171 ; (setq type (intern type)))
|
|
172 (or (x-valid-simple-selection-p data)
|
|
173 (and (vectorp data)
|
|
174 (let ((valid t)
|
|
175 (i (1- (length data))))
|
|
176 (while (>= i 0)
|
|
177 (or (x-valid-simple-selection-p (aref data i))
|
|
178 (setq valid nil))
|
|
179 (setq i (1- i)))
|
|
180 valid))
|
|
181 (signal 'error (list "invalid selection" data)))
|
|
182 (or type (setq type 'PRIMARY))
|
|
183 (if data
|
|
184 (x-own-selection-internal type data)
|
|
185 (x-disown-selection-internal type))
|
|
186 (cond ((eq type 'PRIMARY)
|
|
187 (setq primary-selection-extent
|
|
188 (x-select-make-extent-for-selection
|
|
189 data primary-selection-extent)))
|
|
190 ((eq type 'SECONDARY)
|
|
191 (setq secondary-selection-extent
|
|
192 (x-select-make-extent-for-selection
|
|
193 data secondary-selection-extent))))
|
|
194 (setq zmacs-region-stays t)
|
|
195 data)
|
|
196
|
|
197 (defun x-valid-simple-selection-p (data)
|
|
198 (or (stringp data)
|
|
199 ;FSFmacs huh?? (symbolp data)
|
|
200 (integerp data)
|
|
201 (and (consp data)
|
|
202 (integerp (car data))
|
|
203 (or (integerp (cdr data))
|
|
204 (and (consp (cdr data))
|
|
205 (integerp (car (cdr data))))))
|
|
206 (extentp data)
|
|
207 (and (consp data)
|
|
208 (markerp (car data))
|
|
209 (markerp (cdr data))
|
|
210 (marker-buffer (car data))
|
|
211 (marker-buffer (cdr data))
|
|
212 (eq (marker-buffer (car data))
|
|
213 (marker-buffer (cdr data)))
|
|
214 (buffer-live-p (marker-buffer (car data)))
|
|
215 (buffer-live-p (marker-buffer (cdr data))))))
|
|
216
|
|
217 (defun x-own-secondary-selection (selection &optional type)
|
|
218 "Make a secondary X Selection of the given argument. The argument may be a
|
|
219 string or a cons of two markers (in which case the selection is considered to
|
|
220 be the text between those markers)."
|
|
221 (interactive (if (not current-prefix-arg)
|
|
222 (list (read-string "Store text for pasting: "))
|
|
223 (list (cons ;; these need not be ordered.
|
|
224 (copy-marker (point-marker))
|
|
225 (copy-marker (mark-marker))))))
|
|
226 (x-own-selection selection 'SECONDARY))
|
|
227
|
|
228
|
|
229 (defun x-own-clipboard (string)
|
|
230 "Paste the given string to the X Clipboard."
|
|
231 (x-own-selection string 'CLIPBOARD))
|
|
232
|
|
233
|
|
234 (defun x-disown-selection (&optional secondary-p)
|
|
235 "Assuming we own the selection, disown it. With an argument, discard the
|
|
236 secondary selection instead of the primary selection."
|
|
237 (x-disown-selection-internal (if secondary-p 'SECONDARY 'PRIMARY)))
|
|
238
|
|
239 (defun x-dehilight-selection (selection)
|
|
240 "for use as a value of `x-lost-selection-hooks'."
|
|
241 (cond ((eq selection 'PRIMARY)
|
|
242 (if primary-selection-extent
|
|
243 (let ((inhibit-quit t))
|
|
244 (if (consp primary-selection-extent)
|
|
245 (mapcar 'delete-extent primary-selection-extent)
|
|
246 (delete-extent primary-selection-extent))
|
|
247 (setq primary-selection-extent nil)))
|
|
248 (if zmacs-regions (zmacs-deactivate-region)))
|
|
249 ((eq selection 'SECONDARY)
|
|
250 (if secondary-selection-extent
|
|
251 (let ((inhibit-quit t))
|
|
252 (if (consp secondary-selection-extent)
|
|
253 (mapcar 'delete-extent secondary-selection-extent)
|
|
254 (delete-extent secondary-selection-extent))
|
|
255 (setq secondary-selection-extent nil)))))
|
|
256 nil)
|
|
257
|
|
258 (setq x-lost-selection-hooks 'x-dehilight-selection)
|
|
259
|
|
260 (defun x-notice-selection-requests (selection type successful)
|
|
261 "for possible use as the value of x-sent-selection-hooks."
|
|
262 (if (not successful)
|
|
263 (message "Selection request failed to convert %s to %s"
|
|
264 selection type)
|
|
265 (message "Sent selection %s as %s" selection type)))
|
|
266
|
|
267 (defun x-notice-selection-failures (selection type successful)
|
|
268 "for possible use as the value of x-sent-selection-hooks."
|
|
269 (or successful
|
|
270 (message "Selection request failed to convert %s to %s"
|
|
271 selection type)))
|
|
272
|
|
273 ;(setq x-sent-selection-hooks 'x-notice-selection-requests)
|
|
274 ;(setq x-sent-selection-hooks 'x-notice-selection-failures)
|
|
275
|
|
276
|
|
277 ;;; Selections in killed buffers
|
|
278 ;;; this function is called by kill-buffer as if it were on the
|
|
279 ;;; kill-buffer-hook (though it isn't really).
|
|
280
|
|
281 (defun xselect-kill-buffer-hook ()
|
|
282 ;; Probably the right thing is to write a C function to return a list
|
|
283 ;; of the selections which emacs owns, since it could conceivably own
|
|
284 ;; a user-defined selection type that we've never heard of.
|
|
285 (xselect-kill-buffer-hook-1 'PRIMARY)
|
|
286 (xselect-kill-buffer-hook-1 'SECONDARY)
|
|
287 (xselect-kill-buffer-hook-1 'CLIPBOARD))
|
|
288
|
|
289 (defun xselect-kill-buffer-hook-1 (selection)
|
|
290 (let (value)
|
|
291 (if (and (x-selection-owner-p selection)
|
|
292 (setq value (x-get-selection-internal selection '_EMACS_INTERNAL))
|
|
293 ;; The _EMACS_INTERNAL selection type has a converter registered
|
|
294 ;; for it that does no translation. This only works if emacs is
|
|
295 ;; requesting the selection from itself. We could have done this
|
|
296 ;; by writing a C function to return the raw selection data, and
|
|
297 ;; that might be the right way to do this, but this was easy.
|
|
298 (or (and (consp value)
|
|
299 (markerp (car value))
|
|
300 (eq (current-buffer) (marker-buffer (car value))))
|
|
301 (and (extent-live-p value)
|
|
302 (eq (current-buffer) (extent-object value)))
|
|
303 (and (extentp value) (not (extent-live-p value)))))
|
|
304 (x-disown-selection-internal selection))))
|
|
305
|
|
306
|
|
307 ;;; Cut Buffer support
|
|
308
|
|
309 ;;; FSF name x-get-cut-buffer
|
|
310 (defun x-get-cutbuffer (&optional which-one)
|
|
311 "Returns the value of one of the 8 X server cut buffers. Optional arg
|
|
312 WHICH-ONE should be a number from 0 to 7, defaulting to 0.
|
|
313 Cut buffers are considered obsolete\; you should use selections instead.
|
|
314 This function does nothing if support for cut buffers was not compiled
|
|
315 into Emacs."
|
|
316 (and (fboundp 'x-get-cutbuffer-internal)
|
|
317 (x-get-cutbuffer-internal
|
|
318 (if which-one
|
|
319 (aref [CUT_BUFFER0 CUT_BUFFER1 CUT_BUFFER2 CUT_BUFFER3
|
|
320 CUT_BUFFER4 CUT_BUFFER5 CUT_BUFFER6 CUT_BUFFER7]
|
|
321 which-one)
|
|
322 'CUT_BUFFER0))))
|
|
323
|
|
324 ;;; FSF name x-set-cut-buffer
|
|
325 (defun x-store-cutbuffer (string &optional push)
|
|
326 "Store STRING into the X server's primary cut buffer.
|
|
327 If PUSH is non-nil, also rotate the cut buffers:
|
|
328 this means the previous value of the primary cut buffer moves the second
|
|
329 cut buffer, and the second to the third, and so on (there are 8 buffers.)
|
|
330 Cut buffers are considered obsolete; you should use selections instead.
|
|
331 This function does nothing if support for cut buffers was not compiled
|
|
332 into Emacs."
|
|
333 (and (fboundp 'x-store-cutbuffer-internal)
|
|
334 (progn
|
|
335 ;; Check the data type of STRING.
|
|
336 (substring string 0 0)
|
|
337 (if push
|
|
338 (x-rotate-cutbuffers-internal 1))
|
|
339 (x-store-cutbuffer-internal 'CUT_BUFFER0 string))))
|
|
340
|
|
341
|
|
342 ;;; Random utility functions
|
|
343
|
|
344 (defun x-cut-copy-clear-internal (mode)
|
|
345 (or (memq mode '(cut copy clear)) (error "unkown mode %S" mode))
|
|
346 (or (x-selection-owner-p)
|
|
347 (error "emacs does not own the primary selection"))
|
|
348 (setq last-command nil)
|
|
349 (or primary-selection-extent
|
|
350 (error "the primary selection is not an extent?"))
|
|
351 (save-excursion
|
|
352 (let (rect-p b s e)
|
|
353 (cond
|
|
354 ((consp primary-selection-extent)
|
|
355 (setq rect-p t
|
|
356 b (extent-object (car primary-selection-extent))
|
|
357 s (extent-start-position (car primary-selection-extent))
|
|
358 e (extent-end-position (car (reverse primary-selection-extent)))))
|
|
359 (t
|
|
360 (setq rect-p nil
|
|
361 b (extent-object primary-selection-extent)
|
|
362 s (extent-start-position primary-selection-extent)
|
|
363 e (extent-end-position primary-selection-extent))))
|
|
364 (set-buffer b)
|
|
365 (cond ((memq mode '(cut copy))
|
|
366 (if rect-p
|
|
367 (progn
|
|
368 ;; why is killed-rectangle free? Is it used somewhere?
|
|
369 ;; should it be defvarred?
|
|
370 (setq killed-rectangle (extract-rectangle s e))
|
|
371 (kill-new (mapconcat 'identity killed-rectangle "\n")))
|
|
372 (copy-region-as-kill s e))
|
|
373 ;; Maybe killing doesn't own clipboard. Make sure it happens.
|
|
374 ;; This memq is kind of grody, because they might have done it
|
|
375 ;; some other way, but owning the clipboard twice in that case
|
|
376 ;; wouldn't actually hurt anything.
|
|
377 (or (and (consp kill-hooks) (memq 'x-own-clipboard kill-hooks))
|
|
378 (x-own-clipboard (car kill-ring)))))
|
|
379 (cond ((memq mode '(cut clear))
|
|
380 (if rect-p
|
|
381 (delete-rectangle s e)
|
|
382 (delete-region s e))))
|
|
383 (x-disown-selection nil)
|
|
384 )))
|
|
385
|
|
386 (defun x-copy-primary-selection ()
|
|
387 "Copy the selection to the Clipboard and the kill ring."
|
|
388 (interactive)
|
|
389 (x-cut-copy-clear-internal 'copy))
|
|
390
|
|
391 (defun x-kill-primary-selection ()
|
|
392 "Copy the selection to the Clipboard and the kill ring, then delete it."
|
|
393 (interactive "*")
|
|
394 (x-cut-copy-clear-internal 'cut))
|
|
395
|
|
396 (defun x-delete-primary-selection ()
|
|
397 "Delete the selection without copying it to the Clipboard or the kill ring."
|
|
398 (interactive "*")
|
|
399 (x-cut-copy-clear-internal 'clear))
|
|
400
|
|
401 (defun x-yank-clipboard-selection ()
|
|
402 "Insert the current Clipboard selection at point."
|
|
403 (interactive "*")
|
|
404 (setq last-command nil)
|
|
405 (setq this-command 'yank) ; so that yank-pop works.
|
|
406 (let ((clip (x-get-clipboard)))
|
|
407 (or clip (error "there is no clipboard selection"))
|
|
408 (push-mark)
|
|
409 (insert clip)))
|
|
410
|
|
411 ;;; Functions to convert the selection into various other selection types.
|
|
412 ;;; Every selection type that emacs handles is implemented this way, except
|
|
413 ;;; for TIMESTAMP, which is a special case.
|
|
414
|
|
415 (defun xselect-convert-to-text (selection type value)
|
|
416 (cond ((stringp value)
|
|
417 value)
|
|
418 ((extentp value)
|
|
419 (save-excursion
|
|
420 (set-buffer (extent-object value))
|
|
421 (save-restriction
|
|
422 (widen)
|
|
423 (buffer-substring (extent-start-position value)
|
|
424 (extent-end-position value)))))
|
|
425 ((and (consp value)
|
|
426 (markerp (car value))
|
|
427 (markerp (cdr value)))
|
|
428 (or (eq (marker-buffer (car value)) (marker-buffer (cdr value)))
|
|
429 (signal 'error
|
|
430 (list "markers must be in the same buffer"
|
|
431 (car value) (cdr value))))
|
|
432 (save-excursion
|
|
433 (set-buffer (or (marker-buffer (car value))
|
|
434 (error "selection is in a killed buffer")))
|
|
435 (save-restriction
|
|
436 (widen)
|
|
437 (buffer-substring (car value) (cdr value)))))
|
|
438 (t nil)))
|
|
439
|
|
440 (defun xselect-convert-to-string (selection type value)
|
|
441 (let ((outval (xselect-convert-to-text selection type value)))
|
|
442 ;; force the string to be not in Compound Text format.
|
|
443 (if (stringp outval)
|
|
444 (cons 'STRING outval)
|
|
445 outval)))
|
|
446
|
|
447 (defun xselect-convert-to-compound-text (selection type value)
|
|
448 ;; converts to compound text automatically
|
|
449 (xselect-convert-to-text selection type value))
|
|
450
|
|
451 (defun xselect-convert-to-length (selection type value)
|
|
452 (let ((value
|
|
453 (cond ((stringp value)
|
|
454 (length value))
|
|
455 ((extentp value)
|
|
456 (extent-length value))
|
|
457 ((and (consp value)
|
|
458 (markerp (car value))
|
|
459 (markerp (cdr value)))
|
|
460 (or (eq (marker-buffer (car value))
|
|
461 (marker-buffer (cdr value)))
|
|
462 (signal 'error
|
|
463 (list "markers must be in the same buffer"
|
|
464 (car value) (cdr value))))
|
|
465 (abs (- (car value) (cdr value)))))))
|
|
466 (if value ; force it to be in 32-bit format.
|
|
467 (cons (ash value -16) (logand value 65535))
|
|
468 nil)))
|
|
469
|
|
470 (defun xselect-convert-to-targets (selection type value)
|
|
471 ;; return a vector of atoms, but remove duplicates first.
|
|
472 (let* ((all (cons 'TIMESTAMP (mapcar 'car selection-converter-alist)))
|
|
473 (rest all))
|
|
474 (while rest
|
|
475 (cond ((memq (car rest) (cdr rest))
|
|
476 (setcdr rest (delq (car rest) (cdr rest))))
|
|
477 ((eq (car (cdr rest)) '_EMACS_INTERNAL) ; shh, it's a secret
|
|
478 (setcdr rest (cdr (cdr rest))))
|
|
479 (t
|
|
480 (setq rest (cdr rest)))))
|
|
481 (apply 'vector all)))
|
|
482
|
|
483 (defun xselect-convert-to-delete (selection type value)
|
|
484 (x-disown-selection-internal selection)
|
|
485 ;; A return value of nil means that we do not know how to do this conversion,
|
|
486 ;; and replies with an "error". A return value of NULL means that we have
|
|
487 ;; done the conversion (and any side-effects) but have no value to return.
|
|
488 'NULL)
|
|
489
|
|
490 (defun xselect-convert-to-filename (selection type value)
|
|
491 (cond ((extentp value)
|
|
492 (buffer-file-name (or (extent-object value)
|
|
493 (error "selection is in a killed buffer"))))
|
|
494 ((and (consp value)
|
|
495 (markerp (car value))
|
|
496 (markerp (cdr value)))
|
|
497 (buffer-file-name (or (marker-buffer (car value))
|
|
498 (error "selection is in a killed buffer"))))
|
|
499 (t nil)))
|
|
500
|
|
501 (defun xselect-convert-to-charpos (selection type value)
|
|
502 (let (a b tmp)
|
|
503 (cond ((cond ((extentp value)
|
|
504 (setq a (extent-start-position value)
|
|
505 b (extent-end-position value)))
|
|
506 ((and (consp value)
|
|
507 (markerp (car value))
|
|
508 (markerp (cdr value)))
|
|
509 (setq a (car value)
|
|
510 b (cdr value))))
|
|
511 (setq a (1- a) b (1- b)) ; zero-based
|
|
512 (if (< b a) (setq tmp a a b b tmp))
|
|
513 (cons 'SPAN
|
|
514 (vector (cons (ash a -16) (logand a 65535))
|
|
515 (cons (ash b -16) (logand b 65535))))))))
|
|
516
|
|
517 (defun xselect-convert-to-lineno (selection type value)
|
|
518 (let (a b buf tmp)
|
|
519 (cond ((cond ((extentp value)
|
|
520 (setq buf (extent-object value)
|
|
521 a (extent-start-position value)
|
|
522 b (extent-end-position value)))
|
|
523 ((and (consp value)
|
|
524 (markerp (car value))
|
|
525 (markerp (cdr value)))
|
|
526 (setq a (marker-position (car value))
|
|
527 b (marker-position (cdr value))
|
|
528 buf (marker-buffer (car value)))))
|
|
529 (save-excursion
|
|
530 (set-buffer buf)
|
|
531 (save-restriction
|
|
532 (widen)
|
|
533 (goto-char a)
|
|
534 (beginning-of-line)
|
|
535 (setq a (1+ (count-lines 1 (point))))
|
|
536 (goto-char b)
|
|
537 (beginning-of-line)
|
|
538 (setq b (1+ (count-lines 1 (point))))))
|
|
539 (if (< b a) (setq tmp a a b b tmp))
|
|
540 (cons 'SPAN
|
|
541 (vector (cons (ash a -16) (logand a 65535))
|
|
542 (cons (ash b -16) (logand b 65535))))))))
|
|
543
|
|
544 (defun xselect-convert-to-colno (selection type value)
|
|
545 (let (a b buf tmp)
|
|
546 (cond ((cond ((extentp value)
|
|
547 (setq buf (extent-object value)
|
|
548 a (extent-start-position value)
|
|
549 b (extent-end-position value)))
|
|
550 ((and (consp value)
|
|
551 (markerp (car value))
|
|
552 (markerp (cdr value)))
|
|
553 (setq a (car value)
|
|
554 b (cdr value)
|
|
555 buf (marker-buffer a))))
|
|
556 (save-excursion
|
|
557 (set-buffer buf)
|
|
558 (goto-char a)
|
|
559 (setq a (current-column))
|
|
560 (goto-char b)
|
|
561 (setq b (current-column)))
|
|
562 (if (< b a) (setq tmp a a b b tmp))
|
|
563 (cons 'SPAN
|
|
564 (vector (cons (ash a -16) (logand a 65535))
|
|
565 (cons (ash b -16) (logand b 65535))))))))
|
|
566
|
|
567 (defun xselect-convert-to-sourceloc (selection type value)
|
|
568 (let (a b buf file-name tmp)
|
|
569 (cond ((cond ((extentp value)
|
|
570 (setq buf (or (extent-object value)
|
|
571 (error "selection is in a killed buffer"))
|
|
572 a (extent-start-position value)
|
|
573 b (extent-end-position value)
|
|
574 file-name (buffer-file-name buf)))
|
|
575 ((and (consp value)
|
|
576 (markerp (car value))
|
|
577 (markerp (cdr value)))
|
|
578 (setq a (marker-position (car value))
|
|
579 b (marker-position (cdr value))
|
|
580 buf (or (marker-buffer (car value))
|
|
581 (error "selection is in a killed buffer"))
|
|
582 file-name (buffer-file-name buf))))
|
|
583 (save-excursion
|
|
584 (set-buffer buf)
|
|
585 (save-restriction
|
|
586 (widen)
|
|
587 (goto-char a)
|
|
588 (beginning-of-line)
|
|
589 (setq a (1+ (count-lines 1 (point))))
|
|
590 (goto-char b)
|
|
591 (beginning-of-line)
|
|
592 (setq b (1+ (count-lines 1 (point))))))
|
|
593 (if (< b a) (setq tmp a a b b tmp))
|
|
594 (format "%s:%d" file-name a)))))
|
|
595
|
|
596 (defun xselect-convert-to-os (selection type size)
|
|
597 (symbol-name system-type))
|
|
598
|
|
599 (defun xselect-convert-to-host (selection type size)
|
|
600 (system-name))
|
|
601
|
|
602 (defun xselect-convert-to-user (selection type size)
|
|
603 (user-full-name))
|
|
604
|
|
605 (defun xselect-convert-to-class (selection type size)
|
|
606 x-emacs-application-class)
|
|
607
|
|
608 ;; We do not try to determine the name Emacs was invoked with,
|
|
609 ;; because it is not clean for a program's behavior to depend on that.
|
|
610 (defun xselect-convert-to-name (selection type size)
|
|
611 ;invocation-name
|
|
612 "xemacs")
|
|
613
|
|
614 (defun xselect-convert-to-integer (selection type value)
|
|
615 (and (integerp value)
|
|
616 (cons (ash value -16) (logand value 65535))))
|
|
617
|
|
618 (defun xselect-convert-to-atom (selection type value)
|
|
619 (and (symbolp value) value))
|
|
620
|
|
621 (defun xselect-convert-to-identity (selection type value) ; used internally
|
|
622 (vector value))
|
|
623
|
|
624 (setq selection-converter-alist
|
|
625 '((TEXT . xselect-convert-to-text)
|
|
626 (STRING . xselect-convert-to-string)
|
|
627 (COMPOUND_TEXT . xselect-convert-to-compound-text)
|
|
628 (TARGETS . xselect-convert-to-targets)
|
|
629 (LENGTH . xselect-convert-to-length)
|
|
630 (DELETE . xselect-convert-to-delete)
|
|
631 (FILE_NAME . xselect-convert-to-filename)
|
|
632 (CHARACTER_POSITION . xselect-convert-to-charpos)
|
|
633 (SOURCE_LOC . xselect-convert-to-sourceloc)
|
|
634 (LINE_NUMBER . xselect-convert-to-lineno)
|
|
635 (COLUMN_NUMBER . xselect-convert-to-colno)
|
|
636 (OWNER_OS . xselect-convert-to-os)
|
|
637 (HOST_NAME . xselect-convert-to-host)
|
|
638 (USER . xselect-convert-to-user)
|
|
639 (CLASS . xselect-convert-to-class)
|
|
640 (NAME . xselect-convert-to-name)
|
|
641 (ATOM . xselect-convert-to-atom)
|
|
642 (INTEGER . xselect-convert-to-integer)
|
|
643 (_EMACS_INTERNAL . xselect-convert-to-identity)
|
|
644 ))
|
|
645
|
|
646 ;FSFmacs (provide 'select)
|
|
647
|
|
648 ;;; x-select.el ends here.
|