我使用 GNU emacs-24。 我制作这样的按钮:
(defun go-click (button)
(print (button-get button 'point))
(let ((win (get-buffer-window (button-get button 'buffer))))
(if win
(progn
(select-window win)
(goto-char (button-get button 'point)))
(message "open a window with the location"))))
(let ((p (point)) (buf (current-buffer)))
(with-current-buffer (get-buffer "yyy")
(insert-button "go" 'action #'go-click
'follow-link t
'point p
'buffer buf)))
我在一个窗口的*scratch*缓冲区和另一个带有缓冲区yyy的窗口中有这段代码。我 eval-current-buffer 而重点是,比如说 #'go-click 位置。然后出现 yyy 中的go按钮。
如果我现在单击按钮,它会按预期打印数字,使 *scratch* 处于事件状态,如预期的那样,但不会移动 #'go-click 位置上的点。
但是,如果我通过光标键将点定位在go按钮上,然后按回车键,它就会按预期工作(将点移动到#'go-click位置,无论我把它留在哪里*抓取*之前)。
如何使其同时适用于键盘输入和鼠标单击场景?
最佳答案
这是一个小补丁:
(defun go-click (button)
(print (button-get button 'point))
(let ((win (get-buffer-window (button-get button 'buffer)))
(cur-win (get-buffer-window (current-buffer))))
(select-window cur-win)
(if win
(progn
(select-window win)
(goto-char (button-get button 'point)))
(message "open a window with the location"))))
关于button - 如何使链接 emacs 按钮在另一个缓冲区中单击鼠标时起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14498578/