summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2025-10-12 12:08:31 -0500
committerCraig Jennings <c@cjennings.net>2025-10-12 12:08:31 -0500
commit938c2402c0444f52257f8d5a4513f2f6898db084 (patch)
tree17e61d2e932f2e055e04331d37f086adc04b155f /modules
parent092304d9e0ccc37cc0ddaa9b136457e56a1cac20 (diff)
feat: mousetrap-mode: move mousetrap-mode from wip into module
Diffstat (limited to 'modules')
-rw-r--r--modules/mousetrap-mode.el53
-rw-r--r--modules/wip.el35
2 files changed, 53 insertions, 35 deletions
diff --git a/modules/mousetrap-mode.el b/modules/mousetrap-mode.el
new file mode 100644
index 00000000..0d5210d9
--- /dev/null
+++ b/modules/mousetrap-mode.el
@@ -0,0 +1,53 @@
+;;; mousetrap-mode.el --- -*- coding: utf-8; lexical-binding: t; -*-
+;;
+;;; Commentary:
+;; Mouse Trap Mode is a minor mode for Emacs that globally disables most mouse and
+;; trackpad events to prevent accidental text modifications. Hitting the trackpad and
+;; finding my text is being inserted in an unintended place is quite annoying,
+;; especially when you're overcaffeinated.
+;;
+;; The mode unbinds almost every mouse event, including clicks, drags, and wheel
+;; movements, with various modifiers like Control, Meta, and Shift.
+;;
+;; Inspired by this blog post from Malabarba
+;; https://endlessparentheses.com/disable-mouse-only-inside-emacs.html
+;;
+;;; Code:
+
+;; ------------------------------ Mouse Trap Mode ------------------------------
+
+(defvar mouse-trap-mode-map
+ (let* ((prefixes '("" "C-" "M-" "S-" "C-M-" "C-S-" "M-S-" "C-M-S-")) ; modifiers
+ (buttons (number-sequence 1 5)) ; mouse-1..5
+ (types '("mouse" "down-mouse" "drag-mouse"
+ "double-mouse" "triple-mouse"))
+ (wheel '("wheel-up" "wheel-down" "wheel-left" "wheel-right"))
+ (map (make-sparse-keymap)))
+ ;; clicks, drags, double, triple
+ (dolist (type types)
+ (dolist (pref prefixes)
+ (dolist (n buttons)
+ (define-key map (kbd (format "<%s%s-%d>" pref type n)) #'ignore))))
+ ;; wheel
+ (dolist (evt wheel)
+ (dolist (pref prefixes)
+ (define-key map (kbd (format "<%s%s>" pref evt)) #'ignore)))
+ map)
+ "Keymap for `mouse-trap-mode'. Unbinds almost every mouse event.
+
+Disabling mouse prevents accidental mouse moves modifying text.")
+
+(define-minor-mode mouse-trap-mode
+ "Globally disable most mouse and trackpad events.
+
+When active, <mouse-*>, <down-mouse-*>, <drag-mouse-*>,
+<double-mouse-*>, <triple-mouse-*>, and wheel events are bound to `ignore',
+with or without C-, M-, S- modifiers."
+ :global t
+ :lighter " 🐭"
+ :keymap mouse-trap-mode-map)
+(global-set-key (kbd "C-c M") #'mouse-trap-mode)
+(mouse-trap-mode 1)
+
+(provide 'mousetrap-mode)
+;;; mousetrap-mode.el ends here.
diff --git a/modules/wip.el b/modules/wip.el
index 0fae57e3..6c7c8845 100644
--- a/modules/wip.el
+++ b/modules/wip.el
@@ -70,41 +70,6 @@
:bind ("M-p" . pomm)
:commands (pomm pomm-third-time))
-;; ------------------------------ Mouse Trap Mode ------------------------------
-
-(defvar mouse-trap-mode-map
- (let* ((prefixes '("" "C-" "M-" "S-" "C-M-" "C-S-" "M-S-" "C-M-S-")) ; modifiers
- (buttons (number-sequence 1 5)) ; mouse-1..5
- (types '("mouse" "down-mouse" "drag-mouse"
- "double-mouse" "triple-mouse"))
- (wheel '("wheel-up" "wheel-down" "wheel-left" "wheel-right"))
- (map (make-sparse-keymap)))
- ;; clicks, drags, double, triple
- (dolist (type types)
- (dolist (pref prefixes)
- (dolist (n buttons)
- (define-key map (kbd (format "<%s%s-%d>" pref type n)) #'ignore))))
- ;; wheel
- (dolist (evt wheel)
- (dolist (pref prefixes)
- (define-key map (kbd (format "<%s%s>" pref evt)) #'ignore)))
- map)
- "Keymap for `mouse-trap-mode'. Unbinds almost every mouse event.
-
-Disabling mouse prevents accidental mouse moves modifying text.")
-
-(define-minor-mode mouse-trap-mode
- "Globally disable most mouse and trackpad events.
-
-When active, <mouse-*>, <down-mouse-*>, <drag-mouse-*>,
-<double-mouse-*>, <triple-mouse-*>, and wheel events are bound to `ignore',
-with or without C-, M-, S- modifiers."
- :global t
- :lighter " 🐭"
- :keymap mouse-trap-mode-map)
-(global-set-key (kbd "C-c M") #'mouse-trap-mode)
-(mouse-trap-mode 1)
-
;; --------------------- Debug Code For Package Signatures ---------------------
;; from https://emacs.stackexchange.com/questions/233/how-to-proceed-on-package-el-signature-check-failure