用于PC/Mac的.emacs中的不同设置

pro*_*eek 2 emacs

我需要在.emacs中进行不同的设置,具体取决于我的系统(Mac或PC).

这篇文章讲述了如何知道我的emacs正在运行的系统.

  • 如何检查变量'system-type'是否设置emacs中的内容?
  • 我应该在.emacs中使用哪些代码来为PC和Mac设置不同的代码?
???
(when (eq system-type 'windows-nt') 
)

Sta*_*key 8

你可以这样做:

(if (equal system-type 'windows-nt)
    (progn
         (... various windows-nt stuff ...)))
(if (equal system-type 'darwin)
    (progn
         (... various mac stuff ...)))
Run Code Online (Sandbox Code Playgroud)

我在.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))
Run Code Online (Sandbox Code Playgroud)

然后,您可以根据系统类型和/或计算机名称设置this-config.

然后我使用这段代码:

(cond ((or (equal this-machine "machineX")
           (equal this-machine "machineY"))
       (do some setup for machineX and machineY))
Run Code Online (Sandbox Code Playgroud)

编辑:system-type返回符号,而不是字符串