Emacs:使自定义滚动功能跟随鼠标,但不会更改键盘焦点 [英] Emacs: Make custom scrolling function follow mouse but not change keyboard focus

查看:142
本文介绍了Emacs:使自定义滚动功能跟随鼠标,但不会更改键盘焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Emacs中有一些自定义滚动功能,它帮助我解决了一个错误,一个滚动事件发送两个< mouse-4> < mouse-5> 动作。我有:

 (setq scroll-down-this-time t)

(defun my-滚动下线()
(互动@)
(如果滚动下来 - 这个时间
(progn
(向下滚动)
(setq scroll-down-this-time nil))
(setq scroll-down-this-time t))

(setq scroll-up-this-time t)

(defun my-scroll-up-line()
(interactive@)
(如果scroll-up-this-time
(progn
(向上滚动)
(setq scroll-up-this-time nil))
(setq scroll-up-this-time t))

全局设置键(kbd< mouse-4>)'my-scroll-down-line)
(全局设置键(kbd< mouse-5>)'my-scroll -o-line)

这样做完美,除了 @)不完全是我想要的。这将导致鼠标下面的任何缓冲区滚动并获得键盘焦点。我想要一种方式使其滚动,但不会窃取键盘焦点(如正常滚动库中的(setq mouse-wheel-follow-mouse't))。我如何实现这一点?



我正在使用Emacs的开发版本,所以不要害怕给我任何新功能。

$ b $您不应重新定义< mouse-4>

mouse-5> ,而是:

 (鼠标滚轮模式1)

(defvar alternating-scroll-down-next t)
(defvar alternating-scroll-up-next t)

(defun alternating-scroll-down-line(& ;可选arg)
(当交替滚动下一个
(滚动下行(或arg 1)))
(setq交替滚动下一个(不交替-scroll-down-next)))

(defun alternating-scroll-up-line(& optional arg)
(当交替滚动下一个
滚动线(或arg 1)))
(setq alternating-scroll-up-next(not alternating-scroll-up-next))

(setq mwheel-scroll -up-function'交替上拉行)
(setq mwheel-scroll-down-function'alter nating-scroll-down-line)


I have some custom scrolling functions in Emacs, which help me get around a bug where a single scroll event sends two <mouse-4> or <mouse-5> actions. I have:

(setq scroll-down-this-time t)

(defun my-scroll-down-line ()
    (interactive "@")
    (if scroll-down-this-time
        (progn
          (scroll-down-line)
          (setq scroll-down-this-time nil))
      (setq scroll-down-this-time t)))

(setq scroll-up-this-time t)

(defun my-scroll-up-line ()
    (interactive "@")
    (if scroll-up-this-time
        (progn
          (scroll-up-line)
          (setq scroll-up-this-time nil))
      (setq scroll-up-this-time t)))

(global-set-key (kbd "<mouse-4>") 'my-scroll-down-line)
(global-set-key (kbd "<mouse-5>") 'my-scroll-up-line)

This works perfectly, except that the (interactive "@") isn't exactly what I want. This causes whatever buffer that is under the mouse to scroll and to gain the keyboard focus. I want a way to make it scroll, but not steal the keyboard focus (like (setq mouse-wheel-follow-mouse 't) does for the normal scrolling library). How might I achieve this?

I am using the development version of Emacs, so don't be afraid to give me any new features.

解决方案

You should not redefine <mouse-4> and <mouse-5>, but instead:

(mouse-wheel-mode 1)

(defvar alternating-scroll-down-next t)
(defvar alternating-scroll-up-next t)

(defun alternating-scroll-down-line (&optional arg)
  (when alternating-scroll-down-next
    (scroll-down-line (or arg 1)))
  (setq alternating-scroll-down-next (not alternating-scroll-down-next)))

(defun alternating-scroll-up-line (&optional arg)
  (when alternating-scroll-up-next
    (scroll-up-line (or arg 1)))
  (setq alternating-scroll-up-next (not alternating-scroll-up-next)))

(setq mwheel-scroll-up-function 'alternating-scroll-up-line)
(setq mwheel-scroll-down-function 'alternating-scroll-down-line)

这篇关于Emacs:使自定义滚动功能跟随鼠标,但不会更改键盘焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