annotate lisp/mouse-copy.el @ 19860:c17fd465ea95 libc-970911 libc-970912 libc-970913 libc-970914 libc-970915 libc-970916 libc-970917 libc-970918 libc-970919 libc-970920 libc-970921 libc-970922 libc-970923 libc-970924 libc-970925 libc-970926 libc-970927 libc-970928 libc-970929 libc-970930 libc-971001 libc-971018 libc-971019 libc-971020 libc-971021 libc-971022 libc-971023 libc-971024 libc-971025 libc-971026 libc-971027 libc-971028 libc-971029 libc-971030 libc-971031 libc-971101 libc-971102 libc-971103 libc-971104 libc-971105 libc-971106 libc-971107 libc-971108 libc-971109 libc-971110 libc-971111 libc-971112 libc-971113 libc-971114 libc-971115 libc-971116 libc-971117 libc-971118 libc-971120 libc-971121 libc-971122 libc-971123 libc-971124 libc-971125 libc-971126 libc-971127 libc-971128 libc-971129 libc-971130 libc-971201 libc-971203 libc-971204 libc-971205 libc-971206 libc-971207 libc-971208 libc-971209 libc-971210 libc-971211 libc-971212 libc-971213 libc-971214 libc-971217 libc-971218 libc-971219 libc-971220 libc-971221 libc-971222 libc-971223 libc-971224 libc-971225 libc-971226 libc-971227 libc-971228 libc-971229 libc-971230 libc-971231 libc-980103 libc-980104 libc-980105 libc-980106 libc-980107 libc-980108 libc-980109 libc-980110 libc-980111 libc-980112 libc-980114 libc-980115 libc-980116 libc-980117 libc-980118 libc-980119 libc-980120 libc-980121 libc-980122 libc-980123 libc-980124 libc-980125 libc-980126 libc-980127 libc-980128

