annotate lisp/mwheel.el @ 104979:c545eaa5edad

* mwheel.el (mwheel-installed-bindings): New var. (mouse-wheel-mode): Use it, so as to make sure we really remove all the bindings we set last time. Use custom-initialize-delay. * loadup.el: Load mwheel after term/*-win.el. * startup.el (command-line): Don't reevaluate mouse-wheel-down-event and mouse-wheel-up-event now that their first evaluation is done sufficiently late to be correct.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Sat, 12 Sep 2009 04:38:03 +0000
parents f03494acbd1b
children a3d3fc00075b
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
95835
c11958c9ca00 (mouse-wheel-follow-mouse, mwheel-event-window):
Glenn Morris <rgm@gnu.org>
parents: 94678
diff changeset
3 ;; Copyright (C) 1998, 2000, 2001, 2002, 2002, 2004, 2005, 2006, 2007,
100908
a9dc0e7c3f2b Add 2009 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 97043
diff changeset
4 ;; 2008, 2009 Free Software Foundation, Inc.
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
5 ;; Maintainer: William M. Perry <wmperry@gnu.org>
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
6 ;; Keywords: mouse
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
7
26410
55a234a9fe88 Fix copyright notice. Don't require 'cl at run time.
Gerd Moellmann <gerd@gnu.org>
parents: 26398
diff changeset
8 ;; This file is part of GNU Emacs.
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
9
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94163
diff changeset
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
26410
55a234a9fe88 Fix copyright notice. Don't require 'cl at run time.
Gerd Moellmann <gerd@gnu.org>
parents: 26398
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94163
diff changeset
12 ;; the Free Software Foundation, either version 3 of the License, or
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94163
diff changeset
13 ;; (at your option) any later version.
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
14
26410
55a234a9fe88 Fix copyright notice. Don't require 'cl at run time.
Gerd Moellmann <gerd@gnu.org>
parents: 26398
diff changeset
15 ;; 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
16 ;; 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
17 ;; 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
18 ;; GNU General Public License for more details.
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
19
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 94163
diff changeset
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
22
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
23 ;;; Commentary:
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
24
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
25 ;; 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
26 ;; 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
27 ;; events are sent as button4/button5 events.
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
28
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
29 ;; 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
30 ;; events into different event types, like 'mwheel-up' or
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
31 ;; '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
32 ;; portably), so for now I just live with it.
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
33
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
34 ;; 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
35 ;; file:
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
36 ;;
51271
ff87ff02952e Commentary change.
Glenn Morris <rgm@gnu.org>
parents: 50872
diff changeset
37 ;; (mouse-wheel-mode 1)
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
38
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
39 ;;; Code:
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
40
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
41 (require 'custom)
48574
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
42 (require 'timer)
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
43
38582
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
44 ;; 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
45 ;; 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
46 ;; 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
47
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
48 (defun mouse-wheel-change-button (var button)
104979
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
49 (set-default var button)
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
50 ;; Sync the bindings.
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
51 (when mouse-wheel-mode (mouse-wheel-mode 1)))
38582
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
52
49617
78d4c6395dec (mouse-wheel-down-button, mouse-wheel-up-button, mouse-wheel-click-button): Add
Juanma Barranquero <lekktu@gmail.com>
parents: 49597
diff changeset
53 (defvar mouse-wheel-down-button 4)
78d4c6395dec (mouse-wheel-down-button, mouse-wheel-up-button, mouse-wheel-click-button): Add
Juanma Barranquero <lekktu@gmail.com>
parents: 49597
diff changeset
54 (make-obsolete-variable 'mouse-wheel-down-button
94163
36e553d98d49 (mouse-wheel-down-button, mouse-wheel-up-button, mouse-wheel-click-button):
Juanma Barranquero <lekktu@gmail.com>
parents: 93838
diff changeset
55 'mouse-wheel-down-event
36e553d98d49 (mouse-wheel-down-button, mouse-wheel-up-button, mouse-wheel-click-button):
Juanma Barranquero <lekktu@gmail.com>
parents: 93838
diff changeset
56 "22.1")
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
57 (defcustom mouse-wheel-down-event
104295
f03494acbd1b * mwheel.el (mouse-wheel-down-event, mouse-wheel-up-event): Don't
Chong Yidong <cyd@stupidchicken.com>
parents: 100908
diff changeset
58 (if (or (featurep 'w32-win) (featurep 'ns-win))
51387
97d539e7d0d1 (mouse-wheel-down-event, mouse-wheel-up-event):
Jason Rumney <jasonr@gnu.org>
parents: 51271
diff changeset
59 'wheel-up
104295
f03494acbd1b * mwheel.el (mouse-wheel-down-event, mouse-wheel-up-event): Don't
Chong Yidong <cyd@stupidchicken.com>
parents: 100908
diff changeset
60 (intern (format "mouse-%s" mouse-wheel-down-button)))
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
61 "Event used for scrolling down."
38582
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
62 :group 'mouse
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
63 :type 'symbol
38582
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
64 :set 'mouse-wheel-change-button)
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
65
49617
78d4c6395dec (mouse-wheel-down-button, mouse-wheel-up-button, mouse-wheel-click-button): Add
Juanma Barranquero <lekktu@gmail.com>
parents: 49597
diff changeset
66 (defvar mouse-wheel-up-button 5)
78d4c6395dec (mouse-wheel-down-button, mouse-wheel-up-button, mouse-wheel-click-button): Add
Juanma Barranquero <lekktu@gmail.com>
parents: 49597
diff changeset
67 (make-obsolete-variable 'mouse-wheel-up-button
94163
36e553d98d49 (mouse-wheel-down-button, mouse-wheel-up-button, mouse-wheel-click-button):
Juanma Barranquero <lekktu@gmail.com>
parents: 93838
diff changeset
68 'mouse-wheel-up-event
36e553d98d49 (mouse-wheel-down-button, mouse-wheel-up-button, mouse-wheel-click-button):
Juanma Barranquero <lekktu@gmail.com>
parents: 93838
diff changeset
69 "22.1")
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
70 (defcustom mouse-wheel-up-event
104295
f03494acbd1b * mwheel.el (mouse-wheel-down-event, mouse-wheel-up-event): Don't
Chong Yidong <cyd@stupidchicken.com>
parents: 100908
diff changeset
71 (if (or (featurep 'w32-win) (featurep 'ns-win))
51387
97d539e7d0d1 (mouse-wheel-down-event, mouse-wheel-up-event):
Jason Rumney <jasonr@gnu.org>
parents: 51271
diff changeset
72 'wheel-down
104295
f03494acbd1b * mwheel.el (mouse-wheel-down-event, mouse-wheel-up-event): Don't
Chong Yidong <cyd@stupidchicken.com>
parents: 100908
diff changeset
73 (intern (format "mouse-%s" mouse-wheel-up-button)))
68788
c78868572d4f (mouse-wheel-up-event): Doc fix.
Eli Zaretskii <eliz@gnu.org>
parents: 68651
diff changeset
74 "Event used for scrolling up."
38582
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
75 :group 'mouse
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
76 :type 'symbol
38582
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
77 :set 'mouse-wheel-change-button)
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
78
49617
78d4c6395dec (mouse-wheel-down-button, mouse-wheel-up-button, mouse-wheel-click-button): Add
Juanma Barranquero <lekktu@gmail.com>
parents: 49597
diff changeset
79 (defvar mouse-wheel-click-button 2)
78d4c6395dec (mouse-wheel-down-button, mouse-wheel-up-button, mouse-wheel-click-button): Add
Juanma Barranquero <lekktu@gmail.com>
parents: 49597
diff changeset
80 (make-obsolete-variable 'mouse-wheel-click-button
94163
36e553d98d49 (mouse-wheel-down-button, mouse-wheel-up-button, mouse-wheel-click-button):
Juanma Barranquero <lekktu@gmail.com>
parents: 93838
diff changeset
81 'mouse-wheel-click-event
36e553d98d49 (mouse-wheel-down-button, mouse-wheel-up-button, mouse-wheel-click-button):
Juanma Barranquero <lekktu@gmail.com>
parents: 93838
diff changeset
82 "22.1")
48574
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
83 (defcustom mouse-wheel-click-event
104295
f03494acbd1b * mwheel.el (mouse-wheel-down-event, mouse-wheel-up-event): Don't
Chong Yidong <cyd@stupidchicken.com>
parents: 100908
diff changeset
84 (intern (format "mouse-%s" mouse-wheel-click-button))
48574
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
85 "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
86 The mouse wheel is typically on the mouse-2 button, so it may easily
68882
b7113ead6c0a (mouse-wheel-click-event, mouse-wheel-mode): Fix typos in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents: 68788
diff changeset
87 happen that text is accidentally yanked into the buffer when
48574
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
88 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
89 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
90 :group 'mouse
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
91 :type 'symbol
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
92 :set 'mouse-wheel-change-button)
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
93
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
94 (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
95 "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
96 :group 'mouse
48593
338527f8ef91 (mouse-wheel-inhibit-click-time): Fix custom type.
Markus Rost <rost@math.uni-bielefeld.de>
parents: 48574
diff changeset
97 :type 'number)
48574
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
98
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
99 (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
100 "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
101 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
102 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
103 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
104 MODIFIERS is nil.
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
105
50872
ba2845537409 (mouse-wheel-scroll-amount): Don't quote nil and t in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents: 49617
diff changeset
106 AMOUNT should be the number of lines to scroll, or nil for near full
46001
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
107 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
108 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
109 less than a full screen."
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
110 :group 'mouse
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
111 :type '(cons
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
112 (choice :tag "Normal"
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
113 (const :tag "Full screen" :value nil)
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
114 (integer :tag "Specific # of lines")
48772
baf774b3f991 (mouse-wheel-scroll-amount): Revert previous change -
Markus Rost <rost@math.uni-bielefeld.de>
parents: 48609
diff changeset
115 (float :tag "Fraction of window")
46001
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
116 (cons
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
117 (repeat (choice :tag "modifier"
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
118 (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
119 (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
120 (choice :tag "scroll amount"
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
121 (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
122 (integer :tag "Specific # of lines")
48772
baf774b3f991 (mouse-wheel-scroll-amount): Revert previous change -
Markus Rost <rost@math.uni-bielefeld.de>
parents: 48609
diff changeset
123 (float :tag "Fraction of window"))))
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
124 (repeat
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
125 (cons
46001
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
126 (repeat (choice :tag "modifier"
5133c42d55cc (mouse-wheel-scroll-amount, mwheel-scroll, mouse-wheel-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45994
diff changeset
127 (const alt) (const control) (const hyper)
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
128 (const meta) (const shift) (const super)))
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
129 (choice :tag "scroll amount"
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
130 (const :tag "Full screen" :value nil)
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
131 (integer :tag "Specific # of lines")
48772
baf774b3f991 (mouse-wheel-scroll-amount): Revert previous change -
Markus Rost <rost@math.uni-bielefeld.de>
parents: 48609
diff changeset
132 (float :tag "Fraction of window"))))))
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
133
58160
4ffb29088324 (mouse-wheel-progressive-speed): Fix typo in name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53578
diff changeset
134 (defcustom mouse-wheel-progressive-speed t
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
135 "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
136 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
137 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
138 of button events."
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
139 :group 'mouse
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
140 :type 'boolean)
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
141
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
142 (defcustom mouse-wheel-follow-mouse t
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
143 "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
144 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
145 :group 'mouse
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
146 :type 'boolean)
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
147
95835
c11958c9ca00 (mouse-wheel-follow-mouse, mwheel-event-window):
Glenn Morris <rgm@gnu.org>
parents: 94678
diff changeset
148 (eval-and-compile
c11958c9ca00 (mouse-wheel-follow-mouse, mwheel-event-window):
Glenn Morris <rgm@gnu.org>
parents: 94678
diff changeset
149 (if (fboundp 'event-button)
c11958c9ca00 (mouse-wheel-follow-mouse, mwheel-event-window):
Glenn Morris <rgm@gnu.org>
parents: 94678
diff changeset
150 (fset 'mwheel-event-button 'event-button)
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
151 (defun mwheel-event-button (event)
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
152 (let ((x (event-basic-type event)))
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
153 ;; 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
154 (if (eq 'mouse-wheel x)
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
155 (let ((amount (car (cdr (cdr (cdr event))))))
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
156 (if (< amount 0)
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
157 mouse-wheel-up-event
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
158 mouse-wheel-down-event))
95835
c11958c9ca00 (mouse-wheel-follow-mouse, mwheel-event-window):
Glenn Morris <rgm@gnu.org>
parents: 94678
diff changeset
159 x))))
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
160
95835
c11958c9ca00 (mouse-wheel-follow-mouse, mwheel-event-window):
Glenn Morris <rgm@gnu.org>
parents: 94678
diff changeset
161 (if (fboundp 'event-window)
c11958c9ca00 (mouse-wheel-follow-mouse, mwheel-event-window):
Glenn Morris <rgm@gnu.org>
parents: 94678
diff changeset
162 (fset 'mwheel-event-window 'event-window)
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
163 (defun mwheel-event-window (event)
95835
c11958c9ca00 (mouse-wheel-follow-mouse, mwheel-event-window):
Glenn Morris <rgm@gnu.org>
parents: 94678
diff changeset
164 (posn-window (event-start event)))))
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
165
48574
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
166 (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
167 "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
168
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
169 (defun mwheel-inhibit-click-timeout ()
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
170 "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
171 (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
172 (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
173
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
174 (defun mwheel-filter-click-events ()
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
175 "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
176 (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
177 (setq this-command 'ignore)))
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
178
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
179 (defun mwheel-scroll (event)
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
180 "Scroll up or down according to the EVENT.
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
181 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
182 (interactive (list last-input-event))
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
183 (let* ((curwin (if mouse-wheel-follow-mouse
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
184 (prog1
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
185 (selected-window)
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
186 (select-window (mwheel-event-window event)))))
93838
90f39a5d591c (mwheel-scroll): Deactivate any temporarily active region if point
Chong Yidong <cyd@stupidchicken.com>
parents: 79721
diff changeset
187 (buffer (window-buffer curwin))
90f39a5d591c (mwheel-scroll): Deactivate any temporarily active region if point
Chong Yidong <cyd@stupidchicken.com>
parents: 79721
diff changeset
188 (opoint (with-current-buffer buffer
90f39a5d591c (mwheel-scroll): Deactivate any temporarily active region if point
Chong Yidong <cyd@stupidchicken.com>
parents: 79721
diff changeset
189 (when (eq (car-safe transient-mark-mode) 'only)
90f39a5d591c (mwheel-scroll): Deactivate any temporarily active region if point
Chong Yidong <cyd@stupidchicken.com>
parents: 79721
diff changeset
190 (point))))
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
191 (mods
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
192 (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
193 (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
194 ;; 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
195 (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
196 (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
197 (while (consp (setq amt (pop list-elt))))))
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
198 (if (floatp amt) (setq amt (1+ (truncate (* amt (window-height))))))
58160
4ffb29088324 (mouse-wheel-progressive-speed): Fix typo in name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53578
diff changeset
199 (when (and mouse-wheel-progressive-speed (numberp amt))
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
200 ;; 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
201 ;; 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
202 (setq amt (* amt (event-click-count event))))
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
203 (unwind-protect
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
204 (let ((button (mwheel-event-button event)))
70528
c8171c0fa382 (mwheel-scroll): Make sure that when scrolling multiple
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68882
diff changeset
205 (cond ((eq button mouse-wheel-down-event)
c8171c0fa382 (mwheel-scroll): Make sure that when scrolling multiple
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68882
diff changeset
206 (condition-case nil (scroll-down amt)
c8171c0fa382 (mwheel-scroll): Make sure that when scrolling multiple
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68882
diff changeset
207 ;; Make sure we do indeed scroll to the beginning of
c8171c0fa382 (mwheel-scroll): Make sure that when scrolling multiple
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68882
diff changeset
208 ;; the buffer.
c8171c0fa382 (mwheel-scroll): Make sure that when scrolling multiple
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68882
diff changeset
209 (beginning-of-buffer
c8171c0fa382 (mwheel-scroll): Make sure that when scrolling multiple
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68882
diff changeset
210 (unwind-protect
c8171c0fa382 (mwheel-scroll): Make sure that when scrolling multiple
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68882
diff changeset
211 (scroll-down)
c8171c0fa382 (mwheel-scroll): Make sure that when scrolling multiple
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68882
diff changeset
212 ;; If the first scroll succeeded, then some scrolling
c8171c0fa382 (mwheel-scroll): Make sure that when scrolling multiple
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68882
diff changeset
213 ;; is possible: keep scrolling til the beginning but
c8171c0fa382 (mwheel-scroll): Make sure that when scrolling multiple
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68882
diff changeset
214 ;; do not signal an error. For some reason, we have
96361
a99299e4d2de American English spelling fix.
Glenn Morris <rgm@gnu.org>
parents: 95835
diff changeset
215 ;; to do it even if the first scroll signaled an
70528
c8171c0fa382 (mwheel-scroll): Make sure that when scrolling multiple
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68882
diff changeset
216 ;; error, because otherwise the window is recentered
c8171c0fa382 (mwheel-scroll): Make sure that when scrolling multiple
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68882
diff changeset
217 ;; for a reason that escapes me. This problem seems
c8171c0fa382 (mwheel-scroll): Make sure that when scrolling multiple
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68882
diff changeset
218 ;; to only affect scroll-down. --Stef
c8171c0fa382 (mwheel-scroll): Make sure that when scrolling multiple
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68882
diff changeset
219 (set-window-start (selected-window) (point-min))))))
c8171c0fa382 (mwheel-scroll): Make sure that when scrolling multiple
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68882
diff changeset
220 ((eq button mouse-wheel-up-event)
c8171c0fa382 (mwheel-scroll): Make sure that when scrolling multiple
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68882
diff changeset
221 (condition-case nil (scroll-up amt)
c8171c0fa382 (mwheel-scroll): Make sure that when scrolling multiple
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68882
diff changeset
222 ;; Make sure we do indeed scroll to the end of the buffer.
c8171c0fa382 (mwheel-scroll): Make sure that when scrolling multiple
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 68882
diff changeset
223 (end-of-buffer (while t (scroll-up)))))
45994
65253ed28734 Undo last patch for now.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 45947
diff changeset
224 (t (error "Bad binding in mwheel-scroll"))))
93838
90f39a5d591c (mwheel-scroll): Deactivate any temporarily active region if point
Chong Yidong <cyd@stupidchicken.com>
parents: 79721
diff changeset
225 (if curwin (select-window curwin)))
90f39a5d591c (mwheel-scroll): Deactivate any temporarily active region if point
Chong Yidong <cyd@stupidchicken.com>
parents: 79721
diff changeset
226 ;; If there is a temporarily active region, deactivate it iff
90f39a5d591c (mwheel-scroll): Deactivate any temporarily active region if point
Chong Yidong <cyd@stupidchicken.com>
parents: 79721
diff changeset
227 ;; scrolling moves point.
90f39a5d591c (mwheel-scroll): Deactivate any temporarily active region if point
Chong Yidong <cyd@stupidchicken.com>
parents: 79721
diff changeset
228 (when opoint
90f39a5d591c (mwheel-scroll): Deactivate any temporarily active region if point
Chong Yidong <cyd@stupidchicken.com>
parents: 79721
diff changeset
229 (with-current-buffer buffer
90f39a5d591c (mwheel-scroll): Deactivate any temporarily active region if point
Chong Yidong <cyd@stupidchicken.com>
parents: 79721
diff changeset
230 (when (/= opoint (point))
90f39a5d591c (mwheel-scroll): Deactivate any temporarily active region if point
Chong Yidong <cyd@stupidchicken.com>
parents: 79721
diff changeset
231 (deactivate-mark)))))
48574
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
232 (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
233 (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
234 (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
235 (add-hook 'pre-command-hook 'mwheel-filter-click-events))
49597
e88404e8f2cf Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 48772
diff changeset
236 (setq mwheel-inhibit-click-event-timer
48574
3e3b1f1265f5 Avoid accidental yanking of text while scrolling with
Kim F. Storm <storm@cua.dk>
parents: 48253
diff changeset
237 (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
238 'mwheel-inhibit-click-timeout))))
32867
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
239
104979
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
240 (defvar mwheel-installed-bindings nil)
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
241
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
242 ;;;###autoload
32867
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
243 (define-minor-mode mouse-wheel-mode
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
244 "Toggle mouse wheel support.
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
245 With prefix argument ARG, turn on if positive, otherwise off.
68882
b7113ead6c0a (mouse-wheel-click-event, mouse-wheel-mode): Fix typos in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents: 68788
diff changeset
246 Return non-nil if the new state is enabled."
104979
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
247 :init-value t
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
248 ;; We'd like to use custom-initialize-set here so the setup is done
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
249 ;; before dumping, but at the point where the defcustom is evaluated,
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
250 ;; the corresponding function isn't defined yet, so
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
251 ;; custom-initialize-set signals an error.
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
252 :initialize 'custom-initialize-delay
32867
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
253 :global t
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
254 :group 'mouse
104979
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
255 ;; Remove previous bindings, if any.
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
256 (while mwheel-installed-bindings
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
257 (let ((key (pop mwheel-installed-bindings)))
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
258 (when (eq (lookup-key (current-global-map) key) 'mwheel-scroll)
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
259 (global-unset-key key))))
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
260 ;; Setup bindings as needed.
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
261 (when mouse-wheel-mode
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
262 (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event))
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
263 (dolist (key (mapcar (lambda (amt) `[(,@(if (consp amt) (car amt)) ,event)])
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
264 mouse-wheel-scroll-amount))
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
265 (global-set-key key 'mwheel-scroll)
c545eaa5edad * mwheel.el (mwheel-installed-bindings): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 104295
diff changeset
266 (push key mwheel-installed-bindings)))))
32867
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
267
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
268 ;;; Compatibility entry point
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
269 ;;;###autoload
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
270 (defun mwheel-install (&optional uninstall)
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
271 "Enable mouse wheel support."
46066
99487f98aaa7 (mouse-wheel-change-button): Deactivate before changing.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 46001
diff changeset
272 (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
273
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
274 (provide 'mwheel)
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
275
58160
4ffb29088324 (mouse-wheel-progressive-speed): Fix typo in name.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 53578
diff changeset
276 ;; arch-tag: 50ed00e7-3686-4b7a-8037-fb31aa5c237f
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
277 ;;; mwheel.el ends here