2

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

(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)

这完美地工作,除了(interactive "@")不是我想要的。这会导致鼠标下方的任何缓冲区滚动并获得键盘焦点。我想要一种让它滚动的方法,但不窃取键盘焦点(就像(setq mouse-wheel-follow-mouse 't)普通滚动库一样)。我怎样才能做到这一点?

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

4

1 回答 1

1

您不应该重新定义<mouse-4>and <mouse-5>,而是:

(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)
于 2012-07-17T23:27:01.097 回答