0

Creating a popup menu with

(require 'popup)
(popup-menu* '("aaa" "bbb" "ccc"))

always returns the selected item even if the mouse clicks occurs outside of the menu. I would have expected that a mouse click outside of the menu would be equal to quitting the menu.

Am I missing something or do I really have to implement this myself?

I figured out that (popup-menu-item-of-mouse-event event) actually returns the selected item if the mouse click occurs onto this item and nil if it occurs outside. But going this way would mean to hook into the keymap if I'm not mistaken. Is this the right way to go? It feels like reinventing the wheel.

1
  • To my understanding you should always provide a keymap; also that mouse event is checked in the popup event loop, so I'd ask directly to the package author.
    – Muihlinn
    Apr 17 '20 at 18:14
1

The following seems to work. Though it still feels like reinventing the wheel.

(require 'popup)

(setq my-map
  (let ((map (make-sparse-keymap)))
    (set-keymap-parent map popup-menu-keymap)
    (define-key map [mouse-1] 'mouse-1)
    map))

(defun mouse-1 (event)
  (interactive "e")
   (let ((res (popup-menu-item-of-mouse-event event)))
     (popup-delete menu)
     (cl-return res)))

(popup-menu* '("aaa" "bbb" "ccc")
             :keymap my-map)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.