当我按住 mouse-1 并在缓冲区中移动它时,我只想让光标跟随鼠标。
问问题
630 次
3 回答
1
试试这个。
(global-unset-key [drag-mouse-1])
(global-unset-key [down-mouse-1])
注意:此方法存在鼠标不跟随鼠标的问题。尽管释放鼠标时光标会消失。
期待更好的解决方案。
于 2012-12-21T12:24:45.893 回答
1
要回答原始问题:
(defun my-move-cursor (event)
(interactive "e")
(mouse-set-point event)
(let (event ov)
(track-mouse
(while (progn
(setq event (read-event))
(or (mouse-movement-p event)
(memq (car-safe event) '(switch-frame select-window))))
(mouse-set-point event)
(if ov (move-overlay ov (point) (1+ (point)))
(setq ov (make-overlay (point) (1+ (point))))
(overlay-put ov 'face 'match))))
(when ov (delete-overlay ov))))
我最终做的有点不同。我修改了正常功能,使其不启用瞬态标记模式,并制作了一个恒定的叠加层,突出显示鼠标所在的字符。
于 2013-01-26T03:05:12.790 回答
0
Ian Kelling 解决方案的一个轻微变体,它不使用覆盖,但控制光标闪烁,禁用当前处于活动状态的任何瞬态标记,并避免将鼠标移出 Emacs 窗口时出现问题:
(defun my-move-cursor (event)
(interactive "e")
(deactivate-mark)
(mouse-set-point event)
(let ((blinking (if blink-cursor-mode 1 0)))
(blink-cursor-mode 0)
(let (event)
(track-mouse
(while (progn
(setq event (read-event))
(mouse-movement-p event))
(ignore-errors (mouse-set-point event)))
))
(blink-cursor-mode blinking))
)
我将此定义与我的 init 文件中的以下鼠标重新映射结合起来:
; Set up mouse 1 movement
(global-set-key [drag-mouse-1] 'mouse-set-point)
(global-set-key [down-mouse-1] 'my-move-cursor)
; Set up mouse 3 behavior to emulate standard mouse 1 behavior
(global-set-key [down-mouse-3] 'mouse-drag-region)
(global-set-key [drag-mouse-3] 'mouse-set-region)
于 2013-03-20T21:57:36.430 回答