根據我的系統(Mac或PC),我需要在.emacs中進行不同的設置。在.emacs中爲PC/Mac設置不同的設置
這post教導如何知道我的emacs正在運行的系統。
- 如何檢查變量'system-type'是要設置emacs中的內容?
- 我應該在.emacs中爲PC和Mac設置不同的代碼?
??? (when (eq system-type 'windows-nt') )
根據我的系統(Mac或PC),我需要在.emacs中進行不同的設置。在.emacs中爲PC/Mac設置不同的設置
這post教導如何知道我的emacs正在運行的系統。
??? (when (eq system-type 'windows-nt') )
你可以這樣做:
(if (equal system-type 'windows-nt)
(progn
(... various windows-nt stuff ...)))
(if (equal system-type 'darwin)
(progn
(... various mac stuff ...)))
我做什麼,我的.emacs設置一個變量(我稱之爲這個-配置)基於機器類型和名稱。然後我到處使用相同的.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說達爾文,這對於OSX是建立在開放操作系統的名稱。要查看這些值,請在系統類型上進行describe-variable。
請注意,mac也有幾種可能的窗口類型,因此您可能需要做出更多決定。
這樣做:
(if (eq window-system 'w32)
(progn
... your functions here for Microsoft Windows ...
))
window-system
是一個函數,並返回窗口系統的名稱。
system-type
是一個變量。不要C-Hvsystem-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.