annotate src/select.c @ 410:de805c49cfc1 r21-2-35

Import from CVS: tag r21-2-35
author cvs
date Mon, 13 Aug 2007 11:19:21 +0200
parents 74fd4e045ea6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
1 /* Generic selection processing for XEmacs
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
2 Copyright (C) 1999 Free Software Foundation, Inc.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
3 Copyright (C) 1999 Andy Piper.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
4
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
5 This file is part of XEmacs.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
6
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
10 later version.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
11
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
15 for more details.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
16
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
21
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
22 /* Synched up with: Not synched with FSF. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
23
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
24 #include <config.h>
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
25 #include "lisp.h"
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
26
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
27 #include "buffer.h"
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
28 #include "device.h"
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
29 #include "extents.h"
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
30 #include "console.h"
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
31 #include "objects.h"
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
32
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
33 #include "frame.h"
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
34 #include "opaque.h"
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
35 #include "select.h"
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
36
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
37 /* X Atoms */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
38 Lisp_Object QPRIMARY, QSECONDARY, QSTRING, QINTEGER, QCLIPBOARD, QTIMESTAMP,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
39 QTEXT, QDELETE, QMULTIPLE, QINCR, QEMACS_TMP, QTARGETS, QATOM, QNULL,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
40 QATOM_PAIR, QCOMPOUND_TEXT;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
41
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
42 /* Windows clipboard formats */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
43 Lisp_Object QCF_TEXT, QCF_BITMAP, QCF_METAFILEPICT, QCF_SYLK, QCF_DIF,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
44 QCF_TIFF, QCF_OEMTEXT, QCF_DIB, QCF_PALETTE, QCF_PENDATA, QCF_RIFF,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
45 QCF_WAVE, QCF_UNICODETEXT, QCF_ENHMETAFILE, QCF_HDROP, QCF_LOCALE,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
46 QCF_OWNERDISPLAY, QCF_DSPTEXT, QCF_DSPBITMAP, QCF_DSPMETAFILEPICT,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
47 QCF_DSPENHMETAFILE;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
48
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
49 /* Selection strategy symbols */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
50 Lisp_Object Qreplace_all, Qreplace_existing;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
51
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
52 /* "Selection owner couldn't convert selection" */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
53 Lisp_Object Qselection_conversion_error;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
54
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
55 /* A couple of Lisp functions */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
56 Lisp_Object Qselect_convert_in, Qselect_convert_out;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
57
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
58 /* These are alists whose CARs are selection-types (whose names are the same
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
59 as the names of X Atoms or Windows clipboard formats) and whose CDRs are
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
60 the names of Lisp functions to call to convert the given Emacs selection
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
61 value to a string representing the given selection type. This is for
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
62 elisp-level extension of the emacs selection handling.
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
63 */
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
64 Lisp_Object Vselection_converter_out_alist;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
65 Lisp_Object Vselection_converter_in_alist;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
66 Lisp_Object Vselection_appender_alist;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
67 Lisp_Object Vselection_buffer_killed_alist;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
68 Lisp_Object Vselection_coercible_types;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
69
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
70 Lisp_Object Vlost_selection_hooks;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
71
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
72 /* This is an association list whose elements are of the form
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
73 ( selection-name selection-value selection-timestamp )
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
74 selection-name is a lisp symbol, whose name is the name of an X Atom.
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
75 selection-value is a list of cons pairs that emacs owns for that selection.
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
76 Each pair consists of (type . value), where type is nil or a
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
77 selection data type, and value is any type of Lisp object.
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
78 selection-timestamp is the time at which emacs began owning this selection,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
79 as a cons of two 16-bit numbers (making a 32 bit time).
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
80 If there is an entry in this alist, then it can be assumed that emacs owns
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
81 that selection.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
82 The only (eq) parts of this list that are visible from elisp are the
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
83 selection-values.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
84 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
85 Lisp_Object Vselection_alist;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
86
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
87 /* Given a selection-name and desired type, this looks up our local copy of
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
88 the selection value and converts it to the type. */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
89 static Lisp_Object
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
90 get_local_selection (Lisp_Object selection_symbol, Lisp_Object target_type)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
91 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
92 Lisp_Object local_value = assq_no_quit (selection_symbol, Vselection_alist);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
93
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
94 if (!NILP (local_value))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
95 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
96 Lisp_Object value_list = XCAR (XCDR (local_value));
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
97 Lisp_Object value;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
98
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
99 /* First try to find an entry of the appropriate type */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
100 value = assq_no_quit (target_type, value_list);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
101
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
102 if (!NILP (value))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
103 return XCDR (value);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
104 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
105
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
106 return Qnil;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
107 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
108
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
109 /* #### Should perhaps handle 'MULTIPLE. The code below is now completely
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
110 broken due to a re-organization of get_local_selection, but I've left
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
111 it here should anyone show an interest - ajh */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
112 #if 0
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
113 else if (CONSP (target_type) &&
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
114 XCAR (target_type) == QMULTIPLE)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
115 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
116 Lisp_Object pairs = XCDR (target_type);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
117 int len = XVECTOR_LENGTH (pairs);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
118 int i;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
119 /* If the target is MULTIPLE, then target_type looks like
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
120 (MULTIPLE . [[SELECTION1 TARGET1] [SELECTION2 TARGET2] ... ])
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
121 We modify the second element of each pair in the vector and
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
122 return it as [[SELECTION1 <value1>] [SELECTION2 <value2>] ... ]
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
123 */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
124 for (i = 0; i < len; i++)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
125 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
126 Lisp_Object pair = XVECTOR_DATA (pairs) [i];
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
127 XVECTOR_DATA (pair) [1] =
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
128 x_get_local_selection (XVECTOR_DATA (pair) [0],
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
129 XVECTOR_DATA (pair) [1]);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
130 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
131 return pairs;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
132 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
133 #endif
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
134
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
135 DEFUN ("own-selection-internal", Fown_selection_internal, 2, 5, 0, /*
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
136 Assert a selection of the given NAME with the given VALUE, and
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
137 optional window-system DATA-TYPE. HOW-TO-ADD specifies how the
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
138 selection will be combined with any existing selection(s) - see
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
139 `own-selection' for more information.
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
140 NAME is a symbol, typically PRIMARY, SECONDARY, or CLIPBOARD.
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
141 VALUE is typically a string, or a cons of two markers, but may be
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
142 anything that the functions on selection-converter-out-alist know about.
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
143 */
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
144 (selection_name, selection_value, how_to_add, data_type, device))
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
145 {
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
146 Lisp_Object selection_time, selection_data, prev_value = Qnil,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
147 value_list = Qnil;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
148 Lisp_Object prev_real_value = Qnil;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
149 struct gcpro gcpro1;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
150
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
151 CHECK_SYMBOL (selection_name);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
152 if (NILP (selection_value)) error ("selection-value may not be nil.");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
153
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
154 if (NILP (device))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
155 device = Fselected_device (Qnil);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
156
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
157 if (!EQ (how_to_add, Qappend) && !EQ (how_to_add, Qt)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
158 && !EQ (how_to_add, Qreplace_existing)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
159 && !EQ (how_to_add, Qreplace_all) && !NILP (how_to_add))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
160 error ("how-to-add must be nil, append, replace_all, "
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
161 "replace_existing or t.");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
162
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
163 #ifdef MULE
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
164 if (NILP (data_type))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
165 data_type = QCOMPOUND_TEXT;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
166 #else
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
167 if (NILP (data_type))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
168 data_type = QSTRING;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
169 #endif
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
170
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
171 /* Examine the how-to-add argument */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
172 if (EQ (how_to_add, Qreplace_all) || NILP (how_to_add))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
173 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
174 Lisp_Object local_selection_data = assq_no_quit (selection_name,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
175 Vselection_alist);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
176
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
177 if (!NILP (local_selection_data))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
178 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
179 /* Don't use Fdelq() as that may QUIT;. */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
180 if (EQ (local_selection_data, Fcar (Vselection_alist)))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
181 Vselection_alist = Fcdr (Vselection_alist);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
182 else
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
183 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
184 Lisp_Object rest;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
185 for (rest = Vselection_alist; !NILP (rest); rest = Fcdr (rest))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
186 if (EQ (local_selection_data, Fcar (XCDR (rest))))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
187 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
188 XCDR (rest) = Fcdr (XCDR (rest));
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
189 break;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
190 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
191 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
192 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
193 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
194 else
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
195 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
196 /* Look for a previous value */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
197 prev_value = assq_no_quit (selection_name, Vselection_alist);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
198
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
199 if (!NILP (prev_value))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
200 value_list = XCAR (XCDR (prev_value));
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
201
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
202 if (!NILP (value_list))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
203 prev_real_value = assq_no_quit (data_type, value_list);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
204 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
205
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
206 /* Append values if necessary */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
207 if (!NILP (value_list) && (EQ (how_to_add, Qappend) || EQ (how_to_add, Qt)))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
208 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
209 /* Did we have anything of this type previously? */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
210 if (!NILP (prev_real_value))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
211 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
212 if ((NILP (data_type) && STRINGP (selection_value)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
213 && STRINGP (XCDR (prev_real_value)))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
214 || !NILP (data_type))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
215 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
216 Lisp_Object function = assq_no_quit (data_type,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
217 Vselection_appender_alist);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
218
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
219 if (NILP (function))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
220 error ("cannot append selections of supplied types.");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
221
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
222 function = XCDR (function);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
223
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
224 selection_value = call4 (function,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
225 selection_name,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
226 data_type,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
227 XCDR (prev_real_value),
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
228 selection_value);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
229
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
230 if (NILP (selection_value))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
231 error ("cannot append selections of supplied types.");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
232 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
233 else
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
234 error ("cannot append selections of supplied types.");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
235 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
236
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
237 selection_data = Fcons (data_type, selection_value);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
238 value_list = Fcons (selection_data, value_list);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
239 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
240
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
241 if (!NILP (prev_real_value))
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
242 {
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
243 Lisp_Object rest; /* We know it isn't the CAR, so it's easy. */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
244
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
245 /* Delete the old type entry from the list */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
246 for (rest = value_list; !NILP (rest); rest = Fcdr (rest))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
247 if (EQ (prev_real_value, Fcar (XCDR (rest))))
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
248 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
249 XCDR (rest) = Fcdr (XCDR (rest));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
250 break;
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
251 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
252 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
253 else
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
254 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
255 value_list = Fcons (Fcons (data_type, selection_value),
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
256 value_list);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
257 }
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
258
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
259 /* Complete the local cache update; note that we destructively
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
260 modify the current list entry if there is one */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
261 if (NILP (prev_value))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
262 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
263 selection_data = list3 (selection_name, value_list, Qnil);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
264 Vselection_alist = Fcons (selection_data, Vselection_alist);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
265 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
266 else
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
267 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
268 selection_data = prev_value;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
269 Fsetcar (XCDR (selection_data), value_list);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
270 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
271
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
272 GCPRO1 (selection_data);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
273
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
274 /* have to do device specific stuff last so that methods can access the
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
275 selection_alist */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
276 if (HAS_DEVMETH_P (XDEVICE (device), own_selection))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
277 selection_time = DEVMETH (XDEVICE (device), own_selection,
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
278 (selection_name, selection_value,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
279 how_to_add, data_type));
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
280 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
281 selection_time = Qnil;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
282
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
283 Fsetcar (XCDR (XCDR (selection_data)), selection_time);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
284
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
285 UNGCPRO;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
286
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
287 return selection_value;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
288 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
289
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
290 DEFUN ("register-selection-data-type", Fregister_selection_data_type, 1,2,0, /*
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
291 Register a new selection data type DATA-TYPE, optionally on the specified
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
292 DEVICE. Returns the device-specific data type identifier, or nil if the
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
293 device does not support this feature or the registration fails. */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
294 (data_type, device))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
295 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
296 /* Check arguments */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
297 CHECK_STRING (data_type);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
298
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
299 if (NILP (device))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
300 device = Fselected_device (Qnil);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
301
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
302 if (HAS_DEVMETH_P (XDEVICE (device), register_selection_data_type))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
303 return DEVMETH (XDEVICE (device), register_selection_data_type,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
304 (data_type));
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
305 else
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
306 return Qnil;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
307 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
308
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
309 DEFUN ("selection-data-type-name", Fselection_data_type_name, 1, 2, 0, /*
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
310 Retrieve the name of the specified selection data type DATA-TYPE, optionally
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
311 on the specified DEVICE. Returns either a string or a symbol on success, and
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
312 nil if the device does not support this feature or the type is not known. */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
313 (data_type, device))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
314 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
315 if (NILP (device))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
316 device = Fselected_device (Qnil);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
317
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
318 if (HAS_DEVMETH_P (XDEVICE (device), selection_data_type_name))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
319 return DEVMETH (XDEVICE (device), selection_data_type_name, (data_type));
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
320 else
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
321 return Qnil;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
322 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
323
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
324 DEFUN ("available-selection-types", Favailable_selection_types, 1, 2, 0, /*
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
325 Retrieve a list of currently available types of selection associated with
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
326 the given SELECTION-NAME, optionally on the specified DEVICE. This list
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
327 does not take into account any possible conversions that might take place,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
328 so it should be taken as a minimal estimate of what is available.
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
329 */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
330 (selection_name, device))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
331 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
332 Lisp_Object types = Qnil, rest;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
333 struct gcpro gcpro1;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
334
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
335 CHECK_SYMBOL (selection_name);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
336
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
337 if (NILP (device))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
338 device = Fselected_device (Qnil);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
339
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
340 GCPRO1 (types);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
341
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
342 /* First check the device */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
343 if (HAS_DEVMETH_P (XDEVICE (device), available_selection_types))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
344 types = DEVMETH (XDEVICE (device), available_selection_types,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
345 (selection_name));
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
346
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
347 /* Now look in the list */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
348 rest = assq_no_quit (selection_name, Vselection_alist);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
349
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
350 if (NILP (rest))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
351 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
352 UNGCPRO;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
353
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
354 return types;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
355 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
356
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
357 /* Examine the types and cons them onto the front of the list */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
358 for (rest = XCAR (XCDR (rest)); !NILP (rest); rest = XCDR (rest))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
359 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
360 Lisp_Object value = XCDR (XCAR (rest));
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
361 Lisp_Object type = XCAR (XCAR (rest));
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
362
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
363 types = Fcons (type, types);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
364
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
365 if ((STRINGP (value) || EXTENTP (value))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
366 && (NILP (type) || EQ (type, QSTRING)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
367 || EQ (type, QTEXT) || EQ (type, QCOMPOUND_TEXT)))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
368 types = Fcons (QTEXT, Fcons (QCOMPOUND_TEXT, Fcons (QSTRING, types)));
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
369 else if (INTP (value) && NILP (type))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
370 types = Fcons (QINTEGER, types);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
371 else if (SYMBOLP (value) && NILP (type))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
372 types = Fcons (QATOM, types);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
373 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
374
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
375 UNGCPRO;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
376
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
377 return types;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
378 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
379
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
380 /* remove a selection from our local copy
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
381 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
382 void
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
383 handle_selection_clear (Lisp_Object selection_symbol)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
384 {
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
385 Lisp_Object local_selection_data = assq_no_quit (selection_symbol,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
386 Vselection_alist);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
387
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
388 /* Well, we already believe that we don't own it, so that's just fine. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
389 if (NILP (local_selection_data)) return;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
390
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
391 /* Otherwise, we're really honest and truly being told to drop it.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
392 Don't use Fdelq() as that may QUIT;.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
393 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
394 if (EQ (local_selection_data, Fcar (Vselection_alist)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
395 Vselection_alist = Fcdr (Vselection_alist);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
396 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
397 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
398 Lisp_Object rest;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
399 for (rest = Vselection_alist; !NILP (rest); rest = Fcdr (rest))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
400 if (EQ (local_selection_data, Fcar (XCDR (rest))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
401 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
402 XCDR (rest) = Fcdr (XCDR (rest));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
403 break;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
404 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
405 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
406
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
407 /* Let random lisp code notice that the selection has been stolen.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
408 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
409 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
410 Lisp_Object rest;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
411 Lisp_Object val = Vlost_selection_hooks;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
412 if (!UNBOUNDP (val) && !NILP (val))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
413 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
414 if (CONSP (val) && !EQ (XCAR (val), Qlambda))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
415 for (rest = val; !NILP (rest); rest = Fcdr (rest))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
416 call1 (Fcar (rest), selection_symbol);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
417 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
418 call1 (val, selection_symbol);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
419 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
420 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
421 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
422
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
423 DEFUN ("disown-selection-internal", Fdisown_selection_internal, 1, 3, 0, /*
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
424 If we own the named selection, then disown it (make there be no selection).
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
425 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
426 (selection_name, selection_time, device))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
427 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
428 if (NILP (assq_no_quit (selection_name, Vselection_alist)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
429 return Qnil; /* Don't disown the selection when we're not the owner. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
430
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
431 if (NILP (device))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
432 device = Fselected_device (Qnil);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
433
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
434 MAYBE_DEVMETH (XDEVICE (device), disown_selection,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
435 (selection_name, selection_time));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
436
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
437 handle_selection_clear (selection_name);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
438
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
439 return Qt;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
440 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
441
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
442 DEFUN ("selection-owner-p", Fselection_owner_p, 0, 1, 0, /*
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
443 Return t if current emacs process owns the given Selection.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
444 The arg should be the name of the selection in question, typically one of
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
445 the symbols PRIMARY, SECONDARY, or CLIPBOARD. (For convenience, the symbol
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
446 nil is the same as PRIMARY, and t is the same as SECONDARY.)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
447 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
448 (selection))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
449 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
450 CHECK_SYMBOL (selection);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
451 if (EQ (selection, Qnil)) selection = QPRIMARY;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
452 else if (EQ (selection, Qt)) selection = QSECONDARY;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
453
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
454 return NILP (Fassq (selection, Vselection_alist)) ? Qnil : Qt;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
455 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
456
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
457 DEFUN ("selection-exists-p", Fselection_exists_p, 0, 3, 0, /*
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
458 Whether there is an owner for the given Selection.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
459 The arg should be the name of the selection in question, typically one of
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
460 the symbols PRIMARY, SECONDARY, or CLIPBOARD. (For convenience, the symbol
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
461 nil is the same as PRIMARY, and t is the same as SECONDARY.)
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
462 Optionally the DEVICE and the window-system DATA-TYPE may be specified.
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
463 */
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
464 (selection, data_type, device))
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
465 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
466 CHECK_SYMBOL (selection);
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
467 if (NILP (data_type)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
468 && !NILP (Fselection_owner_p (selection)))
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
469 return Qt;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
470
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
471 if (NILP (device))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
472 device = Fselected_device (Qnil);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
473
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
474 return HAS_DEVMETH_P (XDEVICE (device), selection_exists_p) ?
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
475 DEVMETH (XDEVICE (device), selection_exists_p, (selection, data_type))
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
476 : Qnil;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
477 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
478
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
479 /* Get the timestamp of the given selection */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
480 DEFUN ("get-selection-timestamp", Fget_selection_timestamp, 1, 1, 0, /*
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
481 Return the timestamp associated with the specified SELECTION, if it exists.
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
482 Note that the timestamp is a device-specific object, and may not actually be
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
483 visible from Lisp.
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
484 */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
485 (selection))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
486 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
487 Lisp_Object local_value = assq_no_quit (selection, Vselection_alist);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
488
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
489 if (!NILP (local_value))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
490 return XCAR (XCDR (XCDR (local_value)));
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
491
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
492 return Qnil;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
493 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
494
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
495 /* Request the selection value from the owner. If we are the owner,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
496 simply return our selection value. If we are not the owner, this
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
497 will block until all of the data has arrived.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
498 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
499 DEFUN ("get-selection-internal", Fget_selection_internal, 2, 3, 0, /*
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
500 Return text selected from some window-system window.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
501 SELECTION_SYMBOL is a symbol, typically PRIMARY, SECONDARY, or CLIPBOARD.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
502 TARGET_TYPE is the type of data desired, typically STRING or COMPOUND_TEXT.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
503 Under Mule, if the resultant data comes back as 8-bit data in type
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
504 TEXT or COMPOUND_TEXT, it will be decoded as Compound Text.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
505 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
506 (selection_symbol, target_type, device))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
507 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
508 /* This function can GC */
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
509 Lisp_Object val = Qnil, element = Qnil;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
510 struct gcpro gcpro1, gcpro2, gcpro3;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
511 GCPRO3 (target_type, val, element);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
512 CHECK_SYMBOL (selection_symbol);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
513
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
514 if (NILP (device))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
515 device = Fselected_device (Qnil);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
516
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
517 #ifdef MULE
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
518 if (NILP (target_type))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
519 target_type = QCOMPOUND_TEXT;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
520 #else
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
521 if (NILP (target_type))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
522 target_type = QSTRING;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
523 #endif
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
524
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
525 #if 0 /* #### MULTIPLE doesn't work yet and probably never will */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
526 if (CONSP (target_type) &&
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
527 XCAR (target_type) == QMULTIPLE)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
528 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
529 CHECK_VECTOR (XCDR (target_type));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
530 /* So we don't destructively modify this... */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
531 target_type = copy_multiple_data (target_type);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
532 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
533 #endif
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
534
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
535 /* Used to check that target_type was a symbol. This is no longer
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
536 necessarily the case, because the type might be registered with
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
537 the device (in which case target_type would be a device-specific
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
538 identifier - probably an integer) - ajh */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
539
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
540 val = get_local_selection (selection_symbol, target_type);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
541
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
542 if (NILP (val) && (HAS_DEVMETH_P (XDEVICE (device), get_foreign_selection)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
543 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
544 val = DEVMETH (XDEVICE (device), get_foreign_selection,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
545 (selection_symbol, target_type));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
546 }
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
547
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
548 if (NILP (val))
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
549 {
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
550 /* Still nothing. Try coercion. */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
551
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
552 /* Try looking in selection-coercible-types to see if any of
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
553 them are present for this selection. We try them *in order*;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
554 the first for which a conversion succeeds gets returned. */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
555 EXTERNAL_LIST_LOOP_2 (element, Vselection_coercible_types)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
556 {
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
557 val = get_local_selection (selection_symbol, element);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
558
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
559 if (NILP (val))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
560 continue;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
561
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
562 /* #### Probably should have a Qselection_coercion_alist and a
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
563 select-coerce function. */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
564 val = call3 (Qselect_convert_out,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
565 selection_symbol, target_type, val);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
566
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
567 if (!NILP (val))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
568 break;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
569 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
570 }
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
571
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
572 if (NILP (val))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
573 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
574 UNGCPRO;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
575
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
576 return Qnil;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
577 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
578
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
579 /* Used to call clean_local_selection here... but that really belonged
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
580 in Lisp (so the equivalent is now built-in to the INTEGER conversion
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
581 function select-convert-from-integer) - ajh */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
582
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
583 UNGCPRO;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
584 return val;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
585 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
586
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
587 /* These two are convenient interfaces to the lisp code in select.el;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
588 this way we can rename them easily rather than having to hunt everywhere.
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
589 Also, this gives us access to get_local_selection so that convert_out
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
590 can retrieve the internal selection value automatically if passed a
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
591 value of Qnil. */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
592 Lisp_Object
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
593 select_convert_in (Lisp_Object selection,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
594 Lisp_Object type,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
595 Lisp_Object value)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
596 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
597 return call3 (Qselect_convert_in, selection, type, value);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
598 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
599
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
600 Lisp_Object
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
601 select_convert_out (Lisp_Object selection,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
602 Lisp_Object type,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
603 Lisp_Object value)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
604 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
605 if (NILP (value))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
606 value = get_local_selection (selection, type);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
607
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
608 if (NILP (value))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
609 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
610 Lisp_Object element = Qnil, ret;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
611 struct gcpro gcpro1;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
612 GCPRO1 (element);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
613
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
614 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
615 /* Try looking in selection-coercible-types to see if any of
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
616 them are present for this selection. We try them *in order*;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
617 the first for which a conversion succeeds gets returned. */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
618 EXTERNAL_LIST_LOOP_2 (element, Vselection_coercible_types)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
619 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
620 value = get_local_selection (selection, element);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
621
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
622 if (NILP (value))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
623 continue;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
624
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
625 ret = call3 (Qselect_convert_out, selection, type, value);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
626
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
627 if (!NILP (ret))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
628 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
629 UNGCPRO;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
630
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
631 return ret;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
632 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
633 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
634 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
635
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
636 UNGCPRO;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
637
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
638 return Qnil;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
639 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
640
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
641 return call3 (Qselect_convert_out, selection, type, value);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
642 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
643
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
644
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
645 /* Gets called from kill-buffer; this lets us dispose of buffer-dependent
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
646 selections (or alternatively make them independent of the buffer) when
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
647 it gets vaped. */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
648 void
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
649 select_notify_buffer_kill (Lisp_Object buffer)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
650 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
651 Lisp_Object rest;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
652 struct gcpro gcpro1, gcpro2, gcpro3;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
653
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
654 /* For each element of Vselection_alist */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
655 for (rest = Vselection_alist;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
656 !NILP (rest);)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
657 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
658 Lisp_Object selection, values, prev = Qnil;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
659
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
660 selection = XCAR (rest);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
661
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
662 for (values = XCAR (XCDR (selection));
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
663 !NILP (values);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
664 values = XCDR (values))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
665 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
666 Lisp_Object value, handler_fn;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
667
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
668 /* Extract the (type . value) pair. */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
669 value = XCAR (values);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
670
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
671 /* Find the handler function (if any). */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
672 handler_fn = Fcdr (Fassq (XCAR (value),
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
673 Vselection_buffer_killed_alist));
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
674
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
675 if (!NILP (handler_fn))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
676 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
677 Lisp_Object newval;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
678
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
679 /* Protect ourselves, just in case some tomfool calls
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
680 own-selection from with the buffer-killed handler, then
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
681 causes a GC. Just as a note, *don't do this*. */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
682 GCPRO3 (rest, values, value);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
683
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
684 newval = call4 (handler_fn, XCAR (selection), XCAR (value),
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
685 XCDR (value), buffer);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
686
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
687 UNGCPRO;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
688
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
689 /* Set or delete the value (by destructively modifying
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
690 the list). */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
691 if (!NILP (newval))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
692 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
693 Fsetcdr (value, newval);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
694
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
695 prev = values;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
696 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
697 else
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
698 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
699 if (NILP (prev))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
700 Fsetcar (XCDR (selection), XCDR (values));
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
701 else
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
702 Fsetcdr (prev, XCDR (values));
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
703 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
704 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
705 else
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
706 prev = values;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
707 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
708
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
709 /* If we have no values for this selection */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
710 if (NILP (XCAR (XCDR (selection))))
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
711 {
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
712 /* Move on to the next element *first* */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
713 rest = XCDR (rest);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
714
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
715 /* Protect it and disown this selection */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
716 GCPRO1 (rest);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
717
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
718 Fdisown_selection_internal (XCAR (selection), Qnil, Qnil);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
719
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
720 UNGCPRO;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
721 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
722 else
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
723 rest = XCDR (rest);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
724 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
725 }
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
726
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
727
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
728 void
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
729 syms_of_select (void)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
730 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
731 DEFSUBR (Fown_selection_internal);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
732 DEFSUBR (Fget_selection_internal);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
733 DEFSUBR (Fselection_exists_p);
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
734 DEFSUBR (Fget_selection_timestamp);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
735 DEFSUBR (Fdisown_selection_internal);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
736 DEFSUBR (Fselection_owner_p);
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
737 DEFSUBR (Favailable_selection_types);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
738 DEFSUBR (Fregister_selection_data_type);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
739 DEFSUBR (Fselection_data_type_name);
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
740
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
741 /* Lisp Functions */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
742 defsymbol (&Qselect_convert_in, "select-convert-in");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
743 defsymbol (&Qselect_convert_out, "select-convert-out");
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
744
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
745 /* X Atoms */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
746 defsymbol (&QPRIMARY, "PRIMARY");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
747 defsymbol (&QSECONDARY, "SECONDARY");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
748 defsymbol (&QSTRING, "STRING");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
749 defsymbol (&QINTEGER, "INTEGER");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
750 defsymbol (&QCLIPBOARD, "CLIPBOARD");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
751 defsymbol (&QTIMESTAMP, "TIMESTAMP");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
752 defsymbol (&QTEXT, "TEXT");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
753 defsymbol (&QDELETE, "DELETE");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
754 defsymbol (&QMULTIPLE, "MULTIPLE");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
755 defsymbol (&QINCR, "INCR");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
756 defsymbol (&QEMACS_TMP, "_EMACS_TMP_");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
757 defsymbol (&QTARGETS, "TARGETS");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
758 defsymbol (&QATOM, "ATOM");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
759 defsymbol (&QATOM_PAIR, "ATOM_PAIR");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
760 defsymbol (&QCOMPOUND_TEXT, "COMPOUND_TEXT");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
761 defsymbol (&QNULL, "NULL");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
762
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
763 /* Windows formats - these all start with CF_ */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
764 defsymbol (&QCF_TEXT, "CF_TEXT");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
765 defsymbol (&QCF_BITMAP, "CF_BITMAP");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
766 defsymbol (&QCF_METAFILEPICT, "CF_METAFILEPICT");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
767 defsymbol (&QCF_SYLK, "CF_SYLK");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
768 defsymbol (&QCF_DIF, "CF_DIF");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
769 defsymbol (&QCF_TIFF, "CF_TIFF");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
770 defsymbol (&QCF_OEMTEXT, "CF_OEMTEXT");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
771 defsymbol (&QCF_DIB, "CF_DIB");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
772 defsymbol (&QCF_PALETTE, "CF_PALETTE");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
773 defsymbol (&QCF_PENDATA, "CF_PENDATA");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
774 defsymbol (&QCF_RIFF, "CF_RIFF");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
775 defsymbol (&QCF_WAVE, "CF_WAVE");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
776 defsymbol (&QCF_UNICODETEXT, "CF_UNICODETEXT");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
777 defsymbol (&QCF_ENHMETAFILE, "CF_ENHMETAFILE");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
778 defsymbol (&QCF_HDROP, "CF_HDROP");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
779 defsymbol (&QCF_LOCALE, "CF_LOCALE");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
780 defsymbol (&QCF_OWNERDISPLAY, "CF_OWNERDISPLAY");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
781 defsymbol (&QCF_DSPTEXT, "CF_DSPTEXT");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
782 defsymbol (&QCF_DSPBITMAP, "CF_DSPBITMAP");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
783 defsymbol (&QCF_DSPMETAFILEPICT, "CF_DSPMETAFILEPICT");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
784 defsymbol (&QCF_DSPENHMETAFILE, "CF_DSPENHMETAFILE");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
785
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
786 /* Selection strategies */
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
787 defsymbol (&Qreplace_all, "replace-all");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
788 defsymbol (&Qreplace_existing, "replace-existing");
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
789
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
790 deferror (&Qselection_conversion_error,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
791 "selection-conversion-error",
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
792 "selection-conversion error", Qio_error);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
793 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
794
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
795 void
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
796 vars_of_select (void)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
797 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
798 Vselection_alist = Qnil;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
799 staticpro (&Vselection_alist);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
800
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
801 DEFVAR_LISP ("selection-converter-alist", &Vselection_converter_out_alist /*
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
802 An alist associating selection-types (such as STRING and TIMESTAMP) with
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
803 functions. This is an alias for `selection-converter-out-alist', and should
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
804 be considered obsolete. Use the new name instead. */ );
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
805
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
806 DEFVAR_LISP ("selection-converter-out-alist",
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
807 &Vselection_converter_out_alist /*
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
808 An alist associating selection-types (such as STRING and TIMESTAMP) with
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
809 functions. These functions will be called with three args: the name
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
810 of the selection (typically PRIMARY, SECONDARY, or CLIPBOARD); a
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
811 desired type to which the selection should be converted; and the local
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
812 selection value (whatever had been passed to `own-selection').
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
813
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
814 The return type of these functions depends upon the device in question;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
815 for mswindows, a string should be returned containing data in the requested
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
816 format, or nil to indicate that the conversion could not be done. Additionally,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
817 it is permissible to return a cons of the form (DATA-TYPE . STRING) suggesting
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
818 a new data type to use instead.
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
819
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
820 For X, the return value should be one of:
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
821
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
822 -- nil (the conversion could not be done)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
823 -- a cons of a symbol and any of the following values; the symbol
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
824 explicitly specifies the type that will be sent.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
825 -- a string (If the type is not specified, then if Mule support exists,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
826 the string will be converted to Compound Text and sent in
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
827 the 'COMPOUND_TEXT format; otherwise (no Mule support),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
828 the string will be left as-is and sent in the 'STRING
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
829 format. If the type is specified, the string will be
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
830 left as-is (or converted to binary format under Mule).
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
831 In all cases, 8-bit data it sent.)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
832 -- a character (With Mule support, will be converted to Compound Text
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
833 whether or not a type is specified. If a type is not
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
834 specified, a type of 'STRING or 'COMPOUND_TEXT will be
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
835 sent, as for strings.)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
836 -- the symbol 'NULL (Indicates that there is no meaningful return value.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
837 Empty 32-bit data with a type of 'NULL will be sent.)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
838 -- a symbol (Will be converted into an atom. If the type is not specified,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
839 a type of 'ATOM will be sent.)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
840 -- an integer (Will be converted into a 16-bit or 32-bit integer depending
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
841 on the value. If the type is not specified, a type of
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
842 'INTEGER will be sent.)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
843 -- a cons (HIGH . LOW) of integers (Will be converted into a 32-bit integer.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
844 If the type is not specified, a type of
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
845 'INTEGER will be sent.)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
846 -- a vector of symbols (Will be converted into a list of atoms. If the type
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
847 is not specified, a type of 'ATOM will be sent.)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
848 -- a vector of integers (Will be converted into a list of 16-bit integers.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
849 If the type is not specified, a type of 'INTEGER
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
850 will be sent.)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
851 -- a vector of integers and/or conses (HIGH . LOW) of integers
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
852 (Will be converted into a list of 16-bit integers.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
853 If the type is not specified, a type of 'INTEGER
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
854 will be sent.)
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
855 */ );
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
856 Vselection_converter_out_alist = Qnil;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
857
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
858 DEFVAR_LISP ("selection-converter-in-alist",
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
859 &Vselection_converter_in_alist /*
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
860 An alist associating selection-types (such as STRING and TIMESTAMP) with
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
861 functions. These functions will be called with three args: the name
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
862 of the selection (typically PRIMARY, SECONDARY or CLIPBOARD); the
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
863 type from which the selection should be converted; and the selection
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
864 value. These functions should return a suitable representation of the
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
865 value, or nil to indicate that the conversion was not possible.
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
866
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
867 See also `selection-converter-out-alist'. */ );
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
868 Vselection_converter_in_alist = Qnil;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
869
410
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
870 DEFVAR_LISP ("selection-appender-alist",
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
871 &Vselection_appender_alist /*
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
872 An alist associating selection-types (such as STRING and TIMESTAMP) with
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
873 functions. These functions will be called with four args; the name
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
874 of the selection (typically PRIMARY, SECONDARY or CLIPBOARD); the type
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
875 of the selection; and two selection values. The functions are expected to
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
876 return a value representing the catenation of the two values, or nil to
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
877 indicate that this was not possible. */ );
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
878 Vselection_appender_alist = Qnil;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
879
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
880 DEFVAR_LISP ("selection-buffer-killed-alist",
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
881 &Vselection_buffer_killed_alist /*
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
882 An alist associating selection-types (such as STRING and TIMESTAMP) with
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
883 functions. These functions will be called whenever a buffer is killed,
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
884 with four args: the name of the selection (typically PRIMARY, SECONDARY
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
885 or CLIPBOARD); the type of the selection; the value of the selection; and
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
886 the buffer that has just been killed. These functions should return a new
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
887 selection value, or nil to indicate that the selection value should be
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
888 deleted. */ );
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
889 Vselection_buffer_killed_alist = Qnil;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
890
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
891 DEFVAR_LISP ("selection-coercible-types",
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
892 &Vselection_coercible_types /*
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
893 A list of selection types that are coercible---that is, types that may be
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
894 automatically converted to another type. Selection values with types in this
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
895 list may be subject to conversion attempts to other types. */ );
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
896 Vselection_coercible_types = Qnil;
de805c49cfc1 Import from CVS: tag r21-2-35
cvs
parents: 398
diff changeset
897
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
898 DEFVAR_LISP ("lost-selection-hooks", &Vlost_selection_hooks /*
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
899 A function or functions to be called after we have been notified
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
900 that we have lost the selection. The function(s) will be called with one
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
901 argument, a symbol naming the selection (typically PRIMARY, SECONDARY, or
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
902 CLIPBOARD).
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
903 */ );
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
904 Vlost_selection_hooks = Qunbound;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents:
diff changeset
905 }