annotate lisp/mwheel.el @ 48574:3e3b1f1265f5

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.
author Kim F. Storm <storm@cua.dk>
date Thu, 28 Nov 2002 23:03:30 +0000
parents aa0e0ea91f27
children 338527f8ef91
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
48574
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
1 ;;; mwheel.el --- Wheel mouse support
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
2
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
3 ;; Copyright (C) 1998,2000,2001,2002 Free Software Foundation, Inc.
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
4 ;; Maintainer: William M. Perry <wmperry@gnu.org>
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
5 ;; Keywords: mouse
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
6
26410
55a234a9fe88 Fix copyright notice. Don't require 'cl at run time.
Gerd Moellmann <gerd@gnu.org>
parents: 26398
diff changeset
7 ;; This file is part of GNU Emacs.
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
8
26410
55a234a9fe88 Fix copyright notice. Don't require 'cl at run time.
Gerd Moellmann <gerd@gnu.org>
parents: 26398
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
55a234a9fe88 Fix copyright notice. Don't require 'cl at run time.
Gerd Moellmann <gerd@gnu.org>
parents: 26398
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
12 ;; any later version.
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
13
26410
55a234a9fe88 Fix copyright notice. Don't require 'cl at run time.
Gerd Moellmann <gerd@gnu.org>
parents: 26398
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
55a234a9fe88 Fix copyright notice. Don't require 'cl at run time.
Gerd Moellmann <gerd@gnu.org>
parents: 26398
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
55a234a9fe88 Fix copyright notice. Don't require 'cl at run time.
Gerd Moellmann <gerd@gnu.org>
parents: 26398
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55a234a9fe88 Fix copyright notice. Don't require 'cl at run time.
Gerd Moellmann <gerd@gnu.org>
parents: 26398
diff changeset
17 ;; GNU General Public License for more details.
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
18
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
26410
55a234a9fe88 Fix copyright notice. Don't require 'cl at run time.
Gerd Moellmann <gerd@gnu.org>
parents: 26398
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
22 ;; Boston, MA 02111-1307, USA.
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
23
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
24 ;;; Commentary:
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
25
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
26 ;; This code will enable the use of the infamous 'wheel' on the new
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
27 ;; crop of mice. Under XFree86 and the XSuSE X Servers, the wheel
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
28 ;; events are sent as button4/button5 events.
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
29
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
30 ;; I for one would prefer some way of converting the button4/button5
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
31 ;; events into different event types, like 'mwheel-up' or
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
32 ;; 'mwheel-down', but I cannot find a way to do this very easily (or
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
33 ;; portably), so for now I just live with it.
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
34
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
35 ;; To enable this code, simply put this at the top of your .emacs
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
36 ;; file:
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
37 ;;
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
38 ;; (mwheel-install)
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
39
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
40 ;;; Code:
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
41
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
42 (require 'custom)
48574
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
43 (require 'timer)
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
44
38582
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
45 ;; Setter function for mouse-button user-options. Switch Mouse Wheel
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
46 ;; mode off and on again so that the old button is unbound and
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
47 ;; new button is bound to mwheel-scroll.
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
48
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
49 (defun mouse-wheel-change-button (var button)
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
50 (let ((active mouse-wheel-mode))
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
51 ;; Deactivate before changing the setting.
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
52 (when active (mouse-wheel-mode -1))
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
53 (set-default var button)
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
54 (when active (mouse-wheel-mode 1))))
38582
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
55
48253
aa0e0ea91f27 (mouse-wheel-down-button, mouse-wheel-up-button):
Markus Rost <rost@math.uni-bielefeld.de>
parents: 47114
diff changeset
56 (defvar mouse-wheel-down-button 4
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
57 "Obsolete. Use `mouse-wheel-down-event'.")
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
58 (defcustom mouse-wheel-down-event
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
59 ;; In the latest versions of XEmacs, we could just use mouse-%s as well.
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
60 (intern (format (if (featurep 'xemacs) "button%s" "mouse-%s")
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
61 mouse-wheel-down-button))
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
62 "Event used for scrolling down."
38582
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
63 :group 'mouse
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
64 :type 'symbol
38582
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
65 :set 'mouse-wheel-change-button)
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
66
48253
aa0e0ea91f27 (mouse-wheel-down-button, mouse-wheel-up-button):
Markus Rost <rost@math.uni-bielefeld.de>
parents: 47114
diff changeset
67 (defvar mouse-wheel-up-button 5
47114
b0e4184605e5 * ibuffer.el (ibuffer-update): Use `minibufferp'. Expand `caddr'.
John Paul Wallington <jpw@pobox.com>
parents: 46066
diff changeset
68 "Obsolete. Use `mouse-wheel-up-event'.")
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
69 (defcustom mouse-wheel-up-event
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
70 ;; In the latest versions of XEmacs, we could just use mouse-%s as well.
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
71 (intern (format (if (featurep 'xemacs) "button%s" "mouse-%s")
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
72 mouse-wheel-up-button))
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
73 "Event used for scrolling down."
38582
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
74 :group 'mouse
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
75 :type 'symbol
38582
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
76 :set 'mouse-wheel-change-button)
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
77
48574
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
78 (defvar mouse-wheel-click-button 2
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
79 "Obsolete. Use `mouse-wheel-click-event'.")
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
80 (defcustom mouse-wheel-click-event
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
81 ;; In the latest versions of XEmacs, we could just use mouse-%s as well.
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
82 (intern (format (if (featurep 'xemacs) "button%s" "mouse-%s")
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
83 mouse-wheel-click-button))
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
84 "Event that should be temporarily inhibited after mouse scrolling.
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
85 The mouse wheel is typically on the mouse-2 button, so it may easily
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
86 happen that text is accidentially yanked into the buffer when
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
87 scrolling with the mouse wheel. To prevent that, this variable can be
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
88 set to the event sent when clicking on the mouse wheel button."
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
89 :group 'mouse
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
90 :type 'symbol
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
91 :set 'mouse-wheel-change-button)
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
92
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
93 (defcustom mouse-wheel-inhibit-click-time 0.35
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
94 "Time in seconds to inhibit clicking on mouse wheel button after scroll."
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
95 :group 'mouse
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
96 :type 'float)
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
97
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
98 (defcustom mouse-wheel-scroll-amount '(5 ((shift) . 1) ((control) . nil))
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
99 "Amount to scroll windows by when spinning the mouse wheel.
46001
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
100 This is an alist mapping the modifier key to the amount to scroll when
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
101 the wheel is moved with the modifier key depressed.
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
102 Elements of the list have the form (MODIFIERS . AMOUNT) or just AMOUNT if
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
103 MODIFIERS is nil.
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
104
46001
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
105 AMOUNT should be the number of lines to scroll, or `nil' for near full
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
106 screen. It can also be a floating point number, specifying the fraction of
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
107 a full screen to scroll. A near full screen is `next-screen-context-lines'
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
108 less than a full screen."
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
109 :group 'mouse
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
110 :type '(cons
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
111 (choice :tag "Normal"
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
112 (const :tag "Full screen" :value nil)
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
113 (integer :tag "Specific # of lines")
46001
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
114 (float :tag "Fraction of window")
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
115 (cons
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
116 (repeat (choice :tag "modifier"
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
117 (const alt) (const control) (const hyper)
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
118 (const meta) (const shift) (const super)))
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
119 (choice :tag "scroll amount"
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
120 (const :tag "Full screen" :value nil)
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
121 (integer :tag "Specific # of lines")
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
122 (float :tag "Fraction of window"))))
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
123 (repeat
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
124 (cons
46001
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
125 (repeat (choice :tag "modifier"
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
126 (const alt) (const control) (const hyper)
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
127 (const meta) (const shift) (const super)))
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
128 (choice :tag "scroll amount"
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
129 (const :tag "Full screen" :value nil)
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
130 (integer :tag "Specific # of lines")
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
131 (float :tag "Fraction of window"))))))
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
132
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
133 (defcustom mouse-wheel-progessive-speed t
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
134 "If non-nil, the faster the user moves the wheel, the faster the scrolling.
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
135 Note that this has no effect when `mouse-wheel-scroll-amount' specifies
46001
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
136 a \"near full screen\" scroll or when the mouse wheel sends key instead
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
137 of button events."
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
138 :group 'mouse
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
139 :type 'boolean)
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
140
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
141 (defcustom mouse-wheel-follow-mouse t
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
142 "Whether the mouse wheel should scroll the window that the mouse is over.
46001
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
143 This can be slightly disconcerting, but some people prefer it."
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
144 :group 'mouse
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
145 :type 'boolean)
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
146
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
147 (if (not (fboundp 'event-button))
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
148 (defun mwheel-event-button (event)
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
149 (let ((x (event-basic-type event)))
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
150 ;; Map mouse-wheel events to appropriate buttons
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
151 (if (eq 'mouse-wheel x)
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
152 (let ((amount (car (cdr (cdr (cdr event))))))
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
153 (if (< amount 0)
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
154 mouse-wheel-up-event
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
155 mouse-wheel-down-event))
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
156 x)))
47114
b0e4184605e5 * ibuffer.el (ibuffer-update): Use `minibufferp'. Expand `caddr'.
John Paul Wallington <jpw@pobox.com>
parents: 46066
diff changeset
157 (fset 'mwheel-event-button 'event-button))
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
158
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
159 (if (not (fboundp 'event-window))
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
160 (defun mwheel-event-window (event)
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
161 (posn-window (event-start event)))
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
162 (fset 'mwheel-event-window 'event-window))
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
163
48574
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
164 (defvar mwheel-inhibit-click-event-timer nil
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
165 "Timer running while mouse wheel click event is inhibited.")
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
166
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
167 (defun mwheel-inhibit-click-timeout ()
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
168 "Handler for `mwheel-inhibit-click-event-timer'."
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
169 (setq mwheel-inhibit-click-event-timer nil)
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
170 (remove-hook 'pre-command-hook 'mwheel-filter-click-events))
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
171
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
172 (defun mwheel-filter-click-events ()
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
173 "Discard `mouse-wheel-click-event' while scrolling the mouse."
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
174 (if (eq (event-basic-type last-input-event) mouse-wheel-click-event)
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
175 (setq this-command 'ignore)))
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
176
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
177 (defun mwheel-scroll (event)
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
178 "Scroll up or down according to the EVENT.
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
179 This should only be bound to mouse buttons 4 and 5."
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
180 (interactive (list last-input-event))
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
181 (let* ((curwin (if mouse-wheel-follow-mouse
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
182 (prog1
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
183 (selected-window)
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
184 (select-window (mwheel-event-window event)))))
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
185 (mods
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
186 (delq 'click (delq 'double (delq 'triple (event-modifiers event)))))
46001
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
187 (amt (assoc mods mouse-wheel-scroll-amount)))
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
188 ;; Extract the actual amount or find the element that has no modifiers.
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
189 (if amt (setq amt (cdr amt))
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
190 (let ((list-elt mouse-wheel-scroll-amount))
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
191 (while (consp (setq amt (pop list-elt))))))
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
192 (if (floatp amt) (setq amt (1+ (truncate (* amt (window-height))))))
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
193 (when (and mouse-wheel-progessive-speed (numberp amt))
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
194 ;; When the double-mouse-N comes in, a mouse-N has been executed already,
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
195 ;; So by adding things up we get a squaring up (1, 3, 6, 10, 15, ...).
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
196 (setq amt (* amt (event-click-count event))))
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
197 (unwind-protect
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
198 (let ((button (mwheel-event-button event)))
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
199 (cond ((eq button mouse-wheel-down-event) (scroll-down amt))
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
200 ((eq button mouse-wheel-up-event) (scroll-up amt))
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
201 (t (error "Bad binding in mwheel-scroll"))))
48574
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
202 (if curwin (select-window curwin))))
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
203 (when (and mouse-wheel-click-event mouse-wheel-inhibit-click-time)
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
204 (if mwheel-inhibit-click-event-timer
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
205 (cancel-timer mwheel-inhibit-click-event-timer)
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
206 (add-hook 'pre-command-hook 'mwheel-filter-click-events))
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
207 (setq mwheel-inhibit-click-event-timer
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
208 (run-with-timer mouse-wheel-inhibit-click-time nil
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
209 'mwheel-inhibit-click-timeout))))
32867
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
210
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
211 ;;;###autoload
32867
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
212 (define-minor-mode mouse-wheel-mode
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
213 "Toggle mouse wheel support.
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
214 With prefix argument ARG, turn on if positive, otherwise off.
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
215 Returns non-nil if the new state is enabled."
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
216 :global t
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
217 :group 'mouse
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
218 (let* ((dn mouse-wheel-down-event)
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
219 (up mouse-wheel-up-event)
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
220 (keys
46001
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
221 (nconc (mapcar (lambda (amt) `[(,@(if (consp amt) (car amt)) ,up)])
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
222 mouse-wheel-scroll-amount)
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
223 (mapcar (lambda (amt) `[(,@(if (consp amt) (car amt)) ,dn)])
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
224 mouse-wheel-scroll-amount))))
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
225 ;; This condition-case is here because Emacs 19 will throw an error
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
226 ;; if you try to define a key that it does not know about. I for one
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
227 ;; prefer to just unconditionally do a mwheel-install in my .emacs, so
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
228 ;; that if the wheeled-mouse is there, it just works, and this way it
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
229 ;; doesn't yell at me if I'm on my laptop or another machine, etc.
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
230 (condition-case ()
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
231 (dolist (key keys)
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
232 (cond (mouse-wheel-mode
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
233 (global-set-key key 'mwheel-scroll))
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
234 ((eq (lookup-key (current-global-map) key) 'mwheel-scroll)
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
235 (global-unset-key key))))
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
236 (error nil))))
32867
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
237
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
238 ;;; Compatibility entry point
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
239 ;;;###autoload
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
240 (defun mwheel-install (&optional uninstall)
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
241 "Enable mouse wheel support."
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
242 (mouse-wheel-mode (if uninstall -1 1)))
32867
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
243
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
244 (provide 'mwheel)
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
245
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
246 ;;; mwheel.el ends here