annotate lisp/select.el @ 444:576fb035e263 r21-2-37

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