Function: menu-bar-open

menu-bar-open is an interactive and byte-compiled function defined in menu-bar.el.gz.

Signature

(menu-bar-open &optional FRAME INITIAL-X)

Documentation

Start key navigation of the menu bar in FRAME.

Optional argument INITIAL-X gives the X coordinate of the first TTY menu-bar menu to be dropped down. Interactively, this is the numeric argument to the command. This function decides which method to use to access the menu depending on FRAME's terminal device. On X displays, it calls x-menu-bar-open; on Windows, w32-menu-bar-open; on Haiku, haiku-menu-bar-open; otherwise it calls either popup-menu or tmm-menubar depending on whether tty-menu-open-use-tmm is nil or not.

If FRAME is nil or not given, use the selected frame.

View in manual

Probably introduced at or before Emacs version 24.4.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/menu-bar.el.gz
(defun menu-bar-open (&optional frame initial-x)
  "Start key navigation of the menu bar in FRAME.

Optional argument INITIAL-X gives the X coordinate of the
first TTY menu-bar menu to be dropped down.  Interactively,
this is the numeric argument to the command.
This function decides which method to use to access the menu
depending on FRAME's terminal device.  On X displays, it calls
`x-menu-bar-open'; on Windows, `w32-menu-bar-open'; on Haiku,
`haiku-menu-bar-open'; otherwise it calls either `popup-menu'
or `tmm-menubar' depending on whether `tty-menu-open-use-tmm'
is nil or not.

If FRAME is nil or not given, use the selected frame."
  (interactive
   (list nil (prefix-numeric-value current-prefix-arg)))
  (let* ((type (framep (or frame (selected-frame))))
	 root
	 (frame (if (and (eq type t) (frame-parent frame)
			 (null tty-menu-open-use-tmm)
			 (zerop (or (frame-parameter frame 'menu-bar-lines) 0))
			 (setq root (frame-root-frame))
			 (not (zerop
			       (or (frame-parameter root 'menu-bar-lines) 0))))
		    ;; If FRAME is a tty child frame without its own
		    ;; menu bar, 'tty-menu-open-use-tmm' is false and
		    ;; FRAME's root frame has a menu bar, use that root
		    ;; frame's menu bar.
		    root
		  frame)))
    (cond
     ((eq type 'x) (x-menu-bar-open frame))
     ((eq type 'w32) (w32-menu-bar-open frame))
     ((eq type 'haiku) (haiku-menu-bar-open frame))
     ((eq type 'pgtk) (pgtk-menu-bar-open frame))
     ((and (null tty-menu-open-use-tmm)
	   (not (zerop (or (frame-parameter frame 'menu-bar-lines) 0))))
      ;; Make sure the menu bar is up to date.  One situation where
      ;; this is important is when this function is invoked by name
      ;; via M-x, in which case the menu bar includes the "Minibuf"
      ;; menu item that should be removed when we exit the minibuffer.
      (force-mode-line-update)
      (redisplay)
      (let* ((x (max initial-x tty-menu--initial-menu-x))
	     (menu (menu-bar-menu-at-x-y x 0 frame)))
	(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 0 frame t) nil t)))
     (t (with-selected-frame (or frame (selected-frame))
          (tmm-menubar))))))