annotate lisp/mwheel.el @ 5640:e6b5c49f9e13

Add autoload cookie to custom-set-face-bold
author Vin Shelton <acs@xemacs.org>
date Sun, 08 Jan 2012 22:29:06 -0500
parents 308d34e9f07d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 ;;; mwheel.el --- Mouse support for MS intelli-mouse type mice
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 ;; Copyright (C) 1998, Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 ;; Maintainer: William M. Perry <wmperry@cs.indiana.edu>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 ;; Keywords: mouse
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 ;; This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 2546
diff changeset
9 ;; XEmacs is free software: you can redistribute it and/or modify it
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 2546
diff changeset
10 ;; under the terms of the GNU General Public License as published by the
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 2546
diff changeset
11 ;; Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 2546
diff changeset
12 ;; option) any later version.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 2546
diff changeset
14 ;; XEmacs is distributed in the hope that it will be useful, but WITHOUT
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 2546
diff changeset
15 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 2546
diff changeset
16 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 2546
diff changeset
17 ;; for more details.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 2546
diff changeset
20 ;; along with XEmacs. If not, see <http://www.gnu.org/licenses/>.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 ;;; Synched up with: Not synched.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 ;;; Commentary:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 ;; This code will enable the use of the infamous 'wheel' on the new
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 ;; crop of mice. Under XFree86 and the XSuSE X Servers, the wheel
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 ;; events are sent as button4/button5 events.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 ;; I for one would prefer some way of converting the button4/button5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 ;; events into different event types, like 'mwheel-up' or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 ;; 'mwheel-down', but I cannot find a way to do this very easily (or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 ;; portably), so for now I just live with it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 ;; To enable this code, simply put this at the top of your .emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 ;; file:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 ;;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 ;; (autoload 'mwheel-install "mwheel" "Enable mouse wheel support.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 ;; (mwheel-install)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 ;;; Code:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 (require 'custom)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 (require 'cl)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45
502
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 458
diff changeset
46 (globally-declare-fboundp
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 458
diff changeset
47 '(event-basic-type
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 458
diff changeset
48 posn-window event-start mwheel-event-window mwheel-event-button))
7039e6323819 [xemacs-hg @ 2001-05-04 22:41:46 by ben]
ben
parents: 458
diff changeset
49
1621
9cf129cb99b9 [xemacs-hg @ 2003-08-13 11:22:42 by stephent]
stephent
parents: 502
diff changeset
50 (defcustom mwheel-scroll-amount '(5 1 nil)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 "Amount to scroll windows by when spinning the mouse wheel.
1621
9cf129cb99b9 [xemacs-hg @ 2003-08-13 11:22:42 by stephent]
stephent
parents: 502
diff changeset
52 A list with 3 elements specifying the amount to scroll on: a normal wheel
9cf129cb99b9 [xemacs-hg @ 2003-08-13 11:22:42 by stephent]
stephent
parents: 502
diff changeset
53 event, a wheel event with the shift key pressed, and a wheel event with the
9cf129cb99b9 [xemacs-hg @ 2003-08-13 11:22:42 by stephent]
stephent
parents: 502
diff changeset
54 control key pressed, in that order.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 Each item should be the number of lines to scroll, or `nil' for near
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 full screen.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 A near full screen is `next-screen-context-lines' less than a full screen."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 :group 'mouse
1621
9cf129cb99b9 [xemacs-hg @ 2003-08-13 11:22:42 by stephent]
stephent
parents: 502
diff changeset
60 :type '(list
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 (choice :tag "Normal"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 (const :tag "Full screen" :value nil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 (integer :tag "Specific # of lines"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 (choice :tag "Shifted"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 (const :tag "Full screen" :value nil)
1621
9cf129cb99b9 [xemacs-hg @ 2003-08-13 11:22:42 by stephent]
stephent
parents: 502
diff changeset
66 (integer :tag "Specific # of lines"))
9cf129cb99b9 [xemacs-hg @ 2003-08-13 11:22:42 by stephent]
stephent
parents: 502
diff changeset
67 (choice :tag "Controlled"
9cf129cb99b9 [xemacs-hg @ 2003-08-13 11:22:42 by stephent]
stephent
parents: 502
diff changeset
68 (const :tag "Full screen" :value nil)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 (integer :tag "Specific # of lines"))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 (defcustom mwheel-follow-mouse nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 "Whether the mouse wheel should scroll the window that the mouse is over.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 This can be slightly disconcerting, but some people may prefer it."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 :group 'mouse
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 :type 'boolean)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 (if (not (fboundp 'event-button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 (defun mwheel-event-button (event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 (let ((x (symbol-name (event-basic-type event))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 (if (not (string-match "^mouse-\\([0-9]+\\)" x))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 (error "Not a button event: %S" event))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 (string-to-int (substring x (match-beginning 1) (match-end 1)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 (fset 'mwheel-event-button 'event-button))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 (if (not (fboundp 'event-window))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 (defun mwheel-event-window (event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 (posn-window (event-start event)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 (fset 'mwheel-event-window 'event-window))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 (defun mwheel-scroll (event)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 (interactive "e")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 (let ((curwin (if mwheel-follow-mouse
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 (prog1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 (selected-window)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 (select-window (mwheel-event-window event)))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 (amt (if (memq 'shift (event-modifiers event))
1621
9cf129cb99b9 [xemacs-hg @ 2003-08-13 11:22:42 by stephent]
stephent
parents: 502
diff changeset
97 (cadr mwheel-scroll-amount)
9cf129cb99b9 [xemacs-hg @ 2003-08-13 11:22:42 by stephent]
stephent
parents: 502
diff changeset
98 (if (memq 'control (event-modifiers event))
9cf129cb99b9 [xemacs-hg @ 2003-08-13 11:22:42 by stephent]
stephent
parents: 502
diff changeset
99 (caddr mwheel-scroll-amount)
9cf129cb99b9 [xemacs-hg @ 2003-08-13 11:22:42 by stephent]
stephent
parents: 502
diff changeset
100 (car mwheel-scroll-amount)))))
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 444
diff changeset
101 (unwind-protect
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 444
diff changeset
102 (case (mwheel-event-button event)
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 444
diff changeset
103 (4 (scroll-down amt))
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 444
diff changeset
104 (5 (scroll-up amt))
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 444
diff changeset
105 (otherwise (error "Bad binding in mwheel-scroll")))
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 444
diff changeset
106 (if curwin (select-window curwin)))
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 444
diff changeset
107 ))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 ;;;###autoload
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 (defun mwheel-install ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 "Enable mouse wheel support."
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 428
diff changeset
112 (interactive)
1621
9cf129cb99b9 [xemacs-hg @ 2003-08-13 11:22:42 by stephent]
stephent
parents: 502
diff changeset
113 (let ((keys '([(mouse-4)] [(shift mouse-4)] [(control mouse-4)]
9cf129cb99b9 [xemacs-hg @ 2003-08-13 11:22:42 by stephent]
stephent
parents: 502
diff changeset
114 [(mouse-5)] [(shift mouse-5)] [(control mouse-5)])))
9cf129cb99b9 [xemacs-hg @ 2003-08-13 11:22:42 by stephent]
stephent
parents: 502
diff changeset
115
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 ;; This condition-case is here because Emacs 19 will throw an error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 ;; if you try to define a key that it does not know about. I for one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 ;; prefer to just unconditionally do a mwheel-install in my .emacs, so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 ;; that if the wheeled-mouse is there, it just works, and this way it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 ;; doesn't yell at me if I'm on my laptop or another machine, etc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 (condition-case ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 (while keys
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 (define-key global-map (car keys) 'mwheel-scroll)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 (setq keys (cdr keys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 (error nil))))
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 444
diff changeset
126
2546
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1621
diff changeset
127 ;;;###autoload
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1621
diff changeset
128 (define-behavior 'mwheel
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1621
diff changeset
129 "This code enables the use of the infamous 'wheel' on the new
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1621
diff changeset
130 crop of mice. Under XFree86 and the XSuSE X Servers, the wheel
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1621
diff changeset
131 events are sent as button4/button5 events, which are automatically
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1621
diff changeset
132 set up to do scrolling in the expected way. The actual way that the
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1621
diff changeset
133 scrolling works can be controlled by `mwheel-scroll-amount' and
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1621
diff changeset
134 `mwheel-follow-mouse'."
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1621
diff changeset
135 :group 'mouse
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1621
diff changeset
136 :short-doc "Mouse wheel support for X Windows"
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1621
diff changeset
137 :enable 'mwheel-install)
5d1743698fb3 [xemacs-hg @ 2005-02-03 05:26:39 by ben]
ben
parents: 1621
diff changeset
138
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 (provide 'mwheel)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 ;;; mwheel.el ends here