如何确定elisp中的操作系统?

时间:2009-11-30 00:14:29

标签: emacs elisp

如何以编程方式确定在ELisp中运行的Emacs操作系统?

我想在.emacs中运行不同的代码,具体取决于操作系统。

7 个答案:

答案 0 :(得分:90)

system-type变量:

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.

答案 1 :(得分:74)

对于elisp较新的人,请使用示例:

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

答案 2 :(得分:21)

我创建了一个简单的宏来轻松运行代码,具体取决于系统类型:

(defmacro with-system (type &rest body)
  "Evaluate BODY if `system-type' equals TYPE."
  (declare (indent defun))
  `(when (eq system-type ',type)
     ,@body))

(with-system gnu/linux
  (message "Free as in Beer")
  (message "Free as in Freedom!"))

答案 3 :(得分:10)

在.emacs中,不仅有system-type,还有window-system变量。 当您想要在某些x选项,终端或macos设置之间进行选择时,这非常有用。

答案 4 :(得分:3)

现在还有适用于Windows的Linux子系统(Windows 10下的bash)repoBsystem-type。要检测此系统类型,请使用:

gnu/linux

答案 5 :(得分:2)

这已经得到了回答,但是对于那些感兴趣的人,我只是在FreeBSD上测试了这个,并且报告的值是“berkeley-unix”。

答案 6 :(得分:0)

如果你想调整构建系统的差异,还有(至少24/25)system-configuration

相关问题