annotate lisp/select.el @ 5104:868a5349acee

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