popup-el icon indicating copy to clipboard operation
popup-el copied to clipboard

How do I capture keys in a popup-tip?

Open stsquad opened this issue 10 years ago • 2 comments

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?

stsquad avatar Mar 25 '14 12:03 stsquad

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)

syohex avatar Mar 30 '14 14:03 syohex

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.

stsquad avatar Mar 31 '14 08:03 stsquad