[求助] 如何添加鼠标点击事件 hook

如何在点击鼠标之后 执行一个函数,我没有找到对应的hook , 我现在的实现方法是 (advice-add 'mouse-set-point :filter-return #'better-jumper-set-jump) 但是会产生报错 apply: Wrong number of arguments: (1 . 2), 0 我现在的解决思路找到了两个api 但是用不明白

mouse-leave-buffer-hook

activate-mark-hook

希望有其他比较好的解决思路

1 个赞

好像有个键 mouse-1 这样的, 试试

(define-key xxx-map (kbd "<mouse-1>") #'xxx-cmd)

There were several key-sequences:

at that spot runs the command evil-mouse-drag-region at that spot runs the command mouse-set-point

They’re all described below.

mouse-1 自己是绑定着快捷键的,我不希望覆盖他本身的执行命令,我想在他后面加上一条执行

那不是在自己命令后面直接加一个逻辑就可以了吗?都不用advice了。

参数数量不对,你可以看下它的原型传入对应参数就行

我lisp 能力有限,我一般都是无参数调用的,我应该在那个位置传递参数,

建议描述下你想达到的具体效果。现在的问法我感觉很像个 X-Y 问题

没事,你可以尝试解决下,然后你就发现 lisp 水平又长进了一点。( Learning by doing )

你可以看下函数的 docstring 和原型,通过 C-h f better-jumper-set-jump RET ,然后跟着链接点进去可以看到源码,看它的参数什么含义,能不能用在你这个场景。

如果不行的话,再考虑其他方法。

描述一下我的问题, 我希望点击鼠标之后,能紧接着执行另外一条函数

(defun better-jumper-set-jump (&optional pos)
  "Set jump point at POS.
POS defaults to point."
 
  #f(compiled-function (event &optional promote-to-region) "Move point to the position clicked on with the mouse.\nThis should be bound to a mouse click event type.\nIf PROMOTE-TO-REGION is non-nil and event is a multiple-click, select\nthe corresponding element around point, with the resulting position of\npoint determined by `mouse-select-region-move-to-beginning'." (interactive "e\np") #<bytecode 0x97b9ce0f73431c>)()
  apply(#f(compiled-function (event &optional promote-to-region) "Move point to the position clicked on with the mouse.\nThis should be bound to a mouse click event type.\nIf PROMOTE-TO-REGION is non-nil and event is a multiple-click, select\nthe corresponding element around point, with the resulting position of\npoint determined by `mouse-select-region-move-to-beginning'." (interactive "e\np") #<bytecode 0x97b9ce0f73431c>) nil)
  mouse-set-point()
  funcall-interactively(mouse-set-point)
  command-execute(mouse-set-point)
(add-hook 'mouse-leave-buffer-hook
          (defun set-jump-at-mouse-pos ()
            (when-let ((pos (posn-point (event-end last-input-event))))
              (better-jump-set-jump pos))))

感谢您的帮助