auto-complete / popup-el

Visual Popup Interface Library for Emacs
GNU General Public License v3.0
449 stars 96 forks source link

How do I capture keys in a popup-tip? #68

Open stsquad opened 10 years ago

stsquad commented 10 years ago

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 10 years ago

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 10 years ago

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.