3

I have emacs setup to start as daemon on login (emacs --daemon). When editing files I either launch the graphical client (emacsclient) or when I'm working in the terminal, I use the terminal client (emacsclient -t).

I want to have the menu bar enabled in the graphical client, but I don't want to have it in the terminal client, because I don't like its behavior in the terminal.

The menu bar can be enable/disabled via menu-bar-mode, but it behaves as the help says:

This command applies to all frames that exist and frames to be created in the future.

This means, when I have a graphical client running and I start a terminal client, the terminal client shows the menu bar and when I disable it, it is also disabled in the graphical client.

How can I hide the menu bar from a frame specifically? Is there a frame-local setting for the menu bar?

1 Answers1

7

You can set the frame parameter for menu-bar-lines to 1 if on a graphical display, and 0 if in a terminal, as checked by (display-graphic-p):

(defun contextual-menubar (&optional frame)
  "Display the menubar in FRAME (default: selected frame) if on a
graphical display, but hide it if in terminal."
  (interactive)
  (set-frame-parameter frame 'menu-bar-lines (if (display-graphic-p frame) 1 0)))

You can (add-hook 'after-make-frame-functions 'contextual-menubar) to make it automatic. According to this thread, after-make-frame-functions is not run for the initial frame, so you may need to add it to after-init-hook as well.

Community
  • 1
  • 1
Dan
  • 5,209
  • 1
  • 25
  • 37
  • It works! Thank you. Do you think it's worth reporting or asking to make `mode-menu-bar` frame-local or doesn't the mode (like menu-bar-mode is) concept allow for this? It looks more like a workaround by simply removing the area for the menu bar to draw in. – Wilhelm Schuster Jul 25 '14 at 16:13
  • Up to you. Actually, if you dig into the source code for `menu-bar-mode`, it turns out that it's basically doing the same `(set-frame-parameter ...)`, just on all frames, to add/remove the area for the menu bar. The code itself is pretty short, so it would probably not be hard to add the functionality you're thinking about. – Dan Jul 25 '14 at 16:24