aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim F. Storm2002-11-28 23:03:30 +0000
committerKim F. Storm2002-11-28 23:03:30 +0000
commitd09696f73f17c4ae0bf09e8c72ef7f427f07d31b (patch)
tree76d1cc7880b2a1a1cfa457ae8ad75903a59e3b8c
parent30590488e05be985cd01c76e4cf6d35a00aa11d9 (diff)
downloademacs-d09696f73f17c4ae0bf09e8c72ef7f427f07d31b.tar.gz
emacs-d09696f73f17c4ae0bf09e8c72ef7f427f07d31b.zip
Avoid accidental yanking of text while scrolling with
the mouse wheel. This adds a short period after each mouse wheel scroll event where a click on the mouse wheel button is ignored. (mouse-wheel-click-event, mouse-wheel-inhibit-click-time): New customs. (mouse-wheel-click-button, mwheel-inhibit-click-event-timer): New vars. (mwheel-inhibit-click-timeout,mwheel-filter-click-events): New defuns. (mwheel-scroll): Add mwheel-filter-click-events as pre-command-hook. Start mwheel-inhibit-click-event-timer with timeout handler mwheel-inhibit-click-timeout.
-rw-r--r--lisp/mwheel.el46
1 files changed, 43 insertions, 3 deletions
diff --git a/lisp/mwheel.el b/lisp/mwheel.el
index eefe44c2ad9..478b778bc2b 100644
--- a/lisp/mwheel.el
+++ b/lisp/mwheel.el
@@ -1,4 +1,4 @@
1;;; mwheel.el --- Mouse support for MS intelli-mouse type mice 1;;; mwheel.el --- Wheel mouse support
2 2
3;; Copyright (C) 1998,2000,2001,2002 Free Software Foundation, Inc. 3;; Copyright (C) 1998,2000,2001,2002 Free Software Foundation, Inc.
4;; Maintainer: William M. Perry <wmperry@gnu.org> 4;; Maintainer: William M. Perry <wmperry@gnu.org>
@@ -40,6 +40,7 @@
40;;; Code: 40;;; Code:
41 41
42(require 'custom) 42(require 'custom)
43(require 'timer)
43 44
44;; Setter function for mouse-button user-options. Switch Mouse Wheel 45;; Setter function for mouse-button user-options. Switch Mouse Wheel
45;; mode off and on again so that the old button is unbound and 46;; mode off and on again so that the old button is unbound and
@@ -74,6 +75,26 @@
74 :type 'symbol 75 :type 'symbol
75 :set 'mouse-wheel-change-button) 76 :set 'mouse-wheel-change-button)
76 77
78(defvar mouse-wheel-click-button 2
79 "Obsolete. Use `mouse-wheel-click-event'.")
80(defcustom mouse-wheel-click-event
81 ;; In the latest versions of XEmacs, we could just use mouse-%s as well.
82 (intern (format (if (featurep 'xemacs) "button%s" "mouse-%s")
83 mouse-wheel-click-button))
84 "Event that should be temporarily inhibited after mouse scrolling.
85The mouse wheel is typically on the mouse-2 button, so it may easily
86happen that text is accidentially yanked into the buffer when
87scrolling with the mouse wheel. To prevent that, this variable can be
88set to the event sent when clicking on the mouse wheel button."
89 :group 'mouse
90 :type 'symbol
91 :set 'mouse-wheel-change-button)
92
93(defcustom mouse-wheel-inhibit-click-time 0.35
94 "Time in seconds to inhibit clicking on mouse wheel button after scroll."
95 :group 'mouse
96 :type 'float)
97
77(defcustom mouse-wheel-scroll-amount '(5 ((shift) . 1) ((control) . nil)) 98(defcustom mouse-wheel-scroll-amount '(5 ((shift) . 1) ((control) . nil))
78 "Amount to scroll windows by when spinning the mouse wheel. 99 "Amount to scroll windows by when spinning the mouse wheel.
79This is an alist mapping the modifier key to the amount to scroll when 100This is an alist mapping the modifier key to the amount to scroll when
@@ -140,6 +161,19 @@ This can be slightly disconcerting, but some people prefer it."
140 (posn-window (event-start event))) 161 (posn-window (event-start event)))
141 (fset 'mwheel-event-window 'event-window)) 162 (fset 'mwheel-event-window 'event-window))
142 163
164(defvar mwheel-inhibit-click-event-timer nil
165 "Timer running while mouse wheel click event is inhibited.")
166
167(defun mwheel-inhibit-click-timeout ()
168 "Handler for `mwheel-inhibit-click-event-timer'."
169 (setq mwheel-inhibit-click-event-timer nil)
170 (remove-hook 'pre-command-hook 'mwheel-filter-click-events))
171
172(defun mwheel-filter-click-events ()
173 "Discard `mouse-wheel-click-event' while scrolling the mouse."
174 (if (eq (event-basic-type last-input-event) mouse-wheel-click-event)
175 (setq this-command 'ignore)))
176
143(defun mwheel-scroll (event) 177(defun mwheel-scroll (event)
144 "Scroll up or down according to the EVENT. 178 "Scroll up or down according to the EVENT.
145This should only be bound to mouse buttons 4 and 5." 179This should only be bound to mouse buttons 4 and 5."
@@ -165,8 +199,14 @@ This should only be bound to mouse buttons 4 and 5."
165 (cond ((eq button mouse-wheel-down-event) (scroll-down amt)) 199 (cond ((eq button mouse-wheel-down-event) (scroll-down amt))
166 ((eq button mouse-wheel-up-event) (scroll-up amt)) 200 ((eq button mouse-wheel-up-event) (scroll-up amt))
167 (t (error "Bad binding in mwheel-scroll")))) 201 (t (error "Bad binding in mwheel-scroll"))))
168 (if curwin (select-window curwin))))) 202 (if curwin (select-window curwin))))
169 203 (when (and mouse-wheel-click-event mouse-wheel-inhibit-click-time)
204 (if mwheel-inhibit-click-event-timer
205 (cancel-timer mwheel-inhibit-click-event-timer)
206 (add-hook 'pre-command-hook 'mwheel-filter-click-events))
207 (setq mwheel-inhibit-click-event-timer
208 (run-with-timer mouse-wheel-inhibit-click-time nil
209 'mwheel-inhibit-click-timeout))))
170 210
171;;;###autoload 211;;;###autoload
172(define-minor-mode mouse-wheel-mode 212(define-minor-mode mouse-wheel-mode