Mercurial > emacs
annotate lisp/mwheel.el @ 32069:4b577e4fc758
(vc-responsible-backend): Undo the previous change in the argument
list. Handle multiple backends correctly.
(vc-find-new-backend): Function removed.
(vc-register): Use vc-responsible-backend, as before.
(vc-next-action-on-file): Do use vc-registered, not vc-backend.
author | André Spiegel <spiegel@gnu.org> |
---|---|
date | Mon, 02 Oct 2000 12:01:09 +0000 |
parents | 55a234a9fe88 |
children | 553975760fe9 |
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 |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
3 ;; Copyright (C) 1998, Free Software Foundation, Inc. |
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 |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
44 (defcustom mwheel-scroll-amount '(5 . 1) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
45 "Amount to scroll windows by when spinning the mouse wheel. |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
46 This is actually a cons cell, where the first item is the amount to scroll |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
47 on a normal wheel event, and the second is the amount to scroll when the |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
48 wheel is moved with the shift key depressed. |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
49 |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
50 Each item should be the number of lines to scroll, or `nil' for near |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
51 full screen. |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
52 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
|
53 :group 'mouse |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
54 :type '(cons |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
55 (choice :tag "Normal" |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
56 (const :tag "Full screen" :value nil) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
57 (integer :tag "Specific # of lines")) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
58 (choice :tag "Shifted" |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
59 (const :tag "Full screen" :value nil) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
60 (integer :tag "Specific # of lines")))) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
61 |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
62 (defcustom mwheel-follow-mouse nil |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
63 "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
|
64 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
|
65 :group 'mouse |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
66 :type 'boolean) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
67 |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
68 (if (not (fboundp 'event-button)) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
69 (defun mwheel-event-button (event) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
70 (let ((x (symbol-name (event-basic-type event)))) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
71 (if (not (string-match "^mouse-\\([0-9]+\\)" x)) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
72 (error "Not a button event: %S" event)) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
73 (string-to-int (substring x (match-beginning 1) (match-end 1))))) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
74 (fset 'mwheel-event-button 'event-button)) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
75 |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
76 (if (not (fboundp 'event-window)) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
77 (defun mwheel-event-window (event) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
78 (posn-window (event-start event))) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
79 (fset 'mwheel-event-window 'event-window)) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
80 |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
81 (defun mwheel-scroll (event) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
82 (interactive "e") |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
83 (let ((curwin (if mwheel-follow-mouse |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
84 (prog1 |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
85 (selected-window) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
86 (select-window (mwheel-event-window event))))) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
87 (amt (if (memq 'shift (event-modifiers event)) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
88 (cdr mwheel-scroll-amount) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
89 (car mwheel-scroll-amount)))) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
90 (unwind-protect |
26410
55a234a9fe88
Fix copyright notice. Don't require 'cl at run time.
Gerd Moellmann <gerd@gnu.org>
parents:
26398
diff
changeset
|
91 (let ((button (mwheel-event-button event))) |
55a234a9fe88
Fix copyright notice. Don't require 'cl at run time.
Gerd Moellmann <gerd@gnu.org>
parents:
26398
diff
changeset
|
92 (cond ((= button 4) (scroll-down amt)) |
55a234a9fe88
Fix copyright notice. Don't require 'cl at run time.
Gerd Moellmann <gerd@gnu.org>
parents:
26398
diff
changeset
|
93 ((= button 5) (scroll-up amt)) |
55a234a9fe88
Fix copyright notice. Don't require 'cl at run time.
Gerd Moellmann <gerd@gnu.org>
parents:
26398
diff
changeset
|
94 (t (error "Bad binding in mwheel-scroll")))) |
26398
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
95 (if curwin (select-window curwin))))) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
96 |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
97 ;;;###autoload |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
98 (defun mwheel-install () |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
99 "Enable mouse wheel support." |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
100 ;; In the latest versions of XEmacs, we could just use |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
101 ;; (S-)*mouse-[45], since those are aliases for the button |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
102 ;; 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
|
103 ;; versions of XEmacs as it can. |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
104 (let* ((mwheel-running-xemacs (string-match "XEmacs" (emacs-version))) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
105 (keys (if mwheel-running-xemacs |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
106 '(button4 [(shift button4)] button5 [(shift button5)]) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
107 '([mouse-4] [S-mouse-4] [mouse-5] [S-mouse-5])))) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
108 ;; 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
|
109 ;; 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
|
110 ;; 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
|
111 ;; 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
|
112 ;; 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
|
113 (condition-case () |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
114 (while keys |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
115 (define-key global-map (car keys) 'mwheel-scroll) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
116 (setq keys (cdr keys))) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
117 (error nil)))) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
118 |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
119 (provide 'mwheel) |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
120 |
7eb699cb9ef2
Initial import from perry
William M. Perry <wmperry@aventail.com>
parents:
diff
changeset
|
121 ;;; mwheel.el ends here |