Different setup in .emacs for PC/Mac
I need to have different setup in .emacs depending 开发者_如何学运维on my system (Mac or PC).
This post teaches how to know the system that my emacs is running.
- How can I check the variable 'system-type' is to set what in emacs?
- What code should I have in .emacs to have different setup for PC and Mac?
??? (when (eq system-type 'windows-nt') )
You can do this:
(if (equal system-type 'windows-nt)
(progn
(... various windows-nt stuff ...)))
(if (equal system-type 'darwin)
(progn
(... various mac stuff ...)))
What I do in my .emacs is set a variable (I call it this-config) based on machine type and name. Then I use the same .emacs everywhere.
Using this code, I can pull the machine name out:
(defvar this-machine "default")
(if (getenv "HOST")
(setq this-machine (getenv "HOST")))
(if (string-match "default" this-machine)
(if (getenv "HOSTNAME")
(setq this-machine (getenv "HOSTNAME"))))
(if (string-match "default" this-machine)
(setq this-machine system-name))
You can then set this-config based on system-type and/or machine name.
Then I use this code:
(cond ((or (equal this-machine "machineX")
(equal this-machine "machineY"))
(do some setup for machineX and machineY))
Edit: system-type
returns a symbol, not a string
My emacs says darwin, which is the name for the open OS that OSX is built on. To see the values do a describe-variable on system-type.
Note that the mac also has several possible window types so you might need to make more decisions.
Do this :
(if (eq window-system 'w32)
(progn
... your functions here for Microsoft Windows ...
))
window-system
is a function and returns the name of the window system.
system-type
is a variable. Do C-h v system-type
RET to have the list of supported system-types for your case :
From the help :
`gnu' compiled for a GNU Hurd system. `gnu/linux' compiled for a GNU/Linux system. `gnu/kfreebsd' compiled for a GNU system with a FreeBSD kernel. `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 (in Emacs 23.1, the possibilities are: aix, berkeley-unix, hpux, irix, lynxos 3.0.1, usg-unix-v) indicates some sort of Unix system.
精彩评论