You are not logged in.

#1 2011-07-27 08:29:11

penguin
Member
From: Gotham City
Registered: 2010-12-31
Posts: 168

[SOLVED] Simple Lisp/Emacs if-statem. Want to turn off menu bar in CLI

I'm having some trouble configuring Emacs the way I want it. I want to remove the menu bar if I'm in the terminal or tty, and I've written the if-statement below. It prints the right messages when using gtk/tty, i.e. "Running in X" and  "Running in Terminal", respectively, to the message buffer, but then it will not turn off the menu bar when in a terminal, like I want it to.

;;Skip the non-functional menu when running in terminal/CLI:
(if (eq window-system 'x)
    (progn
      (message "Running in X")
      (menu-bar-mode t))
  (progn
    (message "Running in Terminal")
    (set menu-bar-mode -1)))

I've also tried (in different combinations)

set menu-bar-mode -1
menu-bar-mode nil

to little avail, but I'm no Lisp-programmer.

Also, through Emacs one can do C-h v, and look up menu-bar-mode:

menu-bar-mode is an interactive compiled Lisp function.

(menu-bar-mode &optional ARG)

Toggle display of a menu bar on each frame.
This command applies to all frames that exist and frames to be
created in the future.
With a numeric argument, if the argument is positive,
turn on menu bars; otherwise, turn off menu bars.

EDIT: Setting it as solved.

Last edited by penguin (2011-07-27 14:32:35)

Offline

#2 2011-07-27 11:51:59

lunar
Member
Registered: 2010-10-04
Posts: 95

Re: [SOLVED] Simple Lisp/Emacs if-statem. Want to turn off menu bar in CLI

Did you try "(menu-bar-mode 0)"?

In the code above, the second "progn" is superfluous, because "if" supports more than one "else" form on its own.  Moreover you can do without "progn" completely by using "cond":

(cond 
    ((eq window-system 'x) 
        (message "Running in X")
        (menu-bar-mode 1))
    (t 
        (message "Running in terminal")
        (menu-bar-mode 0)))

Offline

#3 2011-07-27 14:31:13

penguin
Member
From: Gotham City
Registered: 2010-12-31
Posts: 168

Re: [SOLVED] Simple Lisp/Emacs if-statem. Want to turn off menu bar in CLI

Thanks!
Your code works, just like I wanted it to, but it looks a bit cryptic to me, as I generally prefer to have it more like C-style if-statements.

(However the code I posted still won't work with -1 replaced by 0.)

Setting this as solved, thanks again.

Offline

#4 2011-07-27 15:23:08

lunar
Member
Registered: 2010-10-04
Posts: 95

Re: [SOLVED] Simple Lisp/Emacs if-statem. Want to turn off menu bar in CLI

@penguin:  You can think of "cond" as kind of more powerful C-style "switch"-statement.  smile  I'd advise you to become accustomed to "cond", as it is a very powerful and flexible conditional function, and thus very frequently used in elisp.  You'll often see it in other people's code.  And after all, elisp isn't C smile

Your code doesn't work because "(setq menu-bar-mode 0)" is not the same as "(menu-bar-mode 0)".  The former sets the variable "menu-bar-mode", while the latter invokes the function "menu-bar-mode".  The documentation of the variable "menu-bar-mode" (obtained by "C-h v menu-bar-mode") says:

Non-nil if Menu-Bar mode is enabled.
See the command `menu-bar-mode' for a description of this minor mode.
Setting this variable directly does not take effect;
either customize it (see the info node `Easy Customization')
or call the function `menu-bar-mode'.

Offline

#5 2011-07-28 08:50:37

penguin
Member
From: Gotham City
Registered: 2010-12-31
Posts: 168

Re: [SOLVED] Simple Lisp/Emacs if-statem. Want to turn off menu bar in CLI

Thanks!

Offline

Board footer

Powered by FluxBB