tags:

views:

322

answers:

3

Sorry if this has already been asked; however I don't seem to be able to find an answer anywhere grr.

How do I programmatically determine which os emacs is running under in elisp? I would like to run different code in .emacs depending on the os.

+9  A: 

The system-type variable:

system-type is a variable defined in `C source code'.
Its value is darwin

Documentation:
Value is symbol indicating type of operating system you are using.
Special values:
  `gnu'         compiled for a GNU Hurd system.
  `gnu/linux'   compiled for a GNU/Linux system.
  `darwin'      compiled for Darwin (GNU-Darwin, Mac OS X, ...).
  `ms-dos'      compiled as an MS-DOS application.
  `windows-nt'  compiled as a native W32 application.
  `cygwin'      compiled using the Cygwin library.
Anything else indicates some sort of Unix system.
scottfrazer
thanks, that really helps!
kronoz
+1  A: 

In a .emacs, there is not only the system-type, but also the window-system variable. This is useful when you want to choose between some x only option, or a terminal, or macos setting.

Eric
+1  A: 

For folks newer to elisp, a sample usage:

(if (eq system-type 'darwin)
  ; something for OS X if true
  ; optional something if not
)
Endrju