In Gnu Emacs how to set up a global key to toggle the menu-bar

emacskeyboard shortcutsscripting

Using Gnu Emacs 23.1.1 on Ubuntu 10.04…

I've decided to go cold turkey with the Gnome menu bar. (but I do want it to be "available" for the teething transition period… tepid turkey? 🙂

So I'd like to know how to assign a key to toggle it on/off..

I'm currently starting Emacs in full screen mode, with no menu-bar and no tool-bar
I'm trying out a tabbar (when in X, but not when in terminal) ..

I'm almost getting used to it, but I find I feel completely lost sometimes without the menubar… I've read that Emacs without the GUI paraphenalia is the way to go.. and I believe it!… the paradigms clash..

But for now I'd like a menu-bar toggle, and it will be good experience to see how it is done..

Best Answer

If you just want to toggle the menu bar, there's already a command for that (M-x menu-bar-mode). To bind it to a key, you'd do:

(global-set-key (kbd "<f5>") 'menu-bar-mode)

If you want both the menu and toolbar to be toggled, you can do something like this:

(defun toggle-menu-toolbar-modes ()
  (interactive)
  (tool-bar-mode (menu-bar-mode)))
(global-set-key (kbd "<f5>") 'toggle-menu-toolbar-modes)

It's probably worth looking at the Emacs FAQ (also found by C-h C-f). Also, the SO info page for Emacs has a bunch of good links.

Related Question