annotate lisp/emacs-lisp/lselect.el @ 20071:dd3a2332a66f

(L_getit): Always make named tags so that Emacs completion on symbols containing `:' etc. works. (get_scheme): Likewise.
author Karl Heuer <kwzh@gnu.org>
date Thu, 16 Oct 1997 18:17:52 +0000
parents 11218164bc54
children 67b464da13ec
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2234
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
1 ;;; lselect.el --- Lucid interface to X Selections
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
2
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 2571
diff changeset
3 ;; Copyright (C) 1990, 1993 Free Software Foundation, Inc.
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 2571
diff changeset
4
2234
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
5 ;; Keywords: emulations
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
6
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
7 ;; This won't completely work until we support or emulate Lucid-style extents.
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
8 ;; Based on Lucid's selection code.
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
9
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
11
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
15 ;; any later version.
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
16
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
20 ;; GNU General Public License for more details.
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
21
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 2571
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 2571
diff changeset
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 2571
diff changeset
25 ;; Boston, MA 02111-1307, USA.
2234
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
26
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
27 ;;; Code:
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
28
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
29 ;;; The selection code requires us to use certain symbols whose names are
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
30 ;;; all upper-case; this may seem tasteless, but it makes there be a 1:1
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
31 ;;; correspondence between these symbols and X Atoms (which are upcased.)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
32
2571
b65cf676a09b All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2234
diff changeset
33 (defalias 'x-get-cutbuffer 'x-get-cut-buffer)
b65cf676a09b All fsets changed to defaliases.
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 2234
diff changeset
34 (defalias 'x-store-cutbuffer 'x-set-cut-buffer)
2234
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
35
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
36 (or (find-face 'primary-selection)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
37 (make-face 'primary-selection))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
38
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
39 (or (find-face 'secondary-selection)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
40 (make-face 'secondary-selection))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
41
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
42 (defun x-get-secondary-selection ()
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
43 "Return text selected from some X window."
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
44 (x-get-selection-internal 'SECONDARY 'STRING))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
45
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
46 (defvar primary-selection-extent nil
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
47 "The extent of the primary selection; don't use this.")
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
48
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
49 (defvar secondary-selection-extent nil
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
50 "The extent of the secondary selection; don't use this.")
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
51
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
52
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
53 (defun x-select-make-extent-for-selection (selection previous-extent face)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
54 ;; Given a selection, this makes an extent in the buffer which holds that
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
55 ;; selection, for highlighting purposes. If the selection isn't associated
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
56 ;; with a buffer, this does nothing.
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
57 (let ((buffer nil)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
58 (valid (and (extentp previous-extent)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
59 (extent-buffer previous-extent)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
60 (buffer-name (extent-buffer previous-extent))))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
61 start end)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
62 (cond ((stringp selection)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
63 ;; if we're selecting a string, lose the previous extent used
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
64 ;; to highlight the selection.
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
65 (setq valid nil))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
66 ((consp selection)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
67 (setq start (min (car selection) (cdr selection))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
68 end (max (car selection) (cdr selection))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
69 valid (and valid
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
70 (eq (marker-buffer (car selection))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
71 (extent-buffer previous-extent)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
72 buffer (marker-buffer (car selection))))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
73 ((extentp selection)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
74 (setq start (extent-start-position selection)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
75 end (extent-end-position selection)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
76 valid (and valid
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
77 (eq (extent-buffer selection)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
78 (extent-buffer previous-extent)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
79 buffer (extent-buffer selection)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
80 )
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
81 (if (and (not valid)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
82 (extentp previous-extent)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
83 (extent-buffer previous-extent)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
84 (buffer-name (extent-buffer previous-extent)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
85 (delete-extent previous-extent))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
86 (if (not buffer)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
87 ;; string case
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
88 nil
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
89 ;; normal case
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
90 (if valid
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
91 (set-extent-endpoints previous-extent start end)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
92 (setq previous-extent (make-extent start end buffer))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
93 ;; use same priority as mouse-highlighting so that conflicts between
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
94 ;; the selection extent and a mouse-highlighted extent are resolved
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
95 ;; by the usual size-and-endpoint-comparison method.
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
96 (set-extent-priority previous-extent mouse-highlight-priority)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
97 (set-extent-face previous-extent face)))))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
98
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
99
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
100 (defun x-own-selection (selection &optional type)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
101 "Make a primary X Selection of the given argument.
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
102 The argument may be a string, a cons of two markers, or an extent.
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
103 In the latter cases the selection is considered to be the text
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
104 between the markers, or the between extents endpoints."
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
105 (interactive (if (not current-prefix-arg)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
106 (list (read-string "Store text for pasting: "))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
107 (list (cons ;; these need not be ordered.
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
108 (copy-marker (point-marker))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
109 (copy-marker (mark-marker))))))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
110 (or type (setq type 'PRIMARY))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
111 (x-set-selection selection type)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
112 (cond ((eq type 'PRIMARY)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
113 (setq primary-selection-extent
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
114 (x-select-make-extent-for-selection
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
115 selection primary-selection-extent 'primary-selection)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
116 ((eq type 'SECONDARY)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
117 (setq secondary-selection-extent
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
118 (x-select-make-extent-for-selection
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
119 selection secondary-selection-extent 'secondary-selection))))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
120 selection)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
121
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
122
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
123 (defun x-own-secondary-selection (selection &optional type)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
124 "Make a secondary X Selection of the given argument. The argument may be a
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
125 string or a cons of two markers (in which case the selection is considered to
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
126 be the text between those markers.)"
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
127 (interactive (if (not current-prefix-arg)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
128 (list (read-string "Store text for pasting: "))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
129 (list (cons ;; these need not be ordered.
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
130 (copy-marker (point-marker))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
131 (copy-marker (mark-marker))))))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
132 (x-own-selection selection 'SECONDARY))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
133
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
134
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
135 (defun x-own-clipboard (string)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
136 "Paste the given string to the X Clipboard."
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
137 (x-own-selection string 'CLIPBOARD))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
138
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
139
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
140 (defun x-disown-selection (&optional secondary-p)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
141 "Assuming we own the selection, disown it. With an argument, discard the
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
142 secondary selection instead of the primary selection."
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
143 (x-disown-selection-internal (if secondary-p 'SECONDARY 'PRIMARY)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
144
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
145 (defun x-dehilight-selection (selection)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
146 "for use as a value of x-lost-selection-hooks."
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
147 (cond ((eq selection 'PRIMARY)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
148 (if primary-selection-extent
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
149 (let ((inhibit-quit t))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
150 (delete-extent primary-selection-extent)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
151 (setq primary-selection-extent nil)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
152 (if zmacs-regions (zmacs-deactivate-region)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
153 ((eq selection 'SECONDARY)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
154 (if secondary-selection-extent
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
155 (let ((inhibit-quit t))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
156 (delete-extent secondary-selection-extent)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
157 (setq secondary-selection-extent nil)))))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
158 nil)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
159
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
160 (setq x-lost-selection-hooks 'x-dehilight-selection)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
161
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
162 (defun x-notice-selection-requests (selection type successful)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
163 "for possible use as the value of x-sent-selection-hooks."
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
164 (if (not successful)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
165 (message "Selection request failed to convert %s to %s"
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
166 selection type)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
167 (message "Sent selection %s as %s" selection type)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
168
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
169 (defun x-notice-selection-failures (selection type successful)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
170 "for possible use as the value of x-sent-selection-hooks."
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
171 (or successful
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
172 (message "Selection request failed to convert %s to %s"
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
173 selection type)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
174
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
175 ;(setq x-sent-selection-hooks 'x-notice-selection-requests)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
176 ;(setq x-sent-selection-hooks 'x-notice-selection-failures)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
177
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
178
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
179 ;;; Random utility functions
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
180
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
181 (defun x-kill-primary-selection ()
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
182 "If there is a selection, delete the text it covers, and copy it to
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
183 both the kill ring and the Clipboard."
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
184 (interactive)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
185 (or (x-selection-owner-p) (error "emacs does not own the primary selection"))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
186 (setq last-command nil)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
187 (or primary-selection-extent
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
188 (error "the primary selection is not an extent?"))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
189 (save-excursion
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
190 (set-buffer (extent-buffer primary-selection-extent))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
191 (kill-region (extent-start-position primary-selection-extent)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
192 (extent-end-position primary-selection-extent)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
193 (x-disown-selection nil))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
194
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
195 (defun x-delete-primary-selection ()
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
196 "If there is a selection, delete the text it covers *without* copying it to
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
197 the kill ring or the Clipboard."
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
198 (interactive)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
199 (or (x-selection-owner-p) (error "emacs does not own the primary selection"))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
200 (setq last-command nil)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
201 (or primary-selection-extent
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
202 (error "the primary selection is not an extent?"))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
203 (save-excursion
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
204 (set-buffer (extent-buffer primary-selection-extent))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
205 (delete-region (extent-start-position primary-selection-extent)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
206 (extent-end-position primary-selection-extent)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
207 (x-disown-selection nil))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
208
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
209 (defun x-copy-primary-selection ()
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
210 "If there is a selection, copy it to both the kill ring and the Clipboard."
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
211 (interactive)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
212 (setq last-command nil)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
213 (or (x-selection-owner-p) (error "emacs does not own the primary selection"))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
214 (or primary-selection-extent
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
215 (error "the primary selection is not an extent?"))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
216 (save-excursion
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
217 (set-buffer (extent-buffer primary-selection-extent))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
218 (copy-region-as-kill (extent-start-position primary-selection-extent)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
219 (extent-end-position primary-selection-extent))))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
220
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
221 (defun x-yank-clipboard-selection ()
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
222 "If someone owns a Clipboard selection, insert it at point."
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
223 (interactive)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
224 (setq last-command nil)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
225 (let ((clip (x-get-clipboard)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
226 (or clip (error "there is no clipboard selection"))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
227 (push-mark)
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
228 (insert clip)))
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
229
18383
11218164bc54 Add provide call.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
230 (provide 'lselect)
11218164bc54 Add provide call.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
231
2234
53ce64806d58 Initial revision
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
diff changeset
232 ;;; lselect.el ends here.