428
+ − 1 ;;; select.el --- Lisp interface to windows selections.
+ − 2
+ − 3 ;; Copyright (C) 1998 Andy Piper.
+ − 4 ;; Copyright (C) 1990, 1997 Free Software Foundation, Inc.
+ − 5 ;; Copyright (C) 1995 Sun Microsystems.
851
+ − 6 ;; Copyright (C) 2002 Ben Wing.
428
+ − 7
+ − 8 ;; Maintainer: XEmacs Development Team
+ − 9 ;; Keywords: extensions, dumped
+ − 10
+ − 11 ;; This file is part of XEmacs.
+ − 12
+ − 13 ;; XEmacs is free software; you can redistribute it and/or modify it
+ − 14 ;; under the terms of the GNU General Public License as published by
+ − 15 ;; the Free Software Foundation; either version 2, or (at your option)
+ − 16 ;; any later version.
+ − 17
+ − 18 ;; XEmacs is distributed in the hope that it will be useful, but
+ − 19 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
+ − 20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ − 21 ;; General Public License for more details.
+ − 22
+ − 23 ;; You should have received a copy of the GNU General Public License
444
+ − 24 ;; along with XEmacs; see the file COPYING. If not, write to the
428
+ − 25 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ − 26 ;; Boston, MA 02111-1307, USA.
+ − 27
+ − 28 ;;; Synched up with: Not in FSF
+ − 29
+ − 30 ;;; Commentary:
+ − 31
444
+ − 32 ;; This file is dumped with XEmacs
428
+ − 33
+ − 34 ;;; Code:
+ − 35
+ − 36 (defvar selected-text-type
+ − 37 (if (featurep 'mule) '(COMPOUND_TEXT STRING) 'STRING)
+ − 38 "The type atom used to obtain selections from the X server.
+ − 39 Can be either a valid X selection data type, or a list of such types.
+ − 40 COMPOUND_TEXT and STRING are the most commonly used data types.
+ − 41 If a list is provided, the types are tried in sequence until
+ − 42 there is a successful conversion.")
+ − 43
444
+ − 44 (defvar selection-sets-clipboard nil
428
+ − 45 "Controls the selection's relationship to the clipboard.
+ − 46 When non-nil, any operation that sets the primary selection will also
+ − 47 set the clipboard.")
+ − 48
+ − 49 (defun copy-primary-selection ()
851
+ − 50 "Copy the selection to the Clipboard and the kill ring.
+ − 51 This is similar to the command \\[kill-ring-save] except that it will
+ − 52 save to the Clipboard even if that command doesn't, and it handles rectangles
+ − 53 properly."
428
+ − 54 (interactive)
+ − 55 (and (console-on-window-system-p)
+ − 56 (cut-copy-clear-internal 'copy)))
+ − 57
+ − 58 (defun kill-primary-selection ()
851
+ − 59 "Copy the selection to the Clipboard and the kill ring, then deleted it.
+ − 60 This is similar to the command \\[kill-region] except that it will
+ − 61 save to the Clipboard even if that command doesn't, and it handles rectangles
+ − 62 properly."
428
+ − 63 (interactive "*")
+ − 64 (and (console-on-window-system-p)
+ − 65 (cut-copy-clear-internal 'cut)))
+ − 66
+ − 67 (defun delete-primary-selection ()
+ − 68 "Delete the selection without copying it to the Clipboard or the kill ring."
+ − 69 (interactive "*")
+ − 70 (and (console-on-window-system-p)
+ − 71 (cut-copy-clear-internal 'clear)))
+ − 72
+ − 73 (defun yank-clipboard-selection ()
+ − 74 "Insert the current Clipboard selection at point."
+ − 75 (interactive "*")
+ − 76 (when (console-on-window-system-p)
+ − 77 (setq last-command nil)
+ − 78 (setq this-command 'yank) ; so that yank-pop works.
+ − 79 (let ((clip (get-clipboard)))
+ − 80 (or clip (error "there is no clipboard selection"))
+ − 81 (push-mark)
+ − 82 (insert clip))))
+ − 83
+ − 84 (defun get-clipboard ()
829
+ − 85 "Return text pasted to the clipboard.
843
+ − 86 Not suitable for `interprogram-paste-function', use `get-clipboard-foreign'."
+ − 87 (get-selection 'CLIPBOARD))
+ − 88
+ − 89 (defun get-clipboard-foreign ()
+ − 90 "Return text pasted to the clipboard by another program.
829
+ − 91 See `interprogram-paste-function' for more information."
843
+ − 92 (get-selection-foreign 'CLIPBOARD))
428
+ − 93
+ − 94 (define-device-method get-cutbuffer
+ − 95 "Return the value of one of the cut buffers.
+ − 96 This will do nothing under anything other than X.")
+ − 97
+ − 98 (defun get-selection-no-error (&optional type data-type)
442
+ − 99 "Return the value of a window-system selection.
428
+ − 100 The argument TYPE (default `PRIMARY') says which selection,
+ − 101 and the argument DATA-TYPE (default `STRING', or `COMPOUND_TEXT' under Mule)
444
+ − 102 says how to convert the data. Returns NIL if there is no selection."
442
+ − 103 (condition-case nil (get-selection type data-type) (t nil)))
428
+ − 104
+ − 105 (defun get-selection (&optional type data-type)
843
+ − 106 "Return the value of a window-system selection.
428
+ − 107 The argument TYPE (default `PRIMARY') says which selection,
+ − 108 and the argument DATA-TYPE (default `STRING', or `COMPOUND_TEXT' under Mule)
829
+ − 109 says how to convert the data. If there is no selection an error is signalled.
843
+ − 110 Not suitable in a `interprogram-paste-function', q.v."
428
+ − 111 (or type (setq type 'PRIMARY))
+ − 112 (or data-type (setq data-type selected-text-type))
829
+ − 113 (if (consp data-type)
+ − 114 (condition-case err
+ − 115 (get-selection-internal type (car data-type))
+ − 116 (selection-conversion-error
+ − 117 (if (cdr data-type)
+ − 118 (get-selection type (cdr data-type))
+ − 119 (signal (car err) (cdr err)))))
+ − 120 (get-selection-internal type data-type)))
428
+ − 121
847
+ − 122 (defun get-selection-foreign (&optional type data-type)
+ − 123 "Return the value of a window-system selection, or nil if XEmacs owns it.
+ − 124 The argument TYPE (default `PRIMARY') says which selection,
+ − 125 and the argument DATA-TYPE (default `STRING', or `COMPOUND_TEXT' under Mule)
+ − 126 says how to convert the data. If there is no selection an error is signalled.
+ − 127 See `interprogram-paste-function' for more information."
+ − 128 (unless (selection-owner-p type)
+ − 129 (get-selection type data-type)))
+ − 130
428
+ − 131 ;; FSFmacs calls this `x-set-selection', and reverses the
442
+ − 132 ;; first two arguments (duh ...). This order is more logical.
+ − 133 (defun own-selection (data &optional type how-to-add data-type)
+ − 134 "Make a window-system selection of type TYPE and value DATA.
428
+ − 135 The argument TYPE (default `PRIMARY') says which selection,
442
+ − 136 and DATA specifies the contents. DATA may be any lisp data type
+ − 137 that can be converted using the function corresponding to DATA-TYPE
+ − 138 in `select-converter-alist'---strings are the usual choice, but
+ − 139 other types may be permissible depending on the DATA-TYPE parameter
851
+ − 140 \(if DATA-TYPE is not supplied, the default behavior is window
442
+ − 141 system specific, but strings are always accepted).
+ − 142 HOW-TO-ADD may be any of the following:
+ − 143
+ − 144 'replace-all or nil -- replace all data in the selection.
+ − 145 'replace-existing -- replace data for specified DATA-TYPE only.
+ − 146 'append or t -- append data to existing DATA-TYPE data.
+ − 147
+ − 148 DATA-TYPE is the window-system specific data type identifier
851
+ − 149 \(see `register-selection-data-type' for more information).
428
+ − 150
+ − 151 The selection may also be a cons of two markers pointing to the same buffer,
+ − 152 or an overlay. In these cases, the selection is considered to be the text
442
+ − 153 between the markers *at whatever time the selection is examined* (note
+ − 154 that the window system clipboard does not necessarily duplicate this
+ − 155 behavior - it doesn't on mswindows for example).
428
+ − 156 Thus, editing done in the buffer after you specify the selection
+ − 157 can alter the effective value of the selection.
+ − 158
+ − 159 The data may also be a vector of valid non-vector selection values.
+ − 160
+ − 161 Interactively, the text of the region is used as the selection value."
+ − 162 (interactive (if (not current-prefix-arg)
+ − 163 (list (read-string "Store text for pasting: "))
+ − 164 (list (substring (region-beginning) (region-end)))))
442
+ − 165 ;; calling own-selection-internal will mess this up, so preserve it.
+ − 166 (let ((zmacs-region-stays zmacs-region-stays))
+ − 167 ;FSFmacs huh?? It says:
+ − 168 ;; "This is for temporary compatibility with pre-release Emacs 19."
+ − 169 ;(if (stringp type)
+ − 170 ; (setq type (intern type)))
+ − 171 (or type (setq type 'PRIMARY))
+ − 172 (if (null data)
+ − 173 (disown-selection-internal type)
+ − 174 (own-selection-internal type data how-to-add data-type)
+ − 175 (when (and (eq type 'PRIMARY)
+ − 176 selection-sets-clipboard)
+ − 177 (own-selection-internal 'CLIPBOARD data how-to-add data-type)))
+ − 178 (cond ((eq type 'PRIMARY)
+ − 179 (setq primary-selection-extent
+ − 180 (select-make-extent-for-selection
+ − 181 data primary-selection-extent)))
+ − 182 ((eq type 'SECONDARY)
+ − 183 (setq secondary-selection-extent
+ − 184 (select-make-extent-for-selection
+ − 185 data secondary-selection-extent)))))
+ − 186 ;; zmacs-region-stays is for commands, not low-level functions.
+ − 187 ;; when behaving as the latter, we better not set it, or we will
+ − 188 ;; cause unwanted sticky-region behavior in kill-region and friends.
+ − 189 (if (interactive-p)
+ − 190 (setq zmacs-region-stays t))
428
+ − 191 data)
+ − 192
+ − 193 (defun dehilight-selection (selection)
+ − 194 "for use as a value of `lost-selection-hooks'."
+ − 195 (cond ((eq selection 'PRIMARY)
+ − 196 (if primary-selection-extent
+ − 197 (let ((inhibit-quit t))
+ − 198 (if (consp primary-selection-extent)
+ − 199 (mapcar 'delete-extent primary-selection-extent)
+ − 200 (delete-extent primary-selection-extent))
+ − 201 (setq primary-selection-extent nil)))
+ − 202 (if zmacs-regions (zmacs-deactivate-region)))
+ − 203 ((eq selection 'SECONDARY)
+ − 204 (if secondary-selection-extent
+ − 205 (let ((inhibit-quit t))
+ − 206 (if (consp secondary-selection-extent)
+ − 207 (mapcar 'delete-extent secondary-selection-extent)
+ − 208 (delete-extent secondary-selection-extent))
+ − 209 (setq secondary-selection-extent nil)))))
+ − 210 nil)
+ − 211
+ − 212 (setq lost-selection-hooks 'dehilight-selection)
+ − 213
442
+ − 214 (defun own-clipboard (string &optional push)
+ − 215 "Paste the given string to the window system Clipboard.
+ − 216 See `interprogram-cut-function' for more information."
428
+ − 217 (own-selection string 'CLIPBOARD))
+ − 218
+ − 219 (defun disown-selection (&optional secondary-p)
487
+ − 220 "Assuming we own the selection, disown it.
+ − 221 With an argument, discard the secondary selection instead of the
+ − 222 primary selection."
428
+ − 223 (disown-selection-internal (if secondary-p 'SECONDARY 'PRIMARY))
+ − 224 (when (and selection-sets-clipboard
+ − 225 (or (not secondary-p)
+ − 226 (eq secondary-p 'PRIMARY)
+ − 227 (eq secondary-p 'CLIPBOARD)))
+ − 228 (disown-selection-internal 'CLIPBOARD)))
+ − 229
+ − 230 ;; selections and active regions
+ − 231
+ − 232 ;; If and only if zmacs-regions is true:
+ − 233
+ − 234 ;; When a mark is pushed and the region goes into the "active" state, we
+ − 235 ;; assert it as the Primary selection. This causes it to be hilighted.
+ − 236 ;; When the region goes into the "inactive" state, we disown the Primary
+ − 237 ;; selection, causing the region to be dehilighted.
+ − 238
+ − 239 ;; Note that it is possible for the region to be in the "active" state
+ − 240 ;; and not be hilighted, if it is in the active state and then some other
+ − 241 ;; application asserts the selection. This is probably not a big deal.
+ − 242
+ − 243 (defun activate-region-as-selection ()
487
+ − 244 (cond (mouse-track-rectangle-p (mouse-track-activate-rectangular-selection))
+ − 245 ((marker-buffer (mark-marker t))
+ − 246 (own-selection (cons (point-marker t) (mark-marker t))))))
428
+ − 247
+ − 248 (defvar primary-selection-extent nil
+ − 249 "The extent of the primary selection; don't use this.")
+ − 250
+ − 251 (defvar secondary-selection-extent nil
+ − 252 "The extent of the secondary selection; don't use this.")
+ − 253
+ − 254 (defun select-make-extent-for-selection (selection previous-extent)
+ − 255 ;; Given a selection, this makes an extent in the buffer which holds that
+ − 256 ;; selection, for highlighting purposes. If the selection isn't associated
+ − 257 ;; with a buffer, this does nothing.
+ − 258 (let ((buffer nil)
+ − 259 (valid (and (extentp previous-extent)
+ − 260 (extent-object previous-extent)
+ − 261 (buffer-live-p (extent-object previous-extent))))
+ − 262 start end)
+ − 263 (cond ((stringp selection)
+ − 264 ;; if we're selecting a string, lose the previous extent used
+ − 265 ;; to highlight the selection.
+ − 266 (setq valid nil))
+ − 267 ((consp selection)
+ − 268 (setq start (min (car selection) (cdr selection))
+ − 269 end (max (car selection) (cdr selection))
+ − 270 valid (and valid
+ − 271 (eq (marker-buffer (car selection))
+ − 272 (extent-object previous-extent)))
+ − 273 buffer (marker-buffer (car selection))))
+ − 274 ((extentp selection)
+ − 275 (setq start (extent-start-position selection)
+ − 276 end (extent-end-position selection)
+ − 277 valid (and valid
+ − 278 (eq (extent-object selection)
+ − 279 (extent-object previous-extent)))
+ − 280 buffer (extent-object selection)))
+ − 281 (t
+ − 282 (signal 'error (list "invalid selection" selection))))
+ − 283
+ − 284 (if valid
+ − 285 nil
+ − 286 (condition-case ()
+ − 287 (if (listp previous-extent)
+ − 288 (mapcar 'delete-extent previous-extent)
+ − 289 (delete-extent previous-extent))
+ − 290 (error nil)))
+ − 291
+ − 292 (if (not buffer)
+ − 293 ;; string case
+ − 294 nil
+ − 295 ;; normal case
+ − 296 (if valid
+ − 297 (set-extent-endpoints previous-extent start end)
+ − 298 (setq previous-extent (make-extent start end buffer))
+ − 299
+ − 300 ;; Make the extent be closed on the right, which means that if
+ − 301 ;; characters are inserted exactly at the end of the extent, the
+ − 302 ;; extent will grow to cover them. This is important for shell
+ − 303 ;; buffers - suppose one makes a selection, and one end is at
+ − 304 ;; point-max. If the shell produces output, that marker will remain
+ − 305 ;; at point-max (its position will increase). So it's important that
+ − 306 ;; the extent exhibit the same behavior, lest the region covered by
+ − 307 ;; the extent (the visual indication), and the region between point
+ − 308 ;; and mark (the actual selection value) become different!
+ − 309 (set-extent-property previous-extent 'end-open nil)
+ − 310
+ − 311 (cond
+ − 312 (mouse-track-rectangle-p
+ − 313 (setq previous-extent (list previous-extent))
+ − 314 (default-mouse-track-next-move-rect start end previous-extent)
+ − 315 ))
+ − 316 previous-extent))))
+ − 317
+ − 318 (defun valid-simple-selection-p (data)
442
+ − 319 "An obsolete function that tests whether something was a valid simple
+ − 320 selection using the old XEmacs selection support. You shouldn't use this
+ − 321 any more, because just about anything could be a valid selection now."
428
+ − 322 (or (stringp data)
+ − 323 ;FSFmacs huh?? (symbolp data)
+ − 324 (integerp data)
+ − 325 (and (consp data)
+ − 326 (integerp (car data))
+ − 327 (or (integerp (cdr data))
+ − 328 (and (consp (cdr data))
+ − 329 (integerp (car (cdr data))))))
+ − 330 (extentp data)
+ − 331 (and (consp data)
+ − 332 (markerp (car data))
+ − 333 (markerp (cdr data))
+ − 334 (marker-buffer (car data))
+ − 335 (marker-buffer (cdr data))
+ − 336 (eq (marker-buffer (car data))
+ − 337 (marker-buffer (cdr data)))
+ − 338 (buffer-live-p (marker-buffer (car data)))
+ − 339 (buffer-live-p (marker-buffer (cdr data))))))
+ − 340
+ − 341 (defun cut-copy-clear-internal (mode)
+ − 342 (or (memq mode '(cut copy clear)) (error "unkown mode %S" mode))
+ − 343 (or (selection-owner-p)
+ − 344 (error "XEmacs does not own the primary selection"))
+ − 345 (setq last-command nil)
+ − 346 (or primary-selection-extent
+ − 347 (error "the primary selection is not an extent?"))
+ − 348 (save-excursion
+ − 349 (let (rect-p b s e)
+ − 350 (cond
+ − 351 ((consp primary-selection-extent)
+ − 352 (setq rect-p t
+ − 353 b (extent-object (car primary-selection-extent))
+ − 354 s (extent-start-position (car primary-selection-extent))
+ − 355 e (extent-end-position (car (reverse primary-selection-extent)))))
+ − 356 (t
+ − 357 (setq rect-p nil
+ − 358 b (extent-object primary-selection-extent)
+ − 359 s (extent-start-position primary-selection-extent)
+ − 360 e (extent-end-position primary-selection-extent))))
+ − 361 (set-buffer b)
+ − 362 (cond ((memq mode '(cut copy))
+ − 363 (if rect-p
+ − 364 (progn
851
+ − 365 ;; killed-rectangle is defvarred in rect.el
428
+ − 366 (setq killed-rectangle (extract-rectangle s e))
+ − 367 (kill-new (mapconcat #'identity killed-rectangle "\n")))
+ − 368 (copy-region-as-kill s e))
+ − 369 ;; Maybe killing doesn't own clipboard. Make sure it happens.
+ − 370 ;; This memq is kind of grody, because they might have done it
+ − 371 ;; some other way, but owning the clipboard twice in that case
+ − 372 ;; wouldn't actually hurt anything.
+ − 373 (or (and (consp kill-hooks) (memq 'own-clipboard kill-hooks))
851
+ − 374 (eq 'own-clipboard interprogram-cut-function)
428
+ − 375 (own-clipboard (car kill-ring)))))
+ − 376 (cond ((memq mode '(cut clear))
+ − 377 (if rect-p
+ − 378 (delete-rectangle s e)
+ − 379 (delete-region s e))))
+ − 380 (disown-selection nil)
+ − 381 )))
+ − 382
442
+ − 383
428
+ − 384 ;;; Functions to convert the selection into various other selection
442
+ − 385 ;;; types.
+ − 386
+ − 387 ;; These next three functions get called by C code...
+ − 388 (defun select-convert-in (selection type value)
+ − 389 "Attempt to convert the specified external VALUE to the specified DATA-TYPE,
+ − 390 for the specified SELECTION. Return nil if this is impossible, or a
+ − 391 suitable internal representation otherwise."
+ − 392 (when value
+ − 393 (let ((handler-fn (cdr (assq type selection-converter-in-alist))))
+ − 394 (when handler-fn
+ − 395 (apply handler-fn (list selection type value))))))
428
+ − 396
442
+ − 397 (defun select-convert-out (selection type value)
+ − 398 "Attempt to convert the specified internal VALUE for the specified DATA-TYPE
+ − 399 and SELECTION. Return nil if this is impossible, or a suitable external
+ − 400 representation otherwise."
+ − 401 (when value
+ − 402 (let ((handler-fn (cdr (assq type selection-converter-out-alist))))
+ − 403 (when handler-fn
+ − 404 (apply handler-fn (list selection type value))))))
+ − 405
+ − 406 (defun select-coerce (selection type value)
+ − 407 "Attempt to convert the specified internal VALUE to a representation
+ − 408 suitable for return from `get-selection' in the specified DATA-TYPE. Return
+ − 409 nil if this is impossible, or a suitable representation otherwise."
+ − 410 (when value
+ − 411 (let ((handler-fn (cdr (assq type selection-coercion-alist))))
+ − 412 (when handler-fn
+ − 413 (apply handler-fn (list selection type value))))))
+ − 414
+ − 415 ;; The rest of the functions on this "page" are conversion handlers,
+ − 416 ;; append handlers and buffer-kill handlers.
428
+ − 417 (defun select-convert-to-text (selection type value)
+ − 418 (cond ((stringp value)
+ − 419 value)
+ − 420 ((extentp value)
+ − 421 (save-excursion
+ − 422 (set-buffer (extent-object value))
+ − 423 (save-restriction
+ − 424 (widen)
+ − 425 (buffer-substring (extent-start-position value)
+ − 426 (extent-end-position value)))))
+ − 427 ((and (consp value)
+ − 428 (markerp (car value))
+ − 429 (markerp (cdr value)))
+ − 430 (or (eq (marker-buffer (car value)) (marker-buffer (cdr value)))
+ − 431 (signal 'error
+ − 432 (list "markers must be in the same buffer"
+ − 433 (car value) (cdr value))))
+ − 434 (save-excursion
+ − 435 (set-buffer (or (marker-buffer (car value))
+ − 436 (error "selection is in a killed buffer")))
+ − 437 (save-restriction
+ − 438 (widen)
+ − 439 (buffer-substring (car value) (cdr value)))))
+ − 440 (t nil)))
+ − 441
442
+ − 442 (defun select-coerce-to-text (selection type value)
+ − 443 (select-convert-to-text selection type value))
+ − 444
+ − 445 (defun select-convert-from-text (selection type value)
+ − 446 (when (stringp value)
+ − 447 value))
+ − 448
428
+ − 449 (defun select-convert-to-string (selection type value)
+ − 450 (let ((outval (select-convert-to-text selection type value)))
442
+ − 451 ;; force the string to be not in Compound Text format. This grubby
+ − 452 ;; hack will go soon, to be replaced by a more general mechanism.
428
+ − 453 (if (stringp outval)
+ − 454 (cons 'STRING outval)
+ − 455 outval)))
+ − 456
+ − 457 (defun select-convert-to-compound-text (selection type value)
+ − 458 ;; converts to compound text automatically
+ − 459 (select-convert-to-text selection type value))
+ − 460
+ − 461 (defun select-convert-to-length (selection type value)
+ − 462 (let ((value
+ − 463 (cond ((stringp value)
+ − 464 (length value))
+ − 465 ((extentp value)
+ − 466 (extent-length value))
+ − 467 ((and (consp value)
+ − 468 (markerp (car value))
+ − 469 (markerp (cdr value)))
+ − 470 (or (eq (marker-buffer (car value))
+ − 471 (marker-buffer (cdr value)))
+ − 472 (signal 'error
+ − 473 (list "markers must be in the same buffer"
+ − 474 (car value) (cdr value))))
+ − 475 (abs (- (car value) (cdr value)))))))
+ − 476 (if value ; force it to be in 32-bit format.
+ − 477 (cons (ash value -16) (logand value 65535))
+ − 478 nil)))
+ − 479
442
+ − 480 (defun select-convert-from-length (selection type value)
+ − 481 (select-convert-to-length selection type value))
+ − 482
428
+ − 483 (defun select-convert-to-targets (selection type value)
+ − 484 ;; return a vector of atoms, but remove duplicates first.
+ − 485 (let* ((all (cons 'TIMESTAMP (mapcar 'car selection-converter-alist)))
+ − 486 (rest all))
+ − 487 (while rest
+ − 488 (cond ((memq (car rest) (cdr rest))
+ − 489 (setcdr rest (delq (car rest) (cdr rest))))
+ − 490 (t
+ − 491 (setq rest (cdr rest)))))
+ − 492 (apply 'vector all)))
+ − 493
+ − 494 (defun select-convert-to-delete (selection type value)
+ − 495 (disown-selection-internal selection)
+ − 496 ;; A return value of nil means that we do not know how to do this conversion,
+ − 497 ;; and replies with an "error". A return value of NULL means that we have
+ − 498 ;; done the conversion (and any side-effects) but have no value to return.
+ − 499 'NULL)
+ − 500
+ − 501 (defun select-convert-to-filename (selection type value)
+ − 502 (cond ((extentp value)
+ − 503 (buffer-file-name (or (extent-object value)
+ − 504 (error "selection is in a killed buffer"))))
+ − 505 ((and (consp value)
+ − 506 (markerp (car value))
+ − 507 (markerp (cdr value)))
+ − 508 (buffer-file-name (or (marker-buffer (car value))
+ − 509 (error "selection is in a killed buffer"))))
+ − 510 (t nil)))
+ − 511
442
+ − 512 (defun select-convert-from-filename (selection type value)
+ − 513 (when (stringp value)
+ − 514 value))
+ − 515
428
+ − 516 (defun select-convert-to-charpos (selection type value)
+ − 517 (let (a b tmp)
+ − 518 (cond ((cond ((extentp value)
+ − 519 (setq a (extent-start-position value)
+ − 520 b (extent-end-position value)))
+ − 521 ((and (consp value)
+ − 522 (markerp (car value))
+ − 523 (markerp (cdr value)))
+ − 524 (setq a (car value)
+ − 525 b (cdr value))))
+ − 526 (setq a (1- a) b (1- b)) ; zero-based
+ − 527 (if (< b a) (setq tmp a a b b tmp))
+ − 528 (cons 'SPAN
+ − 529 (vector (cons (ash a -16) (logand a 65535))
+ − 530 (cons (ash b -16) (logand b 65535))))))))
+ − 531
+ − 532 (defun select-convert-to-lineno (selection type value)
+ − 533 (let (a b buf tmp)
+ − 534 (cond ((cond ((extentp value)
+ − 535 (setq buf (extent-object value)
+ − 536 a (extent-start-position value)
+ − 537 b (extent-end-position value)))
+ − 538 ((and (consp value)
+ − 539 (markerp (car value))
+ − 540 (markerp (cdr value)))
+ − 541 (setq a (marker-position (car value))
+ − 542 b (marker-position (cdr value))
+ − 543 buf (marker-buffer (car value)))))
+ − 544 (save-excursion
+ − 545 (set-buffer buf)
+ − 546 (save-restriction
+ − 547 (widen)
+ − 548 (goto-char a)
+ − 549 (beginning-of-line)
+ − 550 (setq a (1+ (count-lines 1 (point))))
+ − 551 (goto-char b)
+ − 552 (beginning-of-line)
+ − 553 (setq b (1+ (count-lines 1 (point))))))
+ − 554 (if (< b a) (setq tmp a a b b tmp))
+ − 555 (cons 'SPAN
+ − 556 (vector (cons (ash a -16) (logand a 65535))
+ − 557 (cons (ash b -16) (logand b 65535))))))))
+ − 558
+ − 559 (defun select-convert-to-colno (selection type value)
+ − 560 (let (a b buf tmp)
+ − 561 (cond ((cond ((extentp value)
+ − 562 (setq buf (extent-object value)
+ − 563 a (extent-start-position value)
+ − 564 b (extent-end-position value)))
+ − 565 ((and (consp value)
+ − 566 (markerp (car value))
+ − 567 (markerp (cdr value)))
+ − 568 (setq a (car value)
+ − 569 b (cdr value)
+ − 570 buf (marker-buffer a))))
+ − 571 (save-excursion
+ − 572 (set-buffer buf)
+ − 573 (goto-char a)
+ − 574 (setq a (current-column))
+ − 575 (goto-char b)
+ − 576 (setq b (current-column)))
+ − 577 (if (< b a) (setq tmp a a b b tmp))
+ − 578 (cons 'SPAN
+ − 579 (vector (cons (ash a -16) (logand a 65535))
+ − 580 (cons (ash b -16) (logand b 65535))))))))
+ − 581
+ − 582 (defun select-convert-to-sourceloc (selection type value)
+ − 583 (let (a b buf file-name tmp)
+ − 584 (cond ((cond ((extentp value)
+ − 585 (setq buf (or (extent-object value)
+ − 586 (error "selection is in a killed buffer"))
+ − 587 a (extent-start-position value)
+ − 588 b (extent-end-position value)
+ − 589 file-name (buffer-file-name buf)))
+ − 590 ((and (consp value)
+ − 591 (markerp (car value))
+ − 592 (markerp (cdr value)))
+ − 593 (setq a (marker-position (car value))
+ − 594 b (marker-position (cdr value))
+ − 595 buf (or (marker-buffer (car value))
+ − 596 (error "selection is in a killed buffer"))
+ − 597 file-name (buffer-file-name buf))))
+ − 598 (save-excursion
+ − 599 (set-buffer buf)
+ − 600 (save-restriction
+ − 601 (widen)
+ − 602 (goto-char a)
+ − 603 (beginning-of-line)
+ − 604 (setq a (1+ (count-lines 1 (point))))
+ − 605 (goto-char b)
+ − 606 (beginning-of-line)
+ − 607 (setq b (1+ (count-lines 1 (point))))))
+ − 608 (if (< b a) (setq tmp a a b b tmp))
+ − 609 (format "%s:%d" file-name a)))))
+ − 610
+ − 611 (defun select-convert-to-os (selection type size)
+ − 612 (symbol-name system-type))
+ − 613
+ − 614 (defun select-convert-to-host (selection type size)
+ − 615 (system-name))
+ − 616
+ − 617 (defun select-convert-to-user (selection type size)
+ − 618 (user-full-name))
+ − 619
+ − 620 (defun select-convert-to-class (selection type size)
442
+ − 621 (symbol-value 'x-emacs-application-class))
428
+ − 622
+ − 623 ;; We do not try to determine the name Emacs was invoked with,
+ − 624 ;; because it is not clean for a program's behavior to depend on that.
+ − 625 (defun select-convert-to-name (selection type size)
+ − 626 ;invocation-name
+ − 627 "xemacs")
+ − 628
+ − 629 (defun select-convert-to-integer (selection type value)
+ − 630 (and (integerp value)
+ − 631 (cons (ash value -16) (logand value 65535))))
+ − 632
442
+ − 633 ;; Can convert from the following integer representations
+ − 634 ;;
+ − 635 ;; integer
+ − 636 ;; (integer . integer)
+ − 637 ;; (integer integer)
+ − 638 ;; (list [integer|(integer . integer)]*)
+ − 639 ;; (vector [integer|(integer . integer)]*)
+ − 640 ;;
+ − 641 ;; Cons'd integers get cleaned up a little.
+ − 642
+ − 643 (defun select-convert-from-integer (selection type value)
+ − 644 (cond ((integerp value) ; Integer
+ − 645 value)
444
+ − 646
442
+ − 647 ((and (consp value) ; (integer . integer)
+ − 648 (integerp (car value))
+ − 649 (integerp (cdr value)))
+ − 650 (if (eq (car value) 0)
+ − 651 (cdr value)
+ − 652 (if (and (eq (car value) -1)
+ − 653 (< (cdr value) 0))
+ − 654 (cdr value)
+ − 655 value)))
444
+ − 656
442
+ − 657 ((and (listp value) ; (integer integer)
+ − 658 (eq (length value) 2)
+ − 659 (integerp (car value))
+ − 660 (integerp (cadr value)))
+ − 661 (if (eq (car value) 0)
+ − 662 (cadr value)
+ − 663 (if (and (eq (car value) -1)
+ − 664 (< (cdr value) 0))
+ − 665 (- (cadr value))
+ − 666 (cons (car value) (cadr value)))))
444
+ − 667
442
+ − 668 ((listp value) ; list
+ − 669 (if (cdr value)
+ − 670 (mapcar '(lambda (x)
+ − 671 (select-convert-from-integer selection type x))
+ − 672 value)
+ − 673 (select-convert-from-integer selection type (car value))))
444
+ − 674
442
+ − 675 ((vectorp value) ; vector
+ − 676 (if (eq (length value) 1)
+ − 677 (select-convert-from-integer selection type (aref value 0))
+ − 678 (mapvector '(lambda (x)
+ − 679 (select-convert-from-integer selection type x))
+ − 680 value)))
444
+ − 681
442
+ − 682 (t nil)
+ − 683 ))
+ − 684
428
+ − 685 (defun select-convert-to-atom (selection type value)
+ − 686 (and (symbolp value) value))
+ − 687
442
+ − 688 ;;; CF_xxx conversions
+ − 689 (defun select-convert-from-cf-text (selection type value)
771
+ − 690 (let ((value (decode-coding-string value 'mswindows-multibyte)))
+ − 691 (replace-in-string (if (string-match "\0" value)
+ − 692 (substring value 0 (match-beginning 0))
+ − 693 value)
+ − 694 "\\(\r\n\\|\n\r\\)" "\n" t)))
+ − 695
+ − 696 (defun select-convert-from-cf-unicodetext (selection type value)
+ − 697 (let ((value (decode-coding-string value 'mswindows-unicode)))
+ − 698 (replace-in-string (if (string-match "\0" value)
+ − 699 (substring value 0 (match-beginning 0))
+ − 700 value)
+ − 701 "\\(\r\n\\|\n\r\\)" "\n" t)))
442
+ − 702
+ − 703 (defun select-convert-to-cf-text (selection type value)
+ − 704 (let ((text (select-convert-to-text selection type value)))
771
+ − 705 (encode-coding-string
+ − 706 (concat (replace-in-string text "\n" "\r\n" t) "\0")
+ − 707 'mswindows-multibyte)))
+ − 708
+ − 709 (defun select-convert-to-cf-unicodetext (selection type value)
+ − 710 (let ((text (select-convert-to-text selection type value)))
+ − 711 (encode-coding-string
+ − 712 (concat (replace-in-string text "\n" "\r\n" t) "\0")
+ − 713 'mswindows-unicode)))
442
+ − 714
+ − 715 ;;; Appenders
+ − 716 (defun select-append-to-text (selection type value1 value2)
+ − 717 (let ((text1 (select-convert-to-text selection 'STRING value1))
+ − 718 (text2 (select-convert-to-text selection 'STRING value2)))
+ − 719 (if (and text1 text2)
+ − 720 (concat text1 text2)
+ − 721 nil)))
+ − 722
+ − 723 (defun select-append-to-string (selection type value1 value2)
+ − 724 (select-append-to-text selection type value1 value2))
+ − 725
+ − 726 (defun select-append-to-compound-text (selection type value1 value2)
+ − 727 (select-append-to-text selection type value1 value2))
+ − 728
+ − 729 (defun select-append-to-cf-text (selection type value1 value2)
+ − 730 (let ((text1 (select-convert-from-cf-text selection 'CF_TEXT value1))
+ − 731 (text2 (select-convert-from-cf-text selection 'CF_TEXT value2)))
+ − 732 (if (and text1 text2)
+ − 733 (select-convert-to-cf-text selection type (concat text1 text2))
+ − 734 nil)))
428
+ − 735
771
+ − 736 (defun select-append-to-cf-unicodetext (selection type value1 value2)
+ − 737 (let ((text1 (select-convert-from-cf-unicodetext selection
+ − 738 'CF_UNICODETEXT value1))
+ − 739 (text2 (select-convert-from-cf-unicodetext selection
+ − 740 'CF_UNICODETEXT value2)))
+ − 741 (if (and text1 text2)
+ − 742 (select-convert-to-cf-unicodetext selection type (concat text1 text2))
+ − 743 nil)))
+ − 744
442
+ − 745 (defun select-append-default (selection type value1 value2)
+ − 746 ;; This appender gets used if the type is "nil" - i.e. default.
+ − 747 ;; It should probably have more cases implemented than it does - e.g.
+ − 748 ;; appending numbers to strings, etc...
+ − 749 (cond ((and (stringp value1) (stringp value2))
+ − 750 (select-append-to-string selection 'STRING value1 value2))
+ − 751 (t nil)))
+ − 752
+ − 753 ;;; Buffer kill handlers
+ − 754
+ − 755 (defun select-buffer-killed-default (selection type value buffer)
+ − 756 ;; This handler gets used if the type is "nil".
+ − 757 (cond ((extentp value)
+ − 758 (if (eq (extent-object value) buffer)
+ − 759 ; If this selection is on the clipboard, grab it quick
+ − 760 (when (eq selection 'CLIPBOARD)
+ − 761 (save-excursion
+ − 762 (set-buffer (extent-object value))
+ − 763 (save-restriction
+ − 764 (widen)
+ − 765 (buffer-substring (extent-start-position value)
+ − 766 (extent-end-position value)))))
+ − 767 value))
+ − 768 ((markerp value)
+ − 769 (unless (eq (marker-buffer value) buffer)
+ − 770 value))
+ − 771 ((and (consp value)
+ − 772 (markerp (car value))
+ − 773 (markerp (cdr value)))
+ − 774 (if (or (eq (marker-buffer (car value)) buffer)
+ − 775 (eq (marker-buffer (cdr value)) buffer))
+ − 776 ; If this selection is on the clipboard, grab it quick
+ − 777 (when (eq selection 'CLIPBOARD)
+ − 778 (save-excursion
+ − 779 (set-buffer (marker-buffer (car value)))
+ − 780 (save-restriction
+ − 781 (widen)
+ − 782 (buffer-substring (car value) (cdr value)))))
+ − 783 value))
+ − 784 (t value)))
+ − 785
+ − 786 (defun select-buffer-killed-text (selection type value buffer)
+ − 787 (select-buffer-killed-default selection type value buffer))
444
+ − 788
442
+ − 789 ;; Types listed in here can be selections of XEmacs
+ − 790 (setq selection-converter-out-alist
428
+ − 791 '((TEXT . select-convert-to-text)
+ − 792 (STRING . select-convert-to-string)
+ − 793 (COMPOUND_TEXT . select-convert-to-compound-text)
+ − 794 (TARGETS . select-convert-to-targets)
+ − 795 (LENGTH . select-convert-to-length)
+ − 796 (DELETE . select-convert-to-delete)
+ − 797 (FILE_NAME . select-convert-to-filename)
+ − 798 (CHARACTER_POSITION . select-convert-to-charpos)
+ − 799 (SOURCE_LOC . select-convert-to-sourceloc)
+ − 800 (LINE_NUMBER . select-convert-to-lineno)
+ − 801 (COLUMN_NUMBER . select-convert-to-colno)
+ − 802 (OWNER_OS . select-convert-to-os)
+ − 803 (HOST_NAME . select-convert-to-host)
+ − 804 (USER . select-convert-to-user)
+ − 805 (CLASS . select-convert-to-class)
+ − 806 (NAME . select-convert-to-name)
+ − 807 (ATOM . select-convert-to-atom)
+ − 808 (INTEGER . select-convert-to-integer)
442
+ − 809 (CF_TEXT . select-convert-to-cf-text)
771
+ − 810 (CF_UNICODETEXT . select-convert-to-cf-unicodetext)
442
+ − 811 ))
+ − 812
+ − 813 ;; Types listed here can be selections foreign to XEmacs
+ − 814 (setq selection-converter-in-alist
+ − 815 '(; Specific types that get handled by generic converters
+ − 816 (COMPOUND_TEXT . select-convert-from-text)
+ − 817 (SOURCE_LOC . select-convert-from-text)
+ − 818 (OWNER_OS . select-convert-from-text)
+ − 819 (HOST_NAME . select-convert-from-text)
+ − 820 (USER . select-convert-from-text)
+ − 821 (CLASS . select-convert-from-text)
+ − 822 (NAME . select-convert-from-text)
+ − 823 ; Generic types
+ − 824 (INTEGER . select-convert-from-integer)
+ − 825 (TEXT . select-convert-from-text)
+ − 826 (STRING . select-convert-from-text)
+ − 827 (LENGTH . select-convert-from-length)
+ − 828 (FILE_NAME . select-convert-from-filename)
+ − 829 (CF_TEXT . select-convert-from-cf-text)
771
+ − 830 (CF_UNICODETEXT . select-convert-from-cf-unicodetext)
428
+ − 831 ))
+ − 832
442
+ − 833 ;; Types listed here have special coercion functions that can munge
+ − 834 ;; other types. This can also be used to add special features - e.g.
+ − 835 ;; being able to pass a region or a cons of markers to own-selection,
+ − 836 ;; but getting the *current* text in the region back when calling
+ − 837 ;; get-selection.
+ − 838 ;;
+ − 839 ;; Any function listed in here *will be called* whenever a value of
+ − 840 ;; its type is retrieved from the internal selection cache, or when
+ − 841 ;; no suitable values could be found in which case XEmacs looks for
+ − 842 ;; values with types listed in selection-coercible-types.
+ − 843 (setq selection-coercion-alist
+ − 844 '((TEXT . select-coerce-to-text)
+ − 845 (STRING . select-coerce-to-text)
+ − 846 (COMPOUND_TEXT . select-coerce-to-text)
771
+ − 847 (CF_TEXT . select-coerce-to-text)
+ − 848 (CF_UNICODETEXT . select-coerce-to-text)
+ − 849 ))
442
+ − 850
+ − 851 ;; Types listed here can be appended by own-selection
+ − 852 (setq selection-appender-alist
+ − 853 '((nil . select-append-default)
+ − 854 (TEXT . select-append-to-text)
+ − 855 (STRING . select-append-to-string)
+ − 856 (COMPOUND_TEXT . select-append-to-compound-text)
+ − 857 (CF_TEXT . select-append-to-cf-text)
771
+ − 858 (CF_UNICODETEXT . select-append-to-cf-unicodetext)
442
+ − 859 ))
+ − 860
+ − 861 ;; Types listed here have buffer-kill handlers
+ − 862 (setq selection-buffer-killed-alist
+ − 863 '((nil . select-buffer-killed-default)
+ − 864 (TEXT . select-buffer-killed-text)
+ − 865 (STRING . select-buffer-killed-text)
+ − 866 (COMPOUND_TEXT . select-buffer-killed-text)
771
+ − 867 (CF_TEXT . select-buffer-killed-text)
+ − 868 (CF_UNICODETEXT . select-buffer-killed-text)
+ − 869 ))
442
+ − 870
+ − 871 ;; Lists of types that are coercible (can be converted to other types)
771
+ − 872 (setq selection-coercible-types '(TEXT STRING COMPOUND_TEXT CF_TEXT CF_UNICODETEXT))
442
+ − 873
428
+ − 874 ;;; select.el ends here