summaryrefslogtreecommitdiff
path: root/modules/mousetrap-mode.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2025-10-20 13:25:21 -0500
committerCraig Jennings <c@cjennings.net>2025-10-20 13:25:21 -0500
commit2c41142debe94e7863f1c5365e5f865b1e67cc6a (patch)
tree1f6d7cd5ac91607b7e190511e1d72e5eb0c0c833 /modules/mousetrap-mode.el
parent03627ac73eefb582e8680afcd64c40a0be728ed7 (diff)
feat:mouse-trap-mode: add buffer-local activation and excluded modes
Modify `mouse-trap-mode` to activate buffer-locally and add an exclusion list of major modes where the mode should not be enabled. Update description and bindings for improved text and prog mode integration.
Diffstat (limited to 'modules/mousetrap-mode.el')
-rw-r--r--modules/mousetrap-mode.el27
1 files changed, 20 insertions, 7 deletions
diff --git a/modules/mousetrap-mode.el b/modules/mousetrap-mode.el
index 0d5210d9..fa9ee6dd 100644
--- a/modules/mousetrap-mode.el
+++ b/modules/mousetrap-mode.el
@@ -1,12 +1,12 @@
;;; 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
+;; Mouse Trap Mode is a minor mode for Emacs that 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
+;; 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
@@ -38,16 +38,29 @@
Disabling mouse prevents accidental mouse moves modifying text.")
(define-minor-mode mouse-trap-mode
- "Globally disable most mouse and trackpad events.
+ "Buffer-locally 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)
+ :keymap mouse-trap-mode-map
+ :group 'convenience)
+
+(defvar mouse-trap-excluded-modes
+ '(nov-mode pdf-view-mode dashboard-mode image-mode eww-mode Info-mode dired-mode)
+ "Major modes where `mouse-trap-mode' should not be enabled.")
+
+(defun mouse-trap-maybe-enable ()
+ "Enable `mouse-trap-mode' unless in an excluded mode."
+ (unless (apply #'derived-mode-p mouse-trap-excluded-modes)
+ (mouse-trap-mode 1)))
+
+;; Enable in text and prog modes
+(add-hook 'text-mode-hook #'mouse-trap-maybe-enable)
+(add-hook 'prog-mode-hook #'mouse-trap-maybe-enable)
+
+(keymap-global-set "C-c M" #'mouse-trap-mode)
(provide 'mousetrap-mode)
;;; mousetrap-mode.el ends here.