16

I have this line in my .emacs file:

(tool-bar-mode 0)

because I hate the toolbars in my GUI emacs (/Applications/Emacs.app/Contents/MacOS/Emacs).

But when I start up my other, text-based emacs in the terminal (/opt/local/bin/emacs) it complains about that command:

Symbol's function definition is void: tool-bar-mode

How can I add an if condition so that it executes the tool-bar-mode command only when I'm in the GUI emacs?

Thanks!

user9474
  • 2,368
  • 2
  • 24
  • 26

4 Answers4

23

Okay, found it myself. Just add

;; turn off toolbar
(if window-system
    (tool-bar-mode 0))
user9474
  • 2,368
  • 2
  • 24
  • 26
3

another way to do it would be:

 (if (functionp 'tool-bar-mode) (tool-bar-mode 0))

like this, the function is called only if it exists

Rémi
  • 130
  • 4
0

It works for me without complaint on Linux. You might try nil or -1 instead of 0:

(tool-bar-mode nil)

What happens if you do emacs -nw?

Dennis Williamson
  • 60,515
  • 14
  • 113
  • 148
0

Use of the window-system variable as a boolean is deprecated. Instead, use display-graphic-p or any of the other display-*-p predicates which report frame’s specific UI-related capabilities.

In case you want your code to be backward-compatible with the previous versions of Emacs, then the following compatibility wrapper is the way to go:

(if (< emacs-major-version 23)
    (or window-system (getenv "DISPLAY"))
  (display-graphic-p))