annotate lisp/mouse-copy.el @ 94417:1a8916b995cf

* epa-file.el (auto-encryption-mode): Rename from epa-file-mode. (epa-file-handler): Put 'safe-magic and 'operations properties. * epa.el (epa-global-minor-modes, epa-mode, epa-menu) (epa-menu-items): Remove. * epa-dired.el (epa-dired-do-decrypt, epa-dired-do-verify) (epa-dired-do-sign, epa-dired-do-encrypt): Add autoload cookie. (epa-dired-mode, epa-global-dired-mode): Remove. * dired.el (dired-mode-map): Bind encryption/decryption commands. * menu-bar.el (menu-bar-encryption-decryption-menu): New menu item. * files.el (insert-file-contents-literally): Inhibit epa-file-handler.
author Dan Nicolaescu <dann@ics.uci.edu>
date Sun, 27 Apr 2008 19:49:15 +0000
parents 26ae5706998a
children ee5932bf781d
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
74442
b2e5081b9320 Update copyright years.
Glenn Morris <rgm@gnu.org>
parents: 73756
diff changeset
3 ;; Copyright (C) 1996, 2001, 2002, 2003, 2004, 2005,
79721
73661ddc7ac7 Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 78236
diff changeset
4 ;; 2006, 2007, 2008 Free Software Foundation, Inc.
16321
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
6 ;; Author: John Heidemann <johnh@ISI.EDU>
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Keywords: mouse
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
78236
9355f9b7bbff Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents: 75347
diff changeset
13 ;; the Free Software Foundation; either version 3, or (at your option)
16321
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; any later version.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
64091
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
6fb026ad601f Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
24 ;; Boston, MA 02110-1301, USA.
16321
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
94101
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
28 ;; What is ``mouse-copy.el''?
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
29 ;;
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
30 ;; It provides one-click text copy and move. Rather than the
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
31 ;; standard stroke-out-a-region (down-mouse-1, up-mouse-1) followed
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
32 ;; by a yank (down-mouse-2, up-mouse-2 or C-y), you can now stroke
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
33 ;; out a region and have it automatically pasted at the current
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
34 ;; point. You can also move text just as easily. Although the
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
35 ;; difference may not sound like much, it does make mousing text
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
36 ;; around a lot easier, IMHO.
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
37 ;;
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
38 ;; If you like mouse-copy, you should also check out mouse-drag
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
39 ;; for ``one-click scrolling''.
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
40 ;;
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
41 ;; To use mouse-copy, place the following in your .emacs file:
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
42 ;; (require 'mouse-copy)
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
43 ;; (global-set-key [M-down-mouse-1] 'mouse-drag-secondary-pasting)
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
44 ;; (global-set-key [M-S-down-mouse-1] 'mouse-drag-secondary-moving)
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
45 ;;
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
46 ;; (These definitions override the old binding of M-mouse-1 to
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
47 ;; mouse-drag-secondary. I find I don't use that command much so its
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
48 ;; loss is not important, and it can be made up with a M-mouse-1
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
49 ;; followed by a M-mouse-3. I personally reserve M-mouse bindings
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
50 ;; for my window manager and bind everything to C-mouse.)
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
51 ;;
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
52 ;;
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
53 ;; History and related work:
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
54 ;;
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
55 ;; One-click copying and moving was inspired by lemacs-19.8.
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
56 ;; Throw-scrolling was inspired by MacPaint's ``hand'' and by Tk's
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
57 ;; mouse-2 scrolling. The package mouse-scroll.el by Tom Wurgler
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
58 ;; <twurgler@goodyear.com> is similar to mouse-drag-throw, but
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
59 ;; doesn't pass clicks through.
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
60 ;;
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
61 ;; These functions have been tested in emacs version 19.30,
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
62 ;; and this package has run in the past on 19.25-19.29.
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
63 ;;
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
64 ;; Originally mouse-copy was part of a larger package.
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
65 ;; As of 11 July 96 the scrolling functions were split out
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
66 ;; in preparation for incorporation into (the future) emacs-19.32.
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
67 ;;
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
68 ;;
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
69 ;; Known Bugs:
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
70 ;;
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
71 ;; - Highlighting is sub-optimal under 19.29 and XFree86-3.1.1
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
72 ;; (see \\[mouse-copy-work-around-drag-bug] for details).
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
73 ;; - mouse-drag-secondary-pasting and mouse-drag-secondary-moving
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
74 ;; require X11R5 (or better) and so fail under older versions
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
75 ;; of Open Windows (like that present in Solaris/x86 2.1).
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
76 ;;
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
77 ;;
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
78 ;; Future plans:
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
79 ;;
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
80 ;; I read about the chording features of Plan-9's Acme environment at
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
81 ;; <http://www.zip.com.au/~cs/app/wily/auug.html>. I'd like
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
82 ;; to incorporate some of these ideas into mouse-copy. The only
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
83 ;; lose is that this is not the current Emacs Way Of Doing Things, so
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
84 ;; there would be a learning curve for existing emacs users.
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
85 ;;
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
86 ;;
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
87 ;; Thanks:
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
88 ;;
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
89 ;; Thanks to Kai Grossjohann
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
90 ;; <grossjoh@dusty.informatik.uni-dortmund.de> for reporting bugs, to
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
91 ;; Tom Wurgler <twurgler@goodyear.com> for reporting bugs and
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
92 ;; suggesting fixes, and to Joel Graber <jgraber@ti.com> for
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
93 ;; prompting me to do drag-scrolling and for an initial
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
94 ;; implementation of horizontal drag-scrolling.
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
95 ;;
26ae5706998a Fix comment style.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 93975
diff changeset
96 ;; -johnh, 11-Jul-96
16321
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 ;;; Code:
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 ;;
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 ;; move/paste code
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
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 (defvar mouse-copy-last-paste-start nil
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 "Internal to `mouse-drag-secondary-pasting'.")
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 (defvar mouse-copy-last-paste-end nil
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 "Internal to `mouse-drag-secondary-pasting'.")
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 (defvar mouse-copy-have-drag-bug nil
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 "Set to enable mouse-copy-work-around-drag-bug.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 See `mouse-copy-work-around-drag-bug' for details.")
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (defun mouse-copy-work-around-drag-bug (start-event end-event)
73756
7b9a60623646 (mouse-copy-work-around-drag-bug): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 68651
diff changeset
114 "Code to work around a bug in post-19.29 Emacs: it drops mouse-drag events.
16321
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 The problem occurs under XFree86-3.1.1 (X11R6pl11) but not under X11R5,
73756
7b9a60623646 (mouse-copy-work-around-drag-bug): Fix typo in docstring.
Juanma Barranquero <lekktu@gmail.com>
parents: 68651
diff changeset
116 and under post-19.29 but not early versions of Emacs.
16321
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 19.29 and 19.30 seems to drop mouse drag events
47122
3629687a948d (mouse-copy-work-around-drag-bug): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents: 18027
diff changeset
119 sometimes. (Reproducible under XFree86-3.1.1 (X11R6pl11) and
16321
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 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
121 4.1.1.)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 To see if you have the problem:
47122
3629687a948d (mouse-copy-work-around-drag-bug): Fix typo.
Juanma Barranquero <lekktu@gmail.com>
parents: 18027
diff changeset
124 Disable this routine (with (setq mouse-copy-have-drag-bug nil)).
16321
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 Click and drag for a while.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 If highlighting stops tracking, you have the bug.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 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
128
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 ;; To work-around, call mouse-set-secondary with a fake
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 ;; drag event to set the overlay,
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 ;; the load the x-selection.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 (save-excursion
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133 (let*
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 ((start-posn (event-start start-event))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 (end-posn (event-end end-event))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (end-buffer (window-buffer (posn-window end-posn)))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 ;; First, figure out the region (left as point/mark).
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 (range (progn
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (set-buffer end-buffer)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 (mouse-start-end (posn-point start-posn)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (posn-point end-posn)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (1- (event-click-count start-event)))))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (beg (car range))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (end (car (cdr range))))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 ;; Second, set the overlay.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (if mouse-secondary-overlay
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (move-overlay mouse-secondary-overlay beg end)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (setq mouse-secondary-overlay (make-overlay beg (posn-point end))))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (overlay-put mouse-secondary-overlay 'face 'secondary-selection)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 ;; Third, set the selection.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 ;; (setq me-beg beg me-end end me-range range) ; for debugging
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (set-buffer end-buffer)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (x-set-selection 'SECONDARY (buffer-substring beg end)))))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154
49597
e88404e8f2cf Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47122
diff changeset
155
16321
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (defun mouse-drag-secondary-pasting (start-event)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157 "Drag out a secondary selection, then paste it at the current point.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 To test this function, evaluate:
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (global-set-key [M-down-mouse-1] 'mouse-drag-secondary-pasting)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 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
162 (interactive "e")
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 ;; 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
164 ;; as it proceeds. For a triple-event, this means the double-event
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 ;; has already copied something that the triple-event will re-copy
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 ;; (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
167 ;; a multiple event.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (if (and mouse-copy-last-paste-start
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (>= (event-click-count start-event) 2))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (delete-region mouse-copy-last-paste-start
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 mouse-copy-last-paste-end))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 ;; HACK: We assume that mouse-drag-secondary returns nil if
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 ;; there's no secondary selection. This assumption holds as of
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 ;; 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
176 ;; any other way to get this information.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (if (mouse-drag-secondary start-event)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (progn
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (if mouse-copy-have-drag-bug
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (mouse-copy-work-around-drag-bug start-event last-input-event))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 ;; Remember what we do so we can undo it, if necessary.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (setq mouse-copy-last-paste-start (point))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (insert (x-get-selection 'SECONDARY))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (setq mouse-copy-last-paste-end (point)))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (setq mouse-copy-last-paste-start nil)))
49597
e88404e8f2cf Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 47122
diff changeset
186
16321
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (defun mouse-kill-preserving-secondary ()
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 "Kill the text in the secondary selection, but leave the selection set.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 This command is like \\[mouse-kill-secondary] (that is, the secondary
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 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
193 leaves the secondary buffer active on exit.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 This command was derived from mouse-kill-secondary in emacs-19.28
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 by johnh@ficus.cs.ucla.edu."
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (interactive)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (let* ((keys (this-command-keys))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 (click (elt keys (1- (length keys)))))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (or (eq (overlay-buffer mouse-secondary-overlay)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 (if (listp click)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (window-buffer (posn-window (event-start click)))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (current-buffer)))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (error "Select or click on the buffer where the secondary selection is")))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (save-excursion
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (set-buffer (overlay-buffer mouse-secondary-overlay))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (kill-region (overlay-start mouse-secondary-overlay)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (overlay-end mouse-secondary-overlay)))
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 ;; (delete-overlay mouse-secondary-overlay)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 ;; (x-set-selection 'SECONDARY nil)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 ;; (setq mouse-secondary-overlay nil)
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
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (defun mouse-drag-secondary-moving (start-event)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 "Sweep out a secondary selection, then move it to the current point."
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (interactive "e")
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 ;; HACK: We assume that mouse-drag-secondary returns nil if
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 ;; there's no secondary selection. This works as of emacs-19.22.
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 ;; 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
220 (if (mouse-drag-secondary start-event)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (progn
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (mouse-kill-preserving-secondary)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (insert (x-get-selection 'SECONDARY))))
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
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (provide 'mouse-copy)
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 79721
diff changeset
228 ;; arch-tag: 3d50293b-c089-4273-b412-4fc96a5f26ff
16321
af6d52a93a59 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 ;;; mouse-copy.el ends here