From 029619c86b55876f2feaff55df1e8538f3c092d1 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Fri, 11 Oct 2013 20:44:41 +0300 Subject: [PATCH] Make the same key that opens TTY menus also exit the menu. lisp/menu-bar.el (tty-menu-navigation-map): Remap F10 to tty-menu-exit. --- lisp/ChangeLog | 4 +++ lisp/menu-bar.el | 92 ++++++++++++++++++++++++------------------------ 2 files changed, 50 insertions(+), 46 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index c3d57e88785..de3dfbc7cf7 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,7 @@ +2013-10-11 Eli Zaretskii + + * menu-bar.el (tty-menu-navigation-map): Remap F10 to tty-menu-exit. + 2013-10-11 Stefan Monnier * progmodes/sh-script.el: Provide simpl(e|istic) completion. diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index 25e019f6c3c..6c152c49208 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el @@ -2261,6 +2261,50 @@ If nil, the current mouse position is used." (popup-menu-normalize-position (event-end position))) (t position))) +(defcustom tty-menu-open-use-tmm nil + "If non-nil, \\[menu-bar-open] on a TTY will invoke `tmm-menubar'. + +If nil, \\[menu-bar-open] will drop down the menu corresponding to the +first (leftmost) menu-bar item; you can select other items by typing +\\[forward-char], \\[backward-char], \\[right-char] and \\[left-char]." + :type '(choice (const :tag "F10 drops down TTY menus" nil) + (const :tag "F10 invokes tmm-menubar" t)) + :group 'display + :version "24.4") + +(defvar tty-menu--initial-menu-x 1 + "X coordinate of the first menu-bar menu dropped by F10. + +This is meant to be used only for debugging TTY menus.") + +(defun menu-bar-open (&optional frame) + "Start key navigation of the menu bar in FRAME. + +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'; 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) + (let ((type (framep (or frame (selected-frame))))) + (cond + ((eq type 'x) (x-menu-bar-open frame)) + ((eq type 'w32) (w32-menu-bar-open frame)) + ((and (null tty-menu-open-use-tmm) + (not (zerop (or (frame-parameter nil 'menu-bar-lines) 0)))) + (let* ((x tty-menu--initial-menu-x) + (menu (menu-bar-menu-at-x-y x 0 frame))) + (popup-menu (or + (lookup-key global-map (vector 'menu-bar menu)) + (lookup-key (current-local-map) (vector 'menu-bar menu))) + (posn-at-x-y x 0 nil t) nil t))) + (t (with-selected-frame (or frame (selected-frame)) + (tmm-menubar)))))) + +(global-set-key [f10] 'menu-bar-open) + (defvar tty-menu-navigation-map (let ((map (make-sparse-keymap))) ;; The next line is disabled because it breaks interpretation of @@ -2282,7 +2326,8 @@ If nil, the current mouse position is used." (next-line . tty-menu-next-item) (previous-line . tty-menu-prev-item) (newline . tty-menu-select) - (newline-and-indent . tty-menu-select))) + (newline-and-indent . tty-menu-select) + (menu-bar-open . tty-menu-exit))) (substitute-key-definition (car bind) (cdr bind) map (current-global-map))) @@ -2327,51 +2372,6 @@ If nil, the current mouse position is used." map) "Keymap used while processing TTY menus.") - -(defcustom tty-menu-open-use-tmm nil - "If non-nil, \\[menu-bar-open] on a TTY will invoke `tmm-menubar'. - -If nil, \\[menu-bar-open] will drop down the menu corresponding to the -first (leftmost) menu-bar item; you can select other items by typing -\\[forward-char], \\[backward-char], \\[right-char] and \\[left-char]." - :type '(choice (const :tag "F10 drops down TTY menus" nil) - (const :tag "F10 invokes tmm-menubar" t)) - :group 'display - :version "24.4") - -(defvar tty-menu--initial-menu-x 1 - "X coordinate of the first menu-bar menu dropped by F10. - -This is meant to be used only for debugging TTY menus.") - -(defun menu-bar-open (&optional frame) - "Start key navigation of the menu bar in FRAME. - -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'; 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) - (let ((type (framep (or frame (selected-frame))))) - (cond - ((eq type 'x) (x-menu-bar-open frame)) - ((eq type 'w32) (w32-menu-bar-open frame)) - ((and (null tty-menu-open-use-tmm) - (not (zerop (or (frame-parameter nil 'menu-bar-lines) 0)))) - (let* ((x tty-menu--initial-menu-x) - (menu (menu-bar-menu-at-x-y x 0 frame))) - (popup-menu (or - (lookup-key global-map (vector 'menu-bar menu)) - (lookup-key (current-local-map) (vector 'menu-bar menu))) - (posn-at-x-y x 0 nil t) nil t))) - (t (with-selected-frame (or frame (selected-frame)) - (tmm-menubar)))))) - -(global-set-key [f10] 'menu-bar-open) - (provide 'menu-bar) ;;; menu-bar.el ends here -- 2.39.2