当前位置:  开发笔记 > 编程语言 > 正文

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

如何解决《如何确定elisp中的操作系统?》经验,为你挑选了4个好方法。

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

我想.emacs根据操作系统运行不同的代码.



1> scottfrazer..:

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.



2> 小智..:

对于较新的elisp人员,示例用法:

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


@metakermit你可以像这样使用`cond`:`(case system-type((gnu/linux)"notify-send")((darwin)"growlnotify -a Emacs.app -m"))`

3> Gerstmann..:

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

(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!"))



4> Eric..:

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

推荐阅读
小白也坚强_177
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有