sco*_*zer 92
该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.
Run Code Online (Sandbox Code Playgroud)
小智 76
对于较新的elisp人员,示例用法:
(if (eq system-type 'darwin)
; something for OS X if true
; optional something if not
)
Run Code Online (Sandbox Code Playgroud)
Ger*_*ann 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!"))
Run Code Online (Sandbox Code Playgroud)
现在也有Linux的子系统的基于Windows(Windows 10下的bash),其中system-type为gnu/linux。要检测此系统类型,请使用:
(if
(string-match "Microsoft"
(with-temp-buffer (shell-command "uname -r" t)
(goto-char (point-max))
(delete-char -1)
(buffer-string)))
(message "Running under Linux subsystem for Windows")
(message "Not running under Linux subsystem for Windows")
)
Run Code Online (Sandbox Code Playgroud)