2

我使用 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)))

我在 onw 窗口的*scratch*缓冲区和另一个带有缓冲区yyy的窗口中有这段代码。我 eval-current-buffer 的重点是,比如在 #'go-click 位置。出现按钮进入yyy

如果我现在单击该按钮,它会按预期打印数字,使*scratch*按预期激活,但不会移动 #'go-click 位置上的点。

但是,如果我通过光标键在go按钮上定位点,然后按 Enter,它会按预期工作(移动指向 #'go-click positoin,不管,我之前将它留在*scratch*中的位置)。

如何使其适用于键盘输入和鼠标单击场景?

4

1 回答 1

2

这是小补丁:

(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"))))
于 2013-01-24T13:10:14.977 回答