我想跟踪当前缓冲区中的"当前字".另一个(联网)应用程序将意识到.
我可以通过每次光标移动时发送请求来执行此操作,无论是通过单击还是滚动或箭头等,即光标在缓冲区中的位置发生变化的任何时间.
例如
(add-hook 'cursor-move-hook 'post-request-with-current-word)
Run Code Online (Sandbox Code Playgroud)
使用post-command-hook此命令将在每个命令后运行,包括移动命令.
显然这会比你想要的更频繁地发生,所以在你的钩子中,你可以做一些事情,比如跟踪你在钩子运行时的最后位置,如果当前点与上一个点不同,那么只能触发网络请求. :
(defvar last-post-command-position 0
"Holds the cursor position from the last run of post-command-hooks.")
(make-variable-buffer-local 'last-post-command-position)
(defun do-stuff-if-moved-post-command ()
(unless (equal (point) last-post-command-position)
(let ((my-current-word (thing-at-point 'word)))
;; replace (message ...) with your code
(message "%s" my-current-word)))
(setq last-post-command-position (point)))
(add-to-list 'post-command-hook #'do-stuff-if-moved-post-command)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
734 次 |
| 最近记录: |