[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: initialization elisp for platform ID
From: |
Tom Roche |
Subject: |
Re: initialization elisp for platform ID |
Date: |
Sun, 4 Nov 2001 12:55:31 -0500 (EST) |
I wrote:
> Why doesn't
> (defvar running-on-solaris (string-match "solaris" (getenv "OSTYPE")))
> work? It returns nil even when (much cruft deleted)
> /ncsu/tlroche> printenv
> HOST=uni01du.unity.ncsu.edu
> GROUP=ncsu
> MACHTYPE=sparc
> OSTYPE=solaris
> VENDOR=sun
> HOSTTYPE=sun4
> FWIW,
> (defvar running-on-solaris (eq (getenv "OSTYPE") 'solaris))
> also fails, but running-on-<linux | <<unity-> | windows> all work.
I now know why elisp code is so often studded with whatever-p's.
The code that works follows my .sig. However, I'd still like to know
> * Are there better ways to do what I'm doing?
I've got a lot to learn about elisp.
TIA, Tom_Roche@ncsu.edu--------platform-detection code follows--------
;; from Red Hat Linux default .emacs
;; Are we running XEmacs or Emacs?
(defconst running-xemacs (string-match "XEmacs\\|Lucid" emacs-version))
;; system testing. Note various tests in use within
;; http://home.swipnet.se/Karlssons/Leif/_EMACS
;; He tests 'window-system. There is also a 'window-system-version
;; string-match chokes on nil
(defvar OSTYPE (getenv "OSTYPE"))
(if (not OSTYPE) (setq OSTYPE ""))
(defvar OU (getenv "OU"))
(if (not OU) (setq OU ""))
;; Are we running on X Windows?
(defconst running-on-x (eq window-system 'x))
;; Are we running on MS Windows?
(defconst running-on-windows (eq window-system 'w32))
;; Are we running on Unity Windows?
; (defconst running-on-unity-windows (eq (getenv "OU") 'ZenLab))
; (defconst running-on-unity-windows (string-match "ZenLab" OU))
(defconst running-on-unity-windows
(if (integer-or-marker-p (string-match "ZenLab" OU)) t nil))
;; Are we running on a linux?
; (defconst running-on-linux (string-match "linux" (getenv "OSTYPE")))
; (defconst running-on-linux (string-match "linux" OSTYPE))
(defconst running-on-linux
(if (integer-or-marker-p (string-match "linux" OSTYPE)) t nil))
;; Are we running on Solaris?
; (defconst running-on-solaris (eq (getenv "OSTYPE") 'solaris))
; (defconst running-on-solaris (string-match "solaris" (getenv "OSTYPE")))
; (defconst running-on-solaris (string-match "solaris" OSTYPE))
(defconst running-on-solaris
(if (integer-or-marker-p (string-match "solaris" OSTYPE)) t nil))
;; linux uses HOSTNAME, solaris uses HOST
(defvar HOSTNAME (getenv "HOSTNAME"))
(if (not HOSTNAME)
(if running-on-solaris
(setq HOSTNAME (getenv "HOST"))
(setq HOSTNAME "")))
;; Are we running on Unity Solaris?
(defconst running-on-unity-solaris
(and 'running-on-solaris
; (string-match "unity.ncsu.edu" (getenv "HOSTNAME"))))
; (string-match "unity.ncsu.edu" HOSTNAME)))
(integer-or-marker-p (string-match "unity.ncsu.edu" HOSTNAME))))
;; Are we running in a terminal/in a shell?
(defconst running-on-shell (eq window-system nil))
;; Are we shelling into Americana?
(defconst running-on-americana
(and 'running-on-linux 'running-on-shell
; (string-match "backup.bas.ncsu.edu" HOSTNAME)))
(integer-or-marker-p (string-match "backup.bas.ncsu.edu" HOSTNAME))))