如何使Emacs鼠标拖动不突出显示或设置标记

时间:2012-12-21 08:25:12

标签: emacs elisp

当我按住鼠标1并在缓冲区中移动它时,我只想让光标跟随鼠标。

3 个答案:

答案 0 :(得分:1)

试试这个。

(global-unset-key [drag-mouse-1])

(global-unset-key [down-mouse-1])

注意:此方法存在问题,即鼠标不跟随鼠标。虽然释放鼠标时光标会移动。

期待更好的解决方案。

答案 1 :(得分: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))))

我最终做的事情有点不同。我修改了普通函数,因此它不启用瞬态标记模式,并进行了一个常量叠加,突出显示鼠标所在的字符。

答案 2 :(得分: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)