如何确定elisp中的操作系统?
如何以编程方式确定在ELisp下运行哪个操作系统Emacs?
我想根据操作系统在.emacs运行不同的代码。 
  system-typevariables: 
 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. 
对于更新到elisp的人来说,一个示例用法:
 (if (eq system-type 'darwin) ; something for OS X if true ; optional something if not ) 
我创build了一个简单的macros,可以根据系统types轻松地运行代码:
 (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!")) 
 在.emacs中,不仅有system-type ,而且还有window-systemvariables。 当你想在某个x选项或terminal或macos设置中进行select时,这非常有用。 
这主要是已经回答了,但是对于那些有兴趣的人,我只是在FreeBSD上testing了这个,报告的值是“berkeley-unix”。
 还有(至less24/25) system-configuration ,如果你想调整构build系统的差异。 
 现在还有Windows的Linux子系统(bash在Windows 10下) system-type为gnu/linux 。 要检测这个系统types使用: 
 (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") )