annotate lisp/select.el @ 290:c9fe270a4101 r21-0b43

Import from CVS: tag r21-0b43
author cvs
date Mon, 13 Aug 2007 10:36:47 +0200
parents 57709be46d1b
children 3cc9f0ebfbd1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
1 ;;; select.el --- Lisp interface to windows selections.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
2
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
3 ;; Copyright (C) 1998 Andy Piper.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
4 ;; Copyright (C) 1990, 1997 Free Software Foundation, Inc.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
5 ;; Copyright (C) 1995 Sun Microsystems.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
6
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
7 ;; Maintainer: XEmacs Development Team
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
8 ;; Keywords: extensions, dumped
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
9
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
10 ;; This file is part of XEmacs.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
11
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
12 ;; XEmacs is free software; you can redistribute it and/or modify it
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
13 ;; under the terms of the GNU General Public License as published by
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
15 ;; any later version.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
16
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
17 ;; XEmacs is distributed in the hope that it will be useful, but
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
20 ;; General Public License for more details.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
21
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
23 ;; along with XEmacs; see the file COPYING. If not, write to the
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
25 ;; Boston, MA 02111-1307, USA.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
26
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
27 ;;; Synched up with: Not in FSF
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
28
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
29 ;;; Commentary:
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
30
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
31 ;; This file is dumped with XEmacs
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
32
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
33 ;;; Code:
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
34
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
35 (defun copy-primary-selection ()
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
36 "Copy the selection to the Clipboard and the kill ring."
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
37 (interactive)
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
38 (and (console-on-window-system-p)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
39 (cut-copy-clear-internal 'copy)))
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
40
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
41 (defun kill-primary-selection ()
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
42 "Copy the selection to the Clipboard and the kill ring, then delete it."
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
43 (interactive "*")
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
44 (and (console-on-window-system-p)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
45 (cut-copy-clear-internal 'cut)))
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
46
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
47 (defun delete-primary-selection ()
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
48 "Delete the selection without copying it to the Clipboard or the kill ring."
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
49 (interactive "*")
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
50 (and (console-on-window-system-p)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
51 (cut-copy-clear-internal 'clear)))
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
52
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
53 (defun yank-clipboard-selection ()
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
54 "Insert the current Clipboard selection at point."
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
55 (interactive "*")
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
56 (case (device-type (selected-device))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
57 (x (x-yank-clipboard-selection))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
58 (mswindows (mswindows-paste-clipboard))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
59 (otherwise nil)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
60
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
61 (defun selection-owner-p (&optional selection)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
62 "Return t if current emacs process owns the given Selection.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
63 The arg should be the name of the selection in question, typically one
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
64 of the symbols PRIMARY, SECONDARY, or CLIPBOARD. (For convenience,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
65 the symbol nil is the same as PRIMARY, and t is the same as
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
66 SECONDARY.)"
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
67 (interactive)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
68 (case (device-type (selected-device))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
69 (x (x-selection-owner-p selection))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
70 (mswindows (mswindows-selection-owner-p selection))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
71 (otherwise nil)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
72
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
73 (defun selection-exists-p (&optional selection)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
74 "Whether there is an owner for the given Selection.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
75 The arg should be the name of the selection in question, typically one
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
76 of the symbols PRIMARY, SECONDARY, or CLIPBOARD. (For convenience,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
77 the symbol nil is the same as PRIMARY, and t is the same as
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
78 SECONDARY."
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
79 (interactive)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
80 (case (device-type (selected-device))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
81 (x (x-selection-exists-p selection))
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
82 (mswindows (mswindows-selection-exists-p))
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
83 (otherwise nil)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
84
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
85 (defun own-selection (data &optional type)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
86 "Make an Windows selection of type TYPE and value DATA.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
87 The argument TYPE (default `PRIMARY') says which selection,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
88 and DATA specifies the contents. DATA may be a string,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
89 a symbol, an integer (or a cons of two integers or list of two integers).
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
90
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
91 The selection may also be a cons of two markers pointing to the same buffer,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
92 or an overlay. In these cases, the selection is considered to be the text
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
93 between the markers *at whatever time the selection is examined*.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
94 Thus, editing done in the buffer after you specify the selection
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
95 can alter the effective value of the selection.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
96
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
97 The data may also be a vector of valid non-vector selection values.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
98
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
99 Interactively, the text of the region is used as the selection value."
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
100 (interactive (if (not current-prefix-arg)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
101 (list (read-string "Store text for pasting: "))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
102 (list (substring (region-beginning) (region-end)))))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
103 (case (device-type (selected-device))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
104 (x (x-own-selection data type))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
105 (mswindows (mswindows-own-selection data type))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
106 (otherwise nil)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
107
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
108 (defun own-clipboard (string)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
109 "Paste the given string to the Clipboard."
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
110 (case (device-type (selected-device))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
111 (x (x-own-clipboard string))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
112 (mswindows (mswindows-own-clipboard string))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
113 (otherwise nil)))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
114
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
115 (defun disown-selection (&optional secondary-p)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
116 "Assuming we own the selection, disown it. With an argument, discard the
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
117 secondary selection instead of the primary selection."
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
118 (case (device-type (selected-device))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
119 (x (x-disown-selection secondary-p))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
120 (mswindows (mswindows-disown-selection secondary-p))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
121 (otherwise nil)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
122
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
123
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
124 ;; from x-init.el
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
125 ;; selections and active regions
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
126
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
127 ;; If and only if zmacs-regions is true:
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
128
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
129 ;; When a mark is pushed and the region goes into the "active" state, we
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
130 ;; assert it as the Primary selection. This causes it to be hilighted.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
131 ;; When the region goes into the "inactive" state, we disown the Primary
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
132 ;; selection, causing the region to be dehilighted.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
133
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
134 ;; Note that it is possible for the region to be in the "active" state
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
135 ;; and not be hilighted, if it is in the active state and then some other
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
136 ;; application asserts the selection. This is probably not a big deal.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
137
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
138 (defun activate-region-as-selection ()
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
139 (if (marker-buffer (mark-marker t))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
140 (own-selection (cons (point-marker t) (mark-marker t)))))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
141
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
142 ; moved from x-select.el
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
143 (defvar primary-selection-extent nil
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
144 "The extent of the primary selection; don't use this.")
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
145
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
146 (defvar secondary-selection-extent nil
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
147 "The extent of the secondary selection; don't use this.")
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
148
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
149 (defun select-make-extent-for-selection (selection previous-extent)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
150 ;; Given a selection, this makes an extent in the buffer which holds that
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
151 ;; selection, for highlighting purposes. If the selection isn't associated
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
152 ;; with a buffer, this does nothing.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
153 (let ((buffer nil)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
154 (valid (and (extentp previous-extent)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
155 (extent-object previous-extent)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
156 (buffer-live-p (extent-object previous-extent))))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
157 start end)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
158 (cond ((stringp selection)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
159 ;; if we're selecting a string, lose the previous extent used
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
160 ;; to highlight the selection.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
161 (setq valid nil))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
162 ((consp selection)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
163 (setq start (min (car selection) (cdr selection))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
164 end (max (car selection) (cdr selection))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
165 valid (and valid
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
166 (eq (marker-buffer (car selection))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
167 (extent-object previous-extent)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
168 buffer (marker-buffer (car selection))))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
169 ((extentp selection)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
170 (setq start (extent-start-position selection)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
171 end (extent-end-position selection)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
172 valid (and valid
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
173 (eq (extent-object selection)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
174 (extent-object previous-extent)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
175 buffer (extent-object selection)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
176 (t
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
177 (signal 'error (list "invalid selection" selection))))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
178
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
179 (if valid
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
180 nil
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
181 (condition-case ()
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
182 (if (listp previous-extent)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
183 (mapcar 'delete-extent previous-extent)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
184 (delete-extent previous-extent))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
185 (error nil)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
186
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
187 (if (not buffer)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
188 ;; string case
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
189 nil
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
190 ;; normal case
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
191 (if valid
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
192 (set-extent-endpoints previous-extent start end)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
193 (setq previous-extent (make-extent start end buffer))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
194
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
195 ;; Make the extent be closed on the right, which means that if
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
196 ;; characters are inserted exactly at the end of the extent, the
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
197 ;; extent will grow to cover them. This is important for shell
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
198 ;; buffers - suppose one makes a selection, and one end is at
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
199 ;; point-max. If the shell produces output, that marker will remain
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
200 ;; at point-max (its position will increase). So it's important that
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
201 ;; the extent exhibit the same behavior, lest the region covered by
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
202 ;; the extent (the visual indication), and the region between point
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
203 ;; and mark (the actual selection value) become different!
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
204 (set-extent-property previous-extent 'end-open nil)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
205
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
206 (cond
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
207 (mouse-track-rectangle-p
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
208 (setq previous-extent (list previous-extent))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
209 (default-mouse-track-next-move-rect start end previous-extent)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
210 ))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
211 previous-extent))))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
212
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
213 ;; moved from x-select.el
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
214 (defun valid-simple-selection-p (data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
215 (or (stringp data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
216 ;FSFmacs huh?? (symbolp data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
217 (integerp data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
218 (and (consp data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
219 (integerp (car data))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
220 (or (integerp (cdr data))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
221 (and (consp (cdr data))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
222 (integerp (car (cdr data))))))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
223 (extentp data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
224 (and (consp data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
225 (markerp (car data))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
226 (markerp (cdr data))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
227 (marker-buffer (car data))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
228 (marker-buffer (cdr data))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
229 (eq (marker-buffer (car data))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
230 (marker-buffer (cdr data)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
231 (buffer-live-p (marker-buffer (car data)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
232 (buffer-live-p (marker-buffer (cdr data))))))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
233
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
234 (defun cut-copy-clear-internal (mode)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
235 (or (memq mode '(cut copy clear)) (error "unkown mode %S" mode))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
236 (or (selection-owner-p)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
237 (error "emacs does not own the primary selection"))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
238 (setq last-command nil)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
239 (or primary-selection-extent
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
240 (error "the primary selection is not an extent?"))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
241 (save-excursion
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
242 (let (rect-p b s e)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
243 (cond
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
244 ((consp primary-selection-extent)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
245 (setq rect-p t
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
246 b (extent-object (car primary-selection-extent))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
247 s (extent-start-position (car primary-selection-extent))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
248 e (extent-end-position (car (reverse primary-selection-extent)))))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
249 (t
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
250 (setq rect-p nil
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
251 b (extent-object primary-selection-extent)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
252 s (extent-start-position primary-selection-extent)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
253 e (extent-end-position primary-selection-extent))))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
254 (set-buffer b)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
255 (cond ((memq mode '(cut copy))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
256 (if rect-p
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
257 (progn
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
258 ;; why is killed-rectangle free? Is it used somewhere?
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
259 ;; should it be defvarred?
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
260 (setq killed-rectangle (extract-rectangle s e))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
261 (kill-new (mapconcat 'identity killed-rectangle "\n")))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
262 (copy-region-as-kill s e))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
263 ;; Maybe killing doesn't own clipboard. Make sure it happens.
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
264 ;; This memq is kind of grody, because they might have done it
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
265 ;; some other way, but owning the clipboard twice in that case
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
266 ;; wouldn't actually hurt anything.
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
267 (or (and (consp kill-hooks) (memq 'own-clipboard kill-hooks))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
268 (own-clipboard (car kill-ring)))))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
269 (cond ((memq mode '(cut clear))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
270 (if rect-p
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
271 (delete-rectangle s e)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
272 (delete-region s e))))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
273 (disown-selection nil)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
274 )))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
275
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
276 ;;; select.el ends here