How do I capture keys in a popup-tip?
Opened this issue · 2 comments
stsquad commented
I was looking at enhancing git-messenger to copy the commit for a given commit to the kill-ring if a certain key was pressed. It seems hard to do this with the popup-tip and using the menu machinery seems excessive given I don't want to loose the info in the tip. Any tips?
syohex commented
Sorry too late reply.
There is no way to capture key now.
But you can archive it by hook of git-messenger
and global-map
as below.
(defvar my/git-messenger-last-message nil)
(defun my/git-messenger-hook (message)
(setq my/git-messenger-last-message message))
(add-hook 'git-messenger:before-popup-hook 'my/git-messenger-hook)
(defun my/git-messenger-copy-message ()
(interactive)
(with-temp-buffer
(if (not my/git-messenger-last-message)
(message "no message")
(insert my/git-messenger-last-message)
(copy-region-as-kill (point-min) (point-max)))))
(global-set-key (kbd "C-c C-q") 'my/git-messenger-copy-message)
stsquad commented
That's doable but using the global-map is sub-optimal as you need to ensure you have cleared bindings after the message has been displayed. It would really be useful to have some way of capturing keys only while the popup is active.