summaryrefslogtreecommitdiff
path: root/lisp/mwheel.el
diff options
context:
space:
mode:
authorStefan Monnier <monnier@iro.umontreal.ca>2009-09-12 04:38:03 +0000
committerStefan Monnier <monnier@iro.umontreal.ca>2009-09-12 04:38:03 +0000
commitab5c0fcd35dcdf465a597ed83e5783bbbf70eff1 (patch)
tree024ebc25fb37774578221b859798c7ab61a58beb /lisp/mwheel.el
parent45448e641a75f56a010396d664491dafe5c6d85a (diff)
downloademacs-ab5c0fcd35dcdf465a597ed83e5783bbbf70eff1.tar.gz
* 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.
Diffstat (limited to 'lisp/mwheel.el')
-rw-r--r--lisp/mwheel.el47
1 files changed, 23 insertions, 24 deletions
diff --git a/lisp/mwheel.el b/lisp/mwheel.el
index 37980279a28..d457679d4f2 100644
--- a/lisp/mwheel.el
+++ b/lisp/mwheel.el
@@ -46,11 +46,9 @@
;; new button is bound to mwheel-scroll.
(defun mouse-wheel-change-button (var button)
- (let ((active mouse-wheel-mode))
- ;; Deactivate before changing the setting.
- (when active (mouse-wheel-mode -1))
- (set-default var button)
- (when active (mouse-wheel-mode 1))))
+ (set-default var button)
+ ;; Sync the bindings.
+ (when mouse-wheel-mode (mouse-wheel-mode 1)))
(defvar mouse-wheel-down-button 4)
(make-obsolete-variable 'mouse-wheel-down-button
@@ -239,32 +237,33 @@ This should only be bound to mouse buttons 4 and 5."
(run-with-timer mouse-wheel-inhibit-click-time nil
'mwheel-inhibit-click-timeout))))
+(defvar mwheel-installed-bindings nil)
+
;;;###autoload
(define-minor-mode mouse-wheel-mode
"Toggle mouse wheel support.
With prefix argument ARG, turn on if positive, otherwise off.
Return non-nil if the new state is enabled."
+ :init-value t
+ ;; We'd like to use custom-initialize-set here so the setup is done
+ ;; before dumping, but at the point where the defcustom is evaluated,
+ ;; the corresponding function isn't defined yet, so
+ ;; custom-initialize-set signals an error.
+ :initialize 'custom-initialize-delay
:global t
:group 'mouse
- (let* ((dn mouse-wheel-down-event)
- (up mouse-wheel-up-event)
- (keys
- (nconc (mapcar (lambda (amt) `[(,@(if (consp amt) (car amt)) ,up)])
- mouse-wheel-scroll-amount)
- (mapcar (lambda (amt) `[(,@(if (consp amt) (car amt)) ,dn)])
- mouse-wheel-scroll-amount))))
- ;; This condition-case is here because Emacs 19 will throw an error
- ;; if you try to define a key that it does not know about. I for one
- ;; prefer to just unconditionally do a mwheel-install in my .emacs, so
- ;; that if the wheeled-mouse is there, it just works, and this way it
- ;; doesn't yell at me if I'm on my laptop or another machine, etc.
- (condition-case ()
- (dolist (key keys)
- (cond (mouse-wheel-mode
- (global-set-key key 'mwheel-scroll))
- ((eq (lookup-key (current-global-map) key) 'mwheel-scroll)
- (global-unset-key key))))
- (error nil))))
+ ;; Remove previous bindings, if any.
+ (while mwheel-installed-bindings
+ (let ((key (pop mwheel-installed-bindings)))
+ (when (eq (lookup-key (current-global-map) key) 'mwheel-scroll)
+ (global-unset-key key))))
+ ;; Setup bindings as needed.
+ (when mouse-wheel-mode
+ (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event))
+ (dolist (key (mapcar (lambda (amt) `[(,@(if (consp amt) (car amt)) ,event)])
+ mouse-wheel-scroll-amount))
+ (global-set-key key 'mwheel-scroll)
+ (push key mwheel-installed-bindings)))))
;;; Compatibility entry point
;;;###autoload