aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Zaretskii2013-10-11 20:44:41 +0300
committerEli Zaretskii2013-10-11 20:44:41 +0300
commit029619c86b55876f2feaff55df1e8538f3c092d1 (patch)
treecbc91b3e8fa33dc02a39a7f8c2b15b8384e67e4b
parentabe020201356dca6792d48add69029658b1df0b0 (diff)
downloademacs-029619c86b55876f2feaff55df1e8538f3c092d1.tar.gz
emacs-029619c86b55876f2feaff55df1e8538f3c092d1.zip
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.
-rw-r--r--lisp/ChangeLog4
-rw-r--r--lisp/menu-bar.el92
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 @@
12013-10-11 Eli Zaretskii <eliz@gnu.org>
2
3 * menu-bar.el (tty-menu-navigation-map): Remap F10 to tty-menu-exit.
4
12013-10-11 Stefan Monnier <monnier@iro.umontreal.ca> 52013-10-11 Stefan Monnier <monnier@iro.umontreal.ca>
2 6
3 * progmodes/sh-script.el: Provide simpl(e|istic) completion. 7 * 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."
2261 (popup-menu-normalize-position (event-end position))) 2261 (popup-menu-normalize-position (event-end position)))
2262 (t position))) 2262 (t position)))
2263 2263
2264(defcustom tty-menu-open-use-tmm nil
2265 "If non-nil, \\[menu-bar-open] on a TTY will invoke `tmm-menubar'.
2266
2267If nil, \\[menu-bar-open] will drop down the menu corresponding to the
2268first (leftmost) menu-bar item; you can select other items by typing
2269\\[forward-char], \\[backward-char], \\[right-char] and \\[left-char]."
2270 :type '(choice (const :tag "F10 drops down TTY menus" nil)
2271 (const :tag "F10 invokes tmm-menubar" t))
2272 :group 'display
2273 :version "24.4")
2274
2275(defvar tty-menu--initial-menu-x 1
2276 "X coordinate of the first menu-bar menu dropped by F10.
2277
2278This is meant to be used only for debugging TTY menus.")
2279
2280(defun menu-bar-open (&optional frame)
2281 "Start key navigation of the menu bar in FRAME.
2282
2283This function decides which method to use to access the menu
2284depending on FRAME's terminal device. On X displays, it calls
2285`x-menu-bar-open'; on Windows, `w32-menu-bar-open'; otherwise it
2286calls either `popup-menu' or `tmm-menubar' depending on whether
2287\`tty-menu-open-use-tmm' is nil or not.
2288
2289If FRAME is nil or not given, use the selected frame."
2290 (interactive)
2291 (let ((type (framep (or frame (selected-frame)))))
2292 (cond
2293 ((eq type 'x) (x-menu-bar-open frame))
2294 ((eq type 'w32) (w32-menu-bar-open frame))
2295 ((and (null tty-menu-open-use-tmm)
2296 (not (zerop (or (frame-parameter nil 'menu-bar-lines) 0))))
2297 (let* ((x tty-menu--initial-menu-x)
2298 (menu (menu-bar-menu-at-x-y x 0 frame)))
2299 (popup-menu (or
2300 (lookup-key global-map (vector 'menu-bar menu))
2301 (lookup-key (current-local-map) (vector 'menu-bar menu)))
2302 (posn-at-x-y x 0 nil t) nil t)))
2303 (t (with-selected-frame (or frame (selected-frame))
2304 (tmm-menubar))))))
2305
2306(global-set-key [f10] 'menu-bar-open)
2307
2264(defvar tty-menu-navigation-map 2308(defvar tty-menu-navigation-map
2265 (let ((map (make-sparse-keymap))) 2309 (let ((map (make-sparse-keymap)))
2266 ;; The next line is disabled because it breaks interpretation of 2310 ;; The next line is disabled because it breaks interpretation of
@@ -2282,7 +2326,8 @@ If nil, the current mouse position is used."
2282 (next-line . tty-menu-next-item) 2326 (next-line . tty-menu-next-item)
2283 (previous-line . tty-menu-prev-item) 2327 (previous-line . tty-menu-prev-item)
2284 (newline . tty-menu-select) 2328 (newline . tty-menu-select)
2285 (newline-and-indent . tty-menu-select))) 2329 (newline-and-indent . tty-menu-select)
2330 (menu-bar-open . tty-menu-exit)))
2286 (substitute-key-definition (car bind) (cdr bind) 2331 (substitute-key-definition (car bind) (cdr bind)
2287 map (current-global-map))) 2332 map (current-global-map)))
2288 2333
@@ -2327,51 +2372,6 @@ If nil, the current mouse position is used."
2327 map) 2372 map)
2328 "Keymap used while processing TTY menus.") 2373 "Keymap used while processing TTY menus.")
2329 2374
2330
2331(defcustom tty-menu-open-use-tmm nil
2332 "If non-nil, \\[menu-bar-open] on a TTY will invoke `tmm-menubar'.
2333
2334If nil, \\[menu-bar-open] will drop down the menu corresponding to the
2335first (leftmost) menu-bar item; you can select other items by typing
2336\\[forward-char], \\[backward-char], \\[right-char] and \\[left-char]."
2337 :type '(choice (const :tag "F10 drops down TTY menus" nil)
2338 (const :tag "F10 invokes tmm-menubar" t))
2339 :group 'display
2340 :version "24.4")
2341
2342(defvar tty-menu--initial-menu-x 1
2343 "X coordinate of the first menu-bar menu dropped by F10.
2344
2345This is meant to be used only for debugging TTY menus.")
2346
2347(defun menu-bar-open (&optional frame)
2348 "Start key navigation of the menu bar in FRAME.
2349
2350This function decides which method to use to access the menu
2351depending on FRAME's terminal device. On X displays, it calls
2352`x-menu-bar-open'; on Windows, `w32-menu-bar-open'; otherwise it
2353calls either `popup-menu' or `tmm-menubar' depending on whether
2354\`tty-menu-open-use-tmm' is nil or not.
2355
2356If FRAME is nil or not given, use the selected frame."
2357 (interactive)
2358 (let ((type (framep (or frame (selected-frame)))))
2359 (cond
2360 ((eq type 'x) (x-menu-bar-open frame))
2361 ((eq type 'w32) (w32-menu-bar-open frame))
2362 ((and (null tty-menu-open-use-tmm)
2363 (not (zerop (or (frame-parameter nil 'menu-bar-lines) 0))))
2364 (let* ((x tty-menu--initial-menu-x)
2365 (menu (menu-bar-menu-at-x-y x 0 frame)))
2366 (popup-menu (or
2367 (lookup-key global-map (vector 'menu-bar menu))
2368 (lookup-key (current-local-map) (vector 'menu-bar menu)))
2369 (posn-at-x-y x 0 nil t) nil t)))
2370 (t (with-selected-frame (or frame (selected-frame))
2371 (tmm-menubar))))))
2372
2373(global-set-key [f10] 'menu-bar-open)
2374
2375(provide 'menu-bar) 2375(provide 'menu-bar)
2376 2376
2377;;; menu-bar.el ends here 2377;;; menu-bar.el ends here