annotate lisp/select.el @ 2570:269c376d86ef

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