ELispで実行されているOS Emacsをプログラムで判別するにはどうすればよいですか?
.emacsOSによって異なるコードを実行したいのですが。
回答:
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
)
progn必要な改行で区切られているifとelseの部分)で何度か火傷を負ったので、癖に慣れていないすべての人への推奨事項- この回答を確認してください。
prognelseケースがない場合、@ kermit666は実際には必要ありません。つまり、のwhen代わりに使用できるということですif。これは、(if ... (progn ...) '())
condので、のように:(case system-type ((gnu/linux) "notify-send") ((darwin) "growlnotify -a Emacs.app -m"))
caseではありませんcond。case以来、作品system-typeのようなシンボルである'gnu/linuxかdarwin、ない文字列
現在、Windows用のLinuxサブシステム(Windows 10の場合system-typeはbash)があり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")
)
これはほとんどすでに回答されていますが、興味のある人のために、私はFreeBSDでこれをテストしたところ、報告された値は「berkeley-unix」でした。
system-configurationビルドシステムの違いを調整したい場合は(少なくともバージョン24-26で)もあります。ただし、この変数のドキュメントには、system-type変数のドキュメントのように、変数に含まれる可能性のある値については説明されていません 。