annotate lisp/mouse-drag.el @ 87469:89cfe5d80ddf

(Language Modes): Fix menu.
author Jay Belanger <jay.p.belanger@gmail.com>
date Sat, 29 Dec 2007 01:16:30 +0000
parents ad7b04a38ce4
children 73661ddc7ac7 424b655804ca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17517
8f952e921136 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 16322
diff changeset
1 ;;; mouse-drag.el --- use mouse-2 to do a new style of scrolling
8f952e921136 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 16322
diff changeset
2
64762
41bb365f41c4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64091
diff changeset
3 ;; Copyright (C) 1996, 1997, 2001, 2002, 2003, 2004,
75347
e3694f1cb928 Add 2007 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 68651
diff changeset
4 ;; 2005, 2006, 2007 Free Software Foundation, Inc.
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
5
16322
f4be70df6bb6 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 16320
diff changeset
6 ;; Author: John Heidemann <johnh@ISI.EDU>
f4be70df6bb6 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 16320
diff changeset
7 ;; Keywords: mouse
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; This file is part of GNU Emacs.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
8bd3981bd342 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)
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; any later version.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is distributed in the hope that it will be useful,
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; GNU General Public License for more details.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
8bd3981bd342 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.
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;;; Commentary:
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;;; What is ``mouse-drag.el''?
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;;; Doesn't that scroll bar seem far away when you want to scroll?
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31 ;;; This module overloads mouse-2 to do ``throw'' scrolling. You
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32 ;;; click and drag. The distance you move from your original click
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
33 ;;; turns into a scroll amount. The scroll amount is scaled
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
34 ;;; exponentially to make both large moves and short adjustments easy.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
35 ;;; What this boils down to is that you can easily scroll around the
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 ;;; buffer without much mouse movement. Finally, clicks which aren't
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;;; drags are passed off to the old mouse-2 binding, so old mouse-2
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;;; operations (find-file in dired-mode, yanking in most other modes)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;;; still work.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 ;;; There is an alternative way to scroll, ``drag'' scrolling. You
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 ;;; can click on a character and then drag it around, scrolling the
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;;; buffer with you. The character always stays under the mouse.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;;; Compared to throw-scrolling, this approach provides direct
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;;; manipulation (nice) but requires more mouse movement
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;;; (unfortunate). It is offered as an alternative for those who
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 ;;; prefer it.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 ;;; If you like mouse-drag, you should also check out mouse-copy
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;;; for ``one-click text copy and move''.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;;; To use mouse-drag, place the following in your .emacs file:
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 ;;; (require 'mouse-drag)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 ;;; -and either-
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 ;;; (global-set-key [down-mouse-2] 'mouse-drag-throw)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 ;;; -or-
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 ;;; (global-set-key [down-mouse-2] 'mouse-drag-drag)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;;; Options:
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;;; - reverse the throw-scroll direction with \\[mouse-throw-with-scroll-bar]
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;;; - work around a bug with \\[mouse-extras-work-around-drag-bug]
18026
e3b0e7dc5efd * mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents: 17517
diff changeset
65 ;;; - auto-enable horizontal scrolling with
e3b0e7dc5efd * mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents: 17517
diff changeset
66 ;;; \\[mouse-drag-electric-col-scrolling]
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 ;;; History and related work:
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 ;;; One-click copying and moving was inspired by lemacs-19.8.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 ;;; Throw-scrolling was inspired by MacPaint's ``hand'' and by Tk's
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;;; mouse-2 scrolling. The package mouse-scroll.el by Tom Wurgler
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;;; <twurgler@goodyear.com> is similar to mouse-drag-throw, but
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;;; doesn't pass clicks through.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 ;;; These functions have been tested in emacs version 19.30,
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 ;;; and this package has run in the past on 19.25-19.29.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 ;;; Originally mouse-drag was part of a larger package.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;;; As of 11 July 96 the scrolling functions were split out
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 ;;; in preparation for incorporation into (the future) emacs-19.32.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85 ;;; Thanks:
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;;; Thanks to Kai Grossjohann
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 ;;; <grossjoh@dusty.informatik.uni-dortmund.de> for reporting bugs, to
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;;; Tom Wurgler <twurgler@goodyear.com> for reporting bugs and
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 ;;; suggesting fixes, and to Joel Graber <jgraber@ti.com> for
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 ;;; prompting me to do drag-scrolling and for an initial
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 ;;; implementation of horizontal drag-scrolling.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ;;; -johnh@isi.edu, 11-Jul-96
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 ;;;
18026
e3b0e7dc5efd * mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents: 17517
diff changeset
97 ;;; What's new with mouse-drag 2.24?
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 ;;;
18026
e3b0e7dc5efd * mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents: 17517
diff changeset
99 ;;; - mouse-drag-electric-col-scrolling (default: on)
e3b0e7dc5efd * mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents: 17517
diff changeset
100 ;;; auto-enables horizontal scrolling when clicks on wrapped
e3b0e7dc5efd * mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents: 17517
diff changeset
101 ;;; lines occur
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 ;;; Code:
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 ;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 ;; scrolling code
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 ;;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 (defun mouse-drag-safe-scroll (row-delta &optional col-delta)
18134
2441b667abdd (mouse-drag-safe-scroll): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 18026
diff changeset
110 "Scroll down ROW-DELTA lines and right COL-DELTA, ignoring buffer edge errors.
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 Keep the cursor on the screen as needed."
35085
acc3474759c0 (mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents: 18134
diff changeset
112 (let ((scroll-preserve-screen-position nil))
acc3474759c0 (mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents: 18134
diff changeset
113 (if (and row-delta
acc3474759c0 (mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents: 18134
diff changeset
114 (/= 0 row-delta))
acc3474759c0 (mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents: 18134
diff changeset
115 (condition-case nil ;; catch and ignore movement errors
acc3474759c0 (mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents: 18134
diff changeset
116 (scroll-down row-delta)
acc3474759c0 (mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents: 18134
diff changeset
117 (beginning-of-buffer (message "Beginning of buffer"))
acc3474759c0 (mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents: 18134
diff changeset
118 (end-of-buffer (message "End of buffer"))))
acc3474759c0 (mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents: 18134
diff changeset
119 (if (and col-delta
acc3474759c0 (mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents: 18134
diff changeset
120 (/= 0 col-delta))
acc3474759c0 (mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents: 18134
diff changeset
121 (progn
acc3474759c0 (mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents: 18134
diff changeset
122 (scroll-right col-delta)
acc3474759c0 (mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents: 18134
diff changeset
123 ;; Make sure that the point stays on the visible screen
acc3474759c0 (mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents: 18134
diff changeset
124 ;; (if truncation-lines in set).
acc3474759c0 (mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents: 18134
diff changeset
125 ;; This code mimics the behavior we automatically get
acc3474759c0 (mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents: 18134
diff changeset
126 ;; when doing vertical scrolling.
acc3474759c0 (mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents: 18134
diff changeset
127 ;; Problem identified and a fix suggested by Tom Wurgler.
acc3474759c0 (mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents: 18134
diff changeset
128 (cond
acc3474759c0 (mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents: 18134
diff changeset
129 ((< (current-column) (window-hscroll))
acc3474759c0 (mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents: 18134
diff changeset
130 (move-to-column (window-hscroll))) ; make on left column
acc3474759c0 (mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents: 18134
diff changeset
131 ((> (- (current-column) (window-hscroll) (window-width) -2) 0)
acc3474759c0 (mouse-drag-safe-scroll): Bind
Gerd Moellmann <gerd@gnu.org>
parents: 18134
diff changeset
132 (move-to-column (+ (window-width) (window-hscroll) -3))))))))
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (defun mouse-drag-repeatedly-safe-scroll (row-delta &optional col-delta)
18134
2441b667abdd (mouse-drag-safe-scroll): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 18026
diff changeset
135 "Scroll ROW-DELTA rows and COL-DELTA cols until an event happens."
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
136 (while (sit-for mouse-scroll-delay)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 (mouse-drag-safe-scroll row-delta col-delta)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (defun mouse-drag-events-are-point-events-p (start-posn end-posn)
18134
2441b667abdd (mouse-drag-safe-scroll): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 18026
diff changeset
140 "Determine if START-POSN and END-POSN are \"close\"."
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (let*
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 ((start-col-row (posn-col-row start-posn))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (end-col-row (posn-col-row end-posn)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (and
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 ;; We no longer exclude things by time.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 ;; (< (- (posn-timestamp end-posn) (posn-timestamp start-posn))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 ;; (if (numberp double-click-time)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 ;; (* 2 double-click-time) ;; stretch it a little
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 ;; 999999)) ;; non-numeric => check by position alone
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (= (car start-col-row) (car end-col-row))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (= (cdr start-col-row) (cdr end-col-row)))))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152
18026
e3b0e7dc5efd * mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents: 17517
diff changeset
153 (defvar mouse-drag-electric-col-scrolling t
e3b0e7dc5efd * mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents: 17517
diff changeset
154 "If non-nil, mouse-drag on a long line enables truncate-lines.")
e3b0e7dc5efd * mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents: 17517
diff changeset
155
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (defun mouse-drag-should-do-col-scrolling ()
18134
2441b667abdd (mouse-drag-safe-scroll): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 18026
diff changeset
157 "Determine if it's wise to enable col-scrolling for the current window.
18026
e3b0e7dc5efd * mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents: 17517
diff changeset
158 Basically, we check for existing horizontal scrolling."
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 (or truncate-lines
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 (> (window-hscroll (selected-window)) 0)
78463
ad7b04a38ce4 Use window-full-width-p instead of comparing frame-width and
Martin Rudalics <rudalics@gmx.at>
parents: 78236
diff changeset
161 (not (window-full-width-p))
18026
e3b0e7dc5efd * mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents: 17517
diff changeset
162 (and
e3b0e7dc5efd * mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents: 17517
diff changeset
163 mouse-drag-electric-col-scrolling
e3b0e7dc5efd * mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents: 17517
diff changeset
164 (save-excursion ;; on a long line?
e3b0e7dc5efd * mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents: 17517
diff changeset
165 (let
e3b0e7dc5efd * mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents: 17517
diff changeset
166 ((beg (progn (beginning-of-line) (point)))
e3b0e7dc5efd * mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents: 17517
diff changeset
167 (end (progn (end-of-line) (point))))
e3b0e7dc5efd * mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents: 17517
diff changeset
168 (if (> (- end beg) (window-width))
e3b0e7dc5efd * mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents: 17517
diff changeset
169 (setq truncate-lines t)
e3b0e7dc5efd * mouse-drag.el (mouse-drag-electric-col-scrolling): New variable;
Karl Heuer <kwzh@gnu.org>
parents: 17517
diff changeset
170 nil))))))
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (defvar mouse-throw-with-scroll-bar nil
18134
2441b667abdd (mouse-drag-safe-scroll): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 18026
diff changeset
173 "*Set direction of mouse-throwing.
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 If nil, the text moves in the direction the mouse moves.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 If t, the scroll bar moves in the direction the mouse moves.")
18134
2441b667abdd (mouse-drag-safe-scroll): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 18026
diff changeset
176 (defconst mouse-throw-magnifier-with-scroll-bar
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 [-16 -8 -4 -2 -1 0 0 0 1 2 4 8 16])
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (defconst mouse-throw-magnifier-with-mouse-movement
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 [ 16 8 4 2 1 0 0 0 -1 -2 -4 -8 -16])
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (defconst mouse-throw-magnifier-min -6)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (defconst mouse-throw-magnifier-max 6)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 (defun mouse-drag-throw (start-event)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 "\"Throw\" the page according to a mouse drag.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 A \"throw\" is scrolling the page at a speed relative to the distance
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 from the original mouse click to the current mouse location. Try it;
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 you'll like it. It's easier to observe than to explain.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 If the mouse is clicked and released in the same place of time we
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 assume that the user didn't want to scdebugroll but wanted to whatever
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 mouse-2 used to do, so we pass it through.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194 Throw scrolling was inspired (but is not identical to) the \"hand\"
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 option in MacPaint, or the middle button in Tk text widgets.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 If `mouse-throw-with-scroll-bar' is non-nil, then this command scrolls
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 in the opposite direction. (Different people have different ideas
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 about which direction is natural. Perhaps it has to do with which
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 hemisphere you're in.)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 To test this function, evaluate:
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (global-set-key [down-mouse-2] 'mouse-drag-throw)"
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (interactive "e")
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 ;; we want to do save-selected-window, but that requires 19.29
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (let* ((start-posn (event-start start-event))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (start-window (posn-window start-posn))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
208 (start-row (cdr (posn-col-row start-posn)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
209 (start-col (car (posn-col-row start-posn)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 (old-selected-window (selected-window))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 event end row mouse-delta scroll-delta
41217
096bd345e996 (mouse-drag-throw): Push back non-drag events
Richard M. Stallman <rms@gnu.org>
parents: 35141
diff changeset
212 have-scrolled
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 window-last-row
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 col mouse-col-delta window-last-col
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (scroll-col-delta 0)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 adjusted-mouse-col-delta
16320
56f494ed6b13 (mouse-drag-throw): Bind adjusted-mouse-delta.
Richard M. Stallman <rms@gnu.org>
parents: 16319
diff changeset
217 adjusted-mouse-delta
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 ;; be conservative about allowing horizontal scrolling
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (col-scrolling-p (mouse-drag-should-do-col-scrolling)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (select-window start-window)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (track-mouse
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 (while (progn
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (setq event (read-event)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 end (event-end event)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 row (cdr (posn-col-row end))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 col (car (posn-col-row end)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (or (mouse-movement-p event)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (eq (car-safe event) 'switch-frame)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (if (eq start-window (posn-window end))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 (progn
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (setq mouse-delta (- start-row row)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 adjusted-mouse-delta
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (- (cond
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 ((<= mouse-delta mouse-throw-magnifier-min)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 mouse-throw-magnifier-min)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 ((>= mouse-delta mouse-throw-magnifier-max)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 mouse-throw-magnifier-max)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 (t mouse-delta))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 mouse-throw-magnifier-min)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 scroll-delta (aref (if mouse-throw-with-scroll-bar
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 mouse-throw-magnifier-with-scroll-bar
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 mouse-throw-magnifier-with-mouse-movement)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 adjusted-mouse-delta))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 (if col-scrolling-p
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (setq mouse-col-delta (- start-col col)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 adjusted-mouse-col-delta
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 (- (cond
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 ((<= mouse-col-delta mouse-throw-magnifier-min)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 mouse-throw-magnifier-min)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 ((>= mouse-col-delta mouse-throw-magnifier-max)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 mouse-throw-magnifier-max)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252 (t mouse-col-delta))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 mouse-throw-magnifier-min)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 scroll-col-delta (aref (if mouse-throw-with-scroll-bar
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 mouse-throw-magnifier-with-scroll-bar
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 mouse-throw-magnifier-with-mouse-movement)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 adjusted-mouse-col-delta)))))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (if (or (/= 0 scroll-delta)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 (/= 0 scroll-col-delta))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (progn
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 (setq have-scrolled t)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (mouse-drag-safe-scroll scroll-delta scroll-col-delta)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (mouse-drag-repeatedly-safe-scroll scroll-delta scroll-col-delta))))) ;xxx
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 ;; If it was a click and not a drag, prepare to pass the event on.
41217
096bd345e996 (mouse-drag-throw): Push back non-drag events
Richard M. Stallman <rms@gnu.org>
parents: 35141
diff changeset
265 ;; Is there a more correct way to reconstruct the event?
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (if (and (not have-scrolled)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (mouse-drag-events-are-point-events-p start-posn end))
41217
096bd345e996 (mouse-drag-throw): Push back non-drag events
Richard M. Stallman <rms@gnu.org>
parents: 35141
diff changeset
268 (push (cons (event-basic-type start-event) (cdr start-event))
096bd345e996 (mouse-drag-throw): Push back non-drag events
Richard M. Stallman <rms@gnu.org>
parents: 35141
diff changeset
269 unread-command-events))
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 ;; Now restore the old window.
41217
096bd345e996 (mouse-drag-throw): Push back non-drag events
Richard M. Stallman <rms@gnu.org>
parents: 35141
diff changeset
271 (select-window old-selected-window)))
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (defun mouse-drag-drag (start-event)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 "\"Drag\" the page according to a mouse drag.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 Drag scrolling moves the page according to the movement of the mouse.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 You \"grab\" the character under the mouse and move it around.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 If the mouse is clicked and released in the same place of time we
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 assume that the user didn't want to scroll but wanted to whatever
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 mouse-2 used to do, so we pass it through.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 Drag scrolling is identical to the \"hand\" option in MacPaint, or the
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 middle button in Tk text widgets.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 To test this function, evaluate:
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (global-set-key [down-mouse-2] 'mouse-drag-drag)"
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (interactive "e")
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 ;; we want to do save-selected-window, but that requires 19.29
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (let* ((start-posn (event-start start-event))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 (start-window (posn-window start-posn))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 (start-row (cdr (posn-col-row start-posn)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (start-col (car (posn-col-row start-posn)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 (old-selected-window (selected-window))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 event end row mouse-delta scroll-delta
41217
096bd345e996 (mouse-drag-throw): Push back non-drag events
Richard M. Stallman <rms@gnu.org>
parents: 35141
diff changeset
296 have-scrolled
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 window-last-row
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 col mouse-col-delta window-last-col
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 (scroll-col-delta 0)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 ;; be conservative about allowing horizontal scrolling
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 (col-scrolling-p (mouse-drag-should-do-col-scrolling)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 (select-window start-window)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (setq window-last-row (- (window-height) 2)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 window-last-col (- (window-width) 2))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 (track-mouse
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 (while (progn
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 (setq event (read-event)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 end (event-end event)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 row (cdr (posn-col-row end))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 col (car (posn-col-row end)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 (or (mouse-movement-p event)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 (eq (car-safe event) 'switch-frame)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 ;; Scroll if see if we're on the edge.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 ;; NEEDSWORK: should handle mouse-in-other window.
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 (cond
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 ((not (eq start-window (posn-window end)))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 t) ; wait for return to original window
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 ((<= row 0) (mouse-drag-repeatedly-safe-scroll -1 0))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 ((>= row window-last-row) (mouse-drag-repeatedly-safe-scroll 1 0))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 ((and col-scrolling-p (<= col 1)) (mouse-drag-repeatedly-safe-scroll 0 -1))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 ((and col-scrolling-p (>= col window-last-col)) (mouse-drag-repeatedly-safe-scroll 0 1))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 (t
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 (setq scroll-delta (- row start-row)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 start-row row)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (if col-scrolling-p
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 (setq scroll-col-delta (- col start-col)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 start-col col))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 (if (or (/= 0 scroll-delta)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (/= 0 scroll-col-delta))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 (progn
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 (setq have-scrolled t)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (mouse-drag-safe-scroll scroll-delta scroll-col-delta)))))))
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 ;; If it was a click and not a drag, prepare to pass the event on.
41217
096bd345e996 (mouse-drag-throw): Push back non-drag events
Richard M. Stallman <rms@gnu.org>
parents: 35141
diff changeset
334 ;; Is there a more correct way to reconstruct the event?
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (if (and (not have-scrolled)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (mouse-drag-events-are-point-events-p start-posn end))
41217
096bd345e996 (mouse-drag-throw): Push back non-drag events
Richard M. Stallman <rms@gnu.org>
parents: 35141
diff changeset
337 (push (cons (event-basic-type start-event) (cdr start-event))
096bd345e996 (mouse-drag-throw): Push back non-drag events
Richard M. Stallman <rms@gnu.org>
parents: 35141
diff changeset
338 unread-command-events))
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 ;; Now restore the old window.
41217
096bd345e996 (mouse-drag-throw): Push back non-drag events
Richard M. Stallman <rms@gnu.org>
parents: 35141
diff changeset
340 (select-window old-selected-window)))
096bd345e996 (mouse-drag-throw): Push back non-drag events
Richard M. Stallman <rms@gnu.org>
parents: 35141
diff changeset
341
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 (provide 'mouse-drag)
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 41217
diff changeset
345 ;;; arch-tag: e47354ff-82f5-42c4-b3dc-88dd9c04b770
16319
8bd3981bd342 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 ;;; mouse-drag.el ends here