typos.
author Jeff Law <law@redhat.com>
date Wed, 10 Sep 1997 21:16:20 +0000
parents da252e5249cd
children 3629687a948d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17517
8f952e921136 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 16321
diff changeset
1 ;;; mouse-copy.el --- one-click text copy and move
16321
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1996 Free Software Foundation, Inc.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5 ;; Author: John Heidemann <johnh@ISI.EDU>
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Keywords: mouse
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; any later version.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;;; What is ``mouse-copy.el''?
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;;
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;;; It provides one-click text copy and move. Rather than the
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;;; standard stroke-out-a-region (down-mouse-1, up-mouse-1) followed
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;;; by a yank (down-mouse-2, up-mouse-2 or C-y), you can now stroke
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;;; out a region and have it automatically pasted at the current
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;;; point. You can also move text just as easily. Although the
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;;; difference may not sound like much, it does make mousing text
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;;; around a lot easier, IMHO.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;;;
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;;; If you like mouse-copy, you should also check out mouse-drag
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;;; for ``one-click scrolling''.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;;;
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;;; To use mouse-copy, place the following in your .emacs file:
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;;; (require 'mouse-copy)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;;; (global-set-key [M-down-mouse-1] 'mouse-drag-secondary-pasting)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;;; (global-set-key [M-S-down-mouse-1] 'mouse-drag-secondary-moving)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;;;
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;;; (These definitions override the old binding of M-mouse-1 to
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;;; mouse-drag-secondary. I find I don't use that command much so its
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;;; loss is not important, and it can be made up with a M-mouse-1
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;;; followed by a M-mouse-3. I personally reserve M-mouse bindings
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;;; for my window manager and bind everything to C-mouse.)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;;;
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;;;
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;;; History and related work:
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;;;
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;;; One-click copying and moving was inspired by lemacs-19.8.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;;; Throw-scrolling was inspired by MacPaint's ``hand'' and by Tk's
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;;; mouse-2 scrolling. The package mouse-scroll.el by Tom Wurgler
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;;; <twurgler@goodyear.com> is similar to mouse-drag-throw, but
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;;; doesn't pass clicks through.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;;;
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;;; These functions have been tested in emacs version 19.30,
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;;; and this package has run in the past on 19.25-19.29.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;;;
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;;; Originally mouse-copy was part of a larger package.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;;; As of 11 July 96 the scrolling functions were split out
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;;; in preparation for incorporation into (the future) emacs-19.32.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;;;
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;;;
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;;; Known Bugs:
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;;;
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;;; - Highlighting is sub-optimal under 19.29 and XFree86-3.1.1
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;;; (see \\[mouse-copy-work-around-drag-bug] for details).
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ;;; - mouse-drag-secondary-pasting and mouse-drag-secondary-moving
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;;; require X11R5 (or better) and so fail under older versions
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;;; of Open Windows (like that present in Solaris/x86 2.1).
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;;;
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;;;
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;;; Future plans:
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;;;
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;;; I read about the chording features of Plan-9's Acme environment at
18027
da252e5249cd Update URL in commentary.
Karl Heuer <kwzh@gnu.org>
parents: 17517
diff changeset
80 ;;; <http://www.zip.com.au/~cs/app/wily/auug.html>. I'd like
16321
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;;; to incorporate some of these ideas into mouse-copy. The only
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 ;;; lose is that this is not the current Emacs Way Of Doing Things, so
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;;; there would be a learning curve for existing emacs users.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ;;;
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ;;;
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 ;;; Thanks:
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;;;
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ;;; Thanks to Kai Grossjohann
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;;; <grossjoh@dusty.informatik.uni-dortmund.de> for reporting bugs, to
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 ;;; Tom Wurgler <twurgler@goodyear.com> for reporting bugs and
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 ;;; suggesting fixes, and to Joel Graber <jgraber@ti.com> for
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 ;;; prompting me to do drag-scrolling and for an initial
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 ;;; implementation of horizontal drag-scrolling.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ;;;
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;;; -johnh, 11-Jul-96
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 ;;; Code:
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 ;;
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 ;; move/paste code
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 ;;
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 (defvar mouse-copy-last-paste-start nil
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 "Internal to `mouse-drag-secondary-pasting'.")
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (defvar mouse-copy-last-paste-end nil
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 "Internal to `mouse-drag-secondary-pasting'.")
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (defvar mouse-copy-have-drag-bug nil
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 "Set to enable mouse-copy-work-around-drag-bug.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 See `mouse-copy-work-around-drag-bug' for details.")
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (defun mouse-copy-work-around-drag-bug (start-event end-event)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 "Code to work around a bug in post-19.29 emacs: it drops mouse-drag events.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 The problem occurs under XFree86-3.1.1 (X11R6pl11) but not under X11R5,
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 and under post-19.29 but not early versions of emacs.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 19.29 and 19.30 seems to drop mouse drag events
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 sometimes. (Reproducable under XFree86-3.1.1 (X11R6pl11) and
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 XFree86-3.1.2 under Linux 1.2.x. Doesn't occur under X11R5 and SunOS
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 4.1.1.)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 To see if you have the problem:
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 Disable this routine (with (setq mouse-copy-have-drag-bug nil))..
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 Click and drag for a while.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 If highlighting stops tracking, you have the bug.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 If you have the bug (or the real fix :-), please let me know."
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 ;; To work-around, call mouse-set-secondary with a fake
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 ;; drag event to set the overlay,
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 ;; the load the x-selection.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (save-excursion
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (let*
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 ((start-posn (event-start start-event))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (end-posn (event-end end-event))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (end-buffer (window-buffer (posn-window end-posn)))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 ;; First, figure out the region (left as point/mark).
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (range (progn
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (set-buffer end-buffer)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (mouse-start-end (posn-point start-posn)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (posn-point end-posn)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (1- (event-click-count start-event)))))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (beg (car range))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (end (car (cdr range))))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 ;; Second, set the overlay.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (if mouse-secondary-overlay
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (move-overlay mouse-secondary-overlay beg end)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (setq mouse-secondary-overlay (make-overlay beg (posn-point end))))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (overlay-put mouse-secondary-overlay 'face 'secondary-selection)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 ;; Third, set the selection.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 ;; (setq me-beg beg me-end end me-range range) ; for debugging
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (set-buffer end-buffer)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (x-set-selection 'SECONDARY (buffer-substring beg end)))))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 (defun mouse-drag-secondary-pasting (start-event)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 "Drag out a secondary selection, then paste it at the current point.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 To test this function, evaluate:
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (global-set-key [M-down-mouse-1] 'mouse-drag-secondary-pasting)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 put the point at one place, then click and drag over some other region."
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (interactive "e")
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 ;; Work-around: We see and react to each part of a multi-click event
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 ;; as it proceeds. For a triple-event, this means the double-event
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 ;; has already copied something that the triple-event will re-copy
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 ;; (a Bad Thing). We therefore undo the prior insertion if we're on
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 ;; a multiple event.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (if (and mouse-copy-last-paste-start
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (>= (event-click-count start-event) 2))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (delete-region mouse-copy-last-paste-start
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 mouse-copy-last-paste-end))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 ;; HACK: We assume that mouse-drag-secondary returns nil if
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 ;; there's no secondary selection. This assumption holds as of
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 ;; emacs-19.22 but is not documented. It's not clear that there's
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 ;; any other way to get this information.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (if (mouse-drag-secondary start-event)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (progn
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (if mouse-copy-have-drag-bug
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (mouse-copy-work-around-drag-bug start-event last-input-event))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 ;; Remember what we do so we can undo it, if necessary.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (setq mouse-copy-last-paste-start (point))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (insert (x-get-selection 'SECONDARY))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (setq mouse-copy-last-paste-end (point)))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (setq mouse-copy-last-paste-start nil)))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (defun mouse-kill-preserving-secondary ()
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 "Kill the text in the secondary selection, but leave the selection set.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 This command is like \\[mouse-kill-secondary] (that is, the secondary
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 selection is deleted and placed in the kill ring), except that it also
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 leaves the secondary buffer active on exit.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 This command was derived from mouse-kill-secondary in emacs-19.28
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 by johnh@ficus.cs.ucla.edu."
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (interactive)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (let* ((keys (this-command-keys))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (click (elt keys (1- (length keys)))))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (or (eq (overlay-buffer mouse-secondary-overlay)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (if (listp click)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (window-buffer (posn-window (event-start click)))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (current-buffer)))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (error "Select or click on the buffer where the secondary selection is")))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (save-excursion
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (set-buffer (overlay-buffer mouse-secondary-overlay))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (kill-region (overlay-start mouse-secondary-overlay)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (overlay-end mouse-secondary-overlay)))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 ;; (delete-overlay mouse-secondary-overlay)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 ;; (x-set-selection 'SECONDARY nil)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 ;; (setq mouse-secondary-overlay nil)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 )
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (defun mouse-drag-secondary-moving (start-event)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 "Sweep out a secondary selection, then move it to the current point."
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (interactive "e")
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 ;; HACK: We assume that mouse-drag-secondary returns nil if
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 ;; there's no secondary selection. This works as of emacs-19.22.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 ;; It's not clear that there's any other way to get this information.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (if (mouse-drag-secondary start-event)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (progn
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (mouse-kill-preserving-secondary)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (insert (x-get-selection 'SECONDARY))))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 )
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (provide 'mouse-copy)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 ;;; mouse-copy.el ends here