如何以编程方式确定ELisp中运行的Emacs操作系统?
我想.emacs
根据操作系统运行不同的代码.
该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.
对于较新的elisp人员,示例用法:
(if (eq system-type 'darwin) ; something for OS X if true ; optional something if not )
我创建了一个简单的宏来轻松运行代码,具体取决于系统类型:
(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-system
变量,还有变量.当您想要在某些x选项,终端或macos设置之间进行选择时,这非常有用.