【发布时间】:2010-09-15 15:01:42
【问题描述】:
我需要根据我的系统(Mac 或 PC)在 .emacs 中进行不同的设置。
这个post 教如何知道我的emacs 正在运行的系统。
- 如何检查变量 'system-type' 是在 emacs 中设置什么?
- 我应该在 .emacs 中有什么代码来为 PC 和 Mac 进行不同的设置?
【问题讨论】:
标签: emacs
我需要根据我的系统(Mac 或 PC)在 .emacs 中进行不同的设置。
这个post 教如何知道我的emacs 正在运行的系统。
【问题讨论】:
标签: emacs
你可以这样做:
(if (equal system-type 'windows-nt)
(progn
(... various windows-nt stuff ...)))
(if (equal system-type 'darwin)
(progn
(... various mac stuff ...)))
我在 .emacs 中所做的是根据机器类型和名称设置一个变量(我称之为 this-config)。然后我到处使用相同的 .emacs。
使用此代码,我可以提取机器名称:
(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))
然后您可以根据系统类型和/或机器名称设置此配置。
然后我使用这个代码:
(cond ((or (equal this-machine "machineX")
(equal this-machine "machineY"))
(do some setup for machineX and machineY))
编辑:system-type 返回一个符号,而不是字符串
【讨论】:
我的 emacs 说 darwin,这是构建 OSX 的开放式操作系统的名称。要查看这些值,请在系统类型上执行描述变量。
请注意,mac 也有几种可能的窗口类型,因此您可能需要做出更多决定。
【讨论】:
这样做:
(if (eq window-system 'w32)
(progn
... your functions here for Microsoft Windows ...
))
window-system是一个函数,返回窗口系统的名称。
system-type 是一个变量。执行 C-h v system-type RET 以获得您的案例支持的系统类型列表:
来自帮助:
`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.
【讨论】: