When I click on File
I want to see
and not
What can I change to provide this functionality? This question didn't really get the right answer.
When I click on File
I want to see
and not
What can I change to provide this functionality? This question didn't really get the right answer.
f1 c (describe-key-briefly
) works for mouse clicks and menu items too. So hit f1 c, click on the menu bar, and you'll see <menu-bar> <mouse-1> at that spot runs the command tmm-menubar-mouse
. Whereas f1 c f10 says <f10> runs the command menu-bar-open
. So to rebind:
(define-key global-map (kbd "<menu-bar> <mouse-1>") 'menu-bar-open)
Clicking on a different option than File will still open the file menu
Right, menu-bar-open
doesn't check xy location of the mouse click. Looking at the code of menu-bar-open
I came up with this:
(defun menu-bar-open-xy (mouse-event)
(interactive "e")
(pcase mouse-event
(`(mouse-1 (,_ menu-bar (,x . ,y) . ,_))
(let ((menu (menu-bar-menu-at-x-y x y)))
(popup-menu (or
(lookup-key-ignore-too-long
global-map (vector 'menu-bar menu))
(lookup-key-ignore-too-long
(current-local-map) (vector 'menu-bar menu))
(cdar (minor-mode-key-binding (vector 'menu-bar menu)))
(mouse-menu-bar-map))
(posn-at-x-y x y nil t) nil t)))
(_ (error "unexpected event %S" mouse-event))))
(define-key global-map (kbd "<menu-bar> <mouse-1>") 'menu-bar-open-xy)
The X co-ordinate is a bit off though, not clear why.
Clicking on File once file is open doesn't close the menu, just reopens it
Yeah, I'm not sure how to fix that. I guess that explains why this isn't the default in Emacs yet...
That's a great question.
npostavs's answer is really nice, but has a subtle drawback: the x offset of the popup menu does not matches that of the initially-shown menu name.
So, here is a snippet that fixes this issue: it adds a small recursive function in lisp — given the main function at stake is only available in C code otherwise!
(defun menu-bar-get-minimal-x (menu-symbol x y)
(let ((xx (- x 1)))
(if (< xx tty-menu--initial-menu-x)
x
(if (equal (menu-bar-menu-at-x-y xx y (selected-frame)) menu-symbol)
(menu-bar-get-minimal-x menu-symbol xx y)
x))))
(defun menu-bar-open-x-y (mouse-event)
(interactive "e")
(pcase mouse-event
(`(mouse-1 (,_ menu-bar (,x . ,y) . ,_))
(let ((menu (menu-bar-menu-at-x-y x y)))
(popup-menu (or
(lookup-key-ignore-too-long
global-map (vector 'menu-bar menu))
(lookup-key-ignore-too-long
(current-local-map) (vector 'menu-bar menu))
(cdar (minor-mode-key-binding (vector 'menu-bar menu)))
(mouse-menu-bar-map))
;; this line differs from the initial answer
(posn-at-x-y (menu-bar-get-minimal-x menu x y) y nil t)
nil t)))
(_ (error "unexpected event %S" mouse-event))))
(define-key global-map (kbd "<menu-bar> <mouse-1>") 'menu-bar-open-x-y)