Emacsist RSS --- If never, make it ever: C-h C-h

Disable Mouse only inside Emacs

7473

这里 查看更多 Emacs 相关推荐文章最新 Emacs 圈的动态. 欢迎关注微信公众账号: Emacsist

As laptop touchpads seem to be steadily increasing in size, one unfortunate consequence is that it becomes increasingly harder to avoid touching them by accident while you type. Most systems have safeguards in place that disable the touchpad as you’re typing, but they always seem to fall short for me when it comes to Emacs. While in Emacs, my hands are permanently resting on the keyboard (and over the touchpad), so even if I stop typing for several seconds I don’t want the touchpad to reactivate.

There are ways to permanently deactivate the touchpad with a hotkey, but, so far, the solution that best fits my use-style is to disable it only inside Emacs.

(define-minor-mode disable-mouse-mode
  "A minor-mode that disables all mouse keybinds."
  :global t
  :lighter " ??"
  :keymap (make-sparse-keymap))

(dolist (type '(mouse down-mouse drag-mouse
                      double-mouse triple-mouse))
  (dolist (prefix '("" C- M- S- M-S- C-M- C-S- C-M-S-))
    ;; Yes, I actually HAD to go up to 7 here.
    (dotimes (n 7)
      (let ((k (format "%s%s-%s" prefix type n)))
        (define-key disable-mouse-mode-map
          (vector (intern k)) #'ignore)))))

All we do here is define a minor-mode that binds all mouse-related keys to ignore. This is a slight improvement over the code on this StackOverflow answer. Of course, let’s not forget to enable this.

(disable-mouse-mode 1)

Two relevant limitations:

  • This doesn’t distinguish between a touchpad an an actual mouse.
  • It is still possible for modes to define specific buttons that interact with the mouse, but that’s not a huge problem because these buttons take a small portion of the screen so it’s fairly difficult to touch them by accident.
原文出处: EndlessParenthese
原文地址: http://endlessparentheses.com/disable-mouse-only-inside-emacs.html?source=rss
原文时间: 2016-05-02 08:00
本文地址: http://emacsist.com/10868
整理时间: 2016-05-12 02:04

本文由 Hick 整理,转载请保留以上信息;
COPYLEFTThe articles on this site come from Internet, thanks to all the original authors.
      If anything about COPYRIGHT, or LEFT, please contact Emacsist at gmail dot com .