मैं कैसे निर्धारित करूँ कि कौन से OS Emacs ELisp में चल रहे हैं?
मैं .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
)
prognरेखा द्वारा अलग किया जाता है, ब्लॉकों के लिए आवश्यक है), तो सभी को क्वर्की से परिचित नहीं होने की सिफारिश - इस उत्तर की जांच करें ।
prognमें जरूरत नहीं है अगर आप एक और मामला नहीं है। मेरे कहने का मतलब यह है कि आप 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, स्ट्रिंग नहीं
मैंने सिस्टम-प्रकार के आधार पर आसानी से कोड चलाने के लिए एक साधारण मैक्रो बनाया:
(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!"))
अब विंडोज के लिए लिनक्स सबसिस्टम भी है (विंडोज 10 के तहत बैश) जहां system-typeहै 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 पर यह परीक्षण किया और रिपोर्ट की गई कीमत "बर्कले-यूनिक्स" थी।
system-configurationनिर्माण प्रणाली में अंतर के लिए समायोजित करना चाहते हैं, तो कम से कम (संस्करणों में 24-26) भी है। हालांकि, इस वेरिएबल के डॉक्यूमेंटेशन में उन संभावित वैल्स का वर्णन नहीं किया गया है जिनमें यह हो सकता है जैसे system-typeवेरिएबल का डॉक्यूमेंटेशन हो ।