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