annotate lisp/select.el @ 404:2f8bb876ab1d r21-2-32

Import from CVS: tag r21-2-32
author cvs
date Mon, 13 Aug 2007 11:16:07 +0200
parents 74fd4e045ea6
children de805c49cfc1
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
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
35 (defvar selected-text-type
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
36 (if (featurep 'mule) '(COMPOUND_TEXT STRING) 'STRING)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
37 "The type atom used to obtain selections from the X server.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
38 Can be either a valid X selection data type, or a list of such types.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
39 COMPOUND_TEXT and STRING are the most commonly used data types.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
40 If a list is provided, the types are tried in sequence until
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
41 there is a successful conversion.")
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
42
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
43 (defvar selection-sets-clipboard nil
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
44 "Controls the selection's relationship to the clipboard.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
45 When non-nil, any operation that sets the primary selection will also
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
46 set the clipboard.")
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
47
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
48 (defun copy-primary-selection ()
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
49 "Copy the selection to the Clipboard and the kill ring."
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
50 (interactive)
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
51 (and (console-on-window-system-p)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
52 (cut-copy-clear-internal 'copy)))
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
53
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
54 (defun kill-primary-selection ()
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
55 "Copy the selection to the Clipboard and the kill ring, then delete it."
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
56 (interactive "*")
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
57 (and (console-on-window-system-p)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
58 (cut-copy-clear-internal 'cut)))
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
59
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
60 (defun delete-primary-selection ()
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
61 "Delete the selection without copying it to the Clipboard or the kill ring."
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
62 (interactive "*")
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
63 (and (console-on-window-system-p)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
64 (cut-copy-clear-internal 'clear)))
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
65
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
66 (defun yank-clipboard-selection ()
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
67 "Insert the current Clipboard selection at point."
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
68 (interactive "*")
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
69 (when (console-on-window-system-p)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
70 (setq last-command nil)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
71 (setq this-command 'yank) ; so that yank-pop works.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
72 (let ((clip (get-clipboard)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
73 (or clip (error "there is no clipboard selection"))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
74 (push-mark)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
75 (insert clip))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
76
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
77 (defun get-clipboard ()
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
78 "Return text pasted to the clipboard."
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
79 (get-selection 'CLIPBOARD))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
80
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
81 (define-device-method get-cutbuffer
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
82 "Return the value of one of the cut buffers.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
83 This will do nothing under anything other than X.")
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
84
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
85 (defun get-selection-no-error (&optional type data-type)
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
86 "Return the value of a window-system selection.
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
87 The argument TYPE (default `PRIMARY') says which selection,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
88 and the argument DATA-TYPE (default `STRING', or `COMPOUND_TEXT' under Mule)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
89 says how to convert the data. Returns NIL if there is no selection"
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
90 (condition-case err (get-selection type data-type) (t nil)))
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
91
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
92 (defun get-selection (&optional type data-type)
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
93 "Return the value of a window-system selection.
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
94 The argument TYPE (default `PRIMARY') says which selection,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
95 and the argument DATA-TYPE (default `STRING', or `COMPOUND_TEXT' under Mule)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
96 says how to convert the data. If there is no selection an error is signalled."
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
97 (or type (setq type 'PRIMARY))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
98 (or data-type (setq data-type selected-text-type))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
99 (let ((text
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
100 (if (consp data-type)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
101 (condition-case err
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
102 (get-selection-internal type (car data-type))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
103 (selection-conversion-error
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
104 (if (cdr data-type)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
105 (get-selection type (cdr data-type))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
106 (signal (car err) (cdr err)))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
107 (get-selection-internal type data-type))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
108 (when (and (consp text) (symbolp (car text)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
109 (setq text (cdr text)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
110 (when (not (stringp text))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
111 (error "Selection is not a string: %S" text))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
112 text))
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
113
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
114 ;; FSFmacs calls this `x-set-selection', and reverses the
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
115 ;; first two arguments (duh ...). This order is more logical.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
116 (defun own-selection (data &optional type append)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
117 "Make a window-system selection of type TYPE and value DATA.
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
118 The argument TYPE (default `PRIMARY') says which selection,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
119 and DATA specifies the contents. DATA may be a string,
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
120 a symbol, an integer (or a cons of two integers or list of two integers).
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
121 If APPEND is non-nil, append the data to the existing selection data.
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
122
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
123 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
124 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
125 between the markers *at whatever time the selection is examined*.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
126 Thus, editing done in the buffer after you specify the selection
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
127 can alter the effective value of the selection.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
128
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
129 The data may also be a vector of valid non-vector selection values.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
130
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
131 Interactively, the text of the region is used as the selection value."
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
132 (interactive (if (not current-prefix-arg)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
133 (list (read-string "Store text for pasting: "))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
134 (list (substring (region-beginning) (region-end)))))
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
135 ;; calling own-selection-internal will mess this up, so preserve it.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
136 (let ((zmacs-region-stays zmacs-region-stays))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
137 ;FSFmacs huh?? It says:
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
138 ;; "This is for temporary compatibility with pre-release Emacs 19."
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
139 ;(if (stringp type)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
140 ; (setq type (intern type)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
141 (or (valid-simple-selection-p data)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
142 (and (vectorp data)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
143 (let ((valid t)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
144 (i (1- (length data))))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
145 (while (>= i 0)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
146 (or (valid-simple-selection-p (aref data i))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
147 (setq valid nil))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
148 (setq i (1- i)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
149 valid))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
150 (signal 'error (list "invalid selection" data)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
151 (or type (setq type 'PRIMARY))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
152 (flet ((own-selection-1
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
153 (type data append)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
154 (when append
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
155 (unless (stringp data)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
156 ;; kludge!
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
157 (setq data (select-convert-to-text type 'STRING data))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
158 (if (stringp data)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
159 (setq data (concat (get-selection type) data)))))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
160 (own-selection-internal type data)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
161 (if (null data)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
162 (disown-selection-internal type)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
163 (own-selection-1 type data append)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
164 (when (and (eq type 'PRIMARY)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
165 selection-sets-clipboard)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
166 (own-selection-internal 'CLIPBOARD data append))))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
167 (cond ((eq type 'PRIMARY)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
168 (setq primary-selection-extent
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
169 (select-make-extent-for-selection
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
170 data primary-selection-extent)))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
171 ((eq type 'SECONDARY)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
172 (setq secondary-selection-extent
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
173 (select-make-extent-for-selection
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
174 data secondary-selection-extent)))))
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
175 ;; zmacs-region-stays is for commands, not low-level functions.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
176 ;; when behaving as the latter, we better not set it, or we will
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
177 ;; cause unwanted sticky-region behavior in kill-region and friends.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
178 (if (interactive-p)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
179 (setq zmacs-region-stays t))
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
180 data)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
181
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
182 (defun dehilight-selection (selection)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
183 "for use as a value of `lost-selection-hooks'."
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
184 (cond ((eq selection 'PRIMARY)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
185 (if primary-selection-extent
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
186 (let ((inhibit-quit t))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
187 (if (consp primary-selection-extent)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
188 (mapcar 'delete-extent primary-selection-extent)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
189 (delete-extent primary-selection-extent))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
190 (setq primary-selection-extent nil)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
191 (if zmacs-regions (zmacs-deactivate-region)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
192 ((eq selection 'SECONDARY)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
193 (if secondary-selection-extent
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
194 (let ((inhibit-quit t))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
195 (if (consp secondary-selection-extent)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
196 (mapcar 'delete-extent secondary-selection-extent)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
197 (delete-extent secondary-selection-extent))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
198 (setq secondary-selection-extent nil)))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
199 nil)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
200
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
201 (setq lost-selection-hooks 'dehilight-selection)
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
202
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
203 (defun own-clipboard (string &optional append)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
204 "Paste the given string to the window system Clipboard.
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 398
diff changeset
205 If APPEND is non-nil, append the string to the existing contents."
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
206 (own-selection string 'CLIPBOARD))
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
207
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
208 (defun disown-selection (&optional secondary-p)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
209 "Assuming we own the selection, disown it. With an argument, discard the
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
210 secondary selection instead of the primary selection."
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
211 (disown-selection-internal (if secondary-p 'SECONDARY 'PRIMARY))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
212 (when (and selection-sets-clipboard
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
213 (or (not secondary-p)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
214 (eq secondary-p 'PRIMARY)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
215 (eq secondary-p 'CLIPBOARD)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
216 (disown-selection-internal 'CLIPBOARD)))
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
217
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
218 ;; from x-init.el
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
219 ;; selections and active regions
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
220
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
221 ;; If and only if zmacs-regions is true:
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
222
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
223 ;; 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
224 ;; assert it as the Primary selection. This causes it to be hilighted.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
225 ;; When the region goes into the "inactive" state, we disown the Primary
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
226 ;; selection, causing the region to be dehilighted.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
227
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
228 ;; 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
229 ;; 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
230 ;; application asserts the selection. This is probably not a big deal.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
231
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
232 (defun activate-region-as-selection ()
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
233 (if (marker-buffer (mark-marker t))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
234 (own-selection (cons (point-marker t) (mark-marker t)))))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
235
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
236 ; moved from x-select.el
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
237 (defvar primary-selection-extent nil
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
238 "The extent of the primary selection; don't use this.")
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
239
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
240 (defvar secondary-selection-extent nil
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
241 "The extent of the secondary selection; don't use this.")
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
242
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
243 (defun select-make-extent-for-selection (selection previous-extent)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
244 ;; Given a selection, this makes an extent in the buffer which holds that
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
245 ;; selection, for highlighting purposes. If the selection isn't associated
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
246 ;; with a buffer, this does nothing.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
247 (let ((buffer nil)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
248 (valid (and (extentp previous-extent)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
249 (extent-object previous-extent)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
250 (buffer-live-p (extent-object previous-extent))))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
251 start end)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
252 (cond ((stringp selection)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
253 ;; if we're selecting a string, lose the previous extent used
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
254 ;; to highlight the selection.
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
255 (setq valid nil))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
256 ((consp selection)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
257 (setq start (min (car selection) (cdr selection))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
258 end (max (car selection) (cdr selection))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
259 valid (and valid
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
260 (eq (marker-buffer (car selection))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
261 (extent-object previous-extent)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
262 buffer (marker-buffer (car selection))))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
263 ((extentp selection)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
264 (setq start (extent-start-position selection)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
265 end (extent-end-position selection)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
266 valid (and valid
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
267 (eq (extent-object selection)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
268 (extent-object previous-extent)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
269 buffer (extent-object selection)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
270 (t
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
271 (signal 'error (list "invalid selection" selection))))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
272
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
273 (if valid
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
274 nil
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
275 (condition-case ()
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
276 (if (listp previous-extent)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
277 (mapcar 'delete-extent previous-extent)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
278 (delete-extent previous-extent))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
279 (error nil)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
281 (if (not buffer)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
282 ;; string case
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
283 nil
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
284 ;; normal case
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
285 (if valid
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
286 (set-extent-endpoints previous-extent start end)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
287 (setq previous-extent (make-extent start end buffer))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
288
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
289 ;; Make the extent be closed on the right, which means that if
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
290 ;; characters are inserted exactly at the end of the extent, the
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
291 ;; extent will grow to cover them. This is important for shell
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
292 ;; buffers - suppose one makes a selection, and one end is at
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
293 ;; point-max. If the shell produces output, that marker will remain
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
294 ;; at point-max (its position will increase). So it's important that
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
295 ;; the extent exhibit the same behavior, lest the region covered by
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
296 ;; the extent (the visual indication), and the region between point
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
297 ;; and mark (the actual selection value) become different!
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
298 (set-extent-property previous-extent 'end-open nil)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
299
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
300 (cond
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
301 (mouse-track-rectangle-p
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
302 (setq previous-extent (list previous-extent))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
303 (default-mouse-track-next-move-rect start end previous-extent)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
304 ))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
305 previous-extent))))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
306
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
307 ;; moved from x-select.el
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
308 (defun valid-simple-selection-p (data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
309 (or (stringp data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
310 ;FSFmacs huh?? (symbolp data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
311 (integerp data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
312 (and (consp data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
313 (integerp (car data))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
314 (or (integerp (cdr data))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
315 (and (consp (cdr data))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
316 (integerp (car (cdr data))))))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
317 (extentp data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
318 (and (consp data)
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
319 (markerp (car data))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
320 (markerp (cdr data))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
321 (marker-buffer (car data))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
322 (marker-buffer (cdr data))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
323 (eq (marker-buffer (car data))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
324 (marker-buffer (cdr data)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
325 (buffer-live-p (marker-buffer (car data)))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
326 (buffer-live-p (marker-buffer (cdr data))))))
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
327
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
328 (defun cut-copy-clear-internal (mode)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
329 (or (memq mode '(cut copy clear)) (error "unkown mode %S" mode))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
330 (or (selection-owner-p)
388
aabb7f5b1c81 Import from CVS: tag r21-2-9
cvs
parents: 380
diff changeset
331 (error "XEmacs does not own the primary selection"))
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
332 (setq last-command nil)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
333 (or primary-selection-extent
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
334 (error "the primary selection is not an extent?"))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
335 (save-excursion
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
336 (let (rect-p b s e)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
337 (cond
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
338 ((consp primary-selection-extent)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
339 (setq rect-p t
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
340 b (extent-object (car primary-selection-extent))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
341 s (extent-start-position (car primary-selection-extent))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
342 e (extent-end-position (car (reverse primary-selection-extent)))))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
343 (t
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
344 (setq rect-p nil
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
345 b (extent-object primary-selection-extent)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
346 s (extent-start-position primary-selection-extent)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
347 e (extent-end-position primary-selection-extent))))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
348 (set-buffer b)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
349 (cond ((memq mode '(cut copy))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
350 (if rect-p
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
351 (progn
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
352 ;; why is killed-rectangle free? Is it used somewhere?
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
353 ;; should it be defvarred?
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
354 (setq killed-rectangle (extract-rectangle s e))
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
355 (kill-new (mapconcat #'identity killed-rectangle "\n")))
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
356 (copy-region-as-kill s e))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
357 ;; Maybe killing doesn't own clipboard. Make sure it happens.
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
358 ;; This memq is kind of grody, because they might have done it
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
359 ;; some other way, but owning the clipboard twice in that case
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
360 ;; wouldn't actually hurt anything.
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
361 (or (and (consp kill-hooks) (memq 'own-clipboard kill-hooks))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
362 (own-clipboard (car kill-ring)))))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
363 (cond ((memq mode '(cut clear))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
364 (if rect-p
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
365 (delete-rectangle s e)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
366 (delete-region s e))))
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
367 (disown-selection nil)
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
368 )))
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
369
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
370 ;;; Functions to convert the selection into various other selection
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
371 ;;; types. Every selection type that emacs handles is implemented
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
372 ;;; this way, except for TIMESTAMP, which is a special case. These are
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
373 ;;; all moved from x-select.el
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
374
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
375 (defun select-convert-to-text (selection type value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
376 (cond ((stringp value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
377 value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
378 ((extentp value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
379 (save-excursion
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
380 (set-buffer (extent-object value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
381 (save-restriction
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
382 (widen)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
383 (buffer-substring (extent-start-position value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
384 (extent-end-position value)))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
385 ((and (consp value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
386 (markerp (car value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
387 (markerp (cdr value)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
388 (or (eq (marker-buffer (car value)) (marker-buffer (cdr value)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
389 (signal 'error
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
390 (list "markers must be in the same buffer"
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
391 (car value) (cdr value))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
392 (save-excursion
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
393 (set-buffer (or (marker-buffer (car value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
394 (error "selection is in a killed buffer")))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
395 (save-restriction
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
396 (widen)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
397 (buffer-substring (car value) (cdr value)))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
398 (t nil)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
399
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
400 (defun select-convert-to-string (selection type value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
401 (let ((outval (select-convert-to-text selection type value)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
402 ;; force the string to be not in Compound Text format.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
403 (if (stringp outval)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
404 (cons 'STRING outval)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
405 outval)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
406
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
407 (defun select-convert-to-compound-text (selection type value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
408 ;; converts to compound text automatically
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
409 (select-convert-to-text selection type value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
410
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
411 (defun select-convert-to-length (selection type value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
412 (let ((value
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
413 (cond ((stringp value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
414 (length value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
415 ((extentp value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
416 (extent-length value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
417 ((and (consp value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
418 (markerp (car value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
419 (markerp (cdr value)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
420 (or (eq (marker-buffer (car value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
421 (marker-buffer (cdr value)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
422 (signal 'error
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
423 (list "markers must be in the same buffer"
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
424 (car value) (cdr value))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
425 (abs (- (car value) (cdr value)))))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
426 (if value ; force it to be in 32-bit format.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
427 (cons (ash value -16) (logand value 65535))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
428 nil)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
429
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
430 (defun select-convert-to-targets (selection type value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
431 ;; return a vector of atoms, but remove duplicates first.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
432 (let* ((all (cons 'TIMESTAMP (mapcar 'car selection-converter-alist)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
433 (rest all))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
434 (while rest
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
435 (cond ((memq (car rest) (cdr rest))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
436 (setcdr rest (delq (car rest) (cdr rest))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
437 ((eq (car (cdr rest)) '_EMACS_INTERNAL) ; shh, it's a secret
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
438 (setcdr rest (cdr (cdr rest))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
439 (t
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
440 (setq rest (cdr rest)))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
441 (apply 'vector all)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
442
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
443 (defun select-convert-to-delete (selection type value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
444 (disown-selection-internal selection)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
445 ;; A return value of nil means that we do not know how to do this conversion,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
446 ;; and replies with an "error". A return value of NULL means that we have
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
447 ;; done the conversion (and any side-effects) but have no value to return.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
448 'NULL)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
449
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
450 (defun select-convert-to-filename (selection type value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
451 (cond ((extentp value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
452 (buffer-file-name (or (extent-object value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
453 (error "selection is in a killed buffer"))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
454 ((and (consp value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
455 (markerp (car value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
456 (markerp (cdr value)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
457 (buffer-file-name (or (marker-buffer (car value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
458 (error "selection is in a killed buffer"))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
459 (t nil)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
460
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
461 (defun select-convert-to-charpos (selection type value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
462 (let (a b tmp)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
463 (cond ((cond ((extentp value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
464 (setq a (extent-start-position value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
465 b (extent-end-position value)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
466 ((and (consp value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
467 (markerp (car value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
468 (markerp (cdr value)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
469 (setq a (car value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
470 b (cdr value))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
471 (setq a (1- a) b (1- b)) ; zero-based
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
472 (if (< b a) (setq tmp a a b b tmp))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
473 (cons 'SPAN
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
474 (vector (cons (ash a -16) (logand a 65535))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
475 (cons (ash b -16) (logand b 65535))))))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
476
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
477 (defun select-convert-to-lineno (selection type value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
478 (let (a b buf tmp)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
479 (cond ((cond ((extentp value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
480 (setq buf (extent-object value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
481 a (extent-start-position value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
482 b (extent-end-position value)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
483 ((and (consp value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
484 (markerp (car value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
485 (markerp (cdr value)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
486 (setq a (marker-position (car value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
487 b (marker-position (cdr value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
488 buf (marker-buffer (car value)))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
489 (save-excursion
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
490 (set-buffer buf)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
491 (save-restriction
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
492 (widen)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
493 (goto-char a)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
494 (beginning-of-line)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
495 (setq a (1+ (count-lines 1 (point))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
496 (goto-char b)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
497 (beginning-of-line)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
498 (setq b (1+ (count-lines 1 (point))))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
499 (if (< b a) (setq tmp a a b b tmp))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
500 (cons 'SPAN
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
501 (vector (cons (ash a -16) (logand a 65535))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
502 (cons (ash b -16) (logand b 65535))))))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
503
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
504 (defun select-convert-to-colno (selection type value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
505 (let (a b buf tmp)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
506 (cond ((cond ((extentp value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
507 (setq buf (extent-object value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
508 a (extent-start-position value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
509 b (extent-end-position value)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
510 ((and (consp value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
511 (markerp (car value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
512 (markerp (cdr value)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
513 (setq a (car value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
514 b (cdr value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
515 buf (marker-buffer a))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
516 (save-excursion
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
517 (set-buffer buf)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
518 (goto-char a)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
519 (setq a (current-column))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
520 (goto-char b)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
521 (setq b (current-column)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
522 (if (< b a) (setq tmp a a b b tmp))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
523 (cons 'SPAN
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
524 (vector (cons (ash a -16) (logand a 65535))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
525 (cons (ash b -16) (logand b 65535))))))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
526
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
527 (defun select-convert-to-sourceloc (selection type value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
528 (let (a b buf file-name tmp)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
529 (cond ((cond ((extentp value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
530 (setq buf (or (extent-object value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
531 (error "selection is in a killed buffer"))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
532 a (extent-start-position value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
533 b (extent-end-position value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
534 file-name (buffer-file-name buf)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
535 ((and (consp value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
536 (markerp (car value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
537 (markerp (cdr value)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
538 (setq a (marker-position (car value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
539 b (marker-position (cdr value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
540 buf (or (marker-buffer (car value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
541 (error "selection is in a killed buffer"))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
542 file-name (buffer-file-name buf))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
543 (save-excursion
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
544 (set-buffer buf)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
545 (save-restriction
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
546 (widen)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
547 (goto-char a)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
548 (beginning-of-line)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
549 (setq a (1+ (count-lines 1 (point))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
550 (goto-char b)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
551 (beginning-of-line)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
552 (setq b (1+ (count-lines 1 (point))))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
553 (if (< b a) (setq tmp a a b b tmp))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
554 (format "%s:%d" file-name a)))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
555
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
556 (defun select-convert-to-os (selection type size)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
557 (symbol-name system-type))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
558
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
559 (defun select-convert-to-host (selection type size)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
560 (system-name))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
561
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
562 (defun select-convert-to-user (selection type size)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
563 (user-full-name))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
564
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
565 (defun select-convert-to-class (selection type size)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
566 x-emacs-application-class)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
567
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
568 ;; We do not try to determine the name Emacs was invoked with,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
569 ;; because it is not clean for a program's behavior to depend on that.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
570 (defun select-convert-to-name (selection type size)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
571 ;invocation-name
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
572 "xemacs")
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
573
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
574 (defun select-convert-to-integer (selection type value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
575 (and (integerp value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
576 (cons (ash value -16) (logand value 65535))))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
577
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
578 (defun select-convert-to-atom (selection type value)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
579 (and (symbolp value) value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
580
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
581 (defun select-convert-to-identity (selection type value) ; used internally
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
582 (vector value))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
583
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
584 (setq selection-converter-alist
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
585 '((TEXT . select-convert-to-text)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
586 (STRING . select-convert-to-string)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
587 (COMPOUND_TEXT . select-convert-to-compound-text)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
588 (TARGETS . select-convert-to-targets)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
589 (LENGTH . select-convert-to-length)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
590 (DELETE . select-convert-to-delete)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
591 (FILE_NAME . select-convert-to-filename)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
592 (CHARACTER_POSITION . select-convert-to-charpos)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
593 (SOURCE_LOC . select-convert-to-sourceloc)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
594 (LINE_NUMBER . select-convert-to-lineno)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
595 (COLUMN_NUMBER . select-convert-to-colno)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
596 (OWNER_OS . select-convert-to-os)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
597 (HOST_NAME . select-convert-to-host)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
598 (USER . select-convert-to-user)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
599 (CLASS . select-convert-to-class)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
600 (NAME . select-convert-to-name)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
601 (ATOM . select-convert-to-atom)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
602 (INTEGER . select-convert-to-integer)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
603 (_EMACS_INTERNAL . select-convert-to-identity)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 388
diff changeset
604 ))
286
57709be46d1b Import from CVS: tag r21-0b41
cvs
parents: 284
diff changeset
605
280
7df0dd720c89 Import from CVS: tag r21-0b38
cvs
parents:
diff changeset
606 ;;; select.el ends here