aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2008-04-15 15:20:35 +0000
committerStefan Monnier2008-04-15 15:20:35 +0000
commitea89d7206680f28b3d85788be766d06ac763a50b (patch)
tree36636b96bd0a5fbb56b1eaceff80797c4fdb8735
parent56ca371a7c722c6761d07cce57c291e1785596e8 (diff)
downloademacs-ea89d7206680f28b3d85788be766d06ac763a50b.tar.gz
emacs-ea89d7206680f28b3d85788be766d06ac763a50b.zip
(mouse-throw-magnifier-with-scroll-bar)
(mouse-throw-magnifier-with-mouse-movement): Remove. (mouse-throw-magnifier-base): New const. (mouse-drag-scroll-delta): New fun. (mouse-drag-throw): Use it.
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/mouse-drag.el213
2 files changed, 108 insertions, 113 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index b67374967e4..ceda67a44c8 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,11 @@
12008-04-15 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * mouse-drag.el (mouse-throw-magnifier-with-scroll-bar)
4 (mouse-throw-magnifier-with-mouse-movement): Remove.
5 (mouse-throw-magnifier-base): New const.
6 (mouse-drag-scroll-delta): New fun.
7 (mouse-drag-throw): Use it.
8
12008-04-15 Juanma Barranquero <lekktu@gmail.com> 92008-04-15 Juanma Barranquero <lekktu@gmail.com>
2 10
3 * international/uni-bidi.el, international/uni-category.el: 11 * international/uni-bidi.el, international/uni-category.el:
diff --git a/lisp/mouse-drag.el b/lisp/mouse-drag.el
index b553a99ec35..726d9b69faf 100644
--- a/lisp/mouse-drag.el
+++ b/lisp/mouse-drag.el
@@ -25,81 +25,85 @@
25 25
26;;; Commentary: 26;;; Commentary:
27 27
28;;; What is ``mouse-drag.el''? 28;; What is ``mouse-drag.el''?
29;;; 29;;
30;;; Doesn't that scroll bar seem far away when you want to scroll? 30;; Doesn't that scroll bar seem far away when you want to scroll?
31;;; This module overloads mouse-2 to do ``throw'' scrolling. You 31;; This module overloads mouse-2 to do ``throw'' scrolling. You
32;;; click and drag. The distance you move from your original click 32;; click and drag. The distance you move from your original click
33;;; turns into a scroll amount. The scroll amount is scaled 33;; turns into a scroll amount. The scroll amount is scaled
34;;; exponentially to make both large moves and short adjustments easy. 34;; exponentially to make both large moves and short adjustments easy.
35;;; What this boils down to is that you can easily scroll around the 35;; What this boils down to is that you can easily scroll around the
36;;; buffer without much mouse movement. Finally, clicks which aren't 36;; buffer without much mouse movement. Finally, clicks which aren't
37;;; drags are passed off to the old mouse-2 binding, so old mouse-2 37;; drags are passed off to the old mouse-2 binding, so old mouse-2
38;;; operations (find-file in dired-mode, yanking in most other modes) 38;; operations (find-file in dired-mode, yanking in most other modes)
39;;; still work. 39;; still work.
40;;; 40;;
41;;; There is an alternative way to scroll, ``drag'' scrolling. You 41;; There is an alternative way to scroll, ``drag'' scrolling. You
42;;; can click on a character and then drag it around, scrolling the 42;; can click on a character and then drag it around, scrolling the
43;;; buffer with you. The character always stays under the mouse. 43;; buffer with you. The character always stays under the mouse.
44;;; Compared to throw-scrolling, this approach provides direct 44;; Compared to throw-scrolling, this approach provides direct
45;;; manipulation (nice) but requires more mouse movement 45;; manipulation (nice) but requires more mouse movement
46;;; (unfortunate). It is offered as an alternative for those who 46;; (unfortunate). It is offered as an alternative for those who
47;;; prefer it. 47;; prefer it.
48;;; 48;;
49;;; If you like mouse-drag, you should also check out mouse-copy 49;; If you like mouse-drag, you should also check out mouse-copy
50;;; for ``one-click text copy and move''. 50;; for ``one-click text copy and move''.
51;;; 51;;
52;;; To use mouse-drag, place the following in your .emacs file: 52;; To use mouse-drag, place the following in your .emacs file:
53;;; (require 'mouse-drag) 53;; (require 'mouse-drag)
54;;; -and either- 54;; -and either-
55;;; (global-set-key [down-mouse-2] 'mouse-drag-throw) 55;; (global-set-key [down-mouse-2] 'mouse-drag-throw)
56;;; -or- 56;; -or-
57;;; (global-set-key [down-mouse-2] 'mouse-drag-drag) 57;; (global-set-key [down-mouse-2] 'mouse-drag-drag)
58;;; 58;;
59;;; 59;;
60;;; 60;;
61;;; Options: 61;; Options:
62;;; 62;;
63;;; - reverse the throw-scroll direction with \\[mouse-throw-with-scroll-bar] 63;; - reverse the throw-scroll direction with \\[mouse-throw-with-scroll-bar]
64;;; - work around a bug with \\[mouse-extras-work-around-drag-bug] 64;; - work around a bug with \\[mouse-extras-work-around-drag-bug]
65;;; - auto-enable horizontal scrolling with 65;; - auto-enable horizontal scrolling with
66;;; \\[mouse-drag-electric-col-scrolling] 66;; \\[mouse-drag-electric-col-scrolling]
67;;; 67;;
68;;; 68;;
69;;; History and related work: 69;; History and related work:
70;;; 70;;
71;;; One-click copying and moving was inspired by lemacs-19.8. 71;; One-click copying and moving was inspired by lemacs-19.8.
72;;; Throw-scrolling was inspired by MacPaint's ``hand'' and by Tk's 72;; Throw-scrolling was inspired by MacPaint's ``hand'' and by Tk's
73;;; mouse-2 scrolling. The package mouse-scroll.el by Tom Wurgler 73;; mouse-2 scrolling. The package mouse-scroll.el by Tom Wurgler
74;;; <twurgler@goodyear.com> is similar to mouse-drag-throw, but 74;; <twurgler@goodyear.com> is similar to mouse-drag-throw, but
75;;; doesn't pass clicks through. 75;; doesn't pass clicks through.
76;;; 76;;
77;;; These functions have been tested in emacs version 19.30, 77;; These functions have been tested in emacs version 19.30,
78;;; and this package has run in the past on 19.25-19.29. 78;; and this package has run in the past on 19.25-19.29.
79;;; 79;;
80;;; Originally mouse-drag was part of a larger package. 80;; Originally mouse-drag was part of a larger package.
81;;; As of 11 July 96 the scrolling functions were split out 81;; As of 11 July 96 the scrolling functions were split out
82;;; in preparation for incorporation into (the future) emacs-19.32. 82;; in preparation for incorporation into (the future) emacs-19.32.
83;;; 83;;
84;;; 84http://lists.gnu.org/archive/html/emacs-devel/2008-04/;;
85;;; Thanks: 85;; Thanks:
86;;; 86;;
87;;; Thanks to Kai Grossjohann 87;; Thanks to Kai Grossjohann
88;;; <grossjoh@dusty.informatik.uni-dortmund.de> for reporting bugs, to 88;; <grossjoh@dusty.informatik.uni-dortmund.de> for reporting bugs, to
89;;; Tom Wurgler <twurgler@goodyear.com> for reporting bugs and 89;; Tom Wurgler <twurgler@goodyear.com> for reporting bugs and
90;;; suggesting fixes, and to Joel Graber <jgraber@ti.com> for 90;; suggesting fixes, and to Joel Graber <jgraber@ti.com> for
91;;; prompting me to do drag-scrolling and for an initial 91;; prompting me to do drag-scrolling and for an initial
92;;; implementation of horizontal drag-scrolling. 92;; implementation of horizontal drag-scrolling.
93;;; 93;;
94;;; -johnh@isi.edu, 11-Jul-96 94;; -johnh@isi.edu, 11-Jul-96
95;;; 95;;
96;;; 96;;
97;;; What's new with mouse-drag 2.24? 97;; What's new with mouse-drag 2.24?
98;;; 98;;
99;;; - mouse-drag-electric-col-scrolling (default: on) 99;; - mouse-drag-electric-col-scrolling (default: on)
100;;; auto-enables horizontal scrolling when clicks on wrapped 100;; auto-enables horizontal scrolling when clicks on wrapped
101;;; lines occur 101;; lines occur
102 102
103;; TODO:
104;; - For mouse-drag-throw, we should try and place some visual indicator
105;; of the original mouse position (like Firefox does).
106
103;;; Code: 107;;; Code:
104 108
105;; 109;;
@@ -142,11 +146,11 @@ Keep the cursor on the screen as needed."
142 ((start-col-row (posn-col-row start-posn)) 146 ((start-col-row (posn-col-row start-posn))
143 (end-col-row (posn-col-row end-posn))) 147 (end-col-row (posn-col-row end-posn)))
144 (and 148 (and
145;; We no longer exclude things by time. 149 ;; ;; We no longer exclude things by time.
146;; (< (- (posn-timestamp end-posn) (posn-timestamp start-posn)) 150 ;; (< (- (posn-timestamp end-posn) (posn-timestamp start-posn))
147;; (if (numberp double-click-time) 151 ;; (if (numberp double-click-time)
148;; (* 2 double-click-time) ;; stretch it a little 152 ;; (* 2 double-click-time) ;; stretch it a little
149;; 999999)) ;; non-numeric => check by position alone 153 ;; 999999)) ;; non-numeric => check by position alone
150 (= (car start-col-row) (car end-col-row)) 154 (= (car start-col-row) (car end-col-row))
151 (= (cdr start-col-row) (cdr end-col-row))))) 155 (= (cdr start-col-row) (cdr end-col-row)))))
152 156
@@ -173,12 +177,19 @@ Basically, we check for existing horizontal scrolling."
173 "*Set direction of mouse-throwing. 177 "*Set direction of mouse-throwing.
174If nil, the text moves in the direction the mouse moves. 178If nil, the text moves in the direction the mouse moves.
175If t, the scroll bar moves in the direction the mouse moves.") 179If t, the scroll bar moves in the direction the mouse moves.")
176(defconst mouse-throw-magnifier-with-scroll-bar
177 [-16 -8 -4 -2 -1 0 0 0 1 2 4 8 16])
178(defconst mouse-throw-magnifier-with-mouse-movement
179 [ 16 8 4 2 1 0 0 0 -1 -2 -4 -8 -16])
180(defconst mouse-throw-magnifier-min -6) 180(defconst mouse-throw-magnifier-min -6)
181(defconst mouse-throw-magnifier-max 6) 181(defconst mouse-throw-magnifier-max 6)
182(defconst mouse-throw-magnifier-base 1.5)
183
184(defun mouse-drag-scroll-delta (mouse-delta)
185 ;; Limit the exponential explosion.
186 (setq mouse-delta
187 (max mouse-throw-magnifier-min
188 (min mouse-throw-magnifier-max mouse-delta)))
189 (* (round (exp (* (log mouse-throw-magnifier-base) (abs mouse-delta))))
190 (if (< mouse-delta 0) -1 1)
191 (if mouse-throw-with-scroll-bar 1 -1)))
192
182 193
183(defun mouse-drag-throw (start-event) 194(defun mouse-drag-throw (start-event)
184 "\"Throw\" the page according to a mouse drag. 195 "\"Throw\" the page according to a mouse drag.
@@ -226,35 +237,11 @@ To test this function, evaluate:
226 col (car (posn-col-row end))) 237 col (car (posn-col-row end)))
227 (or (mouse-movement-p event) 238 (or (mouse-movement-p event)
228 (eq (car-safe event) 'switch-frame))) 239 (eq (car-safe event) 'switch-frame)))
229 (if (eq start-window (posn-window end)) 240 (when (eq start-window (posn-window end))
230 (progn 241 (when col-scrolling-p
231 (setq mouse-delta (- start-row row) 242 (setq scroll-col-delta (mouse-drag-scroll-delta (- start-col col))))
232 adjusted-mouse-delta 243 (setq scroll-delta (mouse-drag-scroll-delta (- start-row row))))
233 (- (cond 244
234 ((<= mouse-delta mouse-throw-magnifier-min)
235 mouse-throw-magnifier-min)
236 ((>= mouse-delta mouse-throw-magnifier-max)
237 mouse-throw-magnifier-max)
238 (t mouse-delta))
239 mouse-throw-magnifier-min)
240 scroll-delta (aref (if mouse-throw-with-scroll-bar
241 mouse-throw-magnifier-with-scroll-bar
242 mouse-throw-magnifier-with-mouse-movement)
243 adjusted-mouse-delta))
244 (if col-scrolling-p
245 (setq mouse-col-delta (- start-col col)
246 adjusted-mouse-col-delta
247 (- (cond
248 ((<= mouse-col-delta mouse-throw-magnifier-min)
249 mouse-throw-magnifier-min)
250 ((>= mouse-col-delta mouse-throw-magnifier-max)
251 mouse-throw-magnifier-max)
252 (t mouse-col-delta))
253 mouse-throw-magnifier-min)
254 scroll-col-delta (aref (if mouse-throw-with-scroll-bar
255 mouse-throw-magnifier-with-scroll-bar
256 mouse-throw-magnifier-with-mouse-movement)
257 adjusted-mouse-col-delta)))))
258 (if (or (/= 0 scroll-delta) 245 (if (or (/= 0 scroll-delta)
259 (/= 0 scroll-col-delta)) 246 (/= 0 scroll-col-delta))
260 (progn 247 (progn