Button 如何使链接emacs按钮在另一个缓冲区中单击鼠标时工作?
我使用GNU emacs-24。 我制作的按钮如下:Button 如何使链接emacs按钮在另一个缓冲区中单击鼠标时工作?,button,emacs,elisp,emacs24,Button,Emacs,Elisp,Emacs24,我使用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 '
(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)))
我在onw窗口的*scratch*缓冲区中有此代码,另一个窗口是bufferyyy。我在点处于#'点击位置时评估当前缓冲区。此时会出现进入yyy的按钮
如果我现在单击该按钮,它会打印数字,正如预期的那样,使*scratch*处于活动状态,但不会移动#“点击”位置上的点
但是,如果我用光标键将点定位在go按钮上,并按enter键,它将按预期工作(将点移动到#'go-click位置,不管我之前在*scratch*中将其放在哪里)
如何使其同时适用于键盘输入和鼠标单击场景?以下是小补丁:
(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"))))
我假设在鼠标点击场景中,
点
位于*scratch*缓冲区中,在所有操作之后,emacs只是恢复该点。我使用debug-on-entry
函数goto-char
来澄清行为。