annotate lisp/mwheel.el @ 45674:0ddf92221535

(bookmark-file-or-variation-thereof): Doc fix.
author Richard M. Stallman <rms@gnu.org>
date Sat, 08 Jun 2002 10:42:54 +0000
parents 7648ca9b6024
children d8512fb0b229
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
1 ;;; mwheel.el --- Mouse support for MS intelli-mouse type mice
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
2
38582
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
3 ;; Copyright (C) 1998, 2000, 2001 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)
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)
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
49 (set-default var button)
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
50 (when mouse-wheel-mode
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
51 (mouse-wheel-mode 0)
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
52 (mouse-wheel-mode 1)))
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
53
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
54 (defcustom mouse-wheel-down-button 4
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
55 "Mouse button number for scrolling down."
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
56 :group 'mouse
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
57 :type 'integer
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
58 :set 'mouse-wheel-change-button)
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
59
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
60 (defcustom mouse-wheel-up-button 5
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
61 "Mouse button number for scrolling up."
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
62 :group 'mouse
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
63 :type 'integer
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
43423
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
66 (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
67 "Amount to scroll windows by when spinning the mouse wheel.
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
68 This is actually a cons cell, where the first item is the amount to scroll
43423
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
69 on a normal wheel event, and the rest is an alist mapping the modifier key
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
70 to the amount to scroll when the wheel is moved with the modifier key depressed.
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
71
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
72 Each item should be the number of lines to scroll, or `nil' for near
41290
9985a0fdea47 (mouse-wheel-scroll-amount): Allow float values.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38582
diff changeset
73 full screen. It can also be a floating point number, specifying
9985a0fdea47 (mouse-wheel-scroll-amount): Allow float values.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38582
diff changeset
74 the fraction of the window to scroll.
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
75 A near full screen is `next-screen-context-lines' less than a full screen."
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
76 :group 'mouse
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
77 :type '(cons
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
78 (choice :tag "Normal"
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
79 (const :tag "Full screen" :value nil)
41290
9985a0fdea47 (mouse-wheel-scroll-amount): Allow float values.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38582
diff changeset
80 (integer :tag "Specific # of lines")
9985a0fdea47 (mouse-wheel-scroll-amount): Allow float values.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38582
diff changeset
81 (float :tag "Fraction of window"))
43423
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
82 (repeat
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
83 (cons
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
84 (repeat (choice :tag "modifier" (const alt) (const control) (const hyper)
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
85 (const meta) (const shift) (const super)))
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
86 (choice :tag "scroll amount"
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
87 (const :tag "Full screen" :value nil)
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
88 (integer :tag "Specific # of lines")
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
89 (float :tag "Fraction of window"))))))
41290
9985a0fdea47 (mouse-wheel-scroll-amount): Allow float values.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38582
diff changeset
90
9985a0fdea47 (mouse-wheel-scroll-amount): Allow float values.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38582
diff changeset
91 (defcustom mouse-wheel-progessive-speed t
9985a0fdea47 (mouse-wheel-scroll-amount): Allow float values.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38582
diff changeset
92 "If non-nil, the faster the user moves the wheel, the faster the scrolling.
9985a0fdea47 (mouse-wheel-scroll-amount): Allow float values.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38582
diff changeset
93 Note that this has no effect when `mouse-wheel-scroll-amount' specifies
9985a0fdea47 (mouse-wheel-scroll-amount): Allow float values.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38582
diff changeset
94 a \"near full screen\" scroll."
9985a0fdea47 (mouse-wheel-scroll-amount): Allow float values.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38582
diff changeset
95 :group 'mouse
9985a0fdea47 (mouse-wheel-scroll-amount): Allow float values.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38582
diff changeset
96 :type 'boolean)
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
97
33227
791ce66d397e (mouse-wheel-scroll-amount): Renamed from `mwheel-scroll-amount'.
Miles Bader <miles@gnu.org>
parents: 33193
diff changeset
98 (defcustom mouse-wheel-follow-mouse nil
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
99 "Whether the mouse wheel should scroll the window that the mouse is over.
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
100 This can be slightly disconcerting, but some people may prefer it."
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
101 :group 'mouse
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
102 :type 'boolean)
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
103
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
104 (if (not (fboundp 'event-button))
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
105 (defun mwheel-event-button (event)
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
106 (let ((x (symbol-name (event-basic-type event))))
45123
7648ca9b6024 (mwheel-event-button): Translate mouse-wheel events.
Jason Rumney <jasonr@gnu.org>
parents: 44147
diff changeset
107 ;; Map mouse-wheel events to appropriate buttons
7648ca9b6024 (mwheel-event-button): Translate mouse-wheel events.
Jason Rumney <jasonr@gnu.org>
parents: 44147
diff changeset
108 (if (string-equal "mouse-wheel" x)
7648ca9b6024 (mwheel-event-button): Translate mouse-wheel events.
Jason Rumney <jasonr@gnu.org>
parents: 44147
diff changeset
109 (let ((amount (car (cdr (cdr (cdr event))))))
7648ca9b6024 (mwheel-event-button): Translate mouse-wheel events.
Jason Rumney <jasonr@gnu.org>
parents: 44147
diff changeset
110 (if (< amount 0)
7648ca9b6024 (mwheel-event-button): Translate mouse-wheel events.
Jason Rumney <jasonr@gnu.org>
parents: 44147
diff changeset
111 mouse-wheel-up-button
7648ca9b6024 (mwheel-event-button): Translate mouse-wheel events.
Jason Rumney <jasonr@gnu.org>
parents: 44147
diff changeset
112 mouse-wheel-down-button))
7648ca9b6024 (mwheel-event-button): Translate mouse-wheel events.
Jason Rumney <jasonr@gnu.org>
parents: 44147
diff changeset
113 (if (not (string-match "^mouse-\\([0-9]+\\)" x))
7648ca9b6024 (mwheel-event-button): Translate mouse-wheel events.
Jason Rumney <jasonr@gnu.org>
parents: 44147
diff changeset
114 (error "Not a button event: %S" event)
7648ca9b6024 (mwheel-event-button): Translate mouse-wheel events.
Jason Rumney <jasonr@gnu.org>
parents: 44147
diff changeset
115 (string-to-int (substring x (match-beginning 1) (match-end 1)))))))
7648ca9b6024 (mwheel-event-button): Translate mouse-wheel events.
Jason Rumney <jasonr@gnu.org>
parents: 44147
diff changeset
116 (fset 'mwheel-event-button 'event-button))
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
117
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
118 (if (not (fboundp 'event-window))
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
119 (defun mwheel-event-window (event)
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
120 (posn-window (event-start event)))
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
121 (fset 'mwheel-event-window 'event-window))
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
122
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
123 (defun mwheel-scroll (event)
41290
9985a0fdea47 (mouse-wheel-scroll-amount): Allow float values.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38582
diff changeset
124 "Scroll up or down according to the EVENT.
9985a0fdea47 (mouse-wheel-scroll-amount): Allow float values.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38582
diff changeset
125 This should only be bound to mouse buttons 4 and 5."
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
126 (interactive "e")
43423
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
127 (let* ((curwin (if mouse-wheel-follow-mouse
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
128 (prog1
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
129 (selected-window)
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
130 (select-window (mwheel-event-window event)))))
43627
0f257be5fa6a (mwheel-scroll): Remove `double' and `triple' from the
Miles Bader <miles@gnu.org>
parents: 43543
diff changeset
131 (mods
0f257be5fa6a (mwheel-scroll): Remove `double' and `triple' from the
Miles Bader <miles@gnu.org>
parents: 43543
diff changeset
132 (delq 'click (delq 'double (delq 'triple (event-modifiers event)))))
0f257be5fa6a (mwheel-scroll): Remove `double' and `triple' from the
Miles Bader <miles@gnu.org>
parents: 43543
diff changeset
133 (amt
45123
7648ca9b6024 (mwheel-event-button): Translate mouse-wheel events.
Jason Rumney <jasonr@gnu.org>
parents: 44147
diff changeset
134 (if mods
7648ca9b6024 (mwheel-event-button): Translate mouse-wheel events.
Jason Rumney <jasonr@gnu.org>
parents: 44147
diff changeset
135 (cdr (assoc mods (cdr mouse-wheel-scroll-amount)))
7648ca9b6024 (mwheel-event-button): Translate mouse-wheel events.
Jason Rumney <jasonr@gnu.org>
parents: 44147
diff changeset
136 (car mouse-wheel-scroll-amount))))
41290
9985a0fdea47 (mouse-wheel-scroll-amount): Allow float values.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38582
diff changeset
137 (if (floatp amt) (setq amt (1+ (truncate (* amt (window-height))))))
9985a0fdea47 (mouse-wheel-scroll-amount): Allow float values.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38582
diff changeset
138 (when (and mouse-wheel-progessive-speed (numberp amt))
9985a0fdea47 (mouse-wheel-scroll-amount): Allow float values.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38582
diff changeset
139 ;; When the double-mouse-N comes in, a mouse-N has been executed already,
9985a0fdea47 (mouse-wheel-scroll-amount): Allow float values.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38582
diff changeset
140 ;; So by adding things up we get a squaring up (1, 3, 6, 10, 16, ...).
9985a0fdea47 (mouse-wheel-scroll-amount): Allow float values.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 38582
diff changeset
141 (setq amt (* amt (event-click-count event))))
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
142 (unwind-protect
26410
55a234a9fe88 Fix copyright notice. Don't require 'cl at run time.
Gerd Moellmann <gerd@gnu.org>
parents: 26398
diff changeset
143 (let ((button (mwheel-event-button event)))
38582
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
144 (cond ((= button mouse-wheel-down-button) (scroll-down amt))
96ca8702243e (mouse-wheel-down-button, mouse-wheel-up-button):
Gerd Moellmann <gerd@gnu.org>
parents: 33227
diff changeset
145 ((= button mouse-wheel-up-button) (scroll-up amt))
26410
55a234a9fe88 Fix copyright notice. Don't require 'cl at run time.
Gerd Moellmann <gerd@gnu.org>
parents: 26398
diff changeset
146 (t (error "Bad binding in mwheel-scroll"))))
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
147 (if curwin (select-window curwin)))))
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
148
32867
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
149
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
150 ;;;###autoload
32867
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
151 (define-minor-mode mouse-wheel-mode
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
152 "Toggle mouse wheel support.
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
153 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
154 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
155 :global t
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
156 :group 'mouse
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
157 ;; In the latest versions of XEmacs, we could just use
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
158 ;; (S-)*mouse-[45], since those are aliases for the button
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
159 ;; equivalents in XEmacs, but I want this to work in as many
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
160 ;; versions of XEmacs as it can.
43423
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
161 (let* ((prefix (if (featurep 'xemacs) "button%d" "mouse-%d"))
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
162 (dn (intern (format prefix mouse-wheel-down-button)))
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
163 (up (intern (format prefix mouse-wheel-up-button)))
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
164 (keys
43543
40d7df9af355 (mouse-wheel-mode): Pass vectors instead of symbols
Miles Bader <miles@gnu.org>
parents: 43423
diff changeset
165 (nconc (list (vector dn) (vector up))
43423
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
166 (mapcar (lambda (amt) `[(,@(car amt) ,up)])
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
167 (cdr mouse-wheel-scroll-amount))
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
168 (mapcar (lambda (amt) `[(,@(car amt) ,dn)])
3a576cd9f462 Can specify different scroll amounts for different modifiers now.
Sam Steingold <sds@gnu.org>
parents: 41290
diff changeset
169 (cdr mouse-wheel-scroll-amount)))))
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
170 ;; This condition-case is here because Emacs 19 will throw an error
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
171 ;; if you try to define a key that it does not know about. I for one
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
172 ;; prefer to just unconditionally do a mwheel-install in my .emacs, so
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
173 ;; that if the wheeled-mouse is there, it just works, and this way it
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
174 ;; doesn't yell at me if I'm on my laptop or another machine, etc.
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
175 (condition-case ()
32867
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
176 (dolist (key keys)
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
177 (cond (mouse-wheel-mode
44147
d8a6c969ea05 (mouse-wheel-mode): Use global-set-key and global-unset-key.
Pavel Janík <Pavel@Janik.cz>
parents: 44121
diff changeset
178 (global-set-key key 'mwheel-scroll))
44121
8f34ebe4ff92 (mouse-wheel-mode): Use the result of current-global-map instead of the
Pavel Janík <Pavel@Janik.cz>
parents: 43627
diff changeset
179 ((eq (lookup-key (current-global-map) key) 'mwheel-scroll)
44147
d8a6c969ea05 (mouse-wheel-mode): Use global-set-key and global-unset-key.
Pavel Janík <Pavel@Janik.cz>
parents: 44121
diff changeset
180 (global-unset-key key))))
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
181 (error nil))))
32867
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
182
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
183 ;;; Compatibility entry point
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
184 ;;;###autoload
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
185 (defun mwheel-install (&optional uninstall)
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
186 "Enable mouse wheel support."
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
187 (mouse-wheel-mode t))
553975760fe9 (mouse-wheel-mode): New global minor mode.
Miles Bader <miles@gnu.org>
parents: 26410
diff changeset
188
26398
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
189 (provide 'mwheel)
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
190
7eb699cb9ef2 Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff changeset
191 ;;; mwheel.el ends here