]> git.eshelyaron.com Git - emacs.git/commitdiff
* lisp/mwheel.el: Don't use `custom-initialize-delay`.
authorStefan Monnier <monnier@iro.umontreal.ca>
Sun, 1 Aug 2021 22:13:41 +0000 (18:13 -0400)
committerStefan Monnier <monnier@iro.umontreal.ca>
Sun, 1 Aug 2021 22:13:41 +0000 (18:13 -0400)
Set up the keybindings when loading the file.

(mouse-wheel--installed-bindings-alist): Move to beginning.
(mouse-wheel-change-button): Don't update bindings when they're not installed.
(mouse-wheel--setup-bindings): New function extracted from `mouse-wheel-mode`.
(<topleve>): Call it when loading the file.
(mouse-wheel-mode): Use the default :initializer.

lisp/mwheel.el

index b31805a57581b05146ae8f6c8e55a7fe7f513172..def77587747fa6e650129b1a339fd692edd7ced3 100644 (file)
@@ -40,6 +40,8 @@
 (require 'timer)
 
 (defvar mouse-wheel-mode)
+(defvar mouse-wheel--installed-bindings-alist nil
+  "Alist of all installed mouse wheel key bindings.")
 
 ;; Setter function for mouse-button user-options.  Switch Mouse Wheel
 ;; mode off and on again so that the old button is unbound and
 
 (defun mouse-wheel-change-button (var button)
   (set-default var button)
-  ;; Sync the bindings.
-  (when (bound-and-true-p mouse-wheel-mode) (mouse-wheel-mode 1)))
+  ;; Sync the bindings if they're already setup.
+  (when (and mouse-wheel--installed-bindings-alist
+             (bound-and-true-p mouse-wheel-mode))
+    (mouse-wheel-mode 1)))
 
 (defcustom mouse-wheel-down-event
   (if (or (featurep 'w32-win) (featurep 'ns-win))
@@ -380,9 +384,6 @@ value of ARG, and the command uses it in subsequent scrolls."
                (text-scale-decrease 1)))
       (select-window selected-window))))
 
-(defvar mouse-wheel--installed-bindings-alist nil
-  "Alist of all installed mouse wheel key bindings.")
-
 (defun mouse-wheel--add-binding (key fun)
   "Bind mouse wheel button KEY to function FUN.
 Save it for later removal by `mouse-wheel--remove-bindings'."
@@ -418,30 +419,31 @@ an event used for scrolling, such as `mouse-wheel-down-event'."
 (define-minor-mode mouse-wheel-mode
   "Toggle mouse wheel support (Mouse Wheel mode)."
   :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
   ;; Remove previous bindings, if any.
   (mouse-wheel--remove-bindings)
   ;; Setup bindings as needed.
   (when mouse-wheel-mode
-    (dolist (binding mouse-wheel-scroll-amount)
-      (cond
-       ;; Bindings for changing font size.
-       ((and (consp binding) (eq (cdr binding) 'text-scale))
-        (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event))
-          (mouse-wheel--add-binding `[,(list (caar binding) event)]
-                                    'mouse-wheel-text-scale)))
-       ;; Bindings for scrolling.
-       (t
-        (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event
-                             mouse-wheel-left-event mouse-wheel-right-event))
-          (dolist (key (mouse-wheel--create-scroll-keys binding event))
-            (mouse-wheel--add-binding key 'mwheel-scroll))))))))
+    (mouse-wheel--setup-bindings)))
+
+(defun mouse-wheel--setup-bindings ()
+  (dolist (binding mouse-wheel-scroll-amount)
+    (cond
+     ;; Bindings for changing font size.
+     ((and (consp binding) (eq (cdr binding) 'text-scale))
+      (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event))
+        (mouse-wheel--add-binding `[,(list (caar binding) event)]
+                                  'mouse-wheel-text-scale)))
+     ;; Bindings for scrolling.
+     (t
+      (dolist (event (list mouse-wheel-down-event mouse-wheel-up-event
+                           mouse-wheel-left-event mouse-wheel-right-event))
+        (dolist (key (mouse-wheel--create-scroll-keys binding event))
+          (mouse-wheel--add-binding key 'mwheel-scroll)))))))
+
+(when mouse-wheel-mode
+  (mouse-wheel--setup-bindings))
 
 ;;; Obsolete.