ProgramingTip

elisp에서 운영을 확인하는 방법은 무엇입니까?

bestdevel 2020. 10. 4. 12:03
반응형

elisp에서 운영을 확인하는 방법은 무엇입니까?


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
)

시스템 유형에 따라 코드를 쉽게 만들 수 있습니다.

(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 설정 선택하려는 경우 유용합니다.


이제 Windows 용 Linux 하위 시스템 (Windows 10의 bash) system-typegnu/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"라는 값은 "berkeley-unix"입니다.


system-configuration빌드 시스템의 차이를 조정하려는 경우 ( 적어도 24/25에) 있습니다.

참고 URL : https://stackoverflow.com/questions/1817257/how-to-determine-operating-system-in-elisp

반응형