Elisp: Determine OS, Emacs Version, Machine Host Name

By Xah Lee. Date: . Last updated: .

The following are useful for setting up emacs init file on different machines.

Get Operating System Type

Here's how to find out what operating system emacs is running on.

;; check OS type
 ((string-equal system-type "windows-nt") ; Microsoft Windows
    (message "Microsoft Windows")))
 ((string-equal system-type "darwin") ; Mac OS X
    (message "Mac OS X")))
 ((string-equal system-type "gnu/linux") ; linux
    (message "Linux"))))

Get Emacs Version

The following variables returns emacs version number.

;; full emacs version number. A string.
;; sample value: "24.5.1"

;; A integer, emacs major version number.
;; sample value: 24

;; A integer, emacs minor version number.
;; sample value: 5

Compare Version String

;; check emacs version
(if (version< emacs-version "24.4")
    (message "is before 24.4")
  (message "is 24.4 or after"))

Get Host Name, User Name, Init File Path

Here's some other useful elisp function or variable to determine machine name (host name), user name, emacs init path.

For detail, see:

Check If a Package is Loaded

See: Elisp: Check If a {function, variable, feature} is Defined/Loaded.

Emacs Customization

  1. How to Set Emacs's User Interface
  2. Emacs: How to Install Packages Using ELPA, MELPA
  3. How to Install Emacs Package Manually
  4. Emacs: How to Define Keys
  5. Emacs: M-x customize Tutorial
  6. Emacs: Set File to Open in a Major Mode
  7. Emacs: Organize Init File
  8. Emacs: Byte Compile Elisp Files
  9. Emacs: What's Hook?
  10. Emacs: Set Environment Variables within Emacs
  11. Elisp: Determine OS, Emacs Version, Machine Host Name
  12. Elisp: Check If a {function, variable, feature} is Defined/Loaded
  13. Emacs: Set Default Window (frame) Size
  14. Emacs: Font Configuration
  15. Emacs: Set Color Theme
  16. Emacs: Save Cursor Position
  17. Emacs: Turn Off Auto Backup; Set Backups into a Directory; How to Delete Backup Files
  18. Emacs: Stop Cursor Going into Minibuffer Prompt
Liket it? Put $5 at patreon. Or Buy Xah Emacs Tutorial. Thanks.